~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Martin Pool
  • Date: 2006-05-04 06:03:00 UTC
  • mto: This revision was merged to the branch mainline in revision 1699.
  • Revision ID: mbp@sourcefrog.net-20060504060300-eed0e79351fd6182
Add -p0, -p1 options for diff.

Change --diff-prefix to just --prefix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
976
976
    If files are listed, only the changes in those files are listed.
977
977
    Otherwise, all changes for the tree are listed.
978
978
 
 
979
    "bzr diff -p1" is equivalent to "bzr diff --prefix old/:new/", and
 
980
    produces patches suitable for "patch -p1".
 
981
 
979
982
    examples:
980
983
        bzr diff
981
984
        bzr diff -r1
982
985
        bzr diff -r1..2
 
986
        bzr diff --diff-prefix old/:new/
983
987
    """
984
 
    # TODO: Allow diff across branches.
985
988
    # TODO: Option to use external diff command; could be GNU diff, wdiff,
986
989
    #       or a graphical diff.
987
990
 
988
991
    # TODO: Python difflib is not exactly the same as unidiff; should
989
992
    #       either fix it up or prefer to use an external diff.
990
993
 
991
 
    # TODO: If a directory is given, diff everything under that.
992
 
 
993
994
    # TODO: Selected-file diff is inefficient and doesn't show you
994
995
    #       deleted files.
995
996
 
996
997
    # TODO: This probably handles non-Unix newlines poorly.
997
998
    
 
999
    # TODO: When a prefix is given, it's also shown in the summary lines, e.g.
 
1000
    # "modified file new/foo.c"; perhaps it would be better to omit it from
 
1001
    # there?
 
1002
    
998
1003
    takes_args = ['file*']
999
 
    takes_options = ['revision', 'diff-options', 'diff-prefix']
 
1004
    takes_options = ['revision', 'diff-options', 'prefix']
1000
1005
    aliases = ['di', 'dif']
1001
1006
 
1002
1007
    @display_command
1003
1008
    def run(self, revision=None, file_list=None, diff_options=None,
1004
 
       diff_prefix=None):
 
1009
            prefix=None):
1005
1010
        from bzrlib.diff import diff_cmd_helper, show_diff_trees
1006
1011
 
1007
 
        if diff_prefix:
1008
 
            if not ':' in diff_prefix:
1009
 
                 raise BzrError("--diff-prefix expects two values separated by a colon")
1010
 
            old_label, new_label = diff_prefix.split(":")
1011
 
        else:
 
1012
        if (prefix is None) or (prefix == '0'):
 
1013
            # diff -p0 format
1012
1014
            old_label = ''
1013
1015
            new_label = ''
 
1016
        elif prefix == '1':
 
1017
            old_label = 'old/'
 
1018
            new_label = 'new/'
 
1019
        else:
 
1020
            if not ':' in prefix:
 
1021
                 raise BzrError("--diff-prefix expects two values separated by a colon")
 
1022
            old_label, new_label = prefix.split(":")
1014
1023
        
1015
1024
        try:
1016
1025
            tree1, file_list = internal_tree_files(file_list)