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
import sys, os, random, time, sha, sets, types, re, shutil, tempfile
78
import traceback, socket, fnmatch, difflib
65
import sys, os, time, types, shutil, tempfile, traceback, fnmatch, difflib, os.path
80
66
from sets import Set
81
67
from pprint import pprint
165
151
print Branch('.').revno()
168
155
def cmd_add(file_list, verbose=False):
169
"""Add specified files.
156
"""Add specified files or directories.
158
In non-recursive mode, all the named items are added, regardless
159
of whether they were previously ignored. A warning is given if
160
any of the named files are already versioned.
162
In recursive mode (the default), files are treated the same way
163
but the behaviour for directories is different. Directories that
164
are already versioned do not give a warning. All directories,
165
whether already versioned or not, are searched for files or
166
subdirectories that are neither versioned or ignored, and these
167
are added. This search proceeds recursively into versioned
170
Therefore simply saying 'bzr add .' will version all files that
171
are currently unknown.
173
bzrlib.add.smart_add(file_list, verbose)
171
Fails if the files are already added.
173
Branch('.').add(file_list, verbose=verbose)
176
def cmd_relpath(filename):
177
"""Show path of file relative to root"""
178
print Branch(filename).relpath(filename)
176
182
def cmd_inventory(revision=None):
197
# TODO: Maybe a 'mv' command that has the combined move/rename
198
# special behaviour of Unix?
200
def cmd_move(source_list, dest):
203
b.move([b.relpath(s) for s in source_list], b.relpath(dest))
207
def cmd_rename(from_name, to_name):
208
"""Change the name of an entry.
210
usage: bzr rename FROM_NAME TO_NAME
213
bzr rename frob.c frobber.c
214
bzr rename src/frob.c lib/frob.c
216
It is an error if the destination name exists.
218
See also the 'move' command, which moves files into a different
219
directory without changing their name.
221
TODO: Some way to rename multiple files without invoking bzr for each
224
b.rename_one(b.relpath(from_name), b.relpath(to_name))
229
def cmd_renames(dir='.'):
230
"""Show list of renamed files.
232
usage: bzr renames [BRANCH]
234
TODO: Option to show renames between two historical versions.
236
TODO: Only show renames under dir, rather than in the whole branch.
239
old_inv = b.basis_tree().inventory
240
new_inv = b.read_working_inventory()
242
renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
244
for old_name, new_name in renames:
245
print "%s => %s" % (old_name, new_name)
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,
250
"""info: Show statistical information for this branch
254
info.show_info(Branch('.'))
245
258
def cmd_remove(file_list, verbose=False):
246
Branch('.').remove(file_list, verbose=verbose)
259
b = Branch(file_list[0])
260
b.remove([b.relpath(f) for f in file_list], verbose=verbose)
250
264
def cmd_file_id(filename):
251
i = Branch('.').read_working_inventory().path2id(filename)
253
bailout("%s is not a versioned file" % filename)
265
"""Print file_id of a particular file or directory.
267
usage: bzr file-id FILE
269
The file_id is assigned when the file is first added and remains the
270
same through all revisions where the file exists, even when it is
274
i = b.inventory.path2id(b.relpath(filename))
276
bailout("%r is not a versioned file" % filename)
258
def cmd_find_filename(fileid):
259
n = find_filename(fileid)
261
bailout("%s is not a live file id" % fileid)
281
def cmd_file_id_path(filename):
282
"""Print path of file_ids to a file or directory.
284
usage: bzr file-id-path FILE
286
This prints one line for each directory down to the target,
287
starting at the branch root."""
290
fid = inv.path2id(b.relpath(filename))
292
bailout("%r is not a versioned file" % filename)
293
for fip in inv.get_idpath(fid):
266
297
def cmd_revision_history():
285
328
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.
329
"""bzr diff: Show differences in working tree.
331
usage: bzr diff [-r REV]
334
Show changes since REV, rather than predecessor.
336
TODO: Given two revision arguments, show the difference between them.
338
TODO: Allow diff across branches.
340
TODO: Option to use external diff command; could be GNU diff, wdiff,
343
TODO: Diff selected files.
346
## TODO: Shouldn't be in the cmd function.
422
def cmd_deleted(show_ids=False):
423
"""List files deleted in the working tree.
425
TODO: Show files deleted since a previous revision, or between two revisions.
429
new = b.working_tree()
431
## TODO: Much more efficient way to do this: read in new
432
## directories with readdir, rather than stating each one. Same
433
## level of effort but possibly much less IO. (Or possibly not,
434
## if the directories are very large...)
436
for path, ie in old.inventory.iter_entries():
437
if not new.has_id(ie.file_id):
439
print '%-50s %s' % (path, ie.file_id)
445
def cmd_parse_inventory():
448
cElementTree.ElementTree().parse(file('.bzr/inventory'))
452
def cmd_load_inventory():
453
"""Load inventory for timing purposes"""
454
Branch('.').basis_tree().inventory
458
def cmd_dump_new_inventory():
459
import bzrlib.newinventory
460
inv = Branch('.').basis_tree().inventory
461
bzrlib.newinventory.write_inventory(inv, sys.stdout)
464
def cmd_load_new_inventory():
465
import bzrlib.newinventory
466
bzrlib.newinventory.read_new_inventory(sys.stdin)
469
def cmd_dump_slacker_inventory():
470
import bzrlib.newinventory
471
inv = Branch('.').basis_tree().inventory
472
bzrlib.newinventory.write_slacker_inventory(inv, sys.stdout)
476
def cmd_root(filename=None):
477
"""Print the branch root."""
478
print bzrlib.branch.find_branch_root(filename)
371
481
def cmd_log(timezone='original'):
372
482
"""Show log of this branch.
446
573
def cmd_commit(message=None, verbose=False):
574
"""Commit changes to a new revision.
577
Description of changes in this revision; free form text.
578
It is recommended that the first line be a single-sentence
581
Show status of changed files,
583
TODO: Commit only selected files.
585
TODO: Run hooks on tree to-be-committed, and after commit.
587
TODO: Strict commit that fails if there are unknown or deleted files.
448
591
bailout("please specify a commit message")
449
592
Branch('.').commit(message, verbose=verbose)
453
"""Check consistency of the branch."""
595
def cmd_check(dir='.'):
596
"""check: Consistency check of branch history.
598
usage: bzr check [-v] [BRANCH]
601
--verbose, -v Show progress of checking.
603
This command checks various invariants about the branch storage to
604
detect data corruption or bzr bugs.
607
bzrlib.check.check(Branch(dir, find_root=False))
457
610
def cmd_is(pred, *rest):
586
755
'add': ['file+'],
759
'export': ['revno', 'dest'],
589
760
'file-id': ['filename'],
761
'file-id-path': ['filename'],
590
762
'get-file-text': ['text_id'],
591
763
'get-inventory': ['inventory_id'],
592
764
'get-revision': ['revision_id'],
593
765
'get-revision-inventory': ['revision_id'],
595
769
'lookup-revision': ['revno'],
596
'export': ['revno', 'dest'],
770
'move': ['source$', 'dest'],
771
'relpath': ['filename'],
597
772
'remove': ['file+'],
773
'rename': ['from_name', 'to_name'],
775
'root': ['filename?'],