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
118
106
## can be taken either from their parameters or their working
109
## TODO: rename command, needed soon: check destination doesn't exist
110
## either in working copy or tree; move working copy; update
111
## inventory; write out
113
## TODO: move command; check destination is a directory and will not
116
## TODO: command to show renames, one per line, as to->from
123
121
def cmd_status(all=False):
155
153
print Branch('.').revno()
158
157
def cmd_add(file_list, verbose=False):
159
"""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)
161
Fails if the files are already added.
163
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)
166
183
def cmd_inventory(revision=None):
183
print 'branch format:', b.controlfile('branch-format', 'r').readline().rstrip('\n')
185
def plural(n, base='', pl=None):
193
count_version_dirs = 0
195
count_status = {'A': 0, 'D': 0, 'M': 0, 'R': 0, '?': 0, 'I': 0, '.': 0}
196
for st_tup in bzrlib.diff_trees(b.basis_tree(), b.working_tree()):
198
count_status[fs] += 1
199
if fs not in ['I', '?'] and st_tup[4] == 'directory':
200
count_version_dirs += 1
203
print 'in the working tree:'
204
for name, fs in (('unchanged', '.'),
205
('modified', 'M'), ('added', 'A'), ('removed', 'D'),
206
('renamed', 'R'), ('unknown', '?'), ('ignored', 'I'),
208
print ' %5d %s' % (count_status[fs], name)
209
print ' %5d versioned subdirector%s' % (count_version_dirs,
210
plural(count_version_dirs, 'y', 'ies'))
213
print 'branch history:'
214
history = b.revision_history()
216
print ' %5d revision%s' % (revno, plural(revno))
219
committers.add(b.get_revision(rev).committer)
220
print ' %5d committer%s' % (len(committers), plural(len(committers)))
222
firstrev = b.get_revision(history[0])
223
age = int((time.time() - firstrev.timestamp) / 3600 / 24)
224
print ' %5d day%s old' % (age, plural(age))
225
print ' first revision: %s' % format_date(firstrev.timestamp,
228
lastrev = b.get_revision(history[-1])
229
print ' latest revision: %s' % format_date(lastrev.timestamp,
199
"""info: Show statistical information for this branch
203
info.show_info(Branch('.'))
235
207
def cmd_remove(file_list, verbose=False):
236
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)
240
213
def cmd_file_id(filename):
241
i = Branch('.').read_working_inventory().path2id(filename)
215
i = b.inventory.path2id(b.relpath(filename))
243
217
bailout("%s is not a versioned file" % filename)
275
261
def cmd_diff(revision=None):
276
"""Show diff from basis to working copy.
278
:todo: Take one or two revision arguments, look up those trees,
281
:todo: Allow diff across branches.
283
:todo: Mangle filenames in diff to be more relevant.
285
:todo: Shouldn't be in the cmd function.
262
"""bzr diff: Show differences in working tree.
264
usage: bzr diff [-r REV]
267
Show changes since REV, rather than predecessor.
269
TODO: Given two revision arguments, show the difference between them.
271
TODO: Allow diff across branches.
273
TODO: Option to use external diff command; could be GNU diff, wdiff,
276
TODO: Diff selected files.
279
## TODO: Shouldn't be in the cmd function.
354
def cmd_deleted(show_ids=False):
355
"""List files deleted in the working tree.
357
TODO: Show files deleted since a previous revision, or between two revisions.
361
new = b.working_tree()
363
## TODO: Much more efficient way to do this: read in new
364
## directories with readdir, rather than stating each one. Same
365
## level of effort but possibly much less IO. (Or possibly not,
366
## if the directories are very large...)
368
for path, ie in old.inventory.iter_entries():
369
if not new.has_id(ie.file_id):
371
print '%-50s %s' % (path, ie.file_id)
377
def cmd_parse_inventory():
380
cElementTree.ElementTree().parse(file('.bzr/inventory'))
384
def cmd_load_inventory():
385
inv = Branch('.').basis_tree().inventory
389
def cmd_dump_new_inventory():
390
import bzrlib.newinventory
391
inv = Branch('.').basis_tree().inventory
392
bzrlib.newinventory.write_inventory(inv, sys.stdout)
395
def cmd_load_new_inventory():
396
import bzrlib.newinventory
397
bzrlib.newinventory.read_new_inventory(sys.stdin)
400
def cmd_dump_slacker_inventory():
401
import bzrlib.newinventory
402
inv = Branch('.').basis_tree().inventory
403
bzrlib.newinventory.write_slacker_inventory(inv, sys.stdout)
407
def cmd_root(filename=None):
408
"""Print the branch root."""
409
print bzrlib.branch.find_branch_root(filename)
361
412
def cmd_log(timezone='original'):
362
413
"""Show log of this branch.
453
def cmd_ignored(verbose=True):
454
"""List ignored files and the patterns that matched them.
456
tree = Branch('.').working_tree()
457
for path, file_class, kind, id in tree.list_files():
458
if file_class != 'I':
460
## XXX: Slightly inefficient since this was already calculated
461
pat = tree.is_ignored(path)
462
print '%-50s %s' % (path, pat)
401
465
def cmd_lookup_revision(revno):
403
467
revno = int(revno)
436
def cmd_commit(message, verbose=False):
500
def cmd_commit(message=None, verbose=False):
501
"""Commit changes to a new revision.
504
Description of changes in this revision; free form text.
505
It is recommended that the first line be a single-sentence
508
Show status of changed files,
510
TODO: Commit only selected files.
512
TODO: Run hooks on tree to-be-committed, and after commit.
514
TODO: Strict commit that fails if there are unknown or deleted files.
518
bailout("please specify a commit message")
437
519
Branch('.').commit(message, verbose=verbose)
441
"""Check consistency of the branch."""
522
def cmd_check(dir='.'):
523
"""check: Consistency check of branch history.
525
usage: bzr check [-v] [BRANCH]
528
--verbose, -v Show progress of checking.
530
This command checks various invariants about the branch storage to
531
detect data corruption or bzr bugs.
534
bzrlib.check.check(Branch(dir, find_root=False))
445
537
def cmd_is(pred, *rest):
470
562
print bzrlib.branch._gen_revision_id(time.time())
474
"""Run internal doctest suite"""
565
def cmd_selftest(verbose=False):
566
"""Run internal test suite"""
475
567
## -v, if present, is seen by doctest; the argument is just here
476
568
## so our parser doesn't complain
478
570
## TODO: --verbose option
572
failures, tests = 0, 0
480
import bzr, doctest, bzrlib.store
574
import doctest, bzrlib.store, bzrlib.tests
481
575
bzrlib.trace.verbose = False
483
doctest.testmod(bzrlib.store)
484
doctest.testmod(bzrlib.inventory)
485
doctest.testmod(bzrlib.branch)
486
doctest.testmod(bzrlib.osutils)
487
doctest.testmod(bzrlib.tree)
489
# more strenuous tests;
491
doctest.testmod(bzrlib.tests)
577
for m in bzrlib.store, bzrlib.inventory, bzrlib.branch, bzrlib.osutils, \
578
bzrlib.tree, bzrlib.tests, bzrlib.commands, bzrlib.add:
579
mf, mt = doctest.testmod(m)
582
print '%-40s %3d tests' % (m.__name__, mt),
584
print '%3d FAILED!' % mf
588
print '%-40s %3d tests' % ('total', tests),
590
print '%3d FAILED!' % failures
597
cmd_doctest = cmd_selftest
494
600
######################################################################
499
# TODO: Specific help for particular commands
604
def cmd_help(topic=None):
609
# otherwise, maybe the name of a command?
611
cmdfn = globals()['cmd_' + topic.replace('-', '_')]
613
bailout("no help for %r" % topic)
617
bailout("sorry, no detailed help yet for %r" % topic)
503
624
def cmd_version():
504
print "bzr (bazaar-ng) %s" % __version__
625
print "bzr (bazaar-ng) %s" % bzrlib.__version__
626
print bzrlib.__copyright__
506
627
print "http://bazaar-ng.org/"
547
669
'add': ['verbose'],
548
670
'commit': ['message', 'verbose'],
671
'deleted': ['show-ids'],
549
672
'diff': ['revision'],
550
673
'inventory': ['revision'],
551
'log': ['show-ids', 'timezone'],
552
675
'ls': ['revision', 'verbose'],
553
676
'remove': ['verbose'],
554
677
'status': ['all'],
560
682
'add': ['file+'],
685
'export': ['revno', 'dest'],
563
686
'file-id': ['filename'],
564
687
'get-file-text': ['text_id'],
565
688
'get-inventory': ['inventory_id'],
566
689
'get-revision': ['revision_id'],
567
690
'get-revision-inventory': ['revision_id'],
569
694
'lookup-revision': ['revno'],
570
'export': ['revno', 'dest'],
695
'relpath': ['filename'],
571
696
'remove': ['file+'],
697
'root': ['filename?'],
706
833
log_error('usage: bzr COMMAND\n')
707
834
log_error(' try "bzr help"\n')
711
838
cmd_handler = globals()['cmd_' + cmd.replace('-', '_')]
713
840
bailout("unknown command " + `cmd`)
715
# TODO: special --profile option to turn on the Python profiler
843
if 'profile' in opts:
717
849
# check options are reasonable
718
850
allowed = cmd_options.get(cmd, [])
721
853
bailout("option %r is not allowed for command %r"
856
# mix arguments and options into one dictionary
724
857
cmdargs = _match_args(cmd, args)
727
ret = cmd_handler(**cmdargs) or 0
858
for k, v in opts.items():
859
cmdargs[k.replace('-', '_')] = v
863
prof = hotshot.Profile('.bzr.profile')
864
ret = prof.runcall(cmd_handler, **cmdargs) or 0
868
stats = hotshot.stats.load('.bzr.profile')
870
stats.sort_stats('time')
871
stats.print_stats(20)
873
return cmd_handler(**cmdargs) or 0
735
881
## TODO: If the arguments are wrong, give a usage message rather
736
882
## than just a backtrace.
884
bzrlib.trace.create_tracefile(argv)
739
# TODO: Lift into separate function in trace.py
740
# TODO: Also show contents of /etc/lsb-release, if it can be parsed.
741
# Perhaps that should eventually go into the platform library?
742
# TODO: If the file doesn't exist, add a note describing it.
743
t = bzrlib.trace._tracefile
744
t.write('-' * 60 + '\n')
745
t.write('bzr invoked at %s\n' % format_date(time.time()))
746
t.write(' by %s on %s\n' % (bzrlib.osutils.username(), socket.getfqdn()))
747
t.write(' arguments: %r\n' % argv)
749
starttime = os.times()[4]
752
t.write(' platform: %s\n' % platform.platform())
753
t.write(' python: %s\n' % platform.python_version())
755
887
ret = run_bzr(argv)
758
mutter("finished, %.3fu/%.3fs cpu, %.3fu/%.3fs cum"
760
mutter(" %.3f elapsed" % (times[4] - starttime))
763
889
except BzrError, e:
764
890
log_error('bzr: error: ' + e.args[0] + '\n')