55
60
Show summary of pending changes.
57
62
Make a file not versioned.
59
Show statistics about this branch.
65
# not currently working:
67
# Show some information about this branch.
71
__copyright__ = "Copyright 2005 Canonical Development Ltd."
72
__author__ = "Martin Pool <mbp@canonical.com>"
73
__docformat__ = "restructuredtext en"
65
77
import sys, os, random, time, sha, sets, types, re, shutil, tempfile
172
184
Therefore simply saying 'bzr add .' will version all files that
173
185
are currently unknown.
175
bzrlib.add.smart_add(file_list, verbose)
188
bzrlib.add.smart_add(file_list, verbose)
192
b = Branch(file_list[0], find_root=True)
193
b.add([b.relpath(f) for f in file_list], verbose=verbose)
178
197
def cmd_relpath(filename):
179
"""Show path of file relative to root"""
180
198
print Branch(filename).relpath(filename)
184
201
def cmd_inventory(revision=None):
185
202
"""Show inventory of the current working copy."""
186
203
## TODO: Also optionally show a previous inventory
199
def cmd_mv(source_list, dest):
202
b.rename([b.relpath(s) for s in source_list], b.relpath(dest))
206
def cmd_rename(from_name, to_name):
207
"""Change the name of an entry.
209
usage: bzr rename FROM_NAME TO_NAME
212
bzr rename frob.c frobber.c
213
bzr rename src/frob.c lib/frob.c
215
It is an error if the destination name exists.
217
See also the 'move' command, which moves files into a different
218
directory without changing their name.
220
TODO: Some way to rename multiple files without invoking bzr for each
223
b.rename_one(b.relpath(from_name), b.relpath(to_name))
228
def cmd_renames(dir='.'):
229
"""Show list of renamed files.
231
usage: bzr renames [BRANCH]
233
TODO: Option to show renames between two historical versions.
235
TODO: Only show renames under dir, rather than in the whole branch.
238
old_inv = b.basis_tree().inventory
239
new_inv = b.read_working_inventory()
241
renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
243
for old_name, new_name in renames:
244
print "%s => %s" % (old_name, new_name)
249
"""info: Show statistical information for this branch
253
info.show_info(Branch('.'))
218
print 'branch format:', b.controlfile('branch-format', 'r').readline().rstrip('\n')
220
def plural(n, base='', pl=None):
228
count_version_dirs = 0
230
count_status = {'A': 0, 'D': 0, 'M': 0, 'R': 0, '?': 0, 'I': 0, '.': 0}
231
for st_tup in bzrlib.diff_trees(b.basis_tree(), b.working_tree()):
233
count_status[fs] += 1
234
if fs not in ['I', '?'] and st_tup[4] == 'directory':
235
count_version_dirs += 1
238
print 'in the working tree:'
239
for name, fs in (('unchanged', '.'),
240
('modified', 'M'), ('added', 'A'), ('removed', 'D'),
241
('renamed', 'R'), ('unknown', '?'), ('ignored', 'I'),
243
print ' %5d %s' % (count_status[fs], name)
244
print ' %5d versioned subdirector%s' % (count_version_dirs,
245
plural(count_version_dirs, 'y', 'ies'))
248
print 'branch history:'
249
history = b.revision_history()
251
print ' %5d revision%s' % (revno, plural(revno))
254
committers.add(b.get_revision(rev).committer)
255
print ' %5d committer%s' % (len(committers), plural(len(committers)))
257
firstrev = b.get_revision(history[0])
258
age = int((time.time() - firstrev.timestamp) / 3600 / 24)
259
print ' %5d day%s old' % (age, plural(age))
260
print ' first revision: %s' % format_date(firstrev.timestamp,
263
lastrev = b.get_revision(history[-1])
264
print ' latest revision: %s' % format_date(lastrev.timestamp,
311
312
def cmd_diff(revision=None):
312
"""bzr diff: Show differences in working tree.
314
usage: bzr diff [-r REV]
317
Show changes since REV, rather than predecessor.
319
TODO: Given two revision arguments, show the difference between them.
321
TODO: Allow diff across branches.
323
TODO: Option to use external diff command; could be GNU diff, wdiff,
326
TODO: Diff selected files.
329
## TODO: Shouldn't be in the cmd function.
313
"""Show diff from basis to working copy.
315
:todo: Take one or two revision arguments, look up those trees,
318
:todo: Allow diff across branches.
320
:todo: Mangle filenames in diff to be more relevant.
322
:todo: Shouldn't be in the cmd function.
363
357
# FIXME: Something about the diff format makes patch unhappy
364
358
# with newly-added files.
366
def diffit(oldlines, newlines, **kw):
367
# FIXME: difflib is wrong if there is no trailing newline.
369
# Special workaround for Python2.3, where difflib fails if
370
# both sequences are empty.
371
if oldlines or newlines:
372
sys.stdout.writelines(difflib.unified_diff(oldlines, newlines, **kw))
360
def diffit(*a, **kw):
361
sys.stdout.writelines(difflib.unified_diff(*a, **kw))
375
364
if file_state in ['.', '?', 'I']:
409
def cmd_deleted(show_ids=False):
410
"""List files deleted in the working tree.
412
TODO: Show files deleted since a previous revision, or between two revisions.
416
new = b.working_tree()
418
## TODO: Much more efficient way to do this: read in new
419
## directories with readdir, rather than stating each one. Same
420
## level of effort but possibly much less IO. (Or possibly not,
421
## if the directories are very large...)
423
for path, ie in old.inventory.iter_entries():
424
if not new.has_id(ie.file_id):
426
print '%-50s %s' % (path, ie.file_id)
432
def cmd_parse_inventory():
435
cElementTree.ElementTree().parse(file('.bzr/inventory'))
439
def cmd_load_inventory():
440
inv = Branch('.').basis_tree().inventory
444
def cmd_dump_new_inventory():
445
import bzrlib.newinventory
446
inv = Branch('.').basis_tree().inventory
447
bzrlib.newinventory.write_inventory(inv, sys.stdout)
450
def cmd_load_new_inventory():
451
import bzrlib.newinventory
452
bzrlib.newinventory.read_new_inventory(sys.stdin)
455
def cmd_dump_slacker_inventory():
456
import bzrlib.newinventory
457
inv = Branch('.').basis_tree().inventory
458
bzrlib.newinventory.write_slacker_inventory(inv, sys.stdout)
462
398
def cmd_root(filename=None):
463
399
"""Print the branch root."""
464
400
print bzrlib.branch.find_branch_root(filename)
555
478
def cmd_commit(message=None, verbose=False):
556
"""Commit changes to a new revision.
559
Description of changes in this revision; free form text.
560
It is recommended that the first line be a single-sentence
563
Show status of changed files,
565
TODO: Commit only selected files.
567
TODO: Run hooks on tree to-be-committed, and after commit.
569
TODO: Strict commit that fails if there are unknown or deleted files.
573
480
bailout("please specify a commit message")
574
481
Branch('.').commit(message, verbose=verbose)
577
def cmd_check(dir='.'):
578
"""check: Consistency check of branch history.
580
usage: bzr check [-v] [BRANCH]
583
--verbose, -v Show progress of checking.
585
This command checks various invariants about the branch storage to
586
detect data corruption or bzr bugs.
589
bzrlib.check.check(Branch(dir, find_root=False))
485
"""Check consistency of the branch."""
592
489
def cmd_is(pred, *rest):
659
def cmd_help(topic=None):
664
# otherwise, maybe the name of a command?
666
cmdfn = globals()['cmd_' + topic.replace('-', '_')]
668
bailout("no help for %r" % topic)
672
bailout("sorry, no detailed help yet for %r" % topic)
557
# TODO: Specific help for particular commands
679
561
def cmd_version():
680
print "bzr (bazaar-ng) %s" % bzrlib.__version__
681
print bzrlib.__copyright__
562
print "bzr (bazaar-ng) %s" % __version__
682
564
print "http://bazaar-ng.org/"
737
618
'add': ['file+'],
740
'export': ['revno', 'dest'],
741
621
'file-id': ['filename'],
622
'root': ['filename?'],
623
'relpath': ['filename'],
742
624
'get-file-text': ['text_id'],
743
625
'get-inventory': ['inventory_id'],
744
626
'get-revision': ['revision_id'],
745
627
'get-revision-inventory': ['revision_id'],
749
629
'lookup-revision': ['revno'],
750
'mv': ['source$', 'dest'],
751
'relpath': ['filename'],
630
'export': ['revno', 'dest'],
752
631
'remove': ['file+'],
753
'rename': ['from_name', 'to_name'],
755
'root': ['filename?'],
920
783
bailout("option %r is not allowed for command %r"
923
# mix arguments and options into one dictionary
924
786
cmdargs = _match_args(cmd, args)
925
for k, v in opts.items():
926
cmdargs[k.replace('-', '_')] = v
930
prof = hotshot.Profile('.bzr.profile')
931
ret = prof.runcall(cmd_handler, **cmdargs) or 0
935
stats = hotshot.stats.load('.bzr.profile')
937
stats.sort_stats('time')
938
stats.print_stats(20)
940
return cmd_handler(**cmdargs) or 0
789
ret = cmd_handler(**cmdargs) or 0