/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: Canonical.com Patch Queue Manager
  • Date: 2010-04-28 09:40:23 UTC
  • mfrom: (5155.1.5 320119-exclude-ancestry)
  • Revision ID: pqm@pqm.ubuntu.com-20100428094023-7504mlou1qk28r9n
(vila) Add --exclude-common-ancestry log option (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
528
528
        if tree:
529
529
            try:
530
530
                wt = WorkingTree.open_containing(location)[0]
531
 
                self.add_cleanup(wt.lock_read().unlock)
 
531
                wt.lock_read()
532
532
            except (errors.NoWorkingTree, errors.NotLocalUrl):
533
533
                raise errors.NoWorkingTree(location)
 
534
            self.add_cleanup(wt.unlock)
534
535
            revid = wt.last_revision()
535
536
            try:
536
537
                revno_t = wt.branch.revision_id_to_dotted_revno(revid)
539
540
            revno = ".".join(str(n) for n in revno_t)
540
541
        else:
541
542
            b = Branch.open_containing(location)[0]
542
 
            self.add_cleanup(b.lock_read().unlock)
 
543
            b.lock_read()
 
544
            self.add_cleanup(b.unlock)
543
545
            revno = b.revno()
544
546
        self.cleanup_now()
545
547
        self.outf.write(str(revno) + '\n')
568
570
        try:
569
571
            wt = WorkingTree.open_containing(directory)[0]
570
572
            b = wt.branch
571
 
            self.add_cleanup(wt.lock_read().unlock)
 
573
            wt.lock_read()
 
574
            self.add_cleanup(wt.unlock)
572
575
        except (errors.NoWorkingTree, errors.NotLocalUrl):
573
576
            wt = None
574
577
            b = Branch.open_containing(directory)[0]
575
 
            self.add_cleanup(b.lock_read().unlock)
 
578
            b.lock_read()
 
579
            self.add_cleanup(b.unlock)
576
580
        revision_ids = []
577
581
        if revision is not None:
578
582
            revision_ids.extend(rev.as_revision_id(b) for rev in revision)
677
681
                should_print=(not is_quiet()))
678
682
 
679
683
        if base_tree:
680
 
            self.add_cleanup(base_tree.lock_read().unlock)
 
684
            base_tree.lock_read()
 
685
            self.add_cleanup(base_tree.unlock)
681
686
        tree, file_list = tree_files_for_add(file_list)
682
687
        added, ignored = tree.smart_add(file_list, not
683
688
            no_recurse, action=action, save=not dry_run)
755
760
 
756
761
        revision = _get_one_revision('inventory', revision)
757
762
        work_tree, file_list = tree_files(file_list)
758
 
        self.add_cleanup(work_tree.lock_read().unlock)
 
763
        work_tree.lock_read()
 
764
        self.add_cleanup(work_tree.unlock)
759
765
        if revision is not None:
760
766
            tree = revision.as_tree(work_tree.branch)
761
767
 
762
768
            extra_trees = [work_tree]
763
 
            self.add_cleanup(tree.lock_read().unlock)
 
769
            tree.lock_read()
 
770
            self.add_cleanup(tree.unlock)
764
771
        else:
765
772
            tree = work_tree
766
773
            extra_trees = []
826
833
        if len(names_list) < 2:
827
834
            raise errors.BzrCommandError("missing file argument")
828
835
        tree, rel_names = tree_files(names_list, canonicalize=False)
829
 
        self.add_cleanup(tree.lock_tree_write().unlock)
 
836
        tree.lock_tree_write()
 
837
        self.add_cleanup(tree.unlock)
830
838
        self._run(tree, names_list, rel_names, after)
831
839
 
832
840
    def run_auto(self, names_list, after, dry_run):
837
845
            raise errors.BzrCommandError('--after cannot be specified with'
838
846
                                         ' --auto.')
839
847
        work_tree, file_list = tree_files(names_list, default_branch='.')
840
 
        self.add_cleanup(work_tree.lock_tree_write().unlock)
 
848
        work_tree.lock_tree_write()
 
849
        self.add_cleanup(work_tree.unlock)
841
850
        rename_map.RenameMap.guess_renames(work_tree, dry_run)
842
851
 
843
852
    def _run(self, tree, names_list, rel_names, after):
977
986
        try:
978
987
            tree_to = WorkingTree.open_containing(directory)[0]
979
988
            branch_to = tree_to.branch
980
 
            self.add_cleanup(tree_to.lock_write().unlock)
 
989
            tree_to.lock_write()
 
990
            self.add_cleanup(tree_to.unlock)
981
991
        except errors.NoWorkingTree:
982
992
            tree_to = None
983
993
            branch_to = Branch.open_containing(directory)[0]
984
 
            self.add_cleanup(branch_to.lock_write().unlock)
 
994
            branch_to.lock_write()
 
995
            self.add_cleanup(branch_to.unlock)
985
996
 
986
997
        if local and not branch_to.get_bound_location():
987
998
            raise errors.LocalRequiresBoundBranch()
1018
1029
        else:
1019
1030
            branch_from = Branch.open(location,
1020
1031
                possible_transports=possible_transports)
1021
 
            self.add_cleanup(branch_from.lock_read().unlock)
 
1032
            branch_from.lock_read()
 
1033
            self.add_cleanup(branch_from.unlock)
1022
1034
 
1023
1035
            if branch_to.get_parent() is None or remember:
1024
1036
                branch_to.set_parent(branch_from.base)
1120
1132
        else:
1121
1133
            revision_id = None
1122
1134
        if tree is not None and revision_id is None:
1123
 
            tree.check_changed_or_out_of_date(
1124
 
                strict, 'push_strict',
1125
 
                more_error='Use --no-strict to force the push.',
1126
 
                more_warning='Uncommitted changes will not be pushed.')
 
1135
            tree.warn_if_changed_or_out_of_date(
 
1136
                strict, 'push_strict', 'Use --no-strict to force the push.')
1127
1137
        # Get the stacked_on branch, if any
1128
1138
        if stacked_on is not None:
1129
1139
            stacked_on = urlutils.normalize_url(stacked_on)
1207
1217
        accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1208
1218
            from_location)
1209
1219
        revision = _get_one_revision('branch', revision)
1210
 
        self.add_cleanup(br_from.lock_read().unlock)
 
1220
        br_from.lock_read()
 
1221
        self.add_cleanup(br_from.unlock)
1211
1222
        if revision is not None:
1212
1223
            revision_id = revision.as_revision_id(br_from)
1213
1224
        else:
1353
1364
    @display_command
1354
1365
    def run(self, dir=u'.'):
1355
1366
        tree = WorkingTree.open_containing(dir)[0]
1356
 
        self.add_cleanup(tree.lock_read().unlock)
 
1367
        tree.lock_read()
 
1368
        self.add_cleanup(tree.unlock)
1357
1369
        new_inv = tree.inventory
1358
1370
        old_tree = tree.basis_tree()
1359
 
        self.add_cleanup(old_tree.lock_read().unlock)
 
1371
        old_tree.lock_read()
 
1372
        self.add_cleanup(old_tree.unlock)
1360
1373
        old_inv = old_tree.inventory
1361
1374
        renames = []
1362
1375
        iterator = tree.iter_changes(old_tree, include_unchanged=True)
1400
1413
        master = branch.get_master_branch(
1401
1414
            possible_transports=possible_transports)
1402
1415
        if master is not None:
 
1416
            tree.lock_write()
1403
1417
            branch_location = master.base
1404
 
            tree.lock_write()
1405
1418
        else:
 
1419
            tree.lock_tree_write()
1406
1420
            branch_location = tree.branch.base
1407
 
            tree.lock_tree_write()
1408
1421
        self.add_cleanup(tree.unlock)
1409
1422
        # get rid of the final '/' and be ready for display
1410
1423
        branch_location = urlutils.unescape_for_display(
1530
1543
        if file_list is not None:
1531
1544
            file_list = [f for f in file_list]
1532
1545
 
1533
 
        self.add_cleanup(tree.lock_write().unlock)
 
1546
        tree.lock_write()
 
1547
        self.add_cleanup(tree.unlock)
1534
1548
        # Heuristics should probably all move into tree.remove_smart or
1535
1549
        # some such?
1536
1550
        if new:
1992
2006
    @display_command
1993
2007
    def run(self, show_ids=False):
1994
2008
        tree = WorkingTree.open_containing(u'.')[0]
1995
 
        self.add_cleanup(tree.lock_read().unlock)
 
2009
        tree.lock_read()
 
2010
        self.add_cleanup(tree.unlock)
1996
2011
        old = tree.basis_tree()
1997
 
        self.add_cleanup(old.lock_read().unlock)
 
2012
        old.lock_read()
 
2013
        self.add_cleanup(old.unlock)
1998
2014
        for path, ie in old.inventory.iter_entries():
1999
2015
            if not tree.has_id(ie.file_id):
2000
2016
                self.outf.write(path)
2042
2058
    @display_command
2043
2059
    def run(self, null=False):
2044
2060
        wt = WorkingTree.open_containing(u'.')[0]
2045
 
        self.add_cleanup(wt.lock_read().unlock)
 
2061
        wt.lock_read()
 
2062
        self.add_cleanup(wt.unlock)
2046
2063
        basis = wt.basis_tree()
2047
 
        self.add_cleanup(basis.lock_read().unlock)
 
2064
        basis.lock_read()
 
2065
        self.add_cleanup(basis.unlock)
2048
2066
        basis_inv = basis.inventory
2049
2067
        inv = wt.inventory
2050
2068
        for file_id in inv:
2332
2350
        if file_list:
2333
2351
            # find the file ids to log and check for directory filtering
2334
2352
            b, file_info_list, rev1, rev2 = _get_info_for_log_files(
2335
 
                revision, file_list, self.add_cleanup)
 
2353
                revision, file_list)
 
2354
            self.add_cleanup(b.unlock)
2336
2355
            for relpath, file_id, kind in file_info_list:
2337
2356
                if file_id is None:
2338
2357
                    raise errors.BzrCommandError(
2356
2375
                location = '.'
2357
2376
            dir, relpath = bzrdir.BzrDir.open_containing(location)
2358
2377
            b = dir.open_branch()
2359
 
            self.add_cleanup(b.lock_read().unlock)
 
2378
            b.lock_read()
 
2379
            self.add_cleanup(b.unlock)
2360
2380
            rev1, rev2 = _get_revision_range(revision, b, self.name())
2361
2381
 
2362
2382
        # Decide on the type of delta & diff filtering to use
2486
2506
        tree, relpath = WorkingTree.open_containing(filename)
2487
2507
        file_id = tree.path2id(relpath)
2488
2508
        b = tree.branch
2489
 
        self.add_cleanup(b.lock_read().unlock)
 
2509
        b.lock_read()
 
2510
        self.add_cleanup(b.unlock)
2490
2511
        touching_revs = log.find_touching_revisions(b, file_id)
2491
2512
        for revno, revision_id, what in touching_revs:
2492
2513
            self.outf.write("%6d %s\n" % (revno, what))
2561
2582
                view_str = views.view_display_str(view_files)
2562
2583
                note("Ignoring files outside view. View is %s" % view_str)
2563
2584
 
2564
 
        self.add_cleanup(tree.lock_read().unlock)
 
2585
        tree.lock_read()
 
2586
        self.add_cleanup(tree.unlock)
2565
2587
        for fp, fc, fkind, fid, entry in tree.list_files(include_root=False,
2566
2588
            from_dir=relpath, recursive=recursive):
2567
2589
            # Apply additional masking
2746
2768
    @display_command
2747
2769
    def run(self):
2748
2770
        tree = WorkingTree.open_containing(u'.')[0]
2749
 
        self.add_cleanup(tree.lock_read().unlock)
 
2771
        tree.lock_read()
 
2772
        self.add_cleanup(tree.unlock)
2750
2773
        for path, file_class, kind, file_id, entry in tree.list_files():
2751
2774
            if file_class != 'I':
2752
2775
                continue
2865
2888
                                         " one revision specifier")
2866
2889
        tree, branch, relpath = \
2867
2890
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
2868
 
        self.add_cleanup(branch.lock_read().unlock)
 
2891
        branch.lock_read()
 
2892
        self.add_cleanup(branch.unlock)
2869
2893
        return self._run(tree, branch, relpath, filename, revision,
2870
2894
                         name_from_revision, filters)
2871
2895
 
2874
2898
        if tree is None:
2875
2899
            tree = b.basis_tree()
2876
2900
        rev_tree = _get_one_revision_tree('cat', revision, branch=b)
2877
 
        self.add_cleanup(rev_tree.lock_read().unlock)
 
2901
        rev_tree.lock_read()
 
2902
        self.add_cleanup(rev_tree.unlock)
2878
2903
 
2879
2904
        old_file_id = rev_tree.path2id(relpath)
2880
2905
 
3046
3071
                         "the master branch until a normal commit "
3047
3072
                         "is performed."
3048
3073
                    ),
3049
 
             Option('show-diff', short_name='p',
 
3074
             Option('show-diff',
3050
3075
                    help='When no message is supplied, show the diff along'
3051
3076
                    ' with the status summary in the message editor.'),
3052
3077
             ]
3663
3688
 
3664
3689
        branch1 = Branch.open_containing(branch)[0]
3665
3690
        branch2 = Branch.open_containing(other)[0]
3666
 
        self.add_cleanup(branch1.lock_read().unlock)
3667
 
        self.add_cleanup(branch2.lock_read().unlock)
 
3691
        branch1.lock_read()
 
3692
        self.add_cleanup(branch1.unlock)
 
3693
        branch2.lock_read()
 
3694
        self.add_cleanup(branch2.unlock)
3668
3695
        last1 = ensure_null(branch1.last_revision())
3669
3696
        last2 = ensure_null(branch2.last_revision())
3670
3697
 
3808
3835
            unversioned_filter=tree.is_ignored, view_info=view_info)
3809
3836
        pb = ui.ui_factory.nested_progress_bar()
3810
3837
        self.add_cleanup(pb.finished)
3811
 
        self.add_cleanup(tree.lock_write().unlock)
 
3838
        tree.lock_write()
 
3839
        self.add_cleanup(tree.unlock)
3812
3840
        if location is not None:
3813
3841
            try:
3814
3842
                mergeable = bundle.read_mergeable_from_url(location,
4070
4098
        if merge_type is None:
4071
4099
            merge_type = _mod_merge.Merge3Merger
4072
4100
        tree, file_list = tree_files(file_list)
4073
 
        self.add_cleanup(tree.lock_write().unlock)
 
4101
        tree.lock_write()
 
4102
        self.add_cleanup(tree.unlock)
4074
4103
        parents = tree.get_parent_ids()
4075
4104
        if len(parents) != 2:
4076
4105
            raise errors.BzrCommandError("Sorry, remerge only works after normal"
4186
4215
    def run(self, revision=None, no_backup=False, file_list=None,
4187
4216
            forget_merges=None):
4188
4217
        tree, file_list = tree_files(file_list)
4189
 
        self.add_cleanup(tree.lock_tree_write().unlock)
 
4218
        tree.lock_tree_write()
 
4219
        self.add_cleanup(tree.unlock)
4190
4220
        if forget_merges:
4191
4221
            tree.set_parent_ids(tree.get_parent_ids()[:1])
4192
4222
        else:
4328
4358
            restrict = 'remote'
4329
4359
 
4330
4360
        local_branch = Branch.open_containing(u".")[0]
4331
 
        self.add_cleanup(local_branch.lock_read().unlock)
 
4361
        local_branch.lock_read()
 
4362
        self.add_cleanup(local_branch.unlock)
4332
4363
 
4333
4364
        parent = local_branch.get_parent()
4334
4365
        if other_branch is None:
4345
4376
        if remote_branch.base == local_branch.base:
4346
4377
            remote_branch = local_branch
4347
4378
        else:
4348
 
            self.add_cleanup(remote_branch.lock_read().unlock)
 
4379
            remote_branch.lock_read()
 
4380
            self.add_cleanup(remote_branch.unlock)
4349
4381
 
4350
4382
        local_revid_range = _revision_range_to_revid_range(
4351
4383
            _get_revision_range(my_revision, local_branch,
4406
4438
            message("Branches are up to date.\n")
4407
4439
        self.cleanup_now()
4408
4440
        if not status_code and parent is None and other_branch is not None:
4409
 
            self.add_cleanup(local_branch.lock_write().unlock)
 
4441
            local_branch.lock_write()
 
4442
            self.add_cleanup(local_branch.unlock)
4410
4443
            # handle race conditions - a parent might be set while we run.
4411
4444
            if local_branch.get_parent() is None:
4412
4445
                local_branch.set_parent(remote_branch.base)
4512
4545
            b = Branch.open_containing(branch)[0]
4513
4546
        else:
4514
4547
            b = Branch.open(branch)
4515
 
        self.add_cleanup(b.lock_read().unlock)
 
4548
        b.lock_read()
 
4549
        self.add_cleanup(b.unlock)
4516
4550
        if revision is None:
4517
4551
            rev_id = b.last_revision()
4518
4552
        else:
4552
4586
        wt, branch, relpath = \
4553
4587
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
4554
4588
        if wt is not None:
4555
 
            self.add_cleanup(wt.lock_read().unlock)
 
4589
            wt.lock_read()
 
4590
            self.add_cleanup(wt.unlock)
4556
4591
        else:
4557
 
            self.add_cleanup(branch.lock_read().unlock)
 
4592
            branch.lock_read()
 
4593
            self.add_cleanup(branch.unlock)
4558
4594
        tree = _get_one_revision_tree('annotate', revision, branch=branch)
4559
 
        self.add_cleanup(tree.lock_read().unlock)
 
4595
        tree.lock_read()
 
4596
        self.add_cleanup(tree.unlock)
4560
4597
        if wt is not None:
4561
4598
            file_id = wt.path2id(relpath)
4562
4599
        else:
4588
4625
        if revision_id_list is None and revision is None:
4589
4626
            raise errors.BzrCommandError('You must supply either --revision or a revision_id')
4590
4627
        b = WorkingTree.open_containing(u'.')[0].branch
4591
 
        self.add_cleanup(b.lock_write().unlock)
 
4628
        b.lock_write()
 
4629
        self.add_cleanup(b.unlock)
4592
4630
        return self._run(b, revision_id_list, revision)
4593
4631
 
4594
4632
    def _run(self, b, revision_id_list, revision):
4641
4679
 
4642
4680
class cmd_bind(Command):
4643
4681
    __doc__ = """Convert the current branch into a checkout of the supplied branch.
4644
 
    If no branch is supplied, rebind to the last bound location.
4645
4682
 
4646
4683
    Once converted into a checkout, commits must succeed on the master branch
4647
4684
    before they will be applied to the local branch.
4744
4781
            b = control.open_branch()
4745
4782
 
4746
4783
        if tree is not None:
4747
 
            self.add_cleanup(tree.lock_write().unlock)
 
4784
            tree.lock_write()
 
4785
            self.add_cleanup(tree.unlock)
4748
4786
        else:
4749
 
            self.add_cleanup(b.lock_write().unlock)
 
4787
            b.lock_write()
 
4788
            self.add_cleanup(b.unlock)
4750
4789
        return self._run(b, tree, dry_run, verbose, revision, force, local=local)
4751
4790
 
4752
4791
    def _run(self, b, tree, dry_run, verbose, revision, force, local=False):
5315
5354
            revision=None,
5316
5355
            ):
5317
5356
        branch, relpath = Branch.open_containing(directory)
5318
 
        self.add_cleanup(branch.lock_write().unlock)
 
5357
        branch.lock_write()
 
5358
        self.add_cleanup(branch.unlock)
5319
5359
        if delete:
5320
5360
            if tag_name is None:
5321
5361
                raise errors.BzrCommandError("No tag specified to delete.")
5376
5416
        if not tags:
5377
5417
            return
5378
5418
 
5379
 
        self.add_cleanup(branch.lock_read().unlock)
 
5419
        branch.lock_read()
 
5420
        self.add_cleanup(branch.unlock)
5380
5421
        if revision:
5381
5422
            graph = branch.repository.get_graph()
5382
5423
            rev1, rev2 = _get_revision_range(revision, branch, self.name())
5860
5901
 
5861
5902
    def run_for_list(self):
5862
5903
        tree = WorkingTree.open_containing('.')[0]
5863
 
        self.add_cleanup(tree.lock_read().unlock)
 
5904
        tree.lock_read()
 
5905
        self.add_cleanup(tree.unlock)
5864
5906
        manager = tree.get_shelf_manager()
5865
5907
        shelves = manager.active_shelves()
5866
5908
        if len(shelves) == 0: