1392
1392
class cmd_diff(Command):
1393
"""Show differences in the working tree or between revisions.
1393
"""Show differences in the working tree, between revisions or branches.
1395
If files are listed, only the changes in those files are listed.
1396
Otherwise, all changes for the tree are listed.
1395
If no arguments are given, all changes for the current tree are listed.
1396
If files are given, only the changes in those files are listed.
1397
Remote and multiple branches can be compared by using the --old and
1398
--new options. If not provided, the default for both is derived from
1399
the first argument, if any, or the current tree if no arguments are
1398
1402
"bzr diff -p1" is equivalent to "bzr diff --prefix old/:new/", and
1399
1403
produces patches suitable for "patch -p1".
1418
1422
bzr diff -r1..2
1424
Difference between revision 2 and revision 1 for branch xxx::
1428
Show just the differences for file NEWS::
1432
Show the differences in working tree xxx for file NEWS::
1436
Show the differences from branch xxx to this working tree:
1440
Show the differences between two branches for file NEWS::
1442
bzr diff --old xxx --new yyy NEWS
1420
1444
Same as 'bzr diff' but prefix paths with old/ and new/::
1422
1446
bzr diff --prefix old/:new/
1424
Show the differences between the two working trees::
1426
bzr diff bzr.mine bzr.dev
1428
Show just the differences for 'foo.c'::
1432
1448
# TODO: Option to use external diff command; could be GNU diff, wdiff,
1433
1449
# or a graphical diff.
1458
1482
@display_command
1459
1483
def run(self, revision=None, file_list=None, diff_options=None,
1461
from bzrlib.diff import diff_cmd_helper, show_diff_trees
1484
prefix=None, old=None, new=None):
1485
from bzrlib.diff import _get_trees_to_diff, show_diff_trees
1463
1487
if (prefix is None) or (prefix == '0'):
1464
1488
# diff -p0 format
1478
1502
raise errors.BzrCommandError('bzr diff --revision takes exactly'
1479
1503
' one or two revision specifiers')
1482
tree1, file_list = internal_tree_files(file_list)
1486
except errors.FileInWrongBranch:
1487
if len(file_list) != 2:
1488
raise errors.BzrCommandError("Files are in different branches")
1490
tree1, file1 = WorkingTree.open_containing(file_list[0])
1491
tree2, file2 = WorkingTree.open_containing(file_list[1])
1492
if file1 != "" or file2 != "":
1493
# FIXME diff those two files. rbc 20051123
1494
raise errors.BzrCommandError("Files are in different branches")
1496
except errors.NotBranchError:
1497
if (revision is not None and len(revision) == 2
1498
and not revision[0].needs_branch()
1499
and not revision[1].needs_branch()):
1500
# If both revision specs include a branch, we can
1501
# diff them without needing a local working tree
1502
tree1, tree2 = None, None
1506
if tree2 is not None:
1507
if revision is not None:
1508
# FIXME: but there should be a clean way to diff between
1509
# non-default versions of two trees, it's not hard to do
1511
raise errors.BzrCommandError(
1512
"Sorry, diffing arbitrary revisions across branches "
1513
"is not implemented yet")
1514
return show_diff_trees(tree1, tree2, sys.stdout,
1515
specific_files=file_list,
1516
external_diff_options=diff_options,
1517
old_label=old_label, new_label=new_label)
1519
return diff_cmd_helper(tree1, file_list, diff_options,
1520
revision_specs=revision,
1521
old_label=old_label, new_label=new_label)
1505
old_tree, new_tree, specific_files, extra_trees = \
1506
_get_trees_to_diff(file_list, revision, old, new)
1507
return show_diff_trees(old_tree, new_tree, sys.stdout,
1508
specific_files=specific_files,
1509
external_diff_options=diff_options,
1510
old_label=old_label, new_label=new_label,
1511
extra_trees=extra_trees)
1524
1514
class cmd_deleted(Command):