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.
66
If a revision argument is given, the status is calculated against
67
that revision, or between two revisions if two are provided.
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']
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):
78
75
b = Branch.open_containing(file_list[0])
79
76
file_list = [b.relpath(x) for x in file_list]
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)
92
89
class cmd_cat_revision(Command):
93
"""Write out metadata for a revision.
95
The revision to print can either be specified by a specific
96
revision identifier, or you can use --revision.
90
"""Write out metadata for a revision."""
100
takes_args = ['revision_id?']
101
takes_options = ['revision']
93
takes_args = ['revision_id']
103
def run(self, revision_id=None, revision=None):
104
from bzrlib.revisionspec import RevisionSpec
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:
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())
97
sys.stdout.write(b.get_revision_xml_file(revision_id).read())
121
100
class cmd_revno(Command):
122
101
"""Show current revision number.
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
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')
147
125
b = Branch.open_containing('.')
150
revinfo = rev.in_history(b)
151
if revinfo.revno is None:
152
print ' %s' % revinfo.rev_id
154
print '%4d %s' % (revinfo.revno, revinfo.rev_id)
128
print '%4d %s' % rev.in_history(b)
157
131
class cmd_add(Command):
373
347
To retrieve the branch as of a particular revision, supply the --revision
374
348
parameter, as in "branch foo/bar -r 5".
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.
380
350
takes_args = ['from_location', 'to_location?']
381
takes_options = ['revision', 'basis']
351
takes_options = ['revision']
382
352
aliases = ['get', 'clone']
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
388
358
from shutil import rmtree
404
374
br_from.setup_caching(cache_root)
405
if basis is not None:
406
basis_branch = Branch.open_containing(basis)
409
if len(revision) == 1 and revision[0] is not None:
410
revision_id = revision[0].in_history(br_from)[1]
413
375
if to_location is None:
414
376
to_location = os.path.basename(from_location.rstrip("/\\"))
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"
435
395
rmtree(cache_root)
526
class cmd_ancestry(Command):
527
"""List all revisions merged into this branch."""
531
for revision_id in b.get_ancestry(b.last_revision()):
535
486
class cmd_directories(Command):
536
487
"""Display list of versioned directories in this branch."""
651
603
b = Branch.open_containing('.')
652
604
td = compare_trees(b.basis_tree(), b.working_tree())
654
for path, id, kind, text_modified, meta_modified in td.modified:
606
for path, id, kind in td.modified:
796
748
tree = b.working_tree()
798
750
tree = b.revision_tree(revision.in_history(b).rev_id)
799
for fp, fc, kind, fid, entry in tree.list_files():
752
for fp, fc, kind, fid in tree.list_files():
801
kindch = entry.kind_character()
754
if kind == 'directory':
802
761
print '%-8s %s%s' % (fc, fp, kindch)
878
837
See also: bzr ignore"""
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':
884
843
## XXX: Slightly inefficient since this was already calculated
923
882
b = Branch.open_containing('.')
924
883
if revision is None:
925
rev_id = b.last_revision()
884
rev_id = b.last_patch()
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':
890
root, ext = os.path.splitext(dest)
940
892
if ext in (".tar",):
942
elif ext in (".tar.gz", ".tgz"):
894
elif ext in (".gz", ".tgz"):
944
elif ext in (".tar.bz2", ".tbz2"):
896
elif ext in (".bz2", ".tbz2"):
993
945
aliases = ['ci', 'checkin']
995
947
# TODO: Give better message for -s, --summary, used by tla people
997
# XXX: verbose currently does nothing
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()
977
b.commit(message, verbose=verbose,
1028
978
specific_files=selected_list,
1029
979
allow_pointless=unchanged)
1030
980
except PointlessCommit:
1074
1024
The check command or bzr developers may sometimes advise you to run
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).
1080
1027
takes_args = ['dir?']
1082
1029
def run(self, dir='.'):
1083
1030
from bzrlib.upgrade import upgrade
1031
upgrade(Branch.open_containing(dir))
1087
1035
class cmd_whoami(Command):
1168
1116
history_1 = branch1.revision_history()
1169
1117
history_2 = branch2.revision_history()
1171
last1 = branch1.last_revision()
1172
last2 = branch2.last_revision()
1119
last1 = branch1.last_patch()
1120
last2 = branch2.last_patch()
1174
1122
source = MultipleRevisionSources(branch1, branch2)
1239
1187
if None in revision:
1240
1188
raise BzrCommandError(
1241
1189
"Merge doesn't permit that revision specifier.")
1242
b = Branch.open(branch)
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]
1248
1194
merge(other, base, check_clean=(not force), merge_type=merge_type)
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
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:
1279
1226
elif len(revision) != 1:
1280
1227
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
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)
1328
class cmd_fetch(Command):
1329
"""Copy in history from another branch but don't merge it.
1331
This is an internal method used for pull and merge."""
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)
1343
1272
class cmd_missing(Command):
1344
1273
"""What is missing in this branch relative to other branch.
1346
# TODO: rewrite this in terms of ancestry so that it shows only
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)
1376
1303
return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
1379
1307
class cmd_plugins(Command):
1380
1308
"""List plugins"""