147
148
takes_args = ['file*']
148
149
takes_options = ['all', 'show-ids', 'revision']
149
150
aliases = ['st', 'stat']
152
encoding_type = 'replace'
152
155
def run(self, all=False, show_ids=False, file_list=None, revision=None):
153
tree, file_list = tree_files(file_list)
155
156
from bzrlib.status import show_tree_status
158
tree, file_list = tree_files(file_list)
156
160
show_tree_status(tree, show_unchanged=all, show_ids=show_ids,
157
specific_files=file_list, revision=revision)
161
specific_files=file_list, revision=revision,
160
165
class cmd_cat_revision(Command):
176
181
if revision_id is None and revision is None:
177
182
raise BzrCommandError('You must supply either --revision or a revision_id')
178
183
b = WorkingTree.open_containing(u'.')[0].branch
185
# TODO: jam 20060112 should cat-revision always output utf-8?
179
186
if revision_id is not None:
180
sys.stdout.write(b.repository.get_revision_xml(revision_id))
187
self.outf.write(b.repository.get_revision_xml(revision_id).decode('utf-8'))
181
188
elif revision is not None:
182
189
for rev in revision:
184
191
raise BzrCommandError('You cannot specify a NULL revision.')
185
192
revno, rev_id = rev.in_history(b)
186
sys.stdout.write(b.repository.get_revision_xml(rev_id))
193
self.outf.write(b.repository.get_revision_xml(rev_id).decode('utf-8'))
189
196
class cmd_revno(Command):
190
197
"""Show current revision number.
192
This is equal to the number of revisions on this branch."""
199
This is equal to the number of revisions on this branch.
193
202
takes_args = ['location?']
195
205
def run(self, location=u'.'):
196
print Branch.open_containing(location)[0].revno()
206
self.outf.write(str(Branch.open_containing(location)[0].revno()))
207
self.outf.write('\n')
199
210
class cmd_revision_info(Command):
253
265
takes_args = ['file*']
254
266
takes_options = ['no-recurse', 'dry-run', 'verbose']
267
encoding_type = 'replace'
256
269
def run(self, file_list, no_recurse=False, dry_run=False, verbose=False):
257
270
import bzrlib.add
261
# This is pointless, but I'd rather not raise an error
262
action = bzrlib.add.add_action_null
264
action = bzrlib.add.add_action_print
266
action = bzrlib.add.add_action_add
268
action = bzrlib.add.add_action_add_and_print
272
action = bzrlib.add.AddAction(to_file=self.outf,
273
should_add=(not dry_run), should_print=(not is_quiet()))
270
275
added, ignored = bzrlib.add.smart_add(file_list, not no_recurse,
272
277
if len(ignored) > 0:
273
278
for glob in sorted(ignored.keys()):
274
279
match_len = len(ignored[glob])
276
281
for path in ignored[glob]:
277
print "ignored %s matching \"%s\"" % (path, glob)
282
self.outf.write("ignored %s matching \"%s\"\n"
279
print "ignored %d file(s) matching \"%s\"" % (match_len,
281
print "If you wish to add some of these files, please add them"\
285
self.outf.write("ignored %d file(s) matching \"%s\"\n"
287
self.outf.write("If you wish to add some of these files,"
288
" please add them by name.\n")
285
291
class cmd_mkdir(Command):
288
294
This is equivalent to creating the directory and then adding it.
290
296
takes_args = ['dir+']
297
encoding_type = 'replace'
292
299
def run(self, dir_list):
293
300
for d in dir_list:
295
302
wt, dd = WorkingTree.open_containing(d)
304
self.outf.write('added ')
306
self.outf.write('\n')
300
309
class cmd_relpath(Command):
306
315
def run(self, filename):
316
# TODO: jam 20050106 Can relpath return a munged path if
317
# sys.stdout encoding cannot represent it?
307
318
tree, relpath = WorkingTree.open_containing(filename)
319
self.outf.write(relpath)
320
self.outf.write('\n')
311
323
class cmd_inventory(Command):
355
368
takes_args = ['names*']
356
369
aliases = ['move', 'rename']
371
encoding_type = 'replace'
358
373
def run(self, names_list):
359
374
if len(names_list) < 2:
360
375
raise BzrCommandError("missing file argument")
363
378
if os.path.isdir(names_list[-1]):
364
379
# move into existing directory
365
380
for pair in tree.move(rel_names[:-1], rel_names[-1]):
366
print "%s => %s" % pair
381
self.outf.write("%s => %s\n" % pair)
368
383
if len(names_list) != 2:
369
384
raise BzrCommandError('to mv multiple files the destination '
370
385
'must be a versioned directory')
371
386
tree.rename_one(rel_names[0], rel_names[1])
372
print "%s => %s" % (rel_names[0], rel_names[1])
387
self.outf.write("%s => %s\n" % (rel_names[0], rel_names[1]))
375
390
class cmd_pull(Command):
397
412
takes_options = ['remember', 'overwrite', 'revision', 'verbose']
398
413
takes_args = ['location?']
414
encoding_type = 'replace'
400
416
def run(self, location=None, remember=False, overwrite=False, revision=None, verbose=False):
401
417
# FIXME: too much stuff is in the command class
410
426
if stored_loc is None:
411
427
raise BzrCommandError("No pull location known or specified.")
413
print "Using saved location: %s" % stored_loc
429
self.outf.write("Using saved location: %s\n" % stored_loc)
414
430
location = stored_loc
416
432
if branch_to.get_parent() is None or remember:
437
453
if old_rh != new_rh:
438
454
# Something changed
439
455
from bzrlib.log import show_changed_revisions
440
show_changed_revisions(branch_to, old_rh, new_rh)
456
show_changed_revisions(branch_to, old_rh, new_rh,
443
460
class cmd_push(Command):
464
481
After that, you can omit the location to use the default. To change the
465
482
default, use --remember.
467
takes_options = ['remember', 'overwrite',
484
takes_options = ['remember', 'overwrite', 'verbose',
468
485
Option('create-prefix',
469
486
help='Create the path leading up to the branch '
470
487
'if it does not already exist')]
471
488
takes_args = ['location?']
489
encoding_type = 'replace'
473
491
def run(self, location=None, remember=False, overwrite=False,
474
492
create_prefix=False, verbose=False):
483
501
if stored_loc is None:
484
502
raise BzrCommandError("No push location known or specified.")
486
print "Using saved location: %s" % stored_loc
504
self.outf.write("Using saved location: %s" % stored_loc)
487
505
location = stored_loc
488
506
if br_from.get_push_location() is None or remember:
489
507
br_from.set_push_location(location)
541
559
if old_rh != new_rh:
542
560
# Something changed
543
561
from bzrlib.log import show_changed_revisions
544
show_changed_revisions(br_to, old_rh, new_rh)
562
show_changed_revisions(br_to, old_rh, new_rh,
547
566
class cmd_branch(Command):
729
747
renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
731
749
for old_name, new_name in renames:
732
print "%s => %s" % (old_name, new_name)
750
self.outf.write("%s => %s\n" % (old_name, new_name))
735
753
class cmd_update(Command):
809
828
raise BzrError("%r is not a versioned file" % filename)
831
self.outf.write('\n')
814
834
class cmd_file_path(Command):
815
835
"""Print path of file_ids to a file or directory.
817
837
This prints one line for each directory down to the target,
818
starting at the branch root."""
838
starting at the branch root.
820
841
takes_args = ['filename']
822
844
def run(self, filename):
823
845
tree, relpath = WorkingTree.open_containing(filename)
858
881
class cmd_revision_history(Command):
859
882
"""Display list of revision ids on this branch."""
863
887
branch = WorkingTree.open_containing(u'.')[0].branch
864
888
for patchid in branch.revision_history():
889
self.outf.write(patchid)
890
self.outf.write('\n')
868
893
class cmd_ancestry(Command):
869
894
"""List all revisions merged into this branch."""
873
899
tree = WorkingTree.open_containing(u'.')[0]
875
901
# FIXME. should be tree.last_revision
876
902
for revision_id in b.repository.get_ancestry(b.last_revision()):
903
if revision_id is None:
905
self.outf.write(revision_id)
906
self.outf.write('\n')
880
909
class cmd_init(Command):
1047
1077
# directories with readdir, rather than stating each one. Same
1048
1078
# level of effort but possibly much less IO. (Or possibly not,
1049
1079
# if the directories are very large...)
1080
takes_options = ['show-ids']
1050
1082
@display_command
1051
1083
def run(self, show_ids=False):
1052
1084
tree = WorkingTree.open_containing(u'.')[0]
1053
1085
old = tree.basis_tree()
1054
1086
for path, ie in old.inventory.iter_entries():
1055
1087
if not tree.has_id(ie.file_id):
1088
self.outf.write(path)
1057
print '%-50s %s' % (path, ie.file_id)
1090
self.outf.write(' ')
1091
self.outf.write(ie.file_id)
1092
self.outf.write('\n')
1062
1095
class cmd_modified(Command):
1070
1103
td = compare_trees(tree.basis_tree(), tree)
1072
1105
for path, id, kind, text_modified, meta_modified in td.modified:
1106
self.outf.write(path)
1107
self.outf.write('\n')
1077
1110
class cmd_added(Command):
1102
1135
def run(self, filename=None):
1103
1136
"""Print the branch root."""
1104
1137
tree = WorkingTree.open_containing(filename)[0]
1138
self.outf.write(tree.basedir)
1139
self.outf.write('\n')
1108
1142
class cmd_log(Command):
1150
1186
from bzrlib.log import log_formatter, show_log
1152
1187
assert message is None or isinstance(message, basestring), \
1153
1188
"invalid message argument %r" % message
1154
1189
direction = (forward and 'forward') or 'reverse'
1200
1235
if rev1 > rev2:
1201
1236
(rev2, rev1) = (rev1, rev2)
1203
mutter('encoding log as %r', bzrlib.user_encoding)
1205
# use 'replace' so that we don't abort if trying to write out
1206
# in e.g. the default C locale.
1207
outf = codecs.getwriter(bzrlib.user_encoding)(sys.stdout, errors='replace')
1209
1238
if (log_format == None):
1210
1239
default = bzrlib.config.BranchConfig(b).log_format()
1211
1240
log_format = get_log_format(long=long, short=short, line=line, default=default)
1213
1241
lf = log_formatter(log_format,
1214
1242
show_ids=show_ids,
1216
1244
show_timezone=timezone)
1242
1270
A more user-friendly interface is "bzr log FILE"."""
1244
1272
takes_args = ["filename"]
1273
encoding_type = 'replace'
1245
1275
@display_command
1246
1276
def run(self, filename):
1247
1277
tree, relpath = WorkingTree.open_containing(filename)
1249
1279
inv = tree.read_working_inventory()
1250
1280
file_id = inv.path2id(relpath)
1251
1281
for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
1252
print "%6d %s" % (revno, what)
1282
self.outf.write("%6d %s\n" % (revno, what))
1255
1285
class cmd_ls(Command):
1288
1318
if revision is not None:
1289
1319
tree = tree.branch.repository.revision_tree(
1290
1320
revision[0].in_history(tree.branch).rev_id)
1291
1322
for fp, fc, kind, fid, entry in tree.list_files():
1292
1323
if fp.startswith(relpath):
1293
1324
fp = fp[len(relpath):]
1299
1330
kindch = entry.kind_character()
1300
print '%-8s %s%s' % (fc, fp, kindch)
1331
self.outf.write('%-8s %s%s\n' % (fc, fp, kindch))
1302
sys.stdout.write(fp)
1303
sys.stdout.write('\0')
1334
self.outf.write('\0')
1338
self.outf.write('\n')
1309
1341
class cmd_unknowns(Command):
1535
1568
from bzrlib.msgeditor import edit_commit_message, \
1536
1569
make_commit_message_template
1537
1570
from tempfile import TemporaryFile
1540
1572
# TODO: Need a blackbox test for invoking the external editor; may be
1541
1573
# slightly problematic to run this cross-platform.