~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Aaron Bentley
  • Date: 2005-09-19 02:33:09 UTC
  • mfrom: (1185.3.27)
  • mto: (1185.1.29)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: aaron.bentley@utoronto.ca-20050919023309-24e8871f7f8b31cf
Merged latest from mpool

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