~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Jelmer Vernooij
  • Date: 2010-04-30 11:35:43 UTC
  • mfrom: (5195 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5197.
  • Revision ID: jelmer@samba.org-20100430113543-tiqqhmqa3d8no4iu
merge bzr.dev

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)
1207
1219
        accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1208
1220
            from_location)
1209
1221
        revision = _get_one_revision('branch', revision)
1210
 
        self.add_cleanup(br_from.lock_read().unlock)
 
1222
        br_from.lock_read()
 
1223
        self.add_cleanup(br_from.unlock)
1211
1224
        if revision is not None:
1212
1225
            revision_id = revision.as_revision_id(br_from)
1213
1226
        else:
1353
1366
    @display_command
1354
1367
    def run(self, dir=u'.'):
1355
1368
        tree = WorkingTree.open_containing(dir)[0]
1356
 
        self.add_cleanup(tree.lock_read().unlock)
 
1369
        tree.lock_read()
 
1370
        self.add_cleanup(tree.unlock)
1357
1371
        new_inv = tree.inventory
1358
1372
        old_tree = tree.basis_tree()
1359
 
        self.add_cleanup(old_tree.lock_read().unlock)
 
1373
        old_tree.lock_read()
 
1374
        self.add_cleanup(old_tree.unlock)
1360
1375
        old_inv = old_tree.inventory
1361
1376
        renames = []
1362
1377
        iterator = tree.iter_changes(old_tree, include_unchanged=True)
1400
1415
        master = branch.get_master_branch(
1401
1416
            possible_transports=possible_transports)
1402
1417
        if master is not None:
 
1418
            tree.lock_write()
1403
1419
            branch_location = master.base
1404
 
            tree.lock_write()
1405
1420
        else:
 
1421
            tree.lock_tree_write()
1406
1422
            branch_location = tree.branch.base
1407
 
            tree.lock_tree_write()
1408
1423
        self.add_cleanup(tree.unlock)
1409
1424
        # get rid of the final '/' and be ready for display
1410
1425
        branch_location = urlutils.unescape_for_display(
1530
1545
        if file_list is not None:
1531
1546
            file_list = [f for f in file_list]
1532
1547
 
1533
 
        self.add_cleanup(tree.lock_write().unlock)
 
1548
        tree.lock_write()
 
1549
        self.add_cleanup(tree.unlock)
1534
1550
        # Heuristics should probably all move into tree.remove_smart or
1535
1551
        # some such?
1536
1552
        if new:
1992
2008
    @display_command
1993
2009
    def run(self, show_ids=False):
1994
2010
        tree = WorkingTree.open_containing(u'.')[0]
1995
 
        self.add_cleanup(tree.lock_read().unlock)
 
2011
        tree.lock_read()
 
2012
        self.add_cleanup(tree.unlock)
1996
2013
        old = tree.basis_tree()
1997
 
        self.add_cleanup(old.lock_read().unlock)
 
2014
        old.lock_read()
 
2015
        self.add_cleanup(old.unlock)
1998
2016
        for path, ie in old.inventory.iter_entries():
1999
2017
            if not tree.has_id(ie.file_id):
2000
2018
                self.outf.write(path)
2042
2060
    @display_command
2043
2061
    def run(self, null=False):
2044
2062
        wt = WorkingTree.open_containing(u'.')[0]
2045
 
        self.add_cleanup(wt.lock_read().unlock)
 
2063
        wt.lock_read()
 
2064
        self.add_cleanup(wt.unlock)
2046
2065
        basis = wt.basis_tree()
2047
 
        self.add_cleanup(basis.lock_read().unlock)
 
2066
        basis.lock_read()
 
2067
        self.add_cleanup(basis.unlock)
2048
2068
        basis_inv = basis.inventory
2049
2069
        inv = wt.inventory
2050
2070
        for file_id in inv:
2332
2352
        if file_list:
2333
2353
            # find the file ids to log and check for directory filtering
2334
2354
            b, file_info_list, rev1, rev2 = _get_info_for_log_files(
2335
 
                revision, file_list, self.add_cleanup)
 
2355
                revision, file_list)
 
2356
            self.add_cleanup(b.unlock)
2336
2357
            for relpath, file_id, kind in file_info_list:
2337
2358
                if file_id is None:
2338
2359
                    raise errors.BzrCommandError(
2356
2377
                location = '.'
2357
2378
            dir, relpath = bzrdir.BzrDir.open_containing(location)
2358
2379
            b = dir.open_branch()
2359
 
            self.add_cleanup(b.lock_read().unlock)
 
2380
            b.lock_read()
 
2381
            self.add_cleanup(b.unlock)
2360
2382
            rev1, rev2 = _get_revision_range(revision, b, self.name())
2361
2383
 
2362
2384
        # Decide on the type of delta & diff filtering to use
2486
2508
        tree, relpath = WorkingTree.open_containing(filename)
2487
2509
        file_id = tree.path2id(relpath)
2488
2510
        b = tree.branch
2489
 
        self.add_cleanup(b.lock_read().unlock)
 
2511
        b.lock_read()
 
2512
        self.add_cleanup(b.unlock)
2490
2513
        touching_revs = log.find_touching_revisions(b, file_id)
2491
2514
        for revno, revision_id, what in touching_revs:
2492
2515
            self.outf.write("%6d %s\n" % (revno, what))
2561
2584
                view_str = views.view_display_str(view_files)
2562
2585
                note("Ignoring files outside view. View is %s" % view_str)
2563
2586
 
2564
 
        self.add_cleanup(tree.lock_read().unlock)
 
2587
        tree.lock_read()
 
2588
        self.add_cleanup(tree.unlock)
2565
2589
        for fp, fc, fkind, fid, entry in tree.list_files(include_root=False,
2566
2590
            from_dir=relpath, recursive=recursive):
2567
2591
            # Apply additional masking
2746
2770
    @display_command
2747
2771
    def run(self):
2748
2772
        tree = WorkingTree.open_containing(u'.')[0]
2749
 
        self.add_cleanup(tree.lock_read().unlock)
 
2773
        tree.lock_read()
 
2774
        self.add_cleanup(tree.unlock)
2750
2775
        for path, file_class, kind, file_id, entry in tree.list_files():
2751
2776
            if file_class != 'I':
2752
2777
                continue
2865
2890
                                         " one revision specifier")
2866
2891
        tree, branch, relpath = \
2867
2892
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
2868
 
        self.add_cleanup(branch.lock_read().unlock)
 
2893
        branch.lock_read()
 
2894
        self.add_cleanup(branch.unlock)
2869
2895
        return self._run(tree, branch, relpath, filename, revision,
2870
2896
                         name_from_revision, filters)
2871
2897
 
2874
2900
        if tree is None:
2875
2901
            tree = b.basis_tree()
2876
2902
        rev_tree = _get_one_revision_tree('cat', revision, branch=b)
2877
 
        self.add_cleanup(rev_tree.lock_read().unlock)
 
2903
        rev_tree.lock_read()
 
2904
        self.add_cleanup(rev_tree.unlock)
2878
2905
 
2879
2906
        old_file_id = rev_tree.path2id(relpath)
2880
2907
 
3663
3690
 
3664
3691
        branch1 = Branch.open_containing(branch)[0]
3665
3692
        branch2 = Branch.open_containing(other)[0]
3666
 
        self.add_cleanup(branch1.lock_read().unlock)
3667
 
        self.add_cleanup(branch2.lock_read().unlock)
 
3693
        branch1.lock_read()
 
3694
        self.add_cleanup(branch1.unlock)
 
3695
        branch2.lock_read()
 
3696
        self.add_cleanup(branch2.unlock)
3668
3697
        last1 = ensure_null(branch1.last_revision())
3669
3698
        last2 = ensure_null(branch2.last_revision())
3670
3699
 
3808
3837
            unversioned_filter=tree.is_ignored, view_info=view_info)
3809
3838
        pb = ui.ui_factory.nested_progress_bar()
3810
3839
        self.add_cleanup(pb.finished)
3811
 
        self.add_cleanup(tree.lock_write().unlock)
 
3840
        tree.lock_write()
 
3841
        self.add_cleanup(tree.unlock)
3812
3842
        if location is not None:
3813
3843
            try:
3814
3844
                mergeable = bundle.read_mergeable_from_url(location,
4070
4100
        if merge_type is None:
4071
4101
            merge_type = _mod_merge.Merge3Merger
4072
4102
        tree, file_list = tree_files(file_list)
4073
 
        self.add_cleanup(tree.lock_write().unlock)
 
4103
        tree.lock_write()
 
4104
        self.add_cleanup(tree.unlock)
4074
4105
        parents = tree.get_parent_ids()
4075
4106
        if len(parents) != 2:
4076
4107
            raise errors.BzrCommandError("Sorry, remerge only works after normal"
4186
4217
    def run(self, revision=None, no_backup=False, file_list=None,
4187
4218
            forget_merges=None):
4188
4219
        tree, file_list = tree_files(file_list)
4189
 
        self.add_cleanup(tree.lock_tree_write().unlock)
 
4220
        tree.lock_tree_write()
 
4221
        self.add_cleanup(tree.unlock)
4190
4222
        if forget_merges:
4191
4223
            tree.set_parent_ids(tree.get_parent_ids()[:1])
4192
4224
        else:
4328
4360
            restrict = 'remote'
4329
4361
 
4330
4362
        local_branch = Branch.open_containing(u".")[0]
4331
 
        self.add_cleanup(local_branch.lock_read().unlock)
 
4363
        local_branch.lock_read()
 
4364
        self.add_cleanup(local_branch.unlock)
4332
4365
 
4333
4366
        parent = local_branch.get_parent()
4334
4367
        if other_branch is None:
4345
4378
        if remote_branch.base == local_branch.base:
4346
4379
            remote_branch = local_branch
4347
4380
        else:
4348
 
            self.add_cleanup(remote_branch.lock_read().unlock)
 
4381
            remote_branch.lock_read()
 
4382
            self.add_cleanup(remote_branch.unlock)
4349
4383
 
4350
4384
        local_revid_range = _revision_range_to_revid_range(
4351
4385
            _get_revision_range(my_revision, local_branch,
4406
4440
            message("Branches are up to date.\n")
4407
4441
        self.cleanup_now()
4408
4442
        if not status_code and parent is None and other_branch is not None:
4409
 
            self.add_cleanup(local_branch.lock_write().unlock)
 
4443
            local_branch.lock_write()
 
4444
            self.add_cleanup(local_branch.unlock)
4410
4445
            # handle race conditions - a parent might be set while we run.
4411
4446
            if local_branch.get_parent() is None:
4412
4447
                local_branch.set_parent(remote_branch.base)
4512
4547
            b = Branch.open_containing(branch)[0]
4513
4548
        else:
4514
4549
            b = Branch.open(branch)
4515
 
        self.add_cleanup(b.lock_read().unlock)
 
4550
        b.lock_read()
 
4551
        self.add_cleanup(b.unlock)
4516
4552
        if revision is None:
4517
4553
            rev_id = b.last_revision()
4518
4554
        else:
4552
4588
        wt, branch, relpath = \
4553
4589
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
4554
4590
        if wt is not None:
4555
 
            self.add_cleanup(wt.lock_read().unlock)
 
4591
            wt.lock_read()
 
4592
            self.add_cleanup(wt.unlock)
4556
4593
        else:
4557
 
            self.add_cleanup(branch.lock_read().unlock)
 
4594
            branch.lock_read()
 
4595
            self.add_cleanup(branch.unlock)
4558
4596
        tree = _get_one_revision_tree('annotate', revision, branch=branch)
4559
 
        self.add_cleanup(tree.lock_read().unlock)
 
4597
        tree.lock_read()
 
4598
        self.add_cleanup(tree.unlock)
4560
4599
        if wt is not None:
4561
4600
            file_id = wt.path2id(relpath)
4562
4601
        else:
4588
4627
        if revision_id_list is None and revision is None:
4589
4628
            raise errors.BzrCommandError('You must supply either --revision or a revision_id')
4590
4629
        b = WorkingTree.open_containing(u'.')[0].branch
4591
 
        self.add_cleanup(b.lock_write().unlock)
 
4630
        b.lock_write()
 
4631
        self.add_cleanup(b.unlock)
4592
4632
        return self._run(b, revision_id_list, revision)
4593
4633
 
4594
4634
    def _run(self, b, revision_id_list, revision):
4641
4681
 
4642
4682
class cmd_bind(Command):
4643
4683
    __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
4684
 
4646
4685
    Once converted into a checkout, commits must succeed on the master branch
4647
4686
    before they will be applied to the local branch.
4744
4783
            b = control.open_branch()
4745
4784
 
4746
4785
        if tree is not None:
4747
 
            self.add_cleanup(tree.lock_write().unlock)
 
4786
            tree.lock_write()
 
4787
            self.add_cleanup(tree.unlock)
4748
4788
        else:
4749
 
            self.add_cleanup(b.lock_write().unlock)
 
4789
            b.lock_write()
 
4790
            self.add_cleanup(b.unlock)
4750
4791
        return self._run(b, tree, dry_run, verbose, revision, force, local=local)
4751
4792
 
4752
4793
    def _run(self, b, tree, dry_run, verbose, revision, force, local=False):
5315
5356
            revision=None,
5316
5357
            ):
5317
5358
        branch, relpath = Branch.open_containing(directory)
5318
 
        self.add_cleanup(branch.lock_write().unlock)
 
5359
        branch.lock_write()
 
5360
        self.add_cleanup(branch.unlock)
5319
5361
        if delete:
5320
5362
            if tag_name is None:
5321
5363
                raise errors.BzrCommandError("No tag specified to delete.")
5376
5418
        if not tags:
5377
5419
            return
5378
5420
 
5379
 
        self.add_cleanup(branch.lock_read().unlock)
 
5421
        branch.lock_read()
 
5422
        self.add_cleanup(branch.unlock)
5380
5423
        if revision:
5381
5424
            graph = branch.repository.get_graph()
5382
5425
            rev1, rev2 = _get_revision_range(revision, branch, self.name())
5860
5903
 
5861
5904
    def run_for_list(self):
5862
5905
        tree = WorkingTree.open_containing('.')[0]
5863
 
        self.add_cleanup(tree.lock_read().unlock)
 
5906
        tree.lock_read()
 
5907
        self.add_cleanup(tree.unlock)
5864
5908
        manager = tree.get_shelf_manager()
5865
5909
        shelves = manager.active_shelves()
5866
5910
        if len(shelves) == 0: