~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:52:24 UTC
  • mto: (1185.1.29)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: aaron.bentley@utoronto.ca-20050919025224-1cc3c70640086e09
TODO re tests

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
 
24
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError
25
25
from bzrlib.branch import Branch
26
26
from bzrlib import BZRDIR
27
27
from bzrlib.commands import Command
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
75
            b = Branch.open_containing(file_list[0])
79
76
            file_list = [b.relpath(x) for x in file_list]
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
105
 
 
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')
 
95
    def run(self, revision_id):
110
96
        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
 
    
 
97
        sys.stdout.write(b.get_revision_xml_file(revision_id).read())
 
98
 
120
99
 
121
100
class cmd_revno(Command):
122
101
    """Show current revision number.
132
111
    hidden = True
133
112
    takes_args = ['revision_info*']
134
113
    takes_options = ['revision']
135
 
    def run(self, revision=None, revision_info_list=[]):
 
114
    def run(self, revision=None, revision_info_list=()):
136
115
        from bzrlib.revisionspec import RevisionSpec
137
116
 
138
117
        revs = []
139
118
        if revision is not None:
140
119
            revs.extend(revision)
141
 
        if revision_info_list is not None:
142
 
            for rev in revision_info_list:
143
 
                revs.append(RevisionSpec(rev))
 
120
        for rev in revision_info_list:
 
121
            revs.append(RevisionSpec(revision_info_list))
144
122
        if len(revs) == 0:
145
123
            raise BzrCommandError('You must supply a revision identifier')
146
124
 
147
125
        b = Branch.open_containing('.')
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' % rev.in_history(b)
155
129
 
156
130
    
157
131
class cmd_add(Command):
372
346
 
373
347
    To retrieve the branch as of a particular revision, supply the --revision
374
348
    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
349
    """
380
350
    takes_args = ['from_location', 'to_location?']
381
 
    takes_options = ['revision', 'basis']
 
351
    takes_options = ['revision']
382
352
    aliases = ['get', 'clone']
383
353
 
384
 
    def run(self, from_location, to_location=None, revision=None, basis=None):
385
 
        from bzrlib.clone import copy_branch
 
354
    def run(self, from_location, to_location=None, revision=None):
 
355
        from bzrlib.branch import copy_branch
386
356
        import tempfile
387
357
        import errno
388
358
        from shutil import rmtree
402
372
                else:
403
373
                    raise
404
374
            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
375
            if to_location is None:
414
376
                to_location = os.path.basename(from_location.rstrip("/\\"))
415
377
            try:
424
386
                else:
425
387
                    raise
426
388
            try:
427
 
                copy_branch(br_from, to_location, revision_id, basis_branch)
 
389
                copy_branch(br_from, to_location, revision[0])
428
390
            except bzrlib.errors.NoSuchRevision:
429
391
                rmtree(to_location)
430
392
                msg = "The branch %s has no revision %d." % (from_location, revision[0])
431
393
                raise BzrCommandError(msg)
432
 
            except bzrlib.errors.UnlistableBranch:
433
 
                msg = "The branch %s cannot be used as a --basis"
434
394
        finally:
435
395
            rmtree(cache_root)
436
396
 
523
483
            print patchid
524
484
 
525
485
 
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
486
class cmd_directories(Command):
536
487
    """Display list of versioned directories in this branch."""
537
488
    def run(self):
556
507
        bzr commit -m 'imported project'
557
508
    """
558
509
    def run(self):
 
510
        from bzrlib.branch import Branch
559
511
        Branch.initialize('.')
560
512
 
561
513
 
651
603
        b = Branch.open_containing('.')
652
604
        td = compare_trees(b.basis_tree(), b.working_tree())
653
605
 
654
 
        for path, id, kind, text_modified, meta_modified in td.modified:
 
606
        for path, id, kind in td.modified:
655
607
            print path
656
608
 
657
609
 
796
748
            tree = b.working_tree()
797
749
        else:
798
750
            tree = b.revision_tree(revision.in_history(b).rev_id)
799
 
        for fp, fc, kind, fid, entry in tree.list_files():
 
751
 
 
752
        for fp, fc, kind, fid in tree.list_files():
800
753
            if verbose:
801
 
                kindch = entry.kind_character()
 
754
                if kind == 'directory':
 
755
                    kindch = '/'
 
756
                elif kind == 'file':
 
757
                    kindch = ''
 
758
                else:
 
759
                    kindch = '???'
 
760
 
802
761
                print '%-8s %s%s' % (fc, fp, kindch)
803
762
            else:
804
763
                print fp
878
837
    See also: bzr ignore"""
879
838
    def run(self):
880
839
        tree = Branch.open_containing('.').working_tree()
881
 
        for path, file_class, kind, file_id, entry in tree.list_files():
 
840
        for path, file_class, kind, file_id in tree.list_files():
882
841
            if file_class != 'I':
883
842
                continue
884
843
            ## XXX: Slightly inefficient since this was already calculated
922
881
        import os.path
923
882
        b = Branch.open_containing('.')
924
883
        if revision is None:
925
 
            rev_id = b.last_revision()
 
884
            rev_id = b.last_patch()
926
885
        else:
927
886
            if len(revision) != 1:
928
887
                raise BzrError('bzr export --revision takes exactly 1 argument')
929
888
            rev_id = revision[0].in_history(b).rev_id
930
889
        t = b.revision_tree(rev_id)
931
 
        arg_root, ext = os.path.splitext(os.path.basename(dest))
932
 
        if ext in ('.gz', '.bz2'):
933
 
            new_root, new_ext = os.path.splitext(arg_root)
934
 
            if new_ext == '.tar':
935
 
                arg_root = new_root
936
 
                ext = new_ext + ext
937
 
        if root is None:
938
 
            root = arg_root
 
890
        root, ext = os.path.splitext(dest)
939
891
        if not format:
940
892
            if ext in (".tar",):
941
893
                format = "tar"
942
 
            elif ext in (".tar.gz", ".tgz"):
 
894
            elif ext in (".gz", ".tgz"):
943
895
                format = "tgz"
944
 
            elif ext in (".tar.bz2", ".tbz2"):
 
896
            elif ext in (".bz2", ".tbz2"):
945
897
                format = "tbz2"
946
898
            else:
947
899
                format = "dir"
993
945
    aliases = ['ci', 'checkin']
994
946
 
995
947
    # TODO: Give better message for -s, --summary, used by tla people
996
 
 
997
 
    # XXX: verbose currently does nothing
998
948
    
999
949
    def run(self, message=None, file=None, verbose=True, selected_list=None,
1000
950
            unchanged=False):
1024
974
            message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
1025
975
 
1026
976
        try:
1027
 
            b.commit(message,
 
977
            b.commit(message, verbose=verbose,
1028
978
                     specific_files=selected_list,
1029
979
                     allow_pointless=unchanged)
1030
980
        except PointlessCommit:
1073
1023
 
1074
1024
    The check command or bzr developers may sometimes advise you to run
1075
1025
    this command.
1076
 
 
1077
 
    This version of this command upgrades from the full-text storage
1078
 
    used by bzr 0.0.8 and earlier to the weave format (v5).
1079
1026
    """
1080
1027
    takes_args = ['dir?']
1081
1028
 
1082
1029
    def run(self, dir='.'):
1083
1030
        from bzrlib.upgrade import upgrade
1084
 
        upgrade(dir)
 
1031
        upgrade(Branch.open_containing(dir))
 
1032
 
1085
1033
 
1086
1034
 
1087
1035
class cmd_whoami(Command):
1091
1039
    def run(self, email=False):
1092
1040
        try:
1093
1041
            b = bzrlib.branch.Branch.open_containing('.')
1094
 
        except NotBranchError:
 
1042
        except:
1095
1043
            b = None
1096
1044
        
1097
1045
        if email:
1168
1116
        history_1 = branch1.revision_history()
1169
1117
        history_2 = branch2.revision_history()
1170
1118
 
1171
 
        last1 = branch1.last_revision()
1172
 
        last2 = branch2.last_revision()
 
1119
        last1 = branch1.last_patch()
 
1120
        last2 = branch2.last_patch()
1173
1121
 
1174
1122
        source = MultipleRevisionSources(branch1, branch2)
1175
1123
        
1239
1187
                if None in revision:
1240
1188
                    raise BzrCommandError(
1241
1189
                        "Merge doesn't permit that revision specifier.")
1242
 
                b = Branch.open(branch)
1243
 
 
1244
 
                base = [branch, revision[0].in_history(b).revno]
1245
 
                other = [branch, revision[1].in_history(b).revno]
 
1190
                base = [branch, revision[0].in_history(branch).revno]
 
1191
                other = [branch, revision[1].in_history(branch).revno]
1246
1192
 
1247
1193
        try:
1248
1194
            merge(other, base, check_clean=(not force), merge_type=merge_type)
1269
1215
 
1270
1216
    def run(self, revision=None, no_backup=False, file_list=None):
1271
1217
        from bzrlib.merge import merge
 
1218
        from bzrlib.branch import Branch
1272
1219
        from bzrlib.commands import parse_spec
1273
1220
 
1274
1221
        if file_list is not None:
1275
1222
            if len(file_list) == 0:
1276
1223
                raise BzrCommandError("No files specified")
1277
1224
        if revision is None:
1278
 
            revno = -1
 
1225
            revision = [-1]
1279
1226
        elif len(revision) != 1:
1280
1227
            raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1281
 
        else:
1282
 
            b = Branch.open_containing('.')
1283
 
            revno = revision[0].in_history(b).revno
1284
 
        merge(('.', revno), parse_spec('.'),
 
1228
        merge(('.', revision[0]), parse_spec('.'),
1285
1229
              check_clean=False,
1286
1230
              ignore_zero=True,
1287
1231
              backup_files=not no_backup,
1325
1269
        shellcomplete.shellcomplete(context)
1326
1270
 
1327
1271
 
1328
 
class cmd_fetch(Command):
1329
 
    """Copy in history from another branch but don't merge it.
1330
 
 
1331
 
    This is an internal method used for pull and merge."""
1332
 
    hidden = True
1333
 
    takes_args = ['from_branch', 'to_branch']
1334
 
    def run(self, from_branch, to_branch):
1335
 
        from bzrlib.fetch import Fetcher
1336
 
        from bzrlib.branch import Branch
1337
 
        from_b = Branch(from_branch)
1338
 
        to_b = Branch(to_branch)
1339
 
        Fetcher(to_b, from_b)
1340
 
        
1341
 
 
1342
 
 
1343
1272
class cmd_missing(Command):
1344
1273
    """What is missing in this branch relative to other branch.
1345
1274
    """
1346
 
    # TODO: rewrite this in terms of ancestry so that it shows only
1347
 
    # unmerged things
1348
 
    
1349
1275
    takes_args = ['remote?']
1350
1276
    aliases = ['mis', 'miss']
1351
1277
    # We don't have to add quiet to the list, because 
1373
1299
            # should not change the parent
1374
1300
            b.set_parent(remote)
1375
1301
        br_remote = Branch.open_containing(remote)
 
1302
 
1376
1303
        return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
1377
1304
 
1378
1305
 
 
1306
 
1379
1307
class cmd_plugins(Command):
1380
1308
    """List plugins"""
1381
1309
    hidden = True