19
19
# TODO: Choice of more or less verbose formats:
21
# short: just show revno
22
# long: revno, author, date
23
21
# interposed: show more details between blocks of modified lines
25
23
# TODO: Show which revision caused a line to merge into the parent
31
29
import bzrlib.weave
33
def annotate_file(branch, rev_id, file_id, to_file=None):
30
from bzrlib.config import extract_email_address
33
def annotate_file(branch, rev_id, file_id, verbose=False, full=False,
34
35
if to_file is None:
35
36
to_file = sys.stdout
39
for (revno_str, author, date_str, line_rev_id, text ) in \
40
_annotate_file(branch, rev_id, file_id ):
43
anno = '%5s %-12s %8s ' % (revno_str, author[:12], date_str)
45
anno = "%5s %-7s " % ( revno_str, author[:7] )
47
if anno.lstrip() == "" and full: anno = prevanno
48
print >>to_file, '%s| %s' % (anno, text)
51
def _annotate_file(branch, rev_id, file_id ):
36
53
rh = branch.revision_history()
37
54
w = branch.weave_store.get_weave(file_id, branch.get_transaction())
39
56
for origin, text in w.annotate_iter(rev_id):
40
57
text = text.rstrip('\r\n')
41
58
if origin == last_origin:
59
(revno_str, author, date_str) = ('','','')
44
61
last_origin = origin
45
62
line_rev_id = w.idx_to_name(origin)
46
63
if not branch.has_revision(line_rev_id):
64
(revno_str, author, date_str) = ('?','?','?')
49
66
if line_rev_id in rh:
50
67
revno_str = str(rh.index(line_rev_id) + 1)
56
73
time.gmtime(rev.timestamp + tz))
57
74
# a lazy way to get something like the email address
58
75
# TODO: Get real email address
61
author = author[:author.index('@')]
63
anno = '%5s %-12s %8s' % (revno_str, author, date_str)
64
print '%-27.27s | %s' % (anno, text)
76
author = rev.committer
78
author = extract_email_address(author)
80
pass # use the whole name
81
yield (revno_str, author, date_str, line_rev_id, text)
67
84
if __name__ == '__main__':
74
91
tree = b.revision_tree(b.last_revision())
75
92
file_id = tree.inventory.path2id(rp)
76
93
file_version = tree.inventory[file_id].revision
77
annotate_file(b, file_version, file_id, sys.stdout)
94
annotate_file(b, file_version, file_id, to_file = sys.stdout)