~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

Convert most of the front ends commands to use WorkingTree.open_containing

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
from bzrlib.workingtree import WorkingTree
36
36
 
37
37
 
38
 
def branch_files(file_list, default_branch='.'):
 
38
def tree_files(file_list, default_branch='.'):
39
39
    """\
40
40
    Return a branch and list of branch-relative paths.
41
41
    If supplied file_list is empty or None, the branch default will be used,
42
42
    and returned file_list will match the original.
43
43
    """
44
44
    if file_list is None or len(file_list) == 0:
45
 
        return Branch.open_containing(default_branch)[0], file_list
46
 
    b = Branch.open_containing(file_list[0])[0]
47
 
    
48
 
    # note that if this is a remote branch, we would want
49
 
    # relpath against the transport. RBC 20051018
50
 
    # Most branch ops can't meaningfully operate on files in remote branches;
51
 
    # the above comment was in cmd_status.  ADHB 20051026
52
 
    tree = WorkingTree(b.base, b)
 
45
        return WorkingTree.open_containing(default_branch)[0], file_list
 
46
    tree = WorkingTree.open_containing(file_list[0])[0]
53
47
    new_list = []
54
48
    for filename in file_list:
55
49
        try:
56
50
            new_list.append(tree.relpath(filename))
57
51
        except NotBranchError:
58
 
            raise BzrCommandError("%s is not in the same branch as %s" % 
 
52
            raise BzrCommandError("%s is not in the same tree as %s" % 
59
53
                                  (filename, file_list[0]))
60
 
    return b, new_list
 
54
    return tree, new_list
61
55
 
62
56
 
63
57
# TODO: Make sure no commands unconditionally use the working directory as a
117
111
    
118
112
    @display_command
119
113
    def run(self, all=False, show_ids=False, file_list=None, revision=None):
120
 
        b, file_list = branch_files(file_list)
 
114
        tree, file_list = tree_files(file_list)
121
115
            
122
116
        from bzrlib.status import show_status
123
 
        show_status(b, show_unchanged=all, show_ids=show_ids,
 
117
        show_status(tree.branch, show_unchanged=all, show_ids=show_ids,
124
118
                    specific_files=file_list, revision=revision)
125
119
 
126
120
 
142
136
            raise BzrCommandError('You can only supply one of revision_id or --revision')
143
137
        if revision_id is None and revision is None:
144
138
            raise BzrCommandError('You must supply either --revision or a revision_id')
145
 
        b = Branch.open_containing('.')[0]
 
139
        b = WorkingTree.open_containing('.')[0].branch
146
140
        if revision_id is not None:
147
141
            sys.stdout.write(b.get_revision_xml_file(revision_id).read())
148
142
        elif revision is not None:
180
174
        if len(revs) == 0:
181
175
            raise BzrCommandError('You must supply a revision identifier')
182
176
 
183
 
        b = Branch.open_containing('.')[0]
 
177
        b = WorkingTree.open_containing('.')[0].branch
184
178
 
185
179
        for rev in revs:
186
180
            revinfo = rev.in_history(b)
237
231
        
238
232
        for d in dir_list:
239
233
            os.mkdir(d)
240
 
            b, dd = Branch.open_containing(d)
 
234
            wt, dd = WorkingTree.open_containing(d)
 
235
            b = wt.branch
241
236
            b.add([dd])
242
237
            print 'added', d
243
238
 
249
244
    
250
245
    @display_command
251
246
    def run(self, filename):
252
 
        branch, relpath = Branch.open_containing(filename)
 
247
        tree, relpath = WorkingTree.open_containing(filename)
253
248
        print relpath
254
249
 
255
250
 
259
254
    
260
255
    @display_command
261
256
    def run(self, revision=None, show_ids=False):
262
 
        b = Branch.open_containing('.')[0]
 
257
        tree = WorkingTree.open_containing('.')[0]
263
258
        if revision is None:
264
 
            inv = b.working_tree().read_working_inventory()
 
259
            inv = tree.read_working_inventory()
265
260
        else:
266
261
            if len(revision) > 1:
267
262
                raise BzrCommandError('bzr inventory --revision takes'
268
263
                    ' exactly one revision identifier')
269
 
            inv = b.get_revision_inventory(revision[0].in_history(b).rev_id)
 
264
            inv = tree.branch.get_revision_inventory(
 
265
                revision[0].in_history(tree.branch).rev_id)
270
266
 
271
267
        for path, entry in inv.entries():
272
268
            if show_ids:
285
281
    """
286
282
    takes_args = ['source$', 'dest']
287
283
    def run(self, source_list, dest):
288
 
        b, source_list = branch_files(source_list)
 
284
        tree, source_list = tree_files(source_list)
289
285
 
290
286
        # TODO: glob expansion on windows?
291
 
        tree = WorkingTree(b.base, b)
292
 
        b.move(source_list, tree.relpath(dest))
 
287
        tree.branch.move(source_list, tree.relpath(dest))
293
288
 
294
289
 
295
290
class cmd_rename(Command):
309
304
    takes_args = ['from_name', 'to_name']
310
305
    
311
306
    def run(self, from_name, to_name):
312
 
        b, (from_name, to_name) = branch_files((from_name, to_name))
313
 
        b.rename_one(from_name, to_name)
 
307
        tree, (from_name, to_name) = tree_files((from_name, to_name))
 
308
        tree.branch.rename_one(from_name, to_name)
314
309
 
315
310
 
316
311
class cmd_mv(Command):
330
325
    def run(self, names_list):
331
326
        if len(names_list) < 2:
332
327
            raise BzrCommandError("missing file argument")
333
 
        b, rel_names = branch_files(names_list)
 
328
        tree, rel_names = tree_files(names_list)
334
329
        
335
330
        if os.path.isdir(names_list[-1]):
336
331
            # move into existing directory
337
 
            for pair in b.move(rel_names[:-1], rel_names[-1]):
 
332
            for pair in tree.branch.move(rel_names[:-1], rel_names[-1]):
338
333
                print "%s => %s" % pair
339
334
        else:
340
335
            if len(names_list) != 2:
341
336
                raise BzrCommandError('to mv multiple files the destination '
342
337
                                      'must be a versioned directory')
343
 
            b.rename_one(rel_names[0], rel_names[1])
 
338
            tree.branch.rename_one(rel_names[0], rel_names[1])
344
339
            print "%s => %s" % (rel_names[0], rel_names[1])
345
340
            
346
341
    
370
365
        from shutil import rmtree
371
366
        import errno
372
367
        
373
 
        br_to = Branch.open_containing('.')[0]
374
 
        stored_loc = br_to.get_parent()
 
368
        tree_to = WorkingTree.open_containing('.')[0]
 
369
        stored_loc = tree_to.branch.get_parent()
375
370
        if location is None:
376
371
            if stored_loc is None:
377
372
                raise BzrCommandError("No pull location known or specified.")
380
375
                location = stored_loc
381
376
        br_from = Branch.open(location)
382
377
        try:
383
 
            old_rh = br_to.revision_history()
384
 
            br_to.working_tree().pull(br_from, overwrite)
 
378
            old_rh = tree_to.branch.revision_history()
 
379
            tree_to.pull(br_from, overwrite)
385
380
        except DivergedBranches:
386
381
            raise BzrCommandError("These branches have diverged."
387
382
                                  "  Try merge.")
388
 
        if br_to.get_parent() is None or remember:
389
 
            br_to.set_parent(location)
 
383
        if tree_to.branch.get_parent() is None or remember:
 
384
            tree_to.branch.set_parent(location)
390
385
 
391
386
        if verbose:
392
 
            new_rh = br_to.revision_history()
 
387
            new_rh = tree_to.branch.revision_history()
393
388
            if old_rh != new_rh:
394
389
                # Something changed
395
390
                from bzrlib.log import show_changed_revisions
396
 
                show_changed_revisions(br_to, old_rh, new_rh)
 
391
                show_changed_revisions(tree_to.branch, old_rh, new_rh)
397
392
 
398
393
 
399
394
class cmd_push(Command):
431
426
        from shutil import rmtree
432
427
        from bzrlib.transport import get_transport
433
428
        
434
 
        br_from = Branch.open_containing('.')[0]
435
 
        stored_loc = br_from.get_push_location()
 
429
        tree_from = WorkingTree.open_containing('.')[0]
 
430
        stored_loc = tree_from.branch.get_push_location()
436
431
        if location is None:
437
432
            if stored_loc is None:
438
433
                raise BzrCommandError("No push location known or specified.")
470
465
            br_to = Branch.initialize(location)
471
466
        try:
472
467
            old_rh = br_to.revision_history()
473
 
            br_to.pull(br_from, overwrite)
 
468
            br_to.pull(tree_from.branch, overwrite)
474
469
        except DivergedBranches:
475
470
            raise BzrCommandError("These branches have diverged."
476
471
                                  "  Try a merge then push with overwrite.")
477
 
        if br_from.get_push_location() is None or remember:
478
 
            br_from.set_push_location(location)
 
472
        if tree_from.branch.get_push_location() is None or remember:
 
473
            tree_from.branch.set_push_location(location)
479
474
 
480
475
        if verbose:
481
476
            new_rh = br_to.revision_history()
484
479
                from bzrlib.log import show_changed_revisions
485
480
                show_changed_revisions(br_to, old_rh, new_rh)
486
481
 
 
482
 
487
483
class cmd_branch(Command):
488
484
    """Create a new copy of a branch.
489
485
 
521
517
        br_from.lock_read()
522
518
        try:
523
519
            if basis is not None:
524
 
                basis_branch = Branch.open_containing(basis)[0]
 
520
                basis_branch = WorkingTree.open_containing(basis)[0].branch
525
521
            else:
526
522
                basis_branch = None
527
523
            if len(revision) == 1 and revision[0] is not None:
572
568
 
573
569
    @display_command
574
570
    def run(self, dir='.'):
575
 
        b = Branch.open_containing(dir)[0]
576
 
        old_inv = b.basis_tree().inventory
577
 
        new_inv = b.working_tree().read_working_inventory()
 
571
        tree = WorkingTree.open_containing(dir)[0]
 
572
        old_inv = tree.branch.basis_tree().inventory
 
573
        new_inv = tree.read_working_inventory()
578
574
 
579
575
        renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
580
576
        renames.sort()
589
585
    @display_command
590
586
    def run(self, branch=None):
591
587
        import info
592
 
        b = Branch.open_containing(branch)[0]
 
588
        b = WorkingTree.open_containing(branch)[0].branch
593
589
        info.show_info(b)
594
590
 
595
591
 
604
600
    aliases = ['rm']
605
601
    
606
602
    def run(self, file_list, verbose=False):
607
 
        b, file_list = branch_files(file_list)
608
 
        tree = b.working_tree()
 
603
        tree, file_list = tree_files(file_list)
609
604
        tree.remove(file_list, verbose=verbose)
610
605
 
611
606
 
620
615
    takes_args = ['filename']
621
616
    @display_command
622
617
    def run(self, filename):
623
 
        b, relpath = Branch.open_containing(filename)
624
 
        i = b.inventory.path2id(relpath)
 
618
        tree, relpath = WorkingTree.open_containing(filename)
 
619
        i = tree.inventory.path2id(relpath)
625
620
        if i == None:
626
621
            raise BzrError("%r is not a versioned file" % filename)
627
622
        else:
637
632
    takes_args = ['filename']
638
633
    @display_command
639
634
    def run(self, filename):
640
 
        b, relpath = Branch.open_containing(filename)
641
 
        inv = b.inventory
 
635
        tree, relpath = WorkingTree.open_containing(filename)
 
636
        inv = tree.inventory
642
637
        fid = inv.path2id(relpath)
643
638
        if fid == None:
644
639
            raise BzrError("%r is not a versioned file" % filename)
651
646
    hidden = True
652
647
    @display_command
653
648
    def run(self):
654
 
        for patchid in Branch.open_containing('.')[0].revision_history():
 
649
        branch = WorkingTree.open_containing('.')[0].branch
 
650
        for patchid in branch.revision_history():
655
651
            print patchid
656
652
 
657
653
 
660
656
    hidden = True
661
657
    @display_command
662
658
    def run(self):
663
 
        b = Branch.open_containing('.')[0]
 
659
        tree = WorkingTree.open_containing('.')[0]
 
660
        b = tree.branch
 
661
        # FIXME. should be tree.last_revision
664
662
        for revision_id in b.get_ancestry(b.last_revision()):
665
663
            print revision_id
666
664
 
667
665
 
668
666
class cmd_directories(Command):
669
 
    """Display list of versioned directories in this branch."""
 
667
    """Display list of versioned directories in this tree."""
670
668
    @display_command
671
669
    def run(self):
672
 
        for name, ie in (Branch.open_containing('.')[0].working_tree().
 
670
        for name, ie in (WorkingTree.open_containing('.')[0].
673
671
                         read_working_inventory().directories()):
674
672
            if name == '':
675
673
                print '.'
739
737
    def run(self, revision=None, file_list=None, diff_options=None):
740
738
        from bzrlib.diff import show_diff
741
739
        
742
 
        b, file_list = branch_files(file_list)
 
740
        tree, file_list = tree_files(file_list)
743
741
        if revision is not None:
744
742
            if len(revision) == 1:
745
 
                return show_diff(b, revision[0], specific_files=file_list,
 
743
                return show_diff(tree.branch, revision[0], specific_files=file_list,
746
744
                                 external_diff_options=diff_options)
747
745
            elif len(revision) == 2:
748
 
                return show_diff(b, revision[0], specific_files=file_list,
 
746
                return show_diff(tree.branch, revision[0], specific_files=file_list,
749
747
                                 external_diff_options=diff_options,
750
748
                                 revision2=revision[1])
751
749
            else:
752
750
                raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
753
751
        else:
754
 
            return show_diff(b, None, specific_files=file_list,
 
752
            return show_diff(tree.branch, None, specific_files=file_list,
755
753
                             external_diff_options=diff_options)
756
754
 
757
755
 
766
764
    # if the directories are very large...)
767
765
    @display_command
768
766
    def run(self, show_ids=False):
769
 
        b = Branch.open_containing('.')[0]
770
 
        old = b.basis_tree()
771
 
        new = b.working_tree()
 
767
        tree = WorkingTree.open_containing('.')[0]
 
768
        old = tree.branch.basis_tree()
772
769
        for path, ie in old.inventory.iter_entries():
773
 
            if not new.has_id(ie.file_id):
 
770
            if not tree.has_id(ie.file_id):
774
771
                if show_ids:
775
772
                    print '%-50s %s' % (path, ie.file_id)
776
773
                else:
784
781
    def run(self):
785
782
        from bzrlib.delta import compare_trees
786
783
 
787
 
        b = Branch.open_containing('.')[0]
788
 
        td = compare_trees(b.basis_tree(), b.working_tree())
 
784
        tree = WorkingTree.open_containing('.')[0]
 
785
        td = compare_trees(tree.branch.basis_tree(), tree)
789
786
 
790
787
        for path, id, kind, text_modified, meta_modified in td.modified:
791
788
            print path
797
794
    hidden = True
798
795
    @display_command
799
796
    def run(self):
800
 
        b = Branch.open_containing('.')[0]
801
 
        wt = b.working_tree()
802
 
        basis_inv = b.basis_tree().inventory
 
797
        wt = WorkingTree.open_containing('.')[0]
 
798
        basis_inv = wt.branch.basis_tree().inventory
803
799
        inv = wt.inventory
804
800
        for file_id in inv:
805
801
            if file_id in basis_inv:
820
816
    @display_command
821
817
    def run(self, filename=None):
822
818
        """Print the branch root."""
823
 
        b = Branch.open_containing(filename)[0]
824
 
        print b.base
 
819
        tree = WorkingTree.open_containing(filename)[0]
 
820
        print tree.basedir
825
821
 
826
822
 
827
823
class cmd_log(Command):
863
859
        direction = (forward and 'forward') or 'reverse'
864
860
        
865
861
        if filename:
866
 
            b, fp = Branch.open_containing(filename)
 
862
            # might be a tree:
 
863
            tree = None
 
864
            try:
 
865
                tree, fp = WorkingTree.open_containing(filename)
 
866
                b = tree.branch
 
867
                if fp != '':
 
868
                    inv = tree.read_working_inventory()
 
869
            except NotBranchError:
 
870
                pass
 
871
            if tree is None:
 
872
                b, fp = Branch.open_containing(filename)
 
873
                if fp != '':
 
874
                    inv = b.get_inventory(b.last_revision())
867
875
            if fp != '':
868
 
                try:
869
 
                    inv = b.working_tree().read_working_inventory()
870
 
                except NoWorkingTree:
871
 
                    inv = b.get_inventory(b.last_revision())
872
876
                file_id = inv.path2id(fp)
873
877
            else:
874
878
                file_id = None  # points to branch root
875
879
        else:
876
 
            b, relpath = Branch.open_containing('.')
 
880
            tree, relpath = WorkingTree.open_containing('.')
 
881
            b = tree.branch
877
882
            file_id = None
878
883
 
879
884
        if revision is None:
927
932
    takes_args = ["filename"]
928
933
    @display_command
929
934
    def run(self, filename):
930
 
        b, relpath = Branch.open_containing(filename)[0]
931
 
        inv = b.working_tree().read_working_inventory()
 
935
        tree, relpath = WorkingTree.open_containing(filename)
 
936
        b = tree.branch
 
937
        inv = tree.read_working_inventory()
932
938
        file_id = inv.path2id(relpath)
933
939
        for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
934
940
            print "%6d %s" % (revno, what)
962
968
 
963
969
        selection = {'I':ignored, '?':unknown, 'V':versioned}
964
970
 
965
 
        b, relpath = Branch.open_containing('.')
 
971
        tree, relpath = WorkingTree.open_containing('.')
966
972
        if from_root:
967
973
            relpath = ''
968
974
        elif relpath:
969
975
            relpath += '/'
970
 
        if revision == None:
971
 
            tree = b.working_tree()
972
 
        else:
973
 
            tree = b.revision_tree(revision[0].in_history(b).rev_id)
 
976
        if revision is not None:
 
977
            tree = tree.branch.revision_tree(
 
978
                revision[0].in_history(tree.branch).rev_id)
974
979
        for fp, fc, kind, fid, entry in tree.list_files():
975
980
            if fp.startswith(relpath):
976
981
                fp = fp[len(relpath):]
989
994
                    print fp
990
995
 
991
996
 
992
 
 
993
997
class cmd_unknowns(Command):
994
998
    """List unknown files."""
995
999
    @display_command
996
1000
    def run(self):
997
1001
        from bzrlib.osutils import quotefn
998
 
        for f in Branch.open_containing('.')[0].unknowns():
 
1002
        for f in WorkingTree.open_containing('.')[0].branch.unknowns():
999
1003
            print quotefn(f)
1000
1004
 
1001
1005
 
1002
 
 
1003
1006
class cmd_ignore(Command):
1004
1007
    """Ignore a command or pattern.
1005
1008
 
1025
1028
        from bzrlib.atomicfile import AtomicFile
1026
1029
        import os.path
1027
1030
 
1028
 
        b, relpath = Branch.open_containing('.')
1029
 
        ifn = b.abspath('.bzrignore')
 
1031
        tree, relpath = WorkingTree.open_containing('.')
 
1032
        ifn = tree.abspath('.bzrignore')
1030
1033
 
1031
1034
        if os.path.exists(ifn):
1032
1035
            f = open(ifn, 'rt')
1051
1054
        finally:
1052
1055
            f.close()
1053
1056
 
1054
 
        inv = b.working_tree().inventory
 
1057
        inv = tree.inventory
1055
1058
        if inv.path2id('.bzrignore'):
1056
1059
            mutter('.bzrignore is already versioned')
1057
1060
        else:
1058
1061
            mutter('need to make new .bzrignore file versioned')
1059
 
            b.add(['.bzrignore'])
1060
 
 
 
1062
            tree.branch.add(['.bzrignore'])
1061
1063
 
1062
1064
 
1063
1065
class cmd_ignored(Command):
1066
1068
    See also: bzr ignore"""
1067
1069
    @display_command
1068
1070
    def run(self):
1069
 
        tree = Branch.open_containing('.')[0].working_tree()
 
1071
        tree = WorkingTree.open_containing('.')[0]
1070
1072
        for path, file_class, kind, file_id, entry in tree.list_files():
1071
1073
            if file_class != 'I':
1072
1074
                continue
1091
1093
        except ValueError:
1092
1094
            raise BzrCommandError("not a valid revision-number: %r" % revno)
1093
1095
 
1094
 
        print Branch.open_containing('.')[0].get_rev_id(revno)
 
1096
        print WorkingTree.open_containing('.')[0].branch.get_rev_id(revno)
1095
1097
 
1096
1098
 
1097
1099
class cmd_export(Command):
1110
1112
    takes_options = ['revision', 'format', 'root']
1111
1113
    def run(self, dest, revision=None, format=None, root=None):
1112
1114
        import os.path
1113
 
        b = Branch.open_containing('.')[0]
 
1115
        tree = WorkingTree.open_containing('.')[0]
 
1116
        b = tree.branch
1114
1117
        if revision is None:
1115
 
            rev_id = b.last_revision()
 
1118
            # should be tree.last_revision  FIXME
 
1119
            rev_id = tree.branch.last_revision()
1116
1120
        else:
1117
1121
            if len(revision) != 1:
1118
1122
                raise BzrError('bzr export --revision takes exactly 1 argument')
1150
1154
            raise BzrCommandError("bzr cat requires a revision number")
1151
1155
        elif len(revision) != 1:
1152
1156
            raise BzrCommandError("bzr cat --revision takes exactly one number")
1153
 
        b, relpath = Branch.open_containing(filename)
 
1157
        tree = None
 
1158
        try:
 
1159
            tree, relpath = WorkingTree.open_containing(filename)
 
1160
            b = tree.branch
 
1161
        except NotBranchError:
 
1162
            pass
 
1163
        if tree is None:
 
1164
            b, relpath = Branch.open_containing(filename)
1154
1165
        b.print_file(relpath, revision[0].in_history(b).revno)
1155
1166
 
1156
1167
 
1206
1217
        from bzrlib.status import show_status
1207
1218
        from cStringIO import StringIO
1208
1219
 
1209
 
        b, selected_list = branch_files(selected_list)
 
1220
        tree, selected_list = tree_files(selected_list)
1210
1221
        if message is None and not file:
1211
1222
            catcher = StringIO()
1212
 
            show_status(b, specific_files=selected_list,
 
1223
            show_status(tree.branch, specific_files=selected_list,
1213
1224
                        to_file=catcher)
1214
1225
            message = edit_commit_message(catcher.getvalue())
1215
1226
 
1227
1238
                raise BzrCommandError("empty commit message specified")
1228
1239
            
1229
1240
        try:
1230
 
            b.working_tree().commit(message, specific_files=selected_list,
1231
 
                     allow_pointless=unchanged, strict=strict)
 
1241
            tree.commit(message, specific_files=selected_list,
 
1242
                        allow_pointless=unchanged, strict=strict)
1232
1243
        except PointlessCommit:
1233
1244
            # FIXME: This should really happen before the file is read in;
1234
1245
            # perhaps prepare the commit; get the message; then actually commit
1253
1264
 
1254
1265
    def run(self, dir='.', verbose=False):
1255
1266
        from bzrlib.check import check
1256
 
        check(Branch.open_containing(dir)[0], verbose)
 
1267
        check(WorkingTree.open_containing(dir)[0].branch, verbose)
1257
1268
 
1258
1269
 
1259
1270
class cmd_scan_cache(Command):
1299
1310
    @display_command
1300
1311
    def run(self, email=False):
1301
1312
        try:
1302
 
            b = bzrlib.branch.Branch.open_containing('.')[0]
 
1313
            b = WorkingTree.open_containing('.')[0].branch
1303
1314
            config = bzrlib.config.BranchConfig(b)
1304
1315
        except NotBranchError:
1305
1316
            config = bzrlib.config.GlobalConfig()
1461
1472
        if merge_type is None:
1462
1473
            merge_type = ApplyMerge3
1463
1474
        if branch is None:
1464
 
            branch = Branch.open_containing('.')[0].get_parent()
 
1475
            branch = WorkingTree.open_containing('.')[0].branch.get_parent()
1465
1476
            if branch is None:
1466
1477
                raise BzrCommandError("No merge location known or specified.")
1467
1478
            else:
1524
1535
            file_list = []
1525
1536
        if revision is None:
1526
1537
            revno = -1
1527
 
            b = Branch.open_containing('.')[0]
1528
 
            rev_id = b.last_revision()
 
1538
            tree = WorkingTree.open_containing('.')[0]
 
1539
            # FIXME should be tree.last_revision
 
1540
            rev_id = tree.branch.last_revision()
1529
1541
        elif len(revision) != 1:
1530
1542
            raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1531
1543
        else:
1532
 
            b, file_list = branch_files(file_list)
1533
 
            rev_id = revision[0].in_history(b).rev_id
1534
 
        b.working_tree().revert(file_list, b.revision_tree(rev_id),
 
1544
            tree, file_list = tree_files(file_list)
 
1545
            rev_id = revision[0].in_history(tree.branch).rev_id
 
1546
        tree.revert(file_list, tree.branch.revision_tree(rev_id),
1535
1547
                                not no_backup)
1536
1548
 
1537
1549
 
1614
1626
        if verbose and quiet:
1615
1627
            raise BzrCommandError('Cannot pass both quiet and verbose')
1616
1628
 
1617
 
        b = Branch.open_containing('.')[0]
1618
 
        parent = b.get_parent()
 
1629
        tree = WorkingTree.open_containing('.')[0]
 
1630
        parent = tree.branch.get_parent()
1619
1631
        if remote is None:
1620
1632
            if parent is None:
1621
1633
                raise BzrCommandError("No missing location known or specified.")
1626
1638
        elif parent is None:
1627
1639
            # We only update parent if it did not exist, missing
1628
1640
            # should not change the parent
1629
 
            b.set_parent(remote)
 
1641
            tree.branch.set_parent(remote)
1630
1642
        br_remote = Branch.open_containing(remote)[0]
1631
 
        return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
 
1643
        return show_missing(tree.branch, br_remote, verbose=verbose, quiet=quiet)
1632
1644
 
1633
1645
 
1634
1646
class cmd_plugins(Command):
1658
1670
    @display_command
1659
1671
    def run(self, branch='.', revision=None, long=False):
1660
1672
        from bzrlib.testament import Testament
1661
 
        b = Branch.open_containing(branch)[0]
 
1673
        b = WorkingTree.open_containing(branch)[0].branch
1662
1674
        b.lock_read()
1663
1675
        try:
1664
1676
            if revision is None:
1696
1708
    @display_command
1697
1709
    def run(self, filename, all=False, long=False):
1698
1710
        from bzrlib.annotate import annotate_file
1699
 
        b, relpath = Branch.open_containing(filename)
1700
 
        b.lock_read()
 
1711
        tree, relpath = WorkingTree.open_containing(filename)
 
1712
        branch = tree.branch
 
1713
        branch.lock_read()
1701
1714
        try:
1702
 
            tree = WorkingTree(b.base, b)
1703
 
            tree = b.revision_tree(b.last_revision())
1704
1715
            file_id = tree.inventory.path2id(relpath)
 
1716
            tree = branch.revision_tree(branch.last_revision())
1705
1717
            file_version = tree.inventory[file_id].revision
1706
 
            annotate_file(b, file_version, file_id, long, all, sys.stdout)
 
1718
            annotate_file(branch, file_version, file_id, long, all, sys.stdout)
1707
1719
        finally:
1708
 
            b.unlock()
 
1720
            branch.unlock()
1709
1721
 
1710
1722
 
1711
1723
class cmd_re_sign(Command):
1723
1735
            raise BzrCommandError('You can only supply one of revision_id or --revision')
1724
1736
        if revision_id is None and revision is None:
1725
1737
            raise BzrCommandError('You must supply either --revision or a revision_id')
1726
 
        b = Branch.open_containing('.')[0]
 
1738
        b = WorkingTree.open_containing('.')[0].branch
1727
1739
        gpg_strategy = gpg.GPGStrategy(config.BranchConfig(b))
1728
1740
        if revision_id is not None:
1729
1741
            b.sign_revision(revision_id, gpg_strategy)