~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

lalos branch constructor patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import bzrlib.trace
23
23
from bzrlib.trace import mutter, note, log_error, warning
24
24
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError
25
 
from bzrlib.branch import find_branch
 
25
from bzrlib.branch import Branch
26
26
from bzrlib import BZRDIR
27
27
from bzrlib.commands import Command
28
28
 
72
72
    
73
73
    def run(self, all=False, show_ids=False, file_list=None):
74
74
        if file_list:
75
 
            b = find_branch(file_list[0])
 
75
            b = Branch.open_containing(file_list[0])
76
76
            file_list = [b.relpath(x) for x in file_list]
77
77
            # special case: only one path was given and it's the root
78
78
            # of the branch
79
79
            if file_list == ['']:
80
80
                file_list = None
81
81
        else:
82
 
            b = find_branch('.')
 
82
            b = Branch.open_containing('.')
83
83
            
84
84
        from bzrlib.status import show_status
85
85
        show_status(b, show_unchanged=all, show_ids=show_ids,
93
93
    takes_args = ['revision_id']
94
94
    
95
95
    def run(self, revision_id):
96
 
        b = find_branch('.')
 
96
        b = Branch.open_containing('.')
97
97
        sys.stdout.write(b.get_revision_xml_file(revision_id).read())
98
98
 
99
99
 
102
102
 
103
103
    This is equal to the number of revisions on this branch."""
104
104
    def run(self):
105
 
        print find_branch('.').revno()
 
105
        print Branch.open_containing('.').revno()
106
106
 
107
107
 
108
108
class cmd_revision_info(Command):
111
111
    hidden = True
112
112
    takes_args = ['revision_info*']
113
113
    takes_options = ['revision']
114
 
    def run(self, revision=None, revision_info_list=None):
115
 
        from bzrlib.branch import find_branch
 
114
    def run(self, revision=None, revision_info_list=()):
 
115
        from bzrlib.revisionspec import RevisionSpec
116
116
 
117
117
        revs = []
118
118
        if revision is not None:
119
119
            revs.extend(revision)
120
 
        if revision_info_list is not None:
121
 
            revs.extend(revision_info_list)
 
120
        for rev in revision_info_list:
 
121
            revs.append(RevisionSpec(revision_info_list))
122
122
        if len(revs) == 0:
123
123
            raise BzrCommandError('You must supply a revision identifier')
124
124
 
125
 
        b = find_branch('.')
 
125
        b = Branch.open_containing('.')
126
126
 
127
127
        for rev in revs:
128
 
            print '%4d %s' % b.get_revision_info(rev)
 
128
            print '%4d %s' % rev.in_history(b)
129
129
 
130
130
    
131
131
class cmd_add(Command):
174
174
        for d in dir_list:
175
175
            os.mkdir(d)
176
176
            if not b:
177
 
                b = find_branch(d)
 
177
                b = Branch.open_containing(d)
178
178
            b.add([d])
179
179
            print 'added', d
180
180
 
185
185
    hidden = True
186
186
    
187
187
    def run(self, filename):
188
 
        print find_branch(filename).relpath(filename)
 
188
        print Branch.open_containing(filename).relpath(filename)
189
189
 
190
190
 
191
191
 
194
194
    takes_options = ['revision', 'show-ids']
195
195
    
196
196
    def run(self, revision=None, show_ids=False):
197
 
        b = find_branch('.')
198
 
        if revision == None:
 
197
        b = Branch.open_containing('.')
 
198
        if revision is None:
199
199
            inv = b.read_working_inventory()
200
200
        else:
201
201
            if len(revision) > 1:
202
202
                raise BzrCommandError('bzr inventory --revision takes'
203
203
                    ' exactly one revision identifier')
204
 
            inv = b.get_revision_inventory(b.lookup_revision(revision[0]))
 
204
            inv = b.get_revision_inventory(revision[0].in_history(b).rev_id)
205
205
 
206
206
        for path, entry in inv.entries():
207
207
            if show_ids:
220
220
    """
221
221
    takes_args = ['source$', 'dest']
222
222
    def run(self, source_list, dest):
223
 
        b = find_branch('.')
 
223
        b = Branch.open_containing('.')
224
224
 
225
225
        # TODO: glob expansion on windows?
226
226
        b.move([b.relpath(s) for s in source_list], b.relpath(dest))
243
243
    takes_args = ['from_name', 'to_name']
244
244
    
245
245
    def run(self, from_name, to_name):
246
 
        b = find_branch('.')
 
246
        b = Branch.open_containing('.')
247
247
        b.rename_one(b.relpath(from_name), b.relpath(to_name))
248
248
 
249
249
 
265
265
    def run(self, names_list):
266
266
        if len(names_list) < 2:
267
267
            raise BzrCommandError("missing file argument")
268
 
        b = find_branch(names_list[0])
 
268
        b = Branch.open_containing(names_list[0])
269
269
 
270
270
        rel_names = [b.relpath(x) for x in names_list]
271
271
        
305
305
        from shutil import rmtree
306
306
        import errno
307
307
        
308
 
        br_to = find_branch('.')
 
308
        br_to = Branch.open_containing('.')
309
309
        stored_loc = br_to.get_parent()
310
310
        if location is None:
311
311
            if stored_loc is None:
314
314
                print "Using last location: %s" % stored_loc
315
315
                location = stored_loc
316
316
        cache_root = tempfile.mkdtemp()
317
 
        from bzrlib.branch import DivergedBranches
318
 
        br_from = find_branch(location)
 
317
        from bzrlib.errors import DivergedBranches
 
318
        br_from = Branch.open_containing(location)
319
319
        location = br_from.base
320
320
        old_revno = br_to.revno()
321
321
        try:
322
 
            from branch import find_cached_branch, DivergedBranches
323
 
            br_from = find_cached_branch(location, cache_root)
 
322
            from bzrlib.errors import DivergedBranches
 
323
            br_from = Branch.open(location)
 
324
            br_from.setup_caching(cache_root)
324
325
            location = br_from.base
325
326
            old_revno = br_to.revno()
326
327
            try:
351
352
    aliases = ['get', 'clone']
352
353
 
353
354
    def run(self, from_location, to_location=None, revision=None):
354
 
        from bzrlib.branch import copy_branch, find_cached_branch
 
355
        from bzrlib.branch import copy_branch
355
356
        import tempfile
356
357
        import errno
357
358
        from shutil import rmtree
363
364
                raise BzrCommandError(
364
365
                    'bzr branch --revision takes exactly 1 revision value')
365
366
            try:
366
 
                br_from = find_cached_branch(from_location, cache_root)
 
367
                br_from = Branch.open(from_location)
367
368
            except OSError, e:
368
369
                if e.errno == errno.ENOENT:
369
370
                    raise BzrCommandError('Source location "%s" does not'
370
371
                                          ' exist.' % to_location)
371
372
                else:
372
373
                    raise
 
374
            br_from.setup_caching(cache_root)
373
375
            if to_location is None:
374
376
                to_location = os.path.basename(from_location.rstrip("/\\"))
375
377
            try:
403
405
    takes_args = ['dir?']
404
406
 
405
407
    def run(self, dir='.'):
406
 
        b = find_branch(dir)
 
408
        b = Branch.open_containing(dir)
407
409
        old_inv = b.basis_tree().inventory
408
410
        new_inv = b.read_working_inventory()
409
411
 
420
422
    def run(self, branch=None):
421
423
        import info
422
424
 
423
 
        b = find_branch(branch)
 
425
        b = Branch.open_containing(branch)
424
426
        info.show_info(b)
425
427
 
426
428
 
434
436
    takes_options = ['verbose']
435
437
    
436
438
    def run(self, file_list, verbose=False):
437
 
        b = find_branch(file_list[0])
 
439
        b = Branch.open_containing(file_list[0])
438
440
        b.remove([b.relpath(f) for f in file_list], verbose=verbose)
439
441
 
440
442
 
448
450
    hidden = True
449
451
    takes_args = ['filename']
450
452
    def run(self, filename):
451
 
        b = find_branch(filename)
 
453
        b = Branch.open_containing(filename)
452
454
        i = b.inventory.path2id(b.relpath(filename))
453
455
        if i == None:
454
456
            raise BzrError("%r is not a versioned file" % filename)
464
466
    hidden = True
465
467
    takes_args = ['filename']
466
468
    def run(self, filename):
467
 
        b = find_branch(filename)
 
469
        b = Branch.open_containing(filename)
468
470
        inv = b.inventory
469
471
        fid = inv.path2id(b.relpath(filename))
470
472
        if fid == None:
477
479
    """Display list of revision ids on this branch."""
478
480
    hidden = True
479
481
    def run(self):
480
 
        for patchid in find_branch('.').revision_history():
 
482
        for patchid in Branch.open_containing('.').revision_history():
481
483
            print patchid
482
484
 
483
485
 
484
486
class cmd_directories(Command):
485
487
    """Display list of versioned directories in this branch."""
486
488
    def run(self):
487
 
        for name, ie in find_branch('.').read_working_inventory().directories():
 
489
        for name, ie in Branch.open_containing('.').read_working_inventory().directories():
488
490
            if name == '':
489
491
                print '.'
490
492
            else:
506
508
    """
507
509
    def run(self):
508
510
        from bzrlib.branch import Branch
509
 
        Branch('.', init=True)
 
511
        Branch.initialize('.')
510
512
 
511
513
 
512
514
class cmd_diff(Command):
544
546
        from bzrlib.diff import show_diff
545
547
 
546
548
        if file_list:
547
 
            b = find_branch(file_list[0])
 
549
            b = Branch.open_containing(file_list[0])
548
550
            file_list = [b.relpath(f) for f in file_list]
549
551
            if file_list == ['']:
550
552
                # just pointing to top-of-tree
551
553
                file_list = None
552
554
        else:
553
 
            b = find_branch('.')
 
555
            b = Branch.open_containing('.')
554
556
 
555
557
        if revision is not None:
556
558
            if len(revision) == 1:
575
577
    TODO: Show files deleted since a previous revision, or between two revisions.
576
578
    """
577
579
    def run(self, show_ids=False):
578
 
        b = find_branch('.')
 
580
        b = Branch.open_containing('.')
579
581
        old = b.basis_tree()
580
582
        new = b.working_tree()
581
583
 
598
600
    def run(self):
599
601
        from bzrlib.delta import compare_trees
600
602
 
601
 
        b = find_branch('.')
 
603
        b = Branch.open_containing('.')
602
604
        td = compare_trees(b.basis_tree(), b.working_tree())
603
605
 
604
606
        for path, id, kind in td.modified:
610
612
    """List files added in working tree."""
611
613
    hidden = True
612
614
    def run(self):
613
 
        b = find_branch('.')
 
615
        b = Branch.open_containing('.')
614
616
        wt = b.working_tree()
615
617
        basis_inv = b.basis_tree().inventory
616
618
        inv = wt.inventory
632
634
    takes_args = ['filename?']
633
635
    def run(self, filename=None):
634
636
        """Print the branch root."""
635
 
        b = find_branch(filename)
 
637
        b = Branch.open_containing(filename)
636
638
        print b.base
637
639
 
638
640
 
668
670
        direction = (forward and 'forward') or 'reverse'
669
671
        
670
672
        if filename:
671
 
            b = find_branch(filename)
 
673
            b = Branch.open_containing(filename)
672
674
            fp = b.relpath(filename)
673
675
            if fp:
674
676
                file_id = b.read_working_inventory().path2id(fp)
675
677
            else:
676
678
                file_id = None  # points to branch root
677
679
        else:
678
 
            b = find_branch('.')
 
680
            b = Branch.open_containing('.')
679
681
            file_id = None
680
682
 
681
683
        if revision is None:
682
684
            rev1 = None
683
685
            rev2 = None
684
686
        elif len(revision) == 1:
685
 
            rev1 = rev2 = b.get_revision_info(revision[0])[0]
 
687
            rev1 = rev2 = revision[0].in_history(b).revno
686
688
        elif len(revision) == 2:
687
 
            rev1 = b.get_revision_info(revision[0])[0]
688
 
            rev2 = b.get_revision_info(revision[1])[0]
 
689
            rev1 = revision[0].in_history(b).revno
 
690
            rev2 = revision[1].in_history(b).revno
689
691
        else:
690
692
            raise BzrCommandError('bzr log --revision takes one or two values.')
691
693
 
727
729
    hidden = True
728
730
    takes_args = ["filename"]
729
731
    def run(self, filename):
730
 
        b = find_branch(filename)
 
732
        b = Branch.open_containing(filename)
731
733
        inv = b.read_working_inventory()
732
734
        file_id = inv.path2id(b.relpath(filename))
733
735
        for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
741
743
    """
742
744
    hidden = True
743
745
    def run(self, revision=None, verbose=False):
744
 
        b = find_branch('.')
 
746
        b = Branch.open_containing('.')
745
747
        if revision == None:
746
748
            tree = b.working_tree()
747
749
        else:
748
 
            tree = b.revision_tree(b.lookup_revision(revision))
 
750
            tree = b.revision_tree(revision.in_history(b).rev_id)
749
751
 
750
752
        for fp, fc, kind, fid in tree.list_files():
751
753
            if verbose:
766
768
    """List unknown files."""
767
769
    def run(self):
768
770
        from bzrlib.osutils import quotefn
769
 
        for f in find_branch('.').unknowns():
 
771
        for f in Branch.open_containing('.').unknowns():
770
772
            print quotefn(f)
771
773
 
772
774
 
794
796
        from bzrlib.atomicfile import AtomicFile
795
797
        import os.path
796
798
 
797
 
        b = find_branch('.')
 
799
        b = Branch.open_containing('.')
798
800
        ifn = b.abspath('.bzrignore')
799
801
 
800
802
        if os.path.exists(ifn):
834
836
 
835
837
    See also: bzr ignore"""
836
838
    def run(self):
837
 
        tree = find_branch('.').working_tree()
 
839
        tree = Branch.open_containing('.').working_tree()
838
840
        for path, file_class, kind, file_id in tree.list_files():
839
841
            if file_class != 'I':
840
842
                continue
858
860
        except ValueError:
859
861
            raise BzrCommandError("not a valid revision-number: %r" % revno)
860
862
 
861
 
        print find_branch('.').lookup_revision(revno)
 
863
        print Branch.open_containing('.').get_rev_id(revno)
862
864
 
863
865
 
864
866
class cmd_export(Command):
877
879
    takes_options = ['revision', 'format', 'root']
878
880
    def run(self, dest, revision=None, format=None, root=None):
879
881
        import os.path
880
 
        b = find_branch('.')
 
882
        b = Branch.open_containing('.')
881
883
        if revision is None:
882
884
            rev_id = b.last_patch()
883
885
        else:
884
886
            if len(revision) != 1:
885
887
                raise BzrError('bzr export --revision takes exactly 1 argument')
886
 
            revno, rev_id = b.get_revision_info(revision[0])
 
888
            rev_id = revision[0].in_history(b).rev_id
887
889
        t = b.revision_tree(rev_id)
888
890
        root, ext = os.path.splitext(dest)
889
891
        if not format:
905
907
    takes_args = ['filename']
906
908
 
907
909
    def run(self, filename, revision=None):
908
 
        if revision == None:
 
910
        if revision is None:
909
911
            raise BzrCommandError("bzr cat requires a revision number")
910
912
        elif len(revision) != 1:
911
913
            raise BzrCommandError("bzr cat --revision takes exactly one number")
912
 
        b = find_branch('.')
913
 
        b.print_file(b.relpath(filename), revision[0])
 
914
        b = Branch.open_containing('.')
 
915
        b.print_file(b.relpath(filename), revision[0].in_history(b).revno)
914
916
 
915
917
 
916
918
class cmd_local_time_offset(Command):
951
953
        from bzrlib.status import show_status
952
954
        from cStringIO import StringIO
953
955
 
954
 
        b = find_branch('.')
 
956
        b = Branch.open_containing('.')
955
957
        if selected_list:
956
958
            selected_list = [b.relpath(s) for s in selected_list]
957
959
            
993
995
    def run(self, dir='.'):
994
996
        from bzrlib.check import check
995
997
 
996
 
        check(find_branch(dir))
 
998
        check(Branch.open_containing(dir))
997
999
 
998
1000
 
999
1001
class cmd_scan_cache(Command):
1026
1028
 
1027
1029
    def run(self, dir='.'):
1028
1030
        from bzrlib.upgrade import upgrade
1029
 
        upgrade(find_branch(dir))
 
1031
        upgrade(Branch.open_containing(dir))
1030
1032
 
1031
1033
 
1032
1034
 
1036
1038
    
1037
1039
    def run(self, email=False):
1038
1040
        try:
1039
 
            b = bzrlib.branch.find_branch('.')
 
1041
            b = bzrlib.branch.Branch.open_containing('.')
1040
1042
        except:
1041
1043
            b = None
1042
1044
        
1108
1110
    def run(self, branch, other):
1109
1111
        from bzrlib.revision import common_ancestor, MultipleRevisionSources
1110
1112
        
1111
 
        branch1 = find_branch(branch)
1112
 
        branch2 = find_branch(other)
 
1113
        branch1 = Branch.open_containing(branch)
 
1114
        branch2 = Branch.open_containing(other)
1113
1115
 
1114
1116
        history_1 = branch1.revision_history()
1115
1117
        history_2 = branch2.revision_history()
1178
1180
            other = [branch, -1]
1179
1181
        else:
1180
1182
            if len(revision) == 1:
1181
 
                other = [branch, revision[0]]
1182
1183
                base = [None, None]
 
1184
                other = [branch, revision[0].in_history(branch).revno]
1183
1185
            else:
1184
1186
                assert len(revision) == 2
1185
1187
                if None in revision:
1186
1188
                    raise BzrCommandError(
1187
1189
                        "Merge doesn't permit that revision specifier.")
1188
 
                base = [branch, revision[0]]
1189
 
                other = [branch, revision[1]]
 
1190
                base = [branch, revision[0].in_history(branch).revno]
 
1191
                other = [branch, revision[1].in_history(branch).revno]
1190
1192
 
1191
1193
        try:
1192
1194
            merge(other, base, check_clean=(not force), merge_type=merge_type)
1229
1231
              backup_files=not no_backup,
1230
1232
              file_list=file_list)
1231
1233
        if not file_list:
1232
 
            Branch('.').set_pending_merges([])
 
1234
            Branch.open_containing('.').set_pending_merges([])
1233
1235
 
1234
1236
 
1235
1237
class cmd_assert_fail(Command):
1283
1285
        if verbose and quiet:
1284
1286
            raise BzrCommandError('Cannot pass both quiet and verbose')
1285
1287
 
1286
 
        b = find_branch('.')
 
1288
        b = Branch.open_containing('.')
1287
1289
        parent = b.get_parent()
1288
1290
        if remote is None:
1289
1291
            if parent is None:
1295
1297
        elif parent is None:
1296
1298
            # We only update parent if it did not exist, missing should not change the parent
1297
1299
            b.set_parent(remote)
1298
 
        br_remote = find_branch(remote)
 
1300
        br_remote = Branch.open_containing(remote)
1299
1301
 
1300
1302
        return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
1301
1303