60
55
Show summary of pending changes.
62
57
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"
77
65
import sys, os, random, time, sha, sets, types, re, shutil, tempfile
165
153
print Branch('.').revno()
168
157
def cmd_add(file_list, verbose=False):
169
"""Add specified files.
158
"""Add specified files or directories.
160
In non-recursive mode, all the named items are added, regardless
161
of whether they were previously ignored. A warning is given if
162
any of the named files are already versioned.
164
In recursive mode (the default), files are treated the same way
165
but the behaviour for directories is different. Directories that
166
are already versioned do not give a warning. All directories,
167
whether already versioned or not, are searched for files or
168
subdirectories that are neither versioned or ignored, and these
169
are added. This search proceeds recursively into versioned
172
Therefore simply saying 'bzr add .' will version all files that
173
are currently unknown.
175
bzrlib.add.smart_add(file_list, verbose)
171
Fails if the files are already added.
173
Branch('.').add(file_list, verbose=verbose)
178
def cmd_relpath(filename):
179
"""Show path of file relative to root"""
180
print Branch(filename).relpath(filename)
176
183
def cmd_inventory(revision=None):
193
print 'branch format:', b.controlfile('branch-format', 'r').readline().rstrip('\n')
195
def plural(n, base='', pl=None):
203
count_version_dirs = 0
205
count_status = {'A': 0, 'D': 0, 'M': 0, 'R': 0, '?': 0, 'I': 0, '.': 0}
206
for st_tup in bzrlib.diff_trees(b.basis_tree(), b.working_tree()):
208
count_status[fs] += 1
209
if fs not in ['I', '?'] and st_tup[4] == 'directory':
210
count_version_dirs += 1
213
print 'in the working tree:'
214
for name, fs in (('unchanged', '.'),
215
('modified', 'M'), ('added', 'A'), ('removed', 'D'),
216
('renamed', 'R'), ('unknown', '?'), ('ignored', 'I'),
218
print ' %5d %s' % (count_status[fs], name)
219
print ' %5d versioned subdirector%s' % (count_version_dirs,
220
plural(count_version_dirs, 'y', 'ies'))
223
print 'branch history:'
224
history = b.revision_history()
226
print ' %5d revision%s' % (revno, plural(revno))
229
committers.add(b.get_revision(rev).committer)
230
print ' %5d committer%s' % (len(committers), plural(len(committers)))
232
firstrev = b.get_revision(history[0])
233
age = int((time.time() - firstrev.timestamp) / 3600 / 24)
234
print ' %5d day%s old' % (age, plural(age))
235
print ' first revision: %s' % format_date(firstrev.timestamp,
238
lastrev = b.get_revision(history[-1])
239
print ' latest revision: %s' % format_date(lastrev.timestamp,
199
"""info: Show statistical information for this branch
203
info.show_info(Branch('.'))
245
207
def cmd_remove(file_list, verbose=False):
246
Branch('.').remove(file_list, verbose=verbose)
208
b = Branch(file_list[0])
209
b.remove([b.relpath(f) for f in file_list], verbose=verbose)
250
213
def cmd_file_id(filename):
251
i = Branch('.').read_working_inventory().path2id(filename)
215
i = b.inventory.path2id(b.relpath(filename))
253
217
bailout("%s is not a versioned file" % filename)
285
249
def cmd_diff(revision=None):
286
"""Show diff from basis to working copy.
288
:todo: Take one or two revision arguments, look up those trees,
291
:todo: Allow diff across branches.
293
:todo: Mangle filenames in diff to be more relevant.
295
:todo: Shouldn't be in the cmd function.
250
"""bzr diff: Show differences in working tree.
252
usage: bzr diff [-r REV]
255
Show changes since REV, rather than predecessor.
257
TODO: Given two revision arguments, show the difference between them.
259
TODO: Allow diff across branches.
261
TODO: Option to use external diff command; could be GNU diff, wdiff,
264
TODO: Diff selected files.
267
## TODO: Shouldn't be in the cmd function.
342
def cmd_deleted(show_ids=False):
343
"""List files deleted in the working tree.
345
TODO: Show files deleted since a previous revision, or between two revisions.
349
new = b.working_tree()
351
## TODO: Much more efficient way to do this: read in new
352
## directories with readdir, rather than stating each one. Same
353
## level of effort but possibly much less IO. (Or possibly not,
354
## if the directories are very large...)
356
for path, ie in old.inventory.iter_entries():
357
if not new.has_id(ie.file_id):
359
print '%-50s %s' % (path, ie.file_id)
365
def cmd_parse_inventory():
368
cElementTree.ElementTree().parse(file('.bzr/inventory'))
372
def cmd_load_inventory():
373
inv = Branch('.').basis_tree().inventory
377
def cmd_dump_new_inventory():
378
import bzrlib.newinventory
379
inv = Branch('.').basis_tree().inventory
380
bzrlib.newinventory.write_inventory(inv, sys.stdout)
383
def cmd_dump_slacker_inventory():
384
import bzrlib.newinventory
385
inv = Branch('.').basis_tree().inventory
386
bzrlib.newinventory.write_slacker_inventory(inv, sys.stdout)
390
def cmd_root(filename=None):
391
"""Print the branch root."""
392
print bzrlib.branch.find_branch_root(filename)
371
395
def cmd_log(timezone='original'):
372
396
"""Show log of this branch.
436
def cmd_ignored(verbose=True):
437
"""List ignored files and the patterns that matched them.
439
tree = Branch('.').working_tree()
440
for path, file_class, kind, id in tree.list_files():
441
if file_class != 'I':
443
## XXX: Slightly inefficient since this was already calculated
444
pat = tree.is_ignored(path)
445
print '%-50s %s' % (path, pat)
411
448
def cmd_lookup_revision(revno):
413
450
revno = int(revno)
446
def cmd_commit(message, verbose=False):
483
def cmd_commit(message=None, verbose=False):
484
"""Commit changes to a new revision.
487
Description of changes in this revision; free form text.
488
It is recommended that the first line be a single-sentence
491
Show status of changed files,
493
TODO: Commit only selected files.
495
TODO: Run hooks on tree to-be-committed, and after commit.
497
TODO: Strict commit that fails if there are unknown or deleted files.
501
bailout("please specify a commit message")
447
502
Branch('.').commit(message, verbose=verbose)
451
"""Check consistency of the branch."""
505
def cmd_check(dir='.'):
506
"""check: Consistency check of branch history.
508
usage: bzr check [-v] [BRANCH]
511
--verbose, -v Show progress of checking.
513
This command checks various invariants about the branch storage to
514
detect data corruption or bzr bugs.
517
bzrlib.check.check(Branch(dir, find_root=False))
455
520
def cmd_is(pred, *rest):
480
545
print bzrlib.branch._gen_revision_id(time.time())
484
"""Run internal doctest suite"""
548
def cmd_selftest(verbose=False):
549
"""Run internal test suite"""
485
550
## -v, if present, is seen by doctest; the argument is just here
486
551
## so our parser doesn't complain
488
553
## TODO: --verbose option
555
failures, tests = 0, 0
490
import doctest, bzrlib.store
557
import doctest, bzrlib.store, bzrlib.tests
491
558
bzrlib.trace.verbose = False
492
doctest.testmod(bzrlib.store)
493
doctest.testmod(bzrlib.inventory)
494
doctest.testmod(bzrlib.branch)
495
doctest.testmod(bzrlib.osutils)
496
doctest.testmod(bzrlib.tree)
498
# more strenuous tests;
500
doctest.testmod(bzrlib.tests)
503
cmd_selftest = cmd_doctest
560
for m in bzrlib.store, bzrlib.inventory, bzrlib.branch, bzrlib.osutils, \
561
bzrlib.tree, bzrlib.tests, bzrlib.commands, bzrlib.add:
562
mf, mt = doctest.testmod(m)
565
print '%-40s %3d tests' % (m.__name__, mt),
567
print '%3d FAILED!' % mf
571
print '%-40s %3d tests' % ('total', tests),
573
print '%3d FAILED!' % failures
580
cmd_doctest = cmd_selftest
506
583
######################################################################
511
# TODO: Specific help for particular commands
587
def cmd_help(topic=None):
592
# otherwise, maybe the name of a command?
594
cmdfn = globals()['cmd_' + topic.replace('-', '_')]
596
bailout("no help for %r" % topic)
600
bailout("sorry, no detailed help yet for %r" % topic)
515
607
def cmd_version():
516
print "bzr (bazaar-ng) %s" % __version__
608
print "bzr (bazaar-ng) %s" % bzrlib.__version__
609
print bzrlib.__copyright__
518
610
print "http://bazaar-ng.org/"
559
652
'add': ['verbose'],
560
653
'commit': ['message', 'verbose'],
654
'deleted': ['show-ids'],
561
655
'diff': ['revision'],
562
656
'inventory': ['revision'],
563
'log': ['show-ids', 'timezone'],
564
658
'ls': ['revision', 'verbose'],
565
659
'remove': ['verbose'],
566
660
'status': ['all'],
572
665
'add': ['file+'],
668
'export': ['revno', 'dest'],
575
669
'file-id': ['filename'],
576
670
'get-file-text': ['text_id'],
577
671
'get-inventory': ['inventory_id'],
578
672
'get-revision': ['revision_id'],
579
673
'get-revision-inventory': ['revision_id'],
581
677
'lookup-revision': ['revno'],
582
'export': ['revno', 'dest'],
678
'relpath': ['filename'],
583
679
'remove': ['file+'],
680
'root': ['filename?'],
718
816
log_error('usage: bzr COMMAND\n')
719
817
log_error(' try "bzr help"\n')
723
821
cmd_handler = globals()['cmd_' + cmd.replace('-', '_')]
725
823
bailout("unknown command " + `cmd`)
727
# TODO: special --profile option to turn on the Python profiler
826
if 'profile' in opts:
729
832
# check options are reasonable
730
833
allowed = cmd_options.get(cmd, [])
733
836
bailout("option %r is not allowed for command %r"
839
# mix arguments and options into one dictionary
736
840
cmdargs = _match_args(cmd, args)
739
ret = cmd_handler(**cmdargs) or 0
841
for k, v in opts.items():
842
cmdargs[k.replace('-', '_')] = v
846
prof = hotshot.Profile('.bzr.profile')
847
ret = prof.runcall(cmd_handler, **cmdargs) or 0
851
stats = hotshot.stats.load('.bzr.profile')
853
stats.sort_stats('time')
854
stats.print_stats(20)
856
return cmd_handler(**cmdargs) or 0
747
864
## TODO: If the arguments are wrong, give a usage message rather
748
865
## than just a backtrace.
867
bzrlib.trace.create_tracefile(argv)
751
# TODO: Lift into separate function in trace.py
752
# TODO: Also show contents of /etc/lsb-release, if it can be parsed.
753
# Perhaps that should eventually go into the platform library?
754
# TODO: If the file doesn't exist, add a note describing it.
755
t = bzrlib.trace._tracefile
756
t.write('-' * 60 + '\n')
757
t.write('bzr invoked at %s\n' % format_date(time.time()))
758
t.write(' by %s on %s\n' % (bzrlib.osutils.username(), socket.getfqdn()))
759
t.write(' arguments: %r\n' % argv)
761
starttime = os.times()[4]
764
t.write(' platform: %s\n' % platform.platform())
765
t.write(' python: %s\n' % platform.python_version())
767
870
ret = run_bzr(argv)
770
mutter("finished, %.3fu/%.3fs cpu, %.3fu/%.3fs cum"
772
mutter(" %.3f elapsed" % (times[4] - starttime))
775
872
except BzrError, e:
776
873
log_error('bzr: error: ' + e.args[0] + '\n')