/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

remove more duplicate merged hunks. Bad MERGE3, BAD.

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 Branch
 
25
from bzrlib.branch import find_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 = Branch.open_containing(file_list[0])
 
75
            b = find_branch(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 = Branch.open_containing('.')
 
82
            b = find_branch('.')
83
83
            
84
84
        from bzrlib.status import show_status
85
85
        show_status(b, show_unchanged=all, show_ids=show_ids,
87
87
 
88
88
 
89
89
class cmd_cat_revision(Command):
90
 
    """Write out metadata for a revision.
91
 
    
92
 
    The revision to print can either be specified by a specific
93
 
    revision identifier, or you can use --revision.
94
 
    """
 
90
    """Write out metadata for a revision."""
95
91
 
96
92
    hidden = True
97
 
    takes_args = ['revision_id?']
98
 
    takes_options = ['revision']
 
93
    takes_args = ['revision_id']
99
94
    
100
 
    def run(self, revision_id=None, revision=None):
101
 
        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())
102
98
 
103
 
        if revision_id is not None and revision is not None:
104
 
            raise BzrCommandError('You can only supply one of revision_id or --revision')
105
 
        if revision_id is None and revision is None:
106
 
            raise BzrCommandError('You must supply either --revision or a revision_id')
107
 
        b = Branch.open_containing('.')
108
 
        if revision_id is not None:
109
 
            sys.stdout.write(b.get_revision_xml_file(revision_id).read())
110
 
        elif revision is not None:
111
 
            for rev in revision:
112
 
                if rev is None:
113
 
                    raise BzrCommandError('You cannot specify a NULL revision.')
114
 
                revno, rev_id = rev.in_history(b)
115
 
                sys.stdout.write(b.get_revision_xml_file(rev_id).read())
116
 
    
117
99
 
118
100
class cmd_revno(Command):
119
101
    """Show current revision number.
120
102
 
121
103
    This is equal to the number of revisions on this branch."""
122
104
    def run(self):
123
 
        print Branch.open_containing('.').revno()
 
105
        print find_branch('.').revno()
124
106
 
125
107
 
126
108
class cmd_revision_info(Command):
129
111
    hidden = True
130
112
    takes_args = ['revision_info*']
131
113
    takes_options = ['revision']
132
 
    def run(self, revision=None, revision_info_list=[]):
133
 
        from bzrlib.revisionspec import RevisionSpec
 
114
    def run(self, revision=None, revision_info_list=None):
 
115
        from bzrlib.branch import find_branch
134
116
 
135
117
        revs = []
136
118
        if revision is not None:
137
119
            revs.extend(revision)
138
120
        if revision_info_list is not None:
139
 
            for rev in revision_info_list:
140
 
                revs.append(RevisionSpec(rev))
 
121
            revs.extend(revision_info_list)
141
122
        if len(revs) == 0:
142
123
            raise BzrCommandError('You must supply a revision identifier')
143
124
 
144
 
        b = Branch.open_containing('.')
 
125
        b = find_branch('.')
145
126
 
146
127
        for rev in revs:
147
 
            revinfo = rev.in_history(b)
148
 
            if revinfo.revno is None:
149
 
                print '     %s' % revinfo.rev_id
150
 
            else:
151
 
                print '%4d %s' % (revinfo.revno, revinfo.rev_id)
 
128
            print '%4d %s' % b.get_revision_info(rev)
152
129
 
153
130
    
154
131
class cmd_add(Command):
197
174
        for d in dir_list:
198
175
            os.mkdir(d)
199
176
            if not b:
200
 
                b = Branch.open_containing(d)
 
177
                b = find_branch(d)
201
178
            b.add([d])
202
179
            print 'added', d
203
180
 
208
185
    hidden = True
209
186
    
210
187
    def run(self, filename):
211
 
        print Branch.open_containing(filename).relpath(filename)
 
188
        print find_branch(filename).relpath(filename)
212
189
 
213
190
 
214
191
 
217
194
    takes_options = ['revision', 'show-ids']
218
195
    
219
196
    def run(self, revision=None, show_ids=False):
220
 
        b = Branch.open_containing('.')
221
 
        if revision is None:
 
197
        b = find_branch('.')
 
198
        if revision == None:
222
199
            inv = b.read_working_inventory()
223
200
        else:
224
201
            if len(revision) > 1:
225
202
                raise BzrCommandError('bzr inventory --revision takes'
226
203
                    ' exactly one revision identifier')
227
 
            inv = b.get_revision_inventory(revision[0].in_history(b).rev_id)
 
204
            inv = b.get_revision_inventory(b.lookup_revision(revision[0]))
228
205
 
229
206
        for path, entry in inv.entries():
230
207
            if show_ids:
243
220
    """
244
221
    takes_args = ['source$', 'dest']
245
222
    def run(self, source_list, dest):
246
 
        b = Branch.open_containing('.')
 
223
        b = find_branch('.')
247
224
 
248
225
        # TODO: glob expansion on windows?
249
226
        b.move([b.relpath(s) for s in source_list], b.relpath(dest))
266
243
    takes_args = ['from_name', 'to_name']
267
244
    
268
245
    def run(self, from_name, to_name):
269
 
        b = Branch.open_containing('.')
 
246
        b = find_branch('.')
270
247
        b.rename_one(b.relpath(from_name), b.relpath(to_name))
271
248
 
272
249
 
288
265
    def run(self, names_list):
289
266
        if len(names_list) < 2:
290
267
            raise BzrCommandError("missing file argument")
291
 
        b = Branch.open_containing(names_list[0])
 
268
        b = find_branch(names_list[0])
292
269
 
293
270
        rel_names = [b.relpath(x) for x in names_list]
294
271
        
328
305
        from shutil import rmtree
329
306
        import errno
330
307
        
331
 
        br_to = Branch.open_containing('.')
332
 
        stored_loc = br_to.get_parent()
 
308
        br_to = find_branch('.')
 
309
        stored_loc = None
 
310
        try:
 
311
            stored_loc = br_to.controlfile("x-pull", "rb").read().rstrip('\n')
 
312
        except IOError, e:
 
313
            if e.errno != errno.ENOENT:
 
314
                raise
333
315
        if location is None:
334
316
            if stored_loc is None:
335
317
                raise BzrCommandError("No pull location known or specified.")
337
319
                print "Using last location: %s" % stored_loc
338
320
                location = stored_loc
339
321
        cache_root = tempfile.mkdtemp()
340
 
        from bzrlib.errors import DivergedBranches
341
 
        br_from = Branch.open_containing(location)
 
322
        from bzrlib.branch import DivergedBranches
 
323
        br_from = find_branch(location)
342
324
        location = br_from.base
343
325
        old_revno = br_to.revno()
344
326
        try:
345
 
            from bzrlib.errors import DivergedBranches
346
 
            br_from = Branch.open(location)
347
 
            br_from.setup_caching(cache_root)
 
327
            from branch import find_cached_branch, DivergedBranches
 
328
            br_from = find_cached_branch(location, cache_root)
348
329
            location = br_from.base
349
330
            old_revno = br_to.revno()
350
331
            try:
355
336
                
356
337
            merge(('.', -1), ('.', old_revno), check_clean=False)
357
338
            if location != stored_loc:
358
 
                br_to.set_parent(location)
 
339
                br_to.controlfile("x-pull", "wb").write(location + "\n")
359
340
        finally:
360
341
            rmtree(cache_root)
361
342
 
375
356
    aliases = ['get', 'clone']
376
357
 
377
358
    def run(self, from_location, to_location=None, revision=None):
378
 
        from bzrlib.branch import copy_branch
 
359
        from bzrlib.branch import copy_branch, find_cached_branch
379
360
        import tempfile
380
361
        import errno
381
362
        from shutil import rmtree
387
368
                raise BzrCommandError(
388
369
                    'bzr branch --revision takes exactly 1 revision value')
389
370
            try:
390
 
                br_from = Branch.open(from_location)
 
371
                br_from = find_cached_branch(from_location, cache_root)
391
372
            except OSError, e:
392
373
                if e.errno == errno.ENOENT:
393
374
                    raise BzrCommandError('Source location "%s" does not'
394
375
                                          ' exist.' % to_location)
395
376
                else:
396
377
                    raise
397
 
            br_from.setup_caching(cache_root)
398
378
            if to_location is None:
399
379
                to_location = os.path.basename(from_location.rstrip("/\\"))
400
380
            try:
428
408
    takes_args = ['dir?']
429
409
 
430
410
    def run(self, dir='.'):
431
 
        b = Branch.open_containing(dir)
 
411
        b = find_branch(dir)
432
412
        old_inv = b.basis_tree().inventory
433
413
        new_inv = b.read_working_inventory()
434
414
 
445
425
    def run(self, branch=None):
446
426
        import info
447
427
 
448
 
        b = Branch.open_containing(branch)
 
428
        b = find_branch(branch)
449
429
        info.show_info(b)
450
430
 
451
431
 
459
439
    takes_options = ['verbose']
460
440
    
461
441
    def run(self, file_list, verbose=False):
462
 
        b = Branch.open_containing(file_list[0])
 
442
        b = find_branch(file_list[0])
463
443
        b.remove([b.relpath(f) for f in file_list], verbose=verbose)
464
444
 
465
445
 
473
453
    hidden = True
474
454
    takes_args = ['filename']
475
455
    def run(self, filename):
476
 
        b = Branch.open_containing(filename)
 
456
        b = find_branch(filename)
477
457
        i = b.inventory.path2id(b.relpath(filename))
478
458
        if i == None:
479
459
            raise BzrError("%r is not a versioned file" % filename)
489
469
    hidden = True
490
470
    takes_args = ['filename']
491
471
    def run(self, filename):
492
 
        b = Branch.open_containing(filename)
 
472
        b = find_branch(filename)
493
473
        inv = b.inventory
494
474
        fid = inv.path2id(b.relpath(filename))
495
475
        if fid == None:
502
482
    """Display list of revision ids on this branch."""
503
483
    hidden = True
504
484
    def run(self):
505
 
        for patchid in Branch.open_containing('.').revision_history():
 
485
        for patchid in find_branch('.').revision_history():
506
486
            print patchid
507
487
 
508
488
 
509
489
class cmd_directories(Command):
510
490
    """Display list of versioned directories in this branch."""
511
491
    def run(self):
512
 
        for name, ie in Branch.open_containing('.').read_working_inventory().directories():
 
492
        for name, ie in find_branch('.').read_working_inventory().directories():
513
493
            if name == '':
514
494
                print '.'
515
495
            else:
531
511
    """
532
512
    def run(self):
533
513
        from bzrlib.branch import Branch
534
 
        Branch.initialize('.')
 
514
        Branch('.', init=True)
535
515
 
536
516
 
537
517
class cmd_diff(Command):
569
549
        from bzrlib.diff import show_diff
570
550
 
571
551
        if file_list:
572
 
            b = Branch.open_containing(file_list[0])
 
552
            b = find_branch(file_list[0])
573
553
            file_list = [b.relpath(f) for f in file_list]
574
554
            if file_list == ['']:
575
555
                # just pointing to top-of-tree
576
556
                file_list = None
577
557
        else:
578
 
            b = Branch.open_containing('.')
 
558
            b = find_branch('.')
579
559
 
580
560
        if revision is not None:
581
561
            if len(revision) == 1:
600
580
    TODO: Show files deleted since a previous revision, or between two revisions.
601
581
    """
602
582
    def run(self, show_ids=False):
603
 
        b = Branch.open_containing('.')
 
583
        b = find_branch('.')
604
584
        old = b.basis_tree()
605
585
        new = b.working_tree()
606
586
 
623
603
    def run(self):
624
604
        from bzrlib.delta import compare_trees
625
605
 
626
 
        b = Branch.open_containing('.')
 
606
        b = find_branch('.')
627
607
        td = compare_trees(b.basis_tree(), b.working_tree())
628
608
 
629
609
        for path, id, kind in td.modified:
635
615
    """List files added in working tree."""
636
616
    hidden = True
637
617
    def run(self):
638
 
        b = Branch.open_containing('.')
 
618
        b = find_branch('.')
639
619
        wt = b.working_tree()
640
620
        basis_inv = b.basis_tree().inventory
641
621
        inv = wt.inventory
657
637
    takes_args = ['filename?']
658
638
    def run(self, filename=None):
659
639
        """Print the branch root."""
660
 
        b = Branch.open_containing(filename)
 
640
        b = find_branch(filename)
661
641
        print b.base
662
642
 
663
643
 
693
673
        direction = (forward and 'forward') or 'reverse'
694
674
        
695
675
        if filename:
696
 
            b = Branch.open_containing(filename)
 
676
            b = find_branch(filename)
697
677
            fp = b.relpath(filename)
698
678
            if fp:
699
679
                file_id = b.read_working_inventory().path2id(fp)
700
680
            else:
701
681
                file_id = None  # points to branch root
702
682
        else:
703
 
            b = Branch.open_containing('.')
 
683
            b = find_branch('.')
704
684
            file_id = None
705
685
 
706
686
        if revision is None:
707
687
            rev1 = None
708
688
            rev2 = None
709
689
        elif len(revision) == 1:
710
 
            rev1 = rev2 = revision[0].in_history(b).revno
 
690
            rev1 = rev2 = b.get_revision_info(revision[0])[0]
711
691
        elif len(revision) == 2:
712
 
            rev1 = revision[0].in_history(b).revno
713
 
            rev2 = revision[1].in_history(b).revno
 
692
            rev1 = b.get_revision_info(revision[0])[0]
 
693
            rev2 = b.get_revision_info(revision[1])[0]
714
694
        else:
715
695
            raise BzrCommandError('bzr log --revision takes one or two values.')
716
696
 
752
732
    hidden = True
753
733
    takes_args = ["filename"]
754
734
    def run(self, filename):
755
 
        b = Branch.open_containing(filename)
 
735
        b = find_branch(filename)
756
736
        inv = b.read_working_inventory()
757
737
        file_id = inv.path2id(b.relpath(filename))
758
738
        for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
766
746
    """
767
747
    hidden = True
768
748
    def run(self, revision=None, verbose=False):
769
 
        b = Branch.open_containing('.')
 
749
        b = find_branch('.')
770
750
        if revision == None:
771
751
            tree = b.working_tree()
772
752
        else:
773
 
            tree = b.revision_tree(revision.in_history(b).rev_id)
 
753
            tree = b.revision_tree(b.lookup_revision(revision))
774
754
 
775
755
        for fp, fc, kind, fid in tree.list_files():
776
756
            if verbose:
791
771
    """List unknown files."""
792
772
    def run(self):
793
773
        from bzrlib.osutils import quotefn
794
 
        for f in Branch.open_containing('.').unknowns():
 
774
        for f in find_branch('.').unknowns():
795
775
            print quotefn(f)
796
776
 
797
777
 
819
799
        from bzrlib.atomicfile import AtomicFile
820
800
        import os.path
821
801
 
822
 
        b = Branch.open_containing('.')
 
802
        b = find_branch('.')
823
803
        ifn = b.abspath('.bzrignore')
824
804
 
825
805
        if os.path.exists(ifn):
859
839
 
860
840
    See also: bzr ignore"""
861
841
    def run(self):
862
 
        tree = Branch.open_containing('.').working_tree()
 
842
        tree = find_branch('.').working_tree()
863
843
        for path, file_class, kind, file_id in tree.list_files():
864
844
            if file_class != 'I':
865
845
                continue
883
863
        except ValueError:
884
864
            raise BzrCommandError("not a valid revision-number: %r" % revno)
885
865
 
886
 
        print Branch.open_containing('.').get_rev_id(revno)
 
866
        print find_branch('.').lookup_revision(revno)
887
867
 
888
868
 
889
869
class cmd_export(Command):
902
882
    takes_options = ['revision', 'format', 'root']
903
883
    def run(self, dest, revision=None, format=None, root=None):
904
884
        import os.path
905
 
        b = Branch.open_containing('.')
 
885
        b = find_branch('.')
906
886
        if revision is None:
907
887
            rev_id = b.last_patch()
908
888
        else:
909
889
            if len(revision) != 1:
910
890
                raise BzrError('bzr export --revision takes exactly 1 argument')
911
 
            rev_id = revision[0].in_history(b).rev_id
 
891
            revno, rev_id = b.get_revision_info(revision[0])
912
892
        t = b.revision_tree(rev_id)
913
893
        root, ext = os.path.splitext(dest)
914
894
        if not format:
930
910
    takes_args = ['filename']
931
911
 
932
912
    def run(self, filename, revision=None):
933
 
        if revision is None:
 
913
        if revision == None:
934
914
            raise BzrCommandError("bzr cat requires a revision number")
935
915
        elif len(revision) != 1:
936
916
            raise BzrCommandError("bzr cat --revision takes exactly one number")
937
 
        b = Branch.open_containing('.')
938
 
        b.print_file(b.relpath(filename), revision[0].in_history(b).revno)
 
917
        b = find_branch('.')
 
918
        b.print_file(b.relpath(filename), revision[0])
939
919
 
940
920
 
941
921
class cmd_local_time_offset(Command):
976
956
        from bzrlib.status import show_status
977
957
        from cStringIO import StringIO
978
958
 
979
 
        b = Branch.open_containing('.')
 
959
        b = find_branch('.')
980
960
        if selected_list:
981
961
            selected_list = [b.relpath(s) for s in selected_list]
982
962
            
1012
992
 
1013
993
    This command checks various invariants about the branch storage to
1014
994
    detect data corruption or bzr bugs.
 
995
 
 
996
    If given the --update flag, it will update some optional fields
 
997
    to help ensure data consistency.
1015
998
    """
1016
999
    takes_args = ['dir?']
1017
1000
 
1018
1001
    def run(self, dir='.'):
1019
1002
        from bzrlib.check import check
1020
1003
 
1021
 
        check(Branch.open_containing(dir))
 
1004
        check(find_branch(dir))
1022
1005
 
1023
1006
 
1024
1007
class cmd_scan_cache(Command):
1051
1034
 
1052
1035
    def run(self, dir='.'):
1053
1036
        from bzrlib.upgrade import upgrade
1054
 
        upgrade(Branch.open_containing(dir))
 
1037
        upgrade(find_branch(dir))
1055
1038
 
1056
1039
 
1057
1040
 
1061
1044
    
1062
1045
    def run(self, email=False):
1063
1046
        try:
1064
 
            b = bzrlib.branch.Branch.open_containing('.')
 
1047
            b = bzrlib.branch.find_branch('.')
1065
1048
        except:
1066
1049
            b = None
1067
1050
        
1133
1116
    def run(self, branch, other):
1134
1117
        from bzrlib.revision import common_ancestor, MultipleRevisionSources
1135
1118
        
1136
 
        branch1 = Branch.open_containing(branch)
1137
 
        branch2 = Branch.open_containing(other)
 
1119
        branch1 = find_branch(branch)
 
1120
        branch2 = find_branch(other)
1138
1121
 
1139
1122
        history_1 = branch1.revision_history()
1140
1123
        history_2 = branch2.revision_history()
1203
1186
            other = [branch, -1]
1204
1187
        else:
1205
1188
            if len(revision) == 1:
 
1189
                other = [branch, revision[0]]
1206
1190
                base = [None, None]
1207
 
                other = [branch, revision[0].in_history(branch).revno]
1208
1191
            else:
1209
1192
                assert len(revision) == 2
1210
1193
                if None in revision:
1211
1194
                    raise BzrCommandError(
1212
1195
                        "Merge doesn't permit that revision specifier.")
1213
 
                from bzrlib.branch import Branch
1214
 
                b = Branch.open(branch)
1215
 
 
1216
 
                base = [branch, revision[0].in_history(b).revno]
1217
 
                other = [branch, revision[1].in_history(b).revno]
 
1196
                base = [branch, revision[0]]
 
1197
                other = [branch, revision[1]]
1218
1198
 
1219
1199
        try:
1220
1200
            merge(other, base, check_clean=(not force), merge_type=merge_type)
1248
1228
            if len(file_list) == 0:
1249
1229
                raise BzrCommandError("No files specified")
1250
1230
        if revision is None:
1251
 
            revno = -1
 
1231
            revision = [-1]
1252
1232
        elif len(revision) != 1:
1253
1233
            raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1254
 
        else:
1255
 
            b = Branch.open_containing('.')
1256
 
            revno = revision[0].in_history(b).revno
1257
 
        merge(('.', revno), parse_spec('.'),
 
1234
        merge(('.', revision[0]), parse_spec('.'),
1258
1235
              check_clean=False,
1259
1236
              ignore_zero=True,
1260
1237
              backup_files=not no_backup,
1261
1238
              file_list=file_list)
1262
1239
        if not file_list:
1263
 
            Branch.open_containing('.').set_pending_merges([])
 
1240
            Branch('.').set_pending_merges([])
1264
1241
 
1265
1242
 
1266
1243
class cmd_assert_fail(Command):
1314
1291
        if verbose and quiet:
1315
1292
            raise BzrCommandError('Cannot pass both quiet and verbose')
1316
1293
 
1317
 
        b = Branch.open_containing('.')
 
1294
        b = find_branch('.')
1318
1295
        parent = b.get_parent()
1319
1296
        if remote is None:
1320
1297
            if parent is None:
1324
1301
                    print "Using last location: %s" % parent
1325
1302
                remote = parent
1326
1303
        elif parent is None:
1327
 
            # We only update parent if it did not exist, missing
1328
 
            # should not change the parent
1329
 
            b.set_parent(remote)
1330
 
        br_remote = Branch.open_containing(remote)
 
1304
            # We only update x-pull if it did not exist, missing should not change the parent
 
1305
            b.controlfile('x-pull', 'wb').write(remote + '\n')
 
1306
        br_remote = find_branch(remote)
 
1307
 
1331
1308
        return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
1332
1309
 
1333
1310
 
 
1311
 
1334
1312
class cmd_plugins(Command):
1335
1313
    """List plugins"""
1336
1314
    hidden = True