1380
1380
class cmd_diff(Command):
1381
"""Show differences in the working tree or between revisions.
1381
"""Show differences in the working tree, between revisions or branches.
1383
If files are listed, only the changes in those files are listed.
1384
Otherwise, all changes for the tree are listed.
1383
If no arguments are given, all changes for the current tree are listed.
1384
If files are given, only the changes in those files are listed.
1385
Remote and multiple branches can be compared by using the --old and
1386
--new options. If not provided, the default for both is derived from
1387
the first argument, if any, or the current tree if no arguments are
1386
1390
"bzr diff -p1" is equivalent to "bzr diff --prefix old/:new/", and
1387
1391
produces patches suitable for "patch -p1".
1406
1410
bzr diff -r1..2
1412
Difference between revision 2 and revision 1 for branch xxx::
1416
Show just the differences for file NEWS::
1420
Show the differences in working tree xxx for file NEWS::
1424
Show the differences from branch xxx to this working tree:
1428
Show the differences between two branches for file NEWS::
1430
bzr diff --old=xxx --new=yyy NEWS
1408
1432
Same as 'bzr diff' but prefix paths with old/ and new/::
1410
1434
bzr diff --prefix old/:new/
1412
Show the differences between the two working trees::
1414
bzr diff bzr.mine bzr.dev
1416
Show just the differences for 'foo.c'::
1420
1436
# TODO: Option to use external diff command; could be GNU diff, wdiff,
1421
1437
# or a graphical diff.
1446
1470
@display_command
1447
1471
def run(self, revision=None, file_list=None, diff_options=None,
1449
from bzrlib.diff import diff_cmd_helper, show_diff_trees
1472
prefix=None, old=None, new=None):
1473
from bzrlib.diff import _get_trees_to_diff, show_diff_trees
1451
1475
if (prefix is None) or (prefix == '0'):
1452
1476
# diff -p0 format
1466
1490
raise errors.BzrCommandError('bzr diff --revision takes exactly'
1467
1491
' one or two revision specifiers')
1470
tree1, file_list = internal_tree_files(file_list)
1474
except errors.FileInWrongBranch:
1475
if len(file_list) != 2:
1476
raise errors.BzrCommandError("Files are in different branches")
1478
tree1, file1 = WorkingTree.open_containing(file_list[0])
1479
tree2, file2 = WorkingTree.open_containing(file_list[1])
1480
if file1 != "" or file2 != "":
1481
# FIXME diff those two files. rbc 20051123
1482
raise errors.BzrCommandError("Files are in different branches")
1484
except errors.NotBranchError:
1485
if (revision is not None and len(revision) == 2
1486
and not revision[0].needs_branch()
1487
and not revision[1].needs_branch()):
1488
# If both revision specs include a branch, we can
1489
# diff them without needing a local working tree
1490
tree1, tree2 = None, None
1494
if tree2 is not None:
1495
if revision is not None:
1496
# FIXME: but there should be a clean way to diff between
1497
# non-default versions of two trees, it's not hard to do
1499
raise errors.BzrCommandError(
1500
"Sorry, diffing arbitrary revisions across branches "
1501
"is not implemented yet")
1502
return show_diff_trees(tree1, tree2, sys.stdout,
1503
specific_files=file_list,
1504
external_diff_options=diff_options,
1505
old_label=old_label, new_label=new_label)
1507
return diff_cmd_helper(tree1, file_list, diff_options,
1508
revision_specs=revision,
1509
old_label=old_label, new_label=new_label)
1493
old_tree, new_tree, specific_files, extra_trees = \
1494
_get_trees_to_diff(file_list, revision, old, new)
1495
return show_diff_trees(old_tree, new_tree, sys.stdout,
1496
specific_files=specific_files,
1497
external_diff_options=diff_options,
1498
old_label=old_label, new_label=new_label,
1499
extra_trees=extra_trees)
1512
1502
class cmd_deleted(Command):