/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: Martin Pool
  • Date: 2010-04-28 07:03:38 UTC
  • mfrom: (5188 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5189.
  • Revision ID: mbp@sourcefrog.net-20100428070338-2af8y3takgfkrkyp
merge news

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:
2279
2297
                   help='Show changes made in each revision as a patch.'),
2280
2298
            Option('include-merges',
2281
2299
                   help='Show merged revisions like --levels 0 does.'),
2282
 
            Option('exclude-common-ancestry',
2283
 
                   help='Display only the revisions that are not part'
2284
 
                   ' of both ancestries (require -rX..Y)'
2285
 
                   )
2286
2300
            ]
2287
2301
    encoding_type = 'replace'
2288
2302
 
2298
2312
            message=None,
2299
2313
            limit=None,
2300
2314
            show_diff=False,
2301
 
            include_merges=False,
2302
 
            exclude_common_ancestry=False,
2303
 
            ):
 
2315
            include_merges=False):
2304
2316
        from bzrlib.log import (
2305
2317
            Logger,
2306
2318
            make_log_request_dict,
2307
2319
            _get_info_for_log_files,
2308
2320
            )
2309
2321
        direction = (forward and 'forward') or 'reverse'
2310
 
        if (exclude_common_ancestry
2311
 
            and (revision is None or len(revision) != 2)):
2312
 
            raise errors.BzrCommandError(
2313
 
                '--exclude-common-ancestry requires -r with two revisions')
2314
2322
        if include_merges:
2315
2323
            if levels is None:
2316
2324
                levels = 0
2332
2340
        if file_list:
2333
2341
            # find the file ids to log and check for directory filtering
2334
2342
            b, file_info_list, rev1, rev2 = _get_info_for_log_files(
2335
 
                revision, file_list, self.add_cleanup)
 
2343
                revision, file_list)
 
2344
            self.add_cleanup(b.unlock)
2336
2345
            for relpath, file_id, kind in file_info_list:
2337
2346
                if file_id is None:
2338
2347
                    raise errors.BzrCommandError(
2356
2365
                location = '.'
2357
2366
            dir, relpath = bzrdir.BzrDir.open_containing(location)
2358
2367
            b = dir.open_branch()
2359
 
            self.add_cleanup(b.lock_read().unlock)
 
2368
            b.lock_read()
 
2369
            self.add_cleanup(b.unlock)
2360
2370
            rev1, rev2 = _get_revision_range(revision, b, self.name())
2361
2371
 
2362
2372
        # Decide on the type of delta & diff filtering to use
2407
2417
            direction=direction, specific_fileids=file_ids,
2408
2418
            start_revision=rev1, end_revision=rev2, limit=limit,
2409
2419
            message_search=message, delta_type=delta_type,
2410
 
            diff_type=diff_type, _match_using_deltas=match_using_deltas,
2411
 
            exclude_common_ancestry=exclude_common_ancestry,
2412
 
            )
 
2420
            diff_type=diff_type, _match_using_deltas=match_using_deltas)
2413
2421
        Logger(b, rqst).show(lf)
2414
2422
 
2415
2423
 
2486
2494
        tree, relpath = WorkingTree.open_containing(filename)
2487
2495
        file_id = tree.path2id(relpath)
2488
2496
        b = tree.branch
2489
 
        self.add_cleanup(b.lock_read().unlock)
 
2497
        b.lock_read()
 
2498
        self.add_cleanup(b.unlock)
2490
2499
        touching_revs = log.find_touching_revisions(b, file_id)
2491
2500
        for revno, revision_id, what in touching_revs:
2492
2501
            self.outf.write("%6d %s\n" % (revno, what))
2561
2570
                view_str = views.view_display_str(view_files)
2562
2571
                note("Ignoring files outside view. View is %s" % view_str)
2563
2572
 
2564
 
        self.add_cleanup(tree.lock_read().unlock)
 
2573
        tree.lock_read()
 
2574
        self.add_cleanup(tree.unlock)
2565
2575
        for fp, fc, fkind, fid, entry in tree.list_files(include_root=False,
2566
2576
            from_dir=relpath, recursive=recursive):
2567
2577
            # Apply additional masking
2746
2756
    @display_command
2747
2757
    def run(self):
2748
2758
        tree = WorkingTree.open_containing(u'.')[0]
2749
 
        self.add_cleanup(tree.lock_read().unlock)
 
2759
        tree.lock_read()
 
2760
        self.add_cleanup(tree.unlock)
2750
2761
        for path, file_class, kind, file_id, entry in tree.list_files():
2751
2762
            if file_class != 'I':
2752
2763
                continue
2865
2876
                                         " one revision specifier")
2866
2877
        tree, branch, relpath = \
2867
2878
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
2868
 
        self.add_cleanup(branch.lock_read().unlock)
 
2879
        branch.lock_read()
 
2880
        self.add_cleanup(branch.unlock)
2869
2881
        return self._run(tree, branch, relpath, filename, revision,
2870
2882
                         name_from_revision, filters)
2871
2883
 
2874
2886
        if tree is None:
2875
2887
            tree = b.basis_tree()
2876
2888
        rev_tree = _get_one_revision_tree('cat', revision, branch=b)
2877
 
        self.add_cleanup(rev_tree.lock_read().unlock)
 
2889
        rev_tree.lock_read()
 
2890
        self.add_cleanup(rev_tree.unlock)
2878
2891
 
2879
2892
        old_file_id = rev_tree.path2id(relpath)
2880
2893
 
3046
3059
                         "the master branch until a normal commit "
3047
3060
                         "is performed."
3048
3061
                    ),
3049
 
             Option('show-diff', short_name='p',
 
3062
             Option('show-diff',
3050
3063
                    help='When no message is supplied, show the diff along'
3051
3064
                    ' with the status summary in the message editor.'),
3052
3065
             ]
3663
3676
 
3664
3677
        branch1 = Branch.open_containing(branch)[0]
3665
3678
        branch2 = Branch.open_containing(other)[0]
3666
 
        self.add_cleanup(branch1.lock_read().unlock)
3667
 
        self.add_cleanup(branch2.lock_read().unlock)
 
3679
        branch1.lock_read()
 
3680
        self.add_cleanup(branch1.unlock)
 
3681
        branch2.lock_read()
 
3682
        self.add_cleanup(branch2.unlock)
3668
3683
        last1 = ensure_null(branch1.last_revision())
3669
3684
        last2 = ensure_null(branch2.last_revision())
3670
3685
 
3808
3823
            unversioned_filter=tree.is_ignored, view_info=view_info)
3809
3824
        pb = ui.ui_factory.nested_progress_bar()
3810
3825
        self.add_cleanup(pb.finished)
3811
 
        self.add_cleanup(tree.lock_write().unlock)
 
3826
        tree.lock_write()
 
3827
        self.add_cleanup(tree.unlock)
3812
3828
        if location is not None:
3813
3829
            try:
3814
3830
                mergeable = bundle.read_mergeable_from_url(location,
4070
4086
        if merge_type is None:
4071
4087
            merge_type = _mod_merge.Merge3Merger
4072
4088
        tree, file_list = tree_files(file_list)
4073
 
        self.add_cleanup(tree.lock_write().unlock)
 
4089
        tree.lock_write()
 
4090
        self.add_cleanup(tree.unlock)
4074
4091
        parents = tree.get_parent_ids()
4075
4092
        if len(parents) != 2:
4076
4093
            raise errors.BzrCommandError("Sorry, remerge only works after normal"
4186
4203
    def run(self, revision=None, no_backup=False, file_list=None,
4187
4204
            forget_merges=None):
4188
4205
        tree, file_list = tree_files(file_list)
4189
 
        self.add_cleanup(tree.lock_tree_write().unlock)
 
4206
        tree.lock_tree_write()
 
4207
        self.add_cleanup(tree.unlock)
4190
4208
        if forget_merges:
4191
4209
            tree.set_parent_ids(tree.get_parent_ids()[:1])
4192
4210
        else:
4328
4346
            restrict = 'remote'
4329
4347
 
4330
4348
        local_branch = Branch.open_containing(u".")[0]
4331
 
        self.add_cleanup(local_branch.lock_read().unlock)
 
4349
        local_branch.lock_read()
 
4350
        self.add_cleanup(local_branch.unlock)
4332
4351
 
4333
4352
        parent = local_branch.get_parent()
4334
4353
        if other_branch is None:
4345
4364
        if remote_branch.base == local_branch.base:
4346
4365
            remote_branch = local_branch
4347
4366
        else:
4348
 
            self.add_cleanup(remote_branch.lock_read().unlock)
 
4367
            remote_branch.lock_read()
 
4368
            self.add_cleanup(remote_branch.unlock)
4349
4369
 
4350
4370
        local_revid_range = _revision_range_to_revid_range(
4351
4371
            _get_revision_range(my_revision, local_branch,
4406
4426
            message("Branches are up to date.\n")
4407
4427
        self.cleanup_now()
4408
4428
        if not status_code and parent is None and other_branch is not None:
4409
 
            self.add_cleanup(local_branch.lock_write().unlock)
 
4429
            local_branch.lock_write()
 
4430
            self.add_cleanup(local_branch.unlock)
4410
4431
            # handle race conditions - a parent might be set while we run.
4411
4432
            if local_branch.get_parent() is None:
4412
4433
                local_branch.set_parent(remote_branch.base)
4512
4533
            b = Branch.open_containing(branch)[0]
4513
4534
        else:
4514
4535
            b = Branch.open(branch)
4515
 
        self.add_cleanup(b.lock_read().unlock)
 
4536
        b.lock_read()
 
4537
        self.add_cleanup(b.unlock)
4516
4538
        if revision is None:
4517
4539
            rev_id = b.last_revision()
4518
4540
        else:
4552
4574
        wt, branch, relpath = \
4553
4575
            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
4554
4576
        if wt is not None:
4555
 
            self.add_cleanup(wt.lock_read().unlock)
 
4577
            wt.lock_read()
 
4578
            self.add_cleanup(wt.unlock)
4556
4579
        else:
4557
 
            self.add_cleanup(branch.lock_read().unlock)
 
4580
            branch.lock_read()
 
4581
            self.add_cleanup(branch.unlock)
4558
4582
        tree = _get_one_revision_tree('annotate', revision, branch=branch)
4559
 
        self.add_cleanup(tree.lock_read().unlock)
 
4583
        tree.lock_read()
 
4584
        self.add_cleanup(tree.unlock)
4560
4585
        if wt is not None:
4561
4586
            file_id = wt.path2id(relpath)
4562
4587
        else:
4588
4613
        if revision_id_list is None and revision is None:
4589
4614
            raise errors.BzrCommandError('You must supply either --revision or a revision_id')
4590
4615
        b = WorkingTree.open_containing(u'.')[0].branch
4591
 
        self.add_cleanup(b.lock_write().unlock)
 
4616
        b.lock_write()
 
4617
        self.add_cleanup(b.unlock)
4592
4618
        return self._run(b, revision_id_list, revision)
4593
4619
 
4594
4620
    def _run(self, b, revision_id_list, revision):
4641
4667
 
4642
4668
class cmd_bind(Command):
4643
4669
    __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
4670
 
4646
4671
    Once converted into a checkout, commits must succeed on the master branch
4647
4672
    before they will be applied to the local branch.
4744
4769
            b = control.open_branch()
4745
4770
 
4746
4771
        if tree is not None:
4747
 
            self.add_cleanup(tree.lock_write().unlock)
 
4772
            tree.lock_write()
 
4773
            self.add_cleanup(tree.unlock)
4748
4774
        else:
4749
 
            self.add_cleanup(b.lock_write().unlock)
 
4775
            b.lock_write()
 
4776
            self.add_cleanup(b.unlock)
4750
4777
        return self._run(b, tree, dry_run, verbose, revision, force, local=local)
4751
4778
 
4752
4779
    def _run(self, b, tree, dry_run, verbose, revision, force, local=False):
5315
5342
            revision=None,
5316
5343
            ):
5317
5344
        branch, relpath = Branch.open_containing(directory)
5318
 
        self.add_cleanup(branch.lock_write().unlock)
 
5345
        branch.lock_write()
 
5346
        self.add_cleanup(branch.unlock)
5319
5347
        if delete:
5320
5348
            if tag_name is None:
5321
5349
                raise errors.BzrCommandError("No tag specified to delete.")
5376
5404
        if not tags:
5377
5405
            return
5378
5406
 
5379
 
        self.add_cleanup(branch.lock_read().unlock)
 
5407
        branch.lock_read()
 
5408
        self.add_cleanup(branch.unlock)
5380
5409
        if revision:
5381
5410
            graph = branch.repository.get_graph()
5382
5411
            rev1, rev2 = _get_revision_range(revision, branch, self.name())
5860
5889
 
5861
5890
    def run_for_list(self):
5862
5891
        tree = WorkingTree.open_containing('.')[0]
5863
 
        self.add_cleanup(tree.lock_read().unlock)
 
5892
        tree.lock_read()
 
5893
        self.add_cleanup(tree.unlock)
5864
5894
        manager = tree.get_shelf_manager()
5865
5895
        shelves = manager.active_shelves()
5866
5896
        if len(shelves) == 0: