/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

merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
874
874
            raise errors.BzrCommandError(
875
875
                'bzr branch --revision takes exactly 1 revision value')
876
876
 
877
 
        br_from = Branch.open(from_location)
 
877
        accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
 
878
            from_location)
878
879
        br_from.lock_read()
879
880
        try:
880
881
            if len(revision) == 1 and revision[0] is not None:
902
903
            try:
903
904
                # preserve whatever source format we have.
904
905
                dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
905
 
                                            possible_transports=[to_transport])
 
906
                                            possible_transports=[to_transport],
 
907
                                            accelerator_tree=accelerator_tree)
906
908
                branch = dir.open_branch()
907
909
            except errors.NoSuchRevision:
908
910
                to_transport.delete_tree('.')
947
949
                                 "common operations like diff and status without "
948
950
                                 "such access, and also support local commits."
949
951
                            ),
 
952
                     Option('files-from',
 
953
                            help="Get file contents from this tree.", type=str)
950
954
                     ]
951
955
    aliases = ['co']
952
956
 
953
957
    def run(self, branch_location=None, to_location=None, revision=None,
954
 
            lightweight=False):
 
958
            lightweight=False, files_from=None):
955
959
        if revision is None:
956
960
            revision = [None]
957
961
        elif len(revision) > 1:
960
964
        if branch_location is None:
961
965
            branch_location = osutils.getcwd()
962
966
            to_location = branch_location
963
 
        source = Branch.open(branch_location)
 
967
        accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch(
 
968
            branch_location)
 
969
        if files_from is not None:
 
970
            accelerator_tree = WorkingTree.open(files_from)
964
971
        if len(revision) == 1 and revision[0] is not None:
965
972
            revision_id = _mod_revision.ensure_null(
966
973
                revision[0].in_history(source)[1])
978
985
            except errors.NoWorkingTree:
979
986
                source.bzrdir.create_workingtree(revision_id)
980
987
                return
981
 
        source.create_checkout(to_location, revision_id, lightweight)
 
988
        source.create_checkout(to_location, revision_id, lightweight,
 
989
                               accelerator_tree)
982
990
 
983
991
 
984
992
class cmd_renames(Command):
1390
1398
 
1391
1399
 
1392
1400
class cmd_diff(Command):
1393
 
    """Show differences in the working tree or between revisions.
 
1401
    """Show differences in the working tree, between revisions or branches.
1394
1402
    
1395
 
    If files are listed, only the changes in those files are listed.
1396
 
    Otherwise, all changes for the tree are listed.
 
1403
    If no arguments are given, all changes for the current tree are listed.
 
1404
    If files are given, only the changes in those files are listed.
 
1405
    Remote and multiple branches can be compared by using the --old and
 
1406
    --new options. If not provided, the default for both is derived from
 
1407
    the first argument, if any, or the current tree if no arguments are
 
1408
    given.
1397
1409
 
1398
1410
    "bzr diff -p1" is equivalent to "bzr diff --prefix old/:new/", and
1399
1411
    produces patches suitable for "patch -p1".
1417
1429
 
1418
1430
            bzr diff -r1..2
1419
1431
 
 
1432
        Difference between revision 2 and revision 1 for branch xxx::
 
1433
 
 
1434
            bzr diff -r1..2 xxx
 
1435
 
 
1436
        Show just the differences for file NEWS::
 
1437
 
 
1438
            bzr diff NEWS
 
1439
 
 
1440
        Show the differences in working tree xxx for file NEWS::
 
1441
 
 
1442
            bzr diff xxx/NEWS
 
1443
 
 
1444
        Show the differences from branch xxx to this working tree:
 
1445
 
 
1446
            bzr diff --old xxx
 
1447
 
 
1448
        Show the differences between two branches for file NEWS::
 
1449
 
 
1450
            bzr diff --old xxx --new yyy NEWS
 
1451
 
1420
1452
        Same as 'bzr diff' but prefix paths with old/ and new/::
1421
1453
 
1422
1454
            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
1455
    """
1432
 
    # TODO: Option to use external diff command; could be GNU diff, wdiff,
1433
 
    #       or a graphical diff.
1434
 
 
1435
 
    # TODO: Python difflib is not exactly the same as unidiff; should
1436
 
    #       either fix it up or prefer to use an external diff.
1437
 
 
1438
 
    # TODO: Selected-file diff is inefficient and doesn't show you
1439
 
    #       deleted files.
1440
 
 
1441
 
    # TODO: This probably handles non-Unix newlines poorly.
1442
 
 
1443
1456
    _see_also = ['status']
1444
1457
    takes_args = ['file*']
1445
1458
    takes_options = [
1449
1462
               short_name='p',
1450
1463
               help='Set prefixes added to old and new filenames, as '
1451
1464
                    'two values separated by a colon. (eg "old/:new/").'),
 
1465
        Option('old',
 
1466
            help='Branch/tree to compare from.',
 
1467
            type=unicode,
 
1468
            ),
 
1469
        Option('new',
 
1470
            help='Branch/tree to compare to.',
 
1471
            type=unicode,
 
1472
            ),
1452
1473
        'revision',
1453
1474
        'change',
 
1475
        Option('using',
 
1476
            help='Use this command to compare files.',
 
1477
            type=unicode,
 
1478
            ),
1454
1479
        ]
1455
1480
    aliases = ['di', 'dif']
1456
1481
    encoding_type = 'exact'
1457
1482
 
1458
1483
    @display_command
1459
1484
    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
 
1485
            prefix=None, old=None, new=None, using=None):
 
1486
        from bzrlib.diff import _get_trees_to_diff, show_diff_trees
1462
1487
 
1463
1488
        if (prefix is None) or (prefix == '0'):
1464
1489
            # diff -p0 format
1478
1503
            raise errors.BzrCommandError('bzr diff --revision takes exactly'
1479
1504
                                         ' one or two revision specifiers')
1480
1505
 
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)
 
1506
        old_tree, new_tree, specific_files, extra_trees = \
 
1507
                _get_trees_to_diff(file_list, revision, old, new)
 
1508
        return show_diff_trees(old_tree, new_tree, sys.stdout, 
 
1509
                               specific_files=specific_files,
 
1510
                               external_diff_options=diff_options,
 
1511
                               old_label=old_label, new_label=new_label,
 
1512
                               extra_trees=extra_trees, using=using)
1522
1513
 
1523
1514
 
1524
1515
class cmd_deleted(Command):
1666
1657
                        'regular expression.',
1667
1658
                   type=str),
1668
1659
            Option('limit',
 
1660
                   short_name='l',
1669
1661
                   help='Limit the output to the first N revisions.',
1670
1662
                   argname='N',
1671
1663
                   type=_parse_limit),
2009
2001
    """List ignored files and the patterns that matched them.
2010
2002
    """
2011
2003
 
 
2004
    encoding_type = 'replace'
2012
2005
    _see_also = ['ignore']
 
2006
 
2013
2007
    @display_command
2014
2008
    def run(self):
2015
2009
        tree = WorkingTree.open_containing(u'.')[0]
2020
2014
                    continue
2021
2015
                ## XXX: Slightly inefficient since this was already calculated
2022
2016
                pat = tree.is_ignored(path)
2023
 
                print '%-50s %s' % (path, pat)
 
2017
                self.outf.write('%-50s %s\n' % (path, pat))
2024
2018
        finally:
2025
2019
            tree.unlock()
2026
2020
 
2231
2225
                    "files in the working tree."),
2232
2226
             ListOption('fixes', type=str,
2233
2227
                    help="Mark a bug as being fixed by this revision."),
2234
 
             Option('author', type=str,
 
2228
             Option('author', type=unicode,
2235
2229
                    help="Set the author's name, if it's different "
2236
2230
                         "from the committer."),
2237
2231
             Option('local',
2605
2599
                     Option('strict', help='Fail on missing dependencies or '
2606
2600
                            'known failures.'),
2607
2601
                     Option('coverage', type=str, argname="DIRECTORY",
2608
 
                            help='Generate line coverage report in this'
 
2602
                            help='Generate line coverage report in this '
2609
2603
                                 'directory.'),
2610
2604
                     ]
2611
2605
    encoding_type = 'replace'
3030
3024
                                             " merges.  Not cherrypicking or"
3031
3025
                                             " multi-merges.")
3032
3026
            repository = tree.branch.repository
3033
 
            graph = repository.get_graph()
3034
 
            base_revision = graph.find_unique_lca(parents[0], parents[1])
3035
 
            base_tree = repository.revision_tree(base_revision)
3036
 
            other_tree = repository.revision_tree(parents[1])
3037
3027
            interesting_ids = None
3038
3028
            new_conflicts = []
3039
3029
            conflicts = tree.conflicts()
3069
3059
            # list, we imply that the working tree text has seen and rejected
3070
3060
            # all the changes from the other tree, when in fact those changes
3071
3061
            # have not yet been seen.
 
3062
            pb = ui.ui_factory.nested_progress_bar()
3072
3063
            tree.set_parent_ids(parents[:1])
3073
3064
            try:
3074
 
                conflicts = _mod_merge.merge_inner(
3075
 
                                          tree.branch, other_tree, base_tree,
3076
 
                                          this_tree=tree,
3077
 
                                          interesting_ids=interesting_ids,
3078
 
                                          other_rev_id=parents[1],
3079
 
                                          merge_type=merge_type,
3080
 
                                          show_base=show_base,
3081
 
                                          reprocess=reprocess)
 
3065
                merger = _mod_merge.Merger.from_revision_ids(pb,
 
3066
                                                             tree, parents[1])
 
3067
                merger.interesting_ids = interesting_ids
 
3068
                merger.merge_type = merge_type
 
3069
                merger.show_base = show_base
 
3070
                merger.reprocess = reprocess
 
3071
                conflicts = merger.do_merge()
3082
3072
            finally:
3083
3073
                tree.set_parent_ids(parents)
 
3074
                pb.finished()
3084
3075
        finally:
3085
3076
            tree.unlock()
3086
3077
        if conflicts > 0:
3417
3408
    def run(self, filename, all=False, long=False, revision=None,
3418
3409
            show_ids=False):
3419
3410
        from bzrlib.annotate import annotate_file
3420
 
        tree, relpath = WorkingTree.open_containing(filename)
3421
 
        branch = tree.branch
3422
 
        branch.lock_read()
 
3411
        wt, branch, relpath = \
 
3412
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
3413
        if wt is not None:
 
3414
            wt.lock_read()
 
3415
        else:
 
3416
            branch.lock_read()
3423
3417
        try:
3424
3418
            if revision is None:
3425
3419
                revision_id = branch.last_revision()
3427
3421
                raise errors.BzrCommandError('bzr annotate --revision takes exactly 1 argument')
3428
3422
            else:
3429
3423
                revision_id = revision[0].in_history(branch).rev_id
3430
 
            file_id = tree.path2id(relpath)
 
3424
            tree = branch.repository.revision_tree(revision_id)
 
3425
            if wt is not None:
 
3426
                file_id = wt.path2id(relpath)
 
3427
            else:
 
3428
                file_id = tree.path2id(relpath)
3431
3429
            if file_id is None:
3432
3430
                raise errors.NotVersionedError(filename)
3433
 
            tree = branch.repository.revision_tree(revision_id)
3434
3431
            file_version = tree.inventory[file_id].revision
3435
3432
            annotate_file(branch, file_version, file_id, long, all, self.outf,
3436
3433
                          show_ids=show_ids)
3437
3434
        finally:
3438
 
            branch.unlock()
 
3435
            if wt is not None:
 
3436
                wt.unlock()
 
3437
            else:
 
3438
                branch.unlock()
3439
3439
 
3440
3440
 
3441
3441
class cmd_re_sign(Command):
3579
3579
                    Option('force', help='Say yes to all questions.')]
3580
3580
    takes_args = ['location?']
3581
3581
    aliases = []
 
3582
    encoding_type = 'replace'
3582
3583
 
3583
3584
    def run(self, location=None,
3584
3585
            dry_run=False, verbose=False,
3718
3719
        ]
3719
3720
 
3720
3721
    def run(self, port=None, inet=False, directory=None, allow_writes=False):
 
3722
        from bzrlib import lockdir
3721
3723
        from bzrlib.smart import medium, server
3722
3724
        from bzrlib.transport import get_transport
3723
3725
        from bzrlib.transport.chroot import ChrootServer
3748
3750
        # be changed with care though, as we dont want to use bandwidth sending
3749
3751
        # progress over stderr to smart server clients!
3750
3752
        old_factory = ui.ui_factory
 
3753
        old_lockdir_timeout = lockdir._DEFAULT_TIMEOUT_SECONDS
3751
3754
        try:
3752
3755
            ui.ui_factory = ui.SilentUIFactory()
 
3756
            lockdir._DEFAULT_TIMEOUT_SECONDS = 0
3753
3757
            smart_server.serve()
3754
3758
        finally:
3755
3759
            ui.ui_factory = old_factory
 
3760
            lockdir._DEFAULT_TIMEOUT_SECONDS = old_lockdir_timeout
3756
3761
 
3757
3762
 
3758
3763
class cmd_join(Command):
3810
3815
 
3811
3816
 
3812
3817
class cmd_split(Command):
3813
 
    """Split a tree into two trees.
 
3818
    """Split a subdirectory of a tree into a separate tree.
3814
3819
 
3815
 
    This command is for experimental use only.  It requires the target tree
3816
 
    to be in dirstate-with-subtree format, which cannot be converted into
3817
 
    earlier formats.
 
3820
    This command will produce a target tree in a format that supports
 
3821
    rich roots, like 'rich-root' or 'rich-root-pack'.  These formats cannot be
 
3822
    converted into earlier formats like 'dirstate-tags'.
3818
3823
 
3819
3824
    The TREE argument should be a subdirectory of a working tree.  That
3820
3825
    subdirectory will be converted into an independent tree, with its own
3821
3826
    branch.  Commits in the top-level tree will not apply to the new subtree.
3822
 
    If you want that behavior, do "bzr join --reference TREE".
3823
3827
    """
3824
3828
 
3825
 
    _see_also = ['join']
 
3829
    # join is not un-hidden yet
 
3830
    #_see_also = ['join']
3826
3831
    takes_args = ['tree']
3827
3832
 
3828
 
    hidden = True
3829
 
 
3830
3833
    def run(self, tree):
3831
3834
        containing_tree, subdir = WorkingTree.open_containing(tree)
3832
3835
        sub_id = containing_tree.path2id(subdir)
3838
3841
            raise errors.UpgradeRequired(containing_tree.branch.base)
3839
3842
 
3840
3843
 
3841
 
 
3842
3844
class cmd_merge_directive(Command):
3843
3845
    """Generate a merge directive for auto-merge tools.
3844
3846
 
4025
4027
    def _run(self, submit_branch, revision, public_branch, remember, format,
4026
4028
             no_bundle, no_patch, output, from_, mail_to, message):
4027
4029
        from bzrlib.revision import NULL_REVISION
 
4030
        branch = Branch.open_containing(from_)[0]
4028
4031
        if output is None:
4029
4032
            outfile = StringIO()
4030
4033
        elif output == '-':
4031
4034
            outfile = self.outf
4032
4035
        else:
4033
4036
            outfile = open(output, 'wb')
 
4037
        # we may need to write data into branch's repository to calculate
 
4038
        # the data to send.
 
4039
        branch.lock_write()
4034
4040
        try:
4035
 
            branch = Branch.open_containing(from_)[0]
4036
 
            # we may need to write data into branch's repository to calculate
4037
 
            # the data to send.
4038
 
            branch.lock_write()
4039
4041
            if output is None:
4040
4042
                config = branch.get_config()
4041
4043
                if mail_to is None: