~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Aaron Bentley
  • Date: 2005-10-18 20:19:44 UTC
  • mfrom: (1463) (0.2.1)
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1474.
  • Revision ID: abentley@panoramicfeedback.com-20051018201944-42864e79d8e9ad29
Merged more from Robert

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
    
80
80
    def run(self, all=False, show_ids=False, file_list=None, revision=None):
81
81
        if file_list:
82
 
            b = Branch.open_containing(file_list[0])
83
 
            tree = WorkingTree(b.base, b)
84
 
            file_list = [tree.relpath(x) for x in file_list]
85
 
            # special case: only one path was given and it's the root
86
 
            # of the branch
87
 
            if file_list == ['']:
 
82
            b, relpath = Branch.open_containing(file_list[0])
 
83
            if relpath == '' and len(file_list) == 1:
88
84
                file_list = None
 
85
            else:
 
86
                # generate relative paths.
 
87
                # note that if this is a remote branch, we would want
 
88
                # relpath against the transport. RBC 20051018
 
89
                tree = WorkingTree(b.base, b)
 
90
                file_list = [tree.relpath(x) for x in file_list]
89
91
        else:
90
 
            b = Branch.open_containing('.')
 
92
            b = Branch.open_containing('.')[0]
91
93
            
92
94
        from bzrlib.status import show_status
93
95
        show_status(b, show_unchanged=all, show_ids=show_ids,
111
113
            raise BzrCommandError('You can only supply one of revision_id or --revision')
112
114
        if revision_id is None and revision is None:
113
115
            raise BzrCommandError('You must supply either --revision or a revision_id')
114
 
        b = Branch.open_containing('.')
 
116
        b = Branch.open_containing('.')[0]
115
117
        if revision_id is not None:
116
118
            sys.stdout.write(b.get_revision_xml_file(revision_id).read())
117
119
        elif revision is not None:
127
129
 
128
130
    This is equal to the number of revisions on this branch."""
129
131
    def run(self):
130
 
        print Branch.open_containing('.').revno()
 
132
        print Branch.open_containing('.')[0].revno()
131
133
 
132
134
 
133
135
class cmd_revision_info(Command):
147
149
        if len(revs) == 0:
148
150
            raise BzrCommandError('You must supply a revision identifier')
149
151
 
150
 
        b = Branch.open_containing('.')
 
152
        b = Branch.open_containing('.')[0]
151
153
 
152
154
        for rev in revs:
153
155
            revinfo = rev.in_history(b)
205
207
        for d in dir_list:
206
208
            os.mkdir(d)
207
209
            if not b:
208
 
                b = Branch.open_containing(d)
 
210
                b = Branch.open_containing(d)[0]
209
211
            b.add([d])
210
212
            print 'added', d
211
213
 
216
218
    hidden = True
217
219
    
218
220
    def run(self, filename):
219
 
        branch = Branch.open_containing(filename)
220
 
        print WorkingTree(branch.base, branch).relpath(filename)
 
221
        branch, relpath = Branch.open_containing(filename)
 
222
        print relpath
221
223
 
222
224
 
223
225
class cmd_inventory(Command):
225
227
    takes_options = ['revision', 'show-ids']
226
228
    
227
229
    def run(self, revision=None, show_ids=False):
228
 
        b = Branch.open_containing('.')
 
230
        b = Branch.open_containing('.')[0]
229
231
        if revision is None:
230
232
            inv = b.read_working_inventory()
231
233
        else:
251
253
    """
252
254
    takes_args = ['source$', 'dest']
253
255
    def run(self, source_list, dest):
254
 
        b = Branch.open_containing('.')
 
256
        b = Branch.open_containing('.')[0]
255
257
 
256
258
        # TODO: glob expansion on windows?
257
259
        tree = WorkingTree(b.base, b)
275
277
    takes_args = ['from_name', 'to_name']
276
278
    
277
279
    def run(self, from_name, to_name):
278
 
        b = Branch.open_containing('.')
 
280
        b = Branch.open_containing('.')[0]
279
281
        tree = WorkingTree(b.base, b)
280
282
        b.rename_one(tree.relpath(from_name), tree.relpath(to_name))
281
283
 
297
299
    def run(self, names_list):
298
300
        if len(names_list) < 2:
299
301
            raise BzrCommandError("missing file argument")
300
 
        b = Branch.open_containing(names_list[0])
 
302
        b = Branch.open_containing(names_list[0])[0]
301
303
        tree = WorkingTree(b.base, b)
302
304
        rel_names = [tree.relpath(x) for x in names_list]
303
305
        
329
331
    If branches have diverged, you can use 'bzr merge' to pull the text changes
330
332
    from one into the other.
331
333
    """
332
 
    takes_options = ['remember']
 
334
    takes_options = ['remember', 'clobber']
333
335
    takes_args = ['location?']
334
336
 
335
 
    def run(self, location=None, remember=False):
 
337
    def run(self, location=None, remember=False, clobber=False):
336
338
        from bzrlib.merge import merge
337
339
        import tempfile
338
340
        from shutil import rmtree
339
341
        import errno
340
342
        
341
 
        br_to = Branch.open_containing('.')
 
343
        br_to = Branch.open_containing('.')[0]
342
344
        stored_loc = br_to.get_parent()
343
345
        if location is None:
344
346
            if stored_loc is None:
346
348
            else:
347
349
                print "Using saved location: %s" % stored_loc
348
350
                location = stored_loc
349
 
        cache_root = tempfile.mkdtemp()
350
351
        br_from = Branch.open(location)
351
 
        br_from.lock_read()
352
352
        try:
353
 
            br_from.setup_caching(cache_root)
354
 
            location = br_from.base
355
 
            old_revno = br_to.revno()
356
 
            old_revision_history = br_to.revision_history()
357
 
            try:
358
 
                br_to.update_revisions(br_from)
359
 
            except DivergedBranches:
360
 
                raise BzrCommandError("These branches have diverged."
361
 
                    "  Try merge.")
362
 
            new_revision_history = br_to.revision_history()
363
 
            if new_revision_history != old_revision_history:
364
 
                merge(('.', -1), ('.', old_revno), check_clean=False)
365
 
            if stored_loc is None or remember:
366
 
                br_to.set_parent(location)
367
 
        finally:
368
 
            br_from.unlock()
369
 
            rmtree(cache_root)
370
 
 
 
353
            br_to.working_tree().pull(br_from, remember, clobber)
 
354
        except DivergedBranches:
 
355
            raise BzrCommandError("These branches have diverged."
 
356
                                  "  Try merge.")
371
357
 
372
358
 
373
359
class cmd_branch(Command):
410
396
        try:
411
397
            br_from.setup_caching(cache_root)
412
398
            if basis is not None:
413
 
                basis_branch = Branch.open_containing(basis)
 
399
                basis_branch = Branch.open_containing(basis)[0]
414
400
            else:
415
401
                basis_branch = None
416
402
            if len(revision) == 1 and revision[0] is not None:
452
438
    takes_args = ['dir?']
453
439
 
454
440
    def run(self, dir='.'):
455
 
        b = Branch.open_containing(dir)
 
441
        b = Branch.open_containing(dir)[0]
456
442
        old_inv = b.basis_tree().inventory
457
443
        new_inv = b.read_working_inventory()
458
444
 
468
454
    
469
455
    def run(self, branch=None):
470
456
        import info
471
 
        b = Branch.open_containing(branch)
 
457
        b = Branch.open_containing(branch)[0]
472
458
        info.show_info(b)
473
459
 
474
460
 
483
469
    aliases = ['rm']
484
470
    
485
471
    def run(self, file_list, verbose=False):
486
 
        b = Branch.open_containing(file_list[0])
 
472
        b = Branch.open_containing(file_list[0])[0]
487
473
        tree = WorkingTree(b.base, b)
488
 
        b.remove([tree.relpath(f) for f in file_list], verbose=verbose)
 
474
        tree.remove([tree.relpath(f) for f in file_list], verbose=verbose)
489
475
 
490
476
 
491
477
class cmd_file_id(Command):
498
484
    hidden = True
499
485
    takes_args = ['filename']
500
486
    def run(self, filename):
501
 
        b = Branch.open_containing(filename)
502
 
        tree = WorkingTree(b.base, b)
503
 
        i = b.inventory.path2id(tree.relpath(filename))
 
487
        b, relpath = Branch.open_containing(filename)
 
488
        i = b.inventory.path2id(relpath)
504
489
        if i == None:
505
490
            raise BzrError("%r is not a versioned file" % filename)
506
491
        else:
515
500
    hidden = True
516
501
    takes_args = ['filename']
517
502
    def run(self, filename):
518
 
        b = Branch.open_containing(filename)
 
503
        b, relpath = Branch.open_containing(filename)
519
504
        inv = b.inventory
520
 
        tree = WorkingTree(b.base, b)
521
 
        fid = inv.path2id(tree.relpath(filename))
 
505
        fid = inv.path2id(relpath)
522
506
        if fid == None:
523
507
            raise BzrError("%r is not a versioned file" % filename)
524
508
        for fip in inv.get_idpath(fid):
529
513
    """Display list of revision ids on this branch."""
530
514
    hidden = True
531
515
    def run(self):
532
 
        for patchid in Branch.open_containing('.').revision_history():
 
516
        for patchid in Branch.open_containing('.')[0].revision_history():
533
517
            print patchid
534
518
 
535
519
 
545
529
class cmd_directories(Command):
546
530
    """Display list of versioned directories in this branch."""
547
531
    def run(self):
548
 
        for name, ie in Branch.open_containing('.').read_working_inventory().directories():
 
532
        for name, ie in Branch.open_containing('.')[0].read_working_inventory().directories():
549
533
            if name == '':
550
534
                print '.'
551
535
            else:
602
586
        from bzrlib.diff import show_diff
603
587
 
604
588
        if file_list:
605
 
            b = Branch.open_containing(file_list[0])
 
589
            b = Branch.open_containing(file_list[0])[0]
606
590
            tree = WorkingTree(b.base, b)
607
591
            file_list = [tree.relpath(f) for f in file_list]
608
592
            if file_list == ['']:
609
593
                # just pointing to top-of-tree
610
594
                file_list = None
611
595
        else:
612
 
            b = Branch.open_containing('.')
 
596
            b = Branch.open_containing('.')[0]
613
597
 
614
598
        if revision is not None:
615
599
            if len(revision) == 1:
638
622
    # level of effort but possibly much less IO.  (Or possibly not,
639
623
    # if the directories are very large...)
640
624
    def run(self, show_ids=False):
641
 
        b = Branch.open_containing('.')
 
625
        b = Branch.open_containing('.')[0]
642
626
        old = b.basis_tree()
643
627
        new = b.working_tree()
644
628
        for path, ie in old.inventory.iter_entries():
655
639
    def run(self):
656
640
        from bzrlib.delta import compare_trees
657
641
 
658
 
        b = Branch.open_containing('.')
 
642
        b = Branch.open_containing('.')[0]
659
643
        td = compare_trees(b.basis_tree(), b.working_tree())
660
644
 
661
645
        for path, id, kind, text_modified, meta_modified in td.modified:
667
651
    """List files added in working tree."""
668
652
    hidden = True
669
653
    def run(self):
670
 
        b = Branch.open_containing('.')
 
654
        b = Branch.open_containing('.')[0]
671
655
        wt = b.working_tree()
672
656
        basis_inv = b.basis_tree().inventory
673
657
        inv = wt.inventory
689
673
    takes_args = ['filename?']
690
674
    def run(self, filename=None):
691
675
        """Print the branch root."""
692
 
        b = Branch.open_containing(filename)
 
676
        b = Branch.open_containing(filename)[0]
693
677
        print b.base
694
678
 
695
679
 
732
716
        direction = (forward and 'forward') or 'reverse'
733
717
        
734
718
        if filename:
735
 
            b = Branch.open_containing(filename)
736
 
            tree = WorkingTree(b.base, b)
737
 
            fp = tree.relpath(filename)
738
 
            if fp:
 
719
            b, fp = Branch.open_containing(filename)
 
720
            if fp != '':
739
721
                file_id = b.read_working_inventory().path2id(fp)
740
722
            else:
741
723
                file_id = None  # points to branch root
742
724
        else:
743
 
            b = Branch.open_containing('.')
 
725
            b, relpath = Branch.open_containing('.')
744
726
            file_id = None
745
727
 
746
728
        if revision is None:
793
775
    hidden = True
794
776
    takes_args = ["filename"]
795
777
    def run(self, filename):
796
 
        b = Branch.open_containing(filename)
 
778
        b, relpath = Branch.open_containing(filename)[0]
797
779
        inv = b.read_working_inventory()
798
 
        tree = WorkingTree(b.base, b)
799
 
        file_id = inv.path2id(tree.relpath(filename))
 
780
        file_id = inv.path2id(relpath)
800
781
        for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
801
782
            print "%6d %s" % (revno, what)
802
783
 
807
788
    # TODO: Take a revision or remote path and list that tree instead.
808
789
    hidden = True
809
790
    def run(self, revision=None, verbose=False):
810
 
        b = Branch.open_containing('.')
 
791
        b, relpath = Branch.open_containing('.')[0]
811
792
        if revision == None:
812
793
            tree = b.working_tree()
813
794
        else:
825
806
    """List unknown files."""
826
807
    def run(self):
827
808
        from bzrlib.osutils import quotefn
828
 
        for f in Branch.open_containing('.').unknowns():
 
809
        for f in Branch.open_containing('.')[0].unknowns():
829
810
            print quotefn(f)
830
811
 
831
812
 
855
836
        from bzrlib.atomicfile import AtomicFile
856
837
        import os.path
857
838
 
858
 
        b = Branch.open_containing('.')
 
839
        b, relpath = Branch.open_containing('.')
859
840
        ifn = b.abspath('.bzrignore')
860
841
 
861
842
        if os.path.exists(ifn):
895
876
 
896
877
    See also: bzr ignore"""
897
878
    def run(self):
898
 
        tree = Branch.open_containing('.').working_tree()
 
879
        tree = Branch.open_containing('.')[0].working_tree()
899
880
        for path, file_class, kind, file_id, entry in tree.list_files():
900
881
            if file_class != 'I':
901
882
                continue
919
900
        except ValueError:
920
901
            raise BzrCommandError("not a valid revision-number: %r" % revno)
921
902
 
922
 
        print Branch.open_containing('.').get_rev_id(revno)
 
903
        print Branch.open_containing('.')[0].get_rev_id(revno)
923
904
 
924
905
 
925
906
class cmd_export(Command):
938
919
    takes_options = ['revision', 'format', 'root']
939
920
    def run(self, dest, revision=None, format=None, root=None):
940
921
        import os.path
941
 
        b = Branch.open_containing('.')
 
922
        b = Branch.open_containing('.')[0]
942
923
        if revision is None:
943
924
            rev_id = b.last_revision()
944
925
        else:
977
958
            raise BzrCommandError("bzr cat requires a revision number")
978
959
        elif len(revision) != 1:
979
960
            raise BzrCommandError("bzr cat --revision takes exactly one number")
980
 
        b = Branch.open_containing('.')
981
 
        tree = WorkingTree(b.base, b)
982
 
        b.print_file(tree.relpath(filename), revision[0].in_history(b).revno)
 
961
        b, relpath = Branch.open_containing(filename)
 
962
        b.print_file(relpath, revision[0].in_history(b).revno)
983
963
 
984
964
 
985
965
class cmd_local_time_offset(Command):
1027
1007
        from bzrlib.status import show_status
1028
1008
        from cStringIO import StringIO
1029
1009
 
1030
 
        b = Branch.open_containing('.')
 
1010
        b = Branch.open_containing('.')[0]
1031
1011
        tree = WorkingTree(b.base, b)
1032
1012
        if selected_list:
1033
1013
            selected_list = [tree.relpath(s) for s in selected_list]
1075
1055
 
1076
1056
    def run(self, dir='.', verbose=False):
1077
1057
        from bzrlib.check import check
1078
 
        check(Branch.open_containing(dir), verbose)
 
1058
        check(Branch.open_containing(dir)[0], verbose)
1079
1059
 
1080
1060
 
1081
1061
class cmd_scan_cache(Command):
1120
1100
    
1121
1101
    def run(self, email=False):
1122
1102
        try:
1123
 
            b = bzrlib.branch.Branch.open_containing('.')
 
1103
            b = bzrlib.branch.Branch.open_containing('.')[0]
1124
1104
            config = bzrlib.config.BranchConfig(b)
1125
1105
        except NotBranchError:
1126
1106
            config = bzrlib.config.GlobalConfig()
1212
1192
    def run(self, branch, other):
1213
1193
        from bzrlib.revision import common_ancestor, MultipleRevisionSources
1214
1194
        
1215
 
        branch1 = Branch.open_containing(branch)
1216
 
        branch2 = Branch.open_containing(other)
 
1195
        branch1 = Branch.open_containing(branch)[0]
 
1196
        branch2 = Branch.open_containing(other)[0]
1217
1197
 
1218
1198
        history_1 = branch1.revision_history()
1219
1199
        history_2 = branch2.revision_history()
1277
1257
        if merge_type is None:
1278
1258
            merge_type = ApplyMerge3
1279
1259
        if branch is None:
1280
 
            branch = Branch.open_containing('.').get_parent()
 
1260
            branch = Branch.open_containing('.')[0].get_parent()
1281
1261
            if branch is None:
1282
1262
                raise BzrCommandError("No merge location known or specified.")
1283
1263
            else:
1288
1268
        else:
1289
1269
            if len(revision) == 1:
1290
1270
                base = [None, None]
1291
 
                other_branch = Branch.open_containing(branch)
 
1271
                other_branch = Branch.open_containing(branch)[0]
1292
1272
                revno = revision[0].in_history(other_branch).revno
1293
1273
                other = [branch, revno]
1294
1274
            else:
1296
1276
                if None in revision:
1297
1277
                    raise BzrCommandError(
1298
1278
                        "Merge doesn't permit that revision specifier.")
1299
 
                b = Branch.open_containing(branch)
 
1279
                b = Branch.open_containing(branch)[0]
1300
1280
 
1301
1281
                base = [branch, revision[0].in_history(b).revno]
1302
1282
                other = [branch, revision[1].in_history(b).revno]
1336
1316
        elif len(revision) != 1:
1337
1317
            raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1338
1318
        else:
1339
 
            b = Branch.open_containing('.')
 
1319
            b = Branch.open_containing('.')[0]
1340
1320
            revno = revision[0].in_history(b).revno
1341
1321
        merge(('.', revno), parse_spec('.'),
1342
1322
              check_clean=False,
1344
1324
              backup_files=not no_backup,
1345
1325
              file_list=file_list)
1346
1326
        if not file_list:
1347
 
            Branch.open_containing('.').set_pending_merges([])
 
1327
            Branch.open_containing('.')[0].set_pending_merges([])
1348
1328
 
1349
1329
 
1350
1330
class cmd_assert_fail(Command):
1416
1396
        if verbose and quiet:
1417
1397
            raise BzrCommandError('Cannot pass both quiet and verbose')
1418
1398
 
1419
 
        b = Branch.open_containing('.')
 
1399
        b = Branch.open_containing('.')[0]
1420
1400
        parent = b.get_parent()
1421
1401
        if remote is None:
1422
1402
            if parent is None:
1429
1409
            # We only update parent if it did not exist, missing
1430
1410
            # should not change the parent
1431
1411
            b.set_parent(remote)
1432
 
        br_remote = Branch.open_containing(remote)
 
1412
        br_remote = Branch.open_containing(remote)[0]
1433
1413
        return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
1434
1414
 
1435
1415
 
1458
1438
    takes_args = ['branch?']
1459
1439
    def run(self, branch='.', revision=None, long=False):
1460
1440
        from bzrlib.testament import Testament
1461
 
        b = Branch.open_containing(branch)
 
1441
        b = Branch.open_containing(branch)[0]
1462
1442
        b.lock_read()
1463
1443
        try:
1464
1444
            if revision is None:
1495
1475
 
1496
1476
    def run(self, filename, all=False, long=False):
1497
1477
        from bzrlib.annotate import annotate_file
1498
 
        b = Branch.open_containing(filename)
 
1478
        b, relpath = Branch.open_containing(filename)
1499
1479
        b.lock_read()
1500
1480
        try:
1501
1481
            tree = WorkingTree(b.base, b)
1502
 
            rp = tree.relpath(filename)
1503
1482
            tree = b.revision_tree(b.last_revision())
1504
 
            file_id = tree.inventory.path2id(rp)
 
1483
            file_id = tree.inventory.path2id(relpath)
1505
1484
            file_version = tree.inventory[file_id].revision
1506
1485
            annotate_file(b, file_version, file_id, long, all, sys.stdout)
1507
1486
        finally:
1523
1502
            raise BzrCommandError('You can only supply one of revision_id or --revision')
1524
1503
        if revision_id is None and revision is None:
1525
1504
            raise BzrCommandError('You must supply either --revision or a revision_id')
1526
 
        b = Branch.open_containing('.')
 
1505
        b = Branch.open_containing('.')[0]
1527
1506
        gpg_strategy = gpg.GPGStrategy(config.BranchConfig(b))
1528
1507
        if revision_id is not None:
1529
1508
            b.sign_revision(revision_id, gpg_strategy)