17
17
"""File annotate based on weave storage"""
19
# TODO: Choice of more or less verbose formats:
21
# interposed: show more details between blocks of modified lines
23
# TODO: Show which revision caused a line to merge into the parent
25
# TODO: perhaps abbreviate timescales depending on how recent they are
26
# e.g. "3:12 Tue", "13 Oct", "Oct 2005", etc.
24
def annotate_file(branch, rev_id, file_id, to_file=None):
31
from bzrlib.config import extract_email_address
32
from bzrlib.errors import BzrError
35
def annotate_file(branch, rev_id, file_id, verbose=False, full=False,
25
37
if to_file is None:
26
38
to_file = sys.stdout
41
annotation = list(_annotate_file(branch, rev_id, file_id))
42
max_origin_len = max(len(origin) for origin in set(x[1] for x in annotation))
43
for (revno_str, author, date_str, line_rev_id, text ) in annotation:
45
anno = '%5s %-*s %8s ' % (revno_str, max_origin_len, author, date_str)
47
anno = "%5s %-7s " % ( revno_str, author[:7] )
49
if anno.lstrip() == "" and full: anno = prevanno
50
print >>to_file, '%s| %s' % (anno, text)
53
def _annotate_file(branch, rev_id, file_id ):
27
55
rh = branch.revision_history()
28
w = branch.weave_store.get_weave(file_id)
56
w = branch.repository.weave_store.get_weave(file_id,
57
branch.repository.get_transaction())
30
59
for origin, text in w.annotate_iter(rev_id):
31
60
text = text.rstrip('\r\n')
32
61
if origin == last_origin:
33
print ' | %s' % (text)
62
(revno_str, author, date_str) = ('','','')
35
64
last_origin = origin
36
line_rev_id = w.idx_to_name(origin)
65
if not branch.repository.has_revision(origin):
66
(revno_str, author, date_str) = ('?','?','?')
69
revno_str = str(rh.index(origin) + 1)
72
rev = branch.repository.get_revision(origin)
73
tz = rev.timezone or 0
74
date_str = time.strftime('%Y%m%d',
75
time.gmtime(rev.timestamp + tz))
76
# a lazy way to get something like the email address
77
# TODO: Get real email address
78
author = rev.committer
38
revno = rh.index(line_rev_id) + 1
39
print '%5d | %s' % (revno, text)
41
print 'merge | %s' % (text)
45
if __name__ == '__main__':
46
from bzrlib.branch import find_branch
47
from bzrlib.trace import enable_default_logging
49
enable_default_logging()
50
b = find_branch(sys.argv[1])
51
rp = b.relpath(sys.argv[1])
52
tree = b.revision_tree(b.last_revision())
53
file_id = tree.inventory.path2id(rp)
54
file_version = tree.inventory[file_id].revision
55
annotate_file(b, file_version, file_id, sys.stdout)
80
author = extract_email_address(author)
82
pass # use the whole name
83
yield (revno_str, author, date_str, origin, text)