/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Aaron Bentley
  • Date: 2007-12-19 06:04:19 UTC
  • mfrom: (3127 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3128.
  • Revision ID: aaron.bentley@utoronto.ca-20071219060419-afwva4q14cjlzfta
Merge with bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1390
1390
 
1391
1391
 
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.
1394
1394
    
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
 
1400
    given.
1397
1401
 
1398
1402
    "bzr diff -p1" is equivalent to "bzr diff --prefix old/:new/", and
1399
1403
    produces patches suitable for "patch -p1".
1417
1421
 
1418
1422
            bzr diff -r1..2
1419
1423
 
 
1424
        Difference between revision 2 and revision 1 for branch xxx::
 
1425
 
 
1426
            bzr diff -r1..2 xxx
 
1427
 
 
1428
        Show just the differences for file NEWS::
 
1429
 
 
1430
            bzr diff NEWS
 
1431
 
 
1432
        Show the differences in working tree xxx for file NEWS::
 
1433
 
 
1434
            bzr diff xxx/NEWS
 
1435
 
 
1436
        Show the differences from branch xxx to this working tree:
 
1437
 
 
1438
            bzr diff --old xxx
 
1439
 
 
1440
        Show the differences between two branches for file NEWS::
 
1441
 
 
1442
            bzr diff --old xxx --new yyy NEWS
 
1443
 
1420
1444
        Same as 'bzr diff' but prefix paths with old/ and new/::
1421
1445
 
1422
1446
            bzr diff --prefix old/:new/
1423
 
 
1424
 
        Show the differences between the two working trees::
1425
 
 
1426
 
            bzr diff bzr.mine bzr.dev
1427
 
 
1428
 
        Show just the differences for 'foo.c'::
1429
 
 
1430
 
            bzr diff foo.c
1431
1447
    """
1432
1448
    # TODO: Option to use external diff command; could be GNU diff, wdiff,
1433
1449
    #       or a graphical diff.
1449
1465
               short_name='p',
1450
1466
               help='Set prefixes added to old and new filenames, as '
1451
1467
                    'two values separated by a colon. (eg "old/:new/").'),
 
1468
        Option('old',
 
1469
            help='Branch/tree to compare from.',
 
1470
            type=unicode,
 
1471
            ),
 
1472
        Option('new',
 
1473
            help='Branch/tree to compare to.',
 
1474
            type=unicode,
 
1475
            ),
1452
1476
        'revision',
1453
1477
        'change',
1454
1478
        ]
1457
1481
 
1458
1482
    @display_command
1459
1483
    def run(self, revision=None, file_list=None, diff_options=None,
1460
 
            prefix=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
1462
1486
 
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')
1480
1504
 
1481
 
        try:
1482
 
            tree1, file_list = internal_tree_files(file_list)
1483
 
            tree2 = None
1484
 
            b = None
1485
 
            b2 = None
1486
 
        except errors.FileInWrongBranch:
1487
 
            if len(file_list) != 2:
1488
 
                raise errors.BzrCommandError("Files are in different branches")
1489
 
 
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")
1495
 
            file_list = None
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
1503
 
            else:
1504
 
                raise
1505
 
 
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
1510
 
                # internally...
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)
1518
 
 
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)
1522
1512
 
1523
1513
 
1524
1514
class cmd_deleted(Command):
1666
1656
                        'regular expression.',
1667
1657
                   type=str),
1668
1658
            Option('limit',
 
1659
                   short_name='l',
1669
1660
                   help='Limit the output to the first N revisions.',
1670
1661
                   argname='N',
1671
1662
                   type=_parse_limit),
2009
2000
    """List ignored files and the patterns that matched them.
2010
2001
    """
2011
2002
 
 
2003
    encoding_type = 'replace'
2012
2004
    _see_also = ['ignore']
 
2005
 
2013
2006
    @display_command
2014
2007
    def run(self):
2015
2008
        tree = WorkingTree.open_containing(u'.')[0]
2020
2013
                    continue
2021
2014
                ## XXX: Slightly inefficient since this was already calculated
2022
2015
                pat = tree.is_ignored(path)
2023
 
                print '%-50s %s' % (path, pat)
 
2016
                self.outf.write('%-50s %s\n' % (path, pat))
2024
2017
        finally:
2025
2018
            tree.unlock()
2026
2019