~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: John Arbash Meinel
  • Date: 2005-09-15 21:35:53 UTC
  • mfrom: (907.1.57)
  • mto: (1393.2.1)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: john@arbash-meinel.com-20050915213552-a6c83a5ef1e20897
(broken) Transport work is merged in. Tests do not pass yet.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import bzrlib
22
22
import bzrlib.trace
23
23
from bzrlib.trace import mutter, note, log_error, warning
24
 
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError, NotBranchError
25
 
from bzrlib.branch import Branch
 
24
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError
 
25
from bzrlib.branch import find_branch
26
26
from bzrlib import BZRDIR
27
27
from bzrlib.commands import Command
28
28
 
62
62
    directory is shown.  Otherwise, only the status of the specified
63
63
    files or directories is reported.  If a directory is given, status
64
64
    is reported for everything inside that directory.
65
 
 
66
 
    If a revision argument is given, the status is calculated against
67
 
    that revision, or between two revisions if two are provided.
68
65
    """
69
66
    # XXX: FIXME: bzr status should accept a -r option to show changes
70
67
    # relative to a revision, or between revisions
73
70
    takes_options = ['all', 'show-ids']
74
71
    aliases = ['st', 'stat']
75
72
    
76
 
    def run(self, all=False, show_ids=False, file_list=None, revision=None):
 
73
    def run(self, all=False, show_ids=False, file_list=None):
77
74
        if file_list:
78
 
            b = Branch.open_containing(file_list[0])
 
75
            b = find_branch(file_list[0])
79
76
            file_list = [b.relpath(x) for x in file_list]
80
77
            # special case: only one path was given and it's the root
81
78
            # of the branch
82
79
            if file_list == ['']:
83
80
                file_list = None
84
81
        else:
85
 
            b = Branch.open_containing('.')
 
82
            b = find_branch('.')
86
83
            
87
84
        from bzrlib.status import show_status
88
85
        show_status(b, show_unchanged=all, show_ids=show_ids,
89
 
                    specific_files=file_list, revision=revision)
 
86
                    specific_files=file_list)
90
87
 
91
88
 
92
89
class cmd_cat_revision(Command):
93
 
    """Write out metadata for a revision.
94
 
    
95
 
    The revision to print can either be specified by a specific
96
 
    revision identifier, or you can use --revision.
97
 
    """
 
90
    """Write out metadata for a revision."""
98
91
 
99
92
    hidden = True
100
 
    takes_args = ['revision_id?']
101
 
    takes_options = ['revision']
 
93
    takes_args = ['revision_id']
102
94
    
103
 
    def run(self, revision_id=None, revision=None):
104
 
        from bzrlib.revisionspec import RevisionSpec
 
95
    def run(self, revision_id):
 
96
        b = find_branch('.')
 
97
        sys.stdout.write(b.get_revision_xml_file(revision_id).read())
105
98
 
106
 
        if revision_id is not None and revision is not None:
107
 
            raise BzrCommandError('You can only supply one of revision_id or --revision')
108
 
        if revision_id is None and revision is None:
109
 
            raise BzrCommandError('You must supply either --revision or a revision_id')
110
 
        b = Branch.open_containing('.')
111
 
        if revision_id is not None:
112
 
            sys.stdout.write(b.get_revision_xml_file(revision_id).read())
113
 
        elif revision is not None:
114
 
            for rev in revision:
115
 
                if rev is None:
116
 
                    raise BzrCommandError('You cannot specify a NULL revision.')
117
 
                revno, rev_id = rev.in_history(b)
118
 
                sys.stdout.write(b.get_revision_xml_file(rev_id).read())
119
 
    
120
99
 
121
100
class cmd_revno(Command):
122
101
    """Show current revision number.
123
102
 
124
103
    This is equal to the number of revisions on this branch."""
125
104
    def run(self):
126
 
        print Branch.open_containing('.').revno()
 
105
        print find_branch('.').revno()
127
106
 
128
107
 
129
108
class cmd_revision_info(Command):
132
111
    hidden = True
133
112
    takes_args = ['revision_info*']
134
113
    takes_options = ['revision']
135
 
    def run(self, revision=None, revision_info_list=[]):
136
 
        from bzrlib.revisionspec import RevisionSpec
 
114
    def run(self, revision=None, revision_info_list=None):
 
115
        from bzrlib.branch import find_branch
137
116
 
138
117
        revs = []
139
118
        if revision is not None:
140
119
            revs.extend(revision)
141
120
        if revision_info_list is not None:
142
 
            for rev in revision_info_list:
143
 
                revs.append(RevisionSpec(rev))
 
121
            revs.extend(revision_info_list)
144
122
        if len(revs) == 0:
145
123
            raise BzrCommandError('You must supply a revision identifier')
146
124
 
147
 
        b = Branch.open_containing('.')
 
125
        b = find_branch('.')
148
126
 
149
127
        for rev in revs:
150
 
            revinfo = rev.in_history(b)
151
 
            if revinfo.revno is None:
152
 
                print '     %s' % revinfo.rev_id
153
 
            else:
154
 
                print '%4d %s' % (revinfo.revno, revinfo.rev_id)
 
128
            print '%4d %s' % b.get_revision_info(rev)
155
129
 
156
130
    
157
131
class cmd_add(Command):
200
174
        for d in dir_list:
201
175
            os.mkdir(d)
202
176
            if not b:
203
 
                b = Branch.open_containing(d)
 
177
                b = find_branch(d)
204
178
            b.add([d])
205
179
            print 'added', d
206
180
 
211
185
    hidden = True
212
186
    
213
187
    def run(self, filename):
214
 
        print Branch.open_containing(filename).relpath(filename)
 
188
        print find_branch(filename).relpath(filename)
215
189
 
216
190
 
217
191
 
220
194
    takes_options = ['revision', 'show-ids']
221
195
    
222
196
    def run(self, revision=None, show_ids=False):
223
 
        b = Branch.open_containing('.')
224
 
        if revision is None:
 
197
        b = find_branch('.')
 
198
        if revision == None:
225
199
            inv = b.read_working_inventory()
226
200
        else:
227
201
            if len(revision) > 1:
228
202
                raise BzrCommandError('bzr inventory --revision takes'
229
203
                    ' exactly one revision identifier')
230
 
            inv = b.get_revision_inventory(revision[0].in_history(b).rev_id)
 
204
            inv = b.get_revision_inventory(b.lookup_revision(revision[0]))
231
205
 
232
206
        for path, entry in inv.entries():
233
207
            if show_ids:
246
220
    """
247
221
    takes_args = ['source$', 'dest']
248
222
    def run(self, source_list, dest):
249
 
        b = Branch.open_containing('.')
 
223
        b = find_branch('.')
250
224
 
251
225
        # TODO: glob expansion on windows?
252
226
        b.move([b.relpath(s) for s in source_list], b.relpath(dest))
269
243
    takes_args = ['from_name', 'to_name']
270
244
    
271
245
    def run(self, from_name, to_name):
272
 
        b = Branch.open_containing('.')
 
246
        b = find_branch('.')
273
247
        b.rename_one(b.relpath(from_name), b.relpath(to_name))
274
248
 
275
249
 
291
265
    def run(self, names_list):
292
266
        if len(names_list) < 2:
293
267
            raise BzrCommandError("missing file argument")
294
 
        b = Branch.open_containing(names_list[0])
 
268
        b = find_branch(names_list[0])
295
269
 
296
270
        rel_names = [b.relpath(x) for x in names_list]
297
271
        
331
305
        from shutil import rmtree
332
306
        import errno
333
307
        
334
 
        br_to = Branch.open_containing('.')
 
308
        br_to = find_branch('.')
335
309
        stored_loc = br_to.get_parent()
336
310
        if location is None:
337
311
            if stored_loc is None:
340
314
                print "Using last location: %s" % stored_loc
341
315
                location = stored_loc
342
316
        cache_root = tempfile.mkdtemp()
343
 
        from bzrlib.errors import DivergedBranches
344
 
        br_from = Branch.open_containing(location)
 
317
        from bzrlib.branch import DivergedBranches
 
318
        br_from = find_branch(location)
345
319
        location = br_from.base
346
320
        old_revno = br_to.revno()
347
321
        try:
348
 
            from bzrlib.errors import DivergedBranches
349
 
            br_from = Branch.open(location)
350
 
            br_from.setup_caching(cache_root)
 
322
            from branch import find_cached_branch, DivergedBranches
 
323
            br_from = find_cached_branch(location, cache_root)
351
324
            location = br_from.base
352
325
            old_revno = br_to.revno()
353
326
            try:
372
345
 
373
346
    To retrieve the branch as of a particular revision, supply the --revision
374
347
    parameter, as in "branch foo/bar -r 5".
375
 
 
376
 
    --basis is to speed up branching from remote branches.  When specified, it
377
 
    copies all the file-contents, inventory and revision data from the basis
378
 
    branch before copying anything from the remote branch.
379
348
    """
380
349
    takes_args = ['from_location', 'to_location?']
381
 
    takes_options = ['revision', 'basis']
 
350
    takes_options = ['revision']
382
351
    aliases = ['get', 'clone']
383
352
 
384
 
    def run(self, from_location, to_location=None, revision=None, basis=None):
385
 
        from bzrlib.clone import copy_branch
 
353
    def run(self, from_location, to_location=None, revision=None):
 
354
        from bzrlib.branch import copy_branch, find_cached_branch
386
355
        import tempfile
387
356
        import errno
388
357
        from shutil import rmtree
394
363
                raise BzrCommandError(
395
364
                    'bzr branch --revision takes exactly 1 revision value')
396
365
            try:
397
 
                br_from = Branch.open(from_location)
 
366
                br_from = find_cached_branch(from_location, cache_root)
398
367
            except OSError, e:
399
368
                if e.errno == errno.ENOENT:
400
369
                    raise BzrCommandError('Source location "%s" does not'
401
370
                                          ' exist.' % to_location)
402
371
                else:
403
372
                    raise
404
 
            br_from.setup_caching(cache_root)
405
 
            if basis is not None:
406
 
                basis_branch = Branch.open_containing(basis)
407
 
            else:
408
 
                basis_branch = None
409
 
            if len(revision) == 1 and revision[0] is not None:
410
 
                revision_id = revision[0].in_history(br_from)[1]
411
 
            else:
412
 
                revision_id = None
413
373
            if to_location is None:
414
374
                to_location = os.path.basename(from_location.rstrip("/\\"))
415
375
            try:
424
384
                else:
425
385
                    raise
426
386
            try:
427
 
                copy_branch(br_from, to_location, revision_id, basis_branch)
 
387
                copy_branch(br_from, to_location, revision[0])
428
388
            except bzrlib.errors.NoSuchRevision:
429
389
                rmtree(to_location)
430
390
                msg = "The branch %s has no revision %d." % (from_location, revision[0])
431
391
                raise BzrCommandError(msg)
432
 
            except bzrlib.errors.UnlistableBranch:
433
 
                msg = "The branch %s cannot be used as a --basis"
434
392
        finally:
435
393
            rmtree(cache_root)
436
394
 
445
403
    takes_args = ['dir?']
446
404
 
447
405
    def run(self, dir='.'):
448
 
        b = Branch.open_containing(dir)
 
406
        b = find_branch(dir)
449
407
        old_inv = b.basis_tree().inventory
450
408
        new_inv = b.read_working_inventory()
451
409
 
462
420
    def run(self, branch=None):
463
421
        import info
464
422
 
465
 
        b = Branch.open_containing(branch)
 
423
        b = find_branch(branch)
466
424
        info.show_info(b)
467
425
 
468
426
 
476
434
    takes_options = ['verbose']
477
435
    
478
436
    def run(self, file_list, verbose=False):
479
 
        b = Branch.open_containing(file_list[0])
 
437
        b = find_branch(file_list[0])
480
438
        b.remove([b.relpath(f) for f in file_list], verbose=verbose)
481
439
 
482
440
 
490
448
    hidden = True
491
449
    takes_args = ['filename']
492
450
    def run(self, filename):
493
 
        b = Branch.open_containing(filename)
 
451
        b = find_branch(filename)
494
452
        i = b.inventory.path2id(b.relpath(filename))
495
453
        if i == None:
496
454
            raise BzrError("%r is not a versioned file" % filename)
506
464
    hidden = True
507
465
    takes_args = ['filename']
508
466
    def run(self, filename):
509
 
        b = Branch.open_containing(filename)
 
467
        b = find_branch(filename)
510
468
        inv = b.inventory
511
469
        fid = inv.path2id(b.relpath(filename))
512
470
        if fid == None:
519
477
    """Display list of revision ids on this branch."""
520
478
    hidden = True
521
479
    def run(self):
522
 
        for patchid in Branch.open_containing('.').revision_history():
 
480
        for patchid in find_branch('.').revision_history():
523
481
            print patchid
524
482
 
525
483
 
526
 
class cmd_ancestry(Command):
527
 
    """List all revisions merged into this branch."""
528
 
    hidden = True
529
 
    def run(self):
530
 
        b = find_branch('.')
531
 
        for revision_id in b.get_ancestry(b.last_revision()):
532
 
            print revision_id
533
 
 
534
 
 
535
484
class cmd_directories(Command):
536
485
    """Display list of versioned directories in this branch."""
537
486
    def run(self):
538
 
        for name, ie in Branch.open_containing('.').read_working_inventory().directories():
 
487
        for name, ie in find_branch('.').read_working_inventory().directories():
539
488
            if name == '':
540
489
                print '.'
541
490
            else:
556
505
        bzr commit -m 'imported project'
557
506
    """
558
507
    def run(self):
559
 
        Branch.initialize('.')
 
508
        from bzrlib.branch import Branch
 
509
        Branch('.', init=True)
560
510
 
561
511
 
562
512
class cmd_diff(Command):
594
544
        from bzrlib.diff import show_diff
595
545
 
596
546
        if file_list:
597
 
            b = Branch.open_containing(file_list[0])
 
547
            b = find_branch(file_list[0])
598
548
            file_list = [b.relpath(f) for f in file_list]
599
549
            if file_list == ['']:
600
550
                # just pointing to top-of-tree
601
551
                file_list = None
602
552
        else:
603
 
            b = Branch.open_containing('.')
 
553
            b = find_branch('.')
604
554
 
605
555
        if revision is not None:
606
556
            if len(revision) == 1:
625
575
    TODO: Show files deleted since a previous revision, or between two revisions.
626
576
    """
627
577
    def run(self, show_ids=False):
628
 
        b = Branch.open_containing('.')
 
578
        b = find_branch('.')
629
579
        old = b.basis_tree()
630
580
        new = b.working_tree()
631
581
 
648
598
    def run(self):
649
599
        from bzrlib.delta import compare_trees
650
600
 
651
 
        b = Branch.open_containing('.')
 
601
        b = find_branch('.')
652
602
        td = compare_trees(b.basis_tree(), b.working_tree())
653
603
 
654
 
        for path, id, kind, text_modified, meta_modified in td.modified:
 
604
        for path, id, kind in td.modified:
655
605
            print path
656
606
 
657
607
 
660
610
    """List files added in working tree."""
661
611
    hidden = True
662
612
    def run(self):
663
 
        b = Branch.open_containing('.')
 
613
        b = find_branch('.')
664
614
        wt = b.working_tree()
665
615
        basis_inv = b.basis_tree().inventory
666
616
        inv = wt.inventory
682
632
    takes_args = ['filename?']
683
633
    def run(self, filename=None):
684
634
        """Print the branch root."""
685
 
        b = Branch.open_containing(filename)
 
635
        b = find_branch(filename)
686
636
        print b.base
687
637
 
688
638
 
695
645
 
696
646
    --message allows you to give a regular expression, which will be evaluated
697
647
    so that only matching entries will be displayed.
 
648
 
 
649
    TODO: Make --revision support uuid: and hash: [future tag:] notation.
 
650
  
698
651
    """
699
652
 
700
 
    # TODO: Make --revision support uuid: and hash: [future tag:] notation.
701
 
 
702
653
    takes_args = ['filename?']
703
654
    takes_options = ['forward', 'timezone', 'verbose', 'show-ids', 'revision',
704
655
                     'long', 'message', 'short',]
717
668
        direction = (forward and 'forward') or 'reverse'
718
669
        
719
670
        if filename:
720
 
            b = Branch.open_containing(filename)
 
671
            b = find_branch(filename)
721
672
            fp = b.relpath(filename)
722
673
            if fp:
723
674
                file_id = b.read_working_inventory().path2id(fp)
724
675
            else:
725
676
                file_id = None  # points to branch root
726
677
        else:
727
 
            b = Branch.open_containing('.')
 
678
            b = find_branch('.')
728
679
            file_id = None
729
680
 
730
681
        if revision is None:
731
682
            rev1 = None
732
683
            rev2 = None
733
684
        elif len(revision) == 1:
734
 
            rev1 = rev2 = revision[0].in_history(b).revno
 
685
            rev1 = rev2 = b.get_revision_info(revision[0])[0]
735
686
        elif len(revision) == 2:
736
 
            rev1 = revision[0].in_history(b).revno
737
 
            rev2 = revision[1].in_history(b).revno
 
687
            rev1 = b.get_revision_info(revision[0])[0]
 
688
            rev2 = b.get_revision_info(revision[1])[0]
738
689
        else:
739
690
            raise BzrCommandError('bzr log --revision takes one or two values.')
740
691
 
776
727
    hidden = True
777
728
    takes_args = ["filename"]
778
729
    def run(self, filename):
779
 
        b = Branch.open_containing(filename)
 
730
        b = find_branch(filename)
780
731
        inv = b.read_working_inventory()
781
732
        file_id = inv.path2id(b.relpath(filename))
782
733
        for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
790
741
    """
791
742
    hidden = True
792
743
    def run(self, revision=None, verbose=False):
793
 
        b = Branch.open_containing('.')
 
744
        b = find_branch('.')
794
745
        if revision == None:
795
746
            tree = b.working_tree()
796
747
        else:
797
 
            tree = b.revision_tree(revision.in_history(b).rev_id)
798
 
        for fp, fc, kind, fid, entry in tree.list_files():
 
748
            tree = b.revision_tree(b.lookup_revision(revision))
 
749
 
 
750
        for fp, fc, kind, fid in tree.list_files():
799
751
            if verbose:
800
 
                kindch = entry.kind_character()
 
752
                if kind == 'directory':
 
753
                    kindch = '/'
 
754
                elif kind == 'file':
 
755
                    kindch = ''
 
756
                else:
 
757
                    kindch = '???'
 
758
 
801
759
                print '%-8s %s%s' % (fc, fp, kindch)
802
760
            else:
803
761
                print fp
808
766
    """List unknown files."""
809
767
    def run(self):
810
768
        from bzrlib.osutils import quotefn
811
 
        for f in Branch.open_containing('.').unknowns():
 
769
        for f in find_branch('.').unknowns():
812
770
            print quotefn(f)
813
771
 
814
772
 
836
794
        from bzrlib.atomicfile import AtomicFile
837
795
        import os.path
838
796
 
839
 
        b = Branch.open_containing('.')
 
797
        b = find_branch('.')
840
798
        ifn = b.abspath('.bzrignore')
841
799
 
842
800
        if os.path.exists(ifn):
876
834
 
877
835
    See also: bzr ignore"""
878
836
    def run(self):
879
 
        tree = Branch.open_containing('.').working_tree()
880
 
        for path, file_class, kind, file_id, entry in tree.list_files():
 
837
        tree = find_branch('.').working_tree()
 
838
        for path, file_class, kind, file_id in tree.list_files():
881
839
            if file_class != 'I':
882
840
                continue
883
841
            ## XXX: Slightly inefficient since this was already calculated
900
858
        except ValueError:
901
859
            raise BzrCommandError("not a valid revision-number: %r" % revno)
902
860
 
903
 
        print Branch.open_containing('.').get_rev_id(revno)
 
861
        print find_branch('.').lookup_revision(revno)
904
862
 
905
863
 
906
864
class cmd_export(Command):
919
877
    takes_options = ['revision', 'format', 'root']
920
878
    def run(self, dest, revision=None, format=None, root=None):
921
879
        import os.path
922
 
        b = Branch.open_containing('.')
 
880
        b = find_branch('.')
923
881
        if revision is None:
924
 
            rev_id = b.last_revision()
 
882
            rev_id = b.last_patch()
925
883
        else:
926
884
            if len(revision) != 1:
927
885
                raise BzrError('bzr export --revision takes exactly 1 argument')
928
 
            rev_id = revision[0].in_history(b).rev_id
 
886
            revno, rev_id = b.get_revision_info(revision[0])
929
887
        t = b.revision_tree(rev_id)
930
 
        arg_root, ext = os.path.splitext(os.path.basename(dest))
931
 
        if ext in ('.gz', '.bz2'):
932
 
            new_root, new_ext = os.path.splitext(arg_root)
933
 
            if new_ext == '.tar':
934
 
                arg_root = new_root
935
 
                ext = new_ext + ext
936
 
        if root is None:
937
 
            root = arg_root
 
888
        root, ext = os.path.splitext(dest)
938
889
        if not format:
939
890
            if ext in (".tar",):
940
891
                format = "tar"
941
 
            elif ext in (".tar.gz", ".tgz"):
 
892
            elif ext in (".gz", ".tgz"):
942
893
                format = "tgz"
943
 
            elif ext in (".tar.bz2", ".tbz2"):
 
894
            elif ext in (".bz2", ".tbz2"):
944
895
                format = "tbz2"
945
896
            else:
946
897
                format = "dir"
954
905
    takes_args = ['filename']
955
906
 
956
907
    def run(self, filename, revision=None):
957
 
        if revision is None:
 
908
        if revision == None:
958
909
            raise BzrCommandError("bzr cat requires a revision number")
959
910
        elif len(revision) != 1:
960
911
            raise BzrCommandError("bzr cat --revision takes exactly one number")
961
 
        b = Branch.open_containing('.')
962
 
        b.print_file(b.relpath(filename), revision[0].in_history(b).revno)
 
912
        b = find_branch('.')
 
913
        b.print_file(b.relpath(filename), revision[0])
963
914
 
964
915
 
965
916
class cmd_local_time_offset(Command):
992
943
    aliases = ['ci', 'checkin']
993
944
 
994
945
    # TODO: Give better message for -s, --summary, used by tla people
995
 
 
996
 
    # XXX: verbose currently does nothing
997
946
    
998
947
    def run(self, message=None, file=None, verbose=True, selected_list=None,
999
948
            unchanged=False):
1002
951
        from bzrlib.status import show_status
1003
952
        from cStringIO import StringIO
1004
953
 
1005
 
        b = Branch.open_containing('.')
 
954
        b = find_branch('.')
1006
955
        if selected_list:
1007
956
            selected_list = [b.relpath(s) for s in selected_list]
1008
957
            
1009
 
        if message is None and not file:
 
958
        if not message and not file:
1010
959
            catcher = StringIO()
1011
960
            show_status(b, specific_files=selected_list,
1012
961
                        to_file=catcher)
1013
962
            message = edit_commit_message(catcher.getvalue())
1014
 
 
 
963
            
1015
964
            if message is None:
1016
965
                raise BzrCommandError("please specify a commit message"
1017
966
                                      " with either --message or --file")
1022
971
            import codecs
1023
972
            message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
1024
973
 
1025
 
        if message == "":
1026
 
                raise BzrCommandError("empty commit message specified")
1027
 
            
1028
974
        try:
1029
 
            b.commit(message,
 
975
            b.commit(message, verbose=verbose,
1030
976
                     specific_files=selected_list,
1031
977
                     allow_pointless=unchanged)
1032
978
        except PointlessCommit:
1047
993
    def run(self, dir='.'):
1048
994
        from bzrlib.check import check
1049
995
 
1050
 
        check(Branch.open_containing(dir))
 
996
        check(find_branch(dir))
1051
997
 
1052
998
 
1053
999
class cmd_scan_cache(Command):
1075
1021
 
1076
1022
    The check command or bzr developers may sometimes advise you to run
1077
1023
    this command.
1078
 
 
1079
 
    This version of this command upgrades from the full-text storage
1080
 
    used by bzr 0.0.8 and earlier to the weave format (v5).
1081
1024
    """
1082
1025
    takes_args = ['dir?']
1083
1026
 
1084
1027
    def run(self, dir='.'):
1085
1028
        from bzrlib.upgrade import upgrade
1086
 
        upgrade(dir)
 
1029
        upgrade(find_branch(dir))
 
1030
 
1087
1031
 
1088
1032
 
1089
1033
class cmd_whoami(Command):
1092
1036
    
1093
1037
    def run(self, email=False):
1094
1038
        try:
1095
 
            b = bzrlib.branch.Branch.open_containing('.')
1096
 
        except NotBranchError:
 
1039
            b = bzrlib.branch.find_branch('.')
 
1040
        except:
1097
1041
            b = None
1098
1042
        
1099
1043
        if email:
1103
1047
 
1104
1048
 
1105
1049
class cmd_selftest(Command):
1106
 
    """Run internal test suite.
1107
 
    
1108
 
    This creates temporary test directories in the working directory,
1109
 
    but not existing data is affected.  These directories are deleted
1110
 
    if the tests pass, or left behind to help in debugging if they
1111
 
    fail.
1112
 
    
1113
 
    If arguments are given, they are regular expressions that say
1114
 
    which tests should run."""
1115
 
    # TODO: --list should give a list of all available tests
 
1050
    """Run internal test suite"""
1116
1051
    hidden = True
1117
 
    takes_args = ['testnames*']
1118
1052
    takes_options = ['verbose', 'pattern']
1119
 
    def run(self, testnames_list=None, verbose=False, pattern=".*"):
 
1053
    def run(self, verbose=False, pattern=".*"):
1120
1054
        import bzrlib.ui
1121
1055
        from bzrlib.selftest import selftest
1122
1056
        # we don't want progress meters from the tests to go to the
1126
1060
        bzrlib.trace.info('running tests...')
1127
1061
        try:
1128
1062
            bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1129
 
            result = selftest(verbose=verbose, 
1130
 
                              pattern=pattern,
1131
 
                              testnames=testnames_list)
 
1063
            result = selftest(verbose=verbose, pattern=pattern)
1132
1064
            if result:
1133
1065
                bzrlib.trace.info('tests passed')
1134
1066
            else:
1176
1108
    def run(self, branch, other):
1177
1109
        from bzrlib.revision import common_ancestor, MultipleRevisionSources
1178
1110
        
1179
 
        branch1 = Branch.open_containing(branch)
1180
 
        branch2 = Branch.open_containing(other)
 
1111
        branch1 = find_branch(branch)
 
1112
        branch2 = find_branch(other)
1181
1113
 
1182
1114
        history_1 = branch1.revision_history()
1183
1115
        history_2 = branch2.revision_history()
1184
1116
 
1185
 
        last1 = branch1.last_revision()
1186
 
        last2 = branch2.last_revision()
 
1117
        last1 = branch1.last_patch()
 
1118
        last2 = branch2.last_patch()
1187
1119
 
1188
1120
        source = MultipleRevisionSources(branch1, branch2)
1189
1121
        
1246
1178
            other = [branch, -1]
1247
1179
        else:
1248
1180
            if len(revision) == 1:
 
1181
                other = [branch, revision[0]]
1249
1182
                base = [None, None]
1250
 
                other = [branch, revision[0].in_history(branch).revno]
1251
1183
            else:
1252
1184
                assert len(revision) == 2
1253
1185
                if None in revision:
1254
1186
                    raise BzrCommandError(
1255
1187
                        "Merge doesn't permit that revision specifier.")
1256
 
                b = Branch.open(branch)
1257
 
 
1258
 
                base = [branch, revision[0].in_history(b).revno]
1259
 
                other = [branch, revision[1].in_history(b).revno]
 
1188
                base = [branch, revision[0]]
 
1189
                other = [branch, revision[1]]
1260
1190
 
1261
1191
        try:
1262
1192
            merge(other, base, check_clean=(not force), merge_type=merge_type)
1283
1213
 
1284
1214
    def run(self, revision=None, no_backup=False, file_list=None):
1285
1215
        from bzrlib.merge import merge
 
1216
        from bzrlib.branch import Branch
1286
1217
        from bzrlib.commands import parse_spec
1287
1218
 
1288
1219
        if file_list is not None:
1289
1220
            if len(file_list) == 0:
1290
1221
                raise BzrCommandError("No files specified")
1291
1222
        if revision is None:
1292
 
            revno = -1
 
1223
            revision = [-1]
1293
1224
        elif len(revision) != 1:
1294
1225
            raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1295
 
        else:
1296
 
            b = Branch.open_containing('.')
1297
 
            revno = revision[0].in_history(b).revno
1298
 
        merge(('.', revno), parse_spec('.'),
 
1226
        merge(('.', revision[0]), parse_spec('.'),
1299
1227
              check_clean=False,
1300
1228
              ignore_zero=True,
1301
1229
              backup_files=not no_backup,
1302
1230
              file_list=file_list)
1303
1231
        if not file_list:
1304
 
            Branch.open_containing('.').set_pending_merges([])
 
1232
            Branch('.').set_pending_merges([])
1305
1233
 
1306
1234
 
1307
1235
class cmd_assert_fail(Command):
1339
1267
        shellcomplete.shellcomplete(context)
1340
1268
 
1341
1269
 
1342
 
class cmd_fetch(Command):
1343
 
    """Copy in history from another branch but don't merge it.
1344
 
 
1345
 
    This is an internal method used for pull and merge."""
1346
 
    hidden = True
1347
 
    takes_args = ['from_branch', 'to_branch']
1348
 
    def run(self, from_branch, to_branch):
1349
 
        from bzrlib.fetch import Fetcher
1350
 
        from bzrlib.branch import Branch
1351
 
        from_b = Branch(from_branch)
1352
 
        to_b = Branch(to_branch)
1353
 
        Fetcher(to_b, from_b)
1354
 
        
1355
 
 
1356
 
 
1357
1270
class cmd_missing(Command):
1358
1271
    """What is missing in this branch relative to other branch.
1359
1272
    """
1360
 
    # TODO: rewrite this in terms of ancestry so that it shows only
1361
 
    # unmerged things
1362
 
    
1363
1273
    takes_args = ['remote?']
1364
1274
    aliases = ['mis', 'miss']
1365
1275
    # We don't have to add quiet to the list, because 
1373
1283
        if verbose and quiet:
1374
1284
            raise BzrCommandError('Cannot pass both quiet and verbose')
1375
1285
 
1376
 
        b = Branch.open_containing('.')
 
1286
        b = find_branch('.')
1377
1287
        parent = b.get_parent()
1378
1288
        if remote is None:
1379
1289
            if parent is None:
1383
1293
                    print "Using last location: %s" % parent
1384
1294
                remote = parent
1385
1295
        elif parent is None:
1386
 
            # We only update parent if it did not exist, missing
1387
 
            # should not change the parent
 
1296
            # We only update parent if it did not exist, missing should not change the parent
1388
1297
            b.set_parent(remote)
1389
 
        br_remote = Branch.open_containing(remote)
 
1298
        br_remote = find_branch(remote)
 
1299
 
1390
1300
        return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
1391
1301
 
1392
1302
 
 
1303
 
1393
1304
class cmd_plugins(Command):
1394
1305
    """List plugins"""
1395
1306
    hidden = True