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
# XXX: FIXME: bzr status should accept a -r option to show changes
70
# relative to a revision, or between revisions
67
72
takes_args = ['file*']
68
73
takes_options = ['all', 'show-ids']
69
74
aliases = ['st', 'stat']
71
def run(self, all=False, show_ids=False, file_list=None):
76
def run(self, all=False, show_ids=False, file_list=None, revision=None):
73
b = find_branch(file_list[0])
78
b = Branch.open_containing(file_list[0])
74
79
file_list = [b.relpath(x) for x in file_list]
75
80
# special case: only one path was given and it's the root
77
82
if file_list == ['']:
85
b = Branch.open_containing('.')
82
87
from bzrlib.status import show_status
83
88
show_status(b, show_unchanged=all, show_ids=show_ids,
84
specific_files=file_list)
89
specific_files=file_list, revision=revision)
87
92
class cmd_cat_revision(Command):
88
"""Write out metadata for a revision."""
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.
91
takes_args = ['revision_id']
100
takes_args = ['revision_id?']
101
takes_options = ['revision']
93
def run(self, revision_id):
95
sys.stdout.write(b.get_revision_xml_file(revision_id).read())
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')
110
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())
98
121
class cmd_revno(Command):
99
122
"""Show current revision number.
101
124
This is equal to the number of revisions on this branch."""
103
print find_branch('.').revno()
126
print Branch.open_containing('.').revno()
106
129
class cmd_revision_info(Command):
110
133
takes_args = ['revision_info*']
111
134
takes_options = ['revision']
112
def run(self, revision=None, revision_info_list=None):
113
from bzrlib.branch import find_branch
135
def run(self, revision=None, revision_info_list=[]):
136
from bzrlib.revisionspec import RevisionSpec
116
139
if revision is not None:
117
140
revs.extend(revision)
118
141
if revision_info_list is not None:
119
revs.extend(revision_info_list)
142
for rev in revision_info_list:
143
revs.append(RevisionSpec(rev))
120
144
if len(revs) == 0:
121
145
raise BzrCommandError('You must supply a revision identifier')
147
b = Branch.open_containing('.')
126
print '%4d %s' % b.get_revision_info(rev)
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)
129
157
class cmd_add(Command):
192
220
takes_options = ['revision', 'show-ids']
194
222
def run(self, revision=None, show_ids=False):
223
b = Branch.open_containing('.')
197
225
inv = b.read_working_inventory()
199
227
if len(revision) > 1:
200
228
raise BzrCommandError('bzr inventory --revision takes'
201
229
' exactly one revision identifier')
202
inv = b.get_revision_inventory(b.lookup_revision(revision[0]))
230
inv = b.get_revision_inventory(revision[0].in_history(b).rev_id)
204
232
for path, entry in inv.entries():
318
340
print "Using last location: %s" % stored_loc
319
341
location = stored_loc
320
342
cache_root = tempfile.mkdtemp()
321
from bzrlib.branch import DivergedBranches
322
br_from = find_branch(location)
323
location = pull_loc(br_from)
343
from bzrlib.errors import DivergedBranches
344
br_from = Branch.open_containing(location)
345
location = br_from.base
324
346
old_revno = br_to.revno()
326
from branch import find_cached_branch, DivergedBranches
327
br_from = find_cached_branch(location, cache_root)
328
location = pull_loc(br_from)
348
from bzrlib.errors import DivergedBranches
349
br_from = Branch.open(location)
350
br_from.setup_caching(cache_root)
351
location = br_from.base
329
352
old_revno = br_to.revno()
331
354
br_to.update_revisions(br_from)
367
390
raise BzrCommandError(
368
391
'bzr branch --revision takes exactly 1 revision value')
370
br_from = find_cached_branch(from_location, cache_root)
393
br_from = Branch.open(from_location)
371
394
except OSError, e:
372
395
if e.errno == errno.ENOENT:
373
396
raise BzrCommandError('Source location "%s" does not'
374
397
' exist.' % to_location)
400
br_from.setup_caching(cache_root)
401
if len(revision) == 1 and revision[0] is not None:
402
revno = revision[0].in_history(br_from)[0]
377
405
if to_location is None:
378
406
to_location = os.path.basename(from_location.rstrip("/\\"))
481
509
"""Display list of revision ids on this branch."""
484
for patchid in find_branch('.').revision_history():
512
for patchid in Branch.open_containing('.').revision_history():
488
516
class cmd_directories(Command):
489
517
"""Display list of versioned directories in this branch."""
491
for name, ie in find_branch('.').read_working_inventory().directories():
519
for name, ie in Branch.open_containing('.').read_working_inventory().directories():
672
699
direction = (forward and 'forward') or 'reverse'
675
b = find_branch(filename)
702
b = Branch.open_containing(filename)
676
703
fp = b.relpath(filename)
678
705
file_id = b.read_working_inventory().path2id(fp)
680
707
file_id = None # points to branch root
709
b = Branch.open_containing('.')
685
712
if revision is None:
688
715
elif len(revision) == 1:
689
rev1 = rev2 = b.get_revision_info(revision[0])[0]
716
rev1 = rev2 = revision[0].in_history(b).revno
690
717
elif len(revision) == 2:
691
rev1 = b.get_revision_info(revision[0])[0]
692
rev2 = b.get_revision_info(revision[1])[0]
718
rev1 = revision[0].in_history(b).revno
719
rev2 = revision[1].in_history(b).revno
694
721
raise BzrCommandError('bzr log --revision takes one or two values.')
881
908
takes_options = ['revision', 'format', 'root']
882
909
def run(self, dest, revision=None, format=None, root=None):
911
b = Branch.open_containing('.')
885
912
if revision is None:
886
913
rev_id = b.last_patch()
888
915
if len(revision) != 1:
889
916
raise BzrError('bzr export --revision takes exactly 1 argument')
890
revno, rev_id = b.get_revision_info(revision[0])
917
rev_id = revision[0].in_history(b).rev_id
891
918
t = b.revision_tree(rev_id)
892
919
root, ext = os.path.splitext(dest)
909
936
takes_args = ['filename']
911
938
def run(self, filename, revision=None):
913
940
raise BzrCommandError("bzr cat requires a revision number")
914
941
elif len(revision) != 1:
915
942
raise BzrCommandError("bzr cat --revision takes exactly one number")
917
b.print_file(b.relpath(filename), revision[0])
943
b = Branch.open_containing('.')
944
b.print_file(b.relpath(filename), revision[0].in_history(b).revno)
920
947
class cmd_local_time_offset(Command):
1115
1139
def run(self, branch, other):
1116
1140
from bzrlib.revision import common_ancestor, MultipleRevisionSources
1118
branch1 = find_branch(branch)
1119
branch2 = find_branch(other)
1142
branch1 = Branch.open_containing(branch)
1143
branch2 = Branch.open_containing(other)
1121
1145
history_1 = branch1.revision_history()
1122
1146
history_2 = branch2.revision_history()
1185
1209
other = [branch, -1]
1187
1211
if len(revision) == 1:
1188
other = [branch, revision[0]]
1189
1212
base = [None, None]
1213
other = [branch, revision[0].in_history(branch).revno]
1191
1215
assert len(revision) == 2
1192
1216
if None in revision:
1193
1217
raise BzrCommandError(
1194
1218
"Merge doesn't permit that revision specifier.")
1195
base = [branch, revision[0]]
1196
other = [branch, revision[1]]
1219
b = Branch.open(branch)
1221
base = [branch, revision[0].in_history(b).revno]
1222
other = [branch, revision[1].in_history(b).revno]
1199
1225
merge(other, base, check_clean=(not force), merge_type=merge_type)
1221
1247
def run(self, revision=None, no_backup=False, file_list=None):
1222
1248
from bzrlib.merge import merge
1223
from bzrlib.branch import Branch
1224
1249
from bzrlib.commands import parse_spec
1226
1251
if file_list is not None:
1227
1252
if len(file_list) == 0:
1228
1253
raise BzrCommandError("No files specified")
1229
1254
if revision is None:
1231
1256
elif len(revision) != 1:
1232
1257
raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1233
merge(('.', revision[0]), parse_spec('.'),
1259
b = Branch.open_containing('.')
1260
revno = revision[0].in_history(b).revno
1261
merge(('.', revno), parse_spec('.'),
1234
1262
check_clean=False,
1235
1263
ignore_zero=True,
1236
1264
backup_files=not no_backup,
1237
1265
file_list=file_list)
1238
1266
if not file_list:
1239
Branch('.').set_pending_merges([])
1267
Branch.open_containing('.').set_pending_merges([])
1242
1270
class cmd_assert_fail(Command):
1300
1328
print "Using last location: %s" % parent
1301
1329
remote = parent
1302
1330
elif parent is None:
1303
# We only update x-pull if it did not exist, missing should not change the parent
1304
b.controlfile('x-pull', 'wb').write(remote + '\n')
1305
br_remote = find_branch(remote)
1331
# We only update parent if it did not exist, missing
1332
# should not change the parent
1333
b.set_parent(remote)
1334
br_remote = Branch.open_containing(remote)
1307
1336
return show_missing(b, br_remote, verbose=verbose, quiet=quiet)