31
35
from bzrlib.config import extract_email_address
32
from bzrlib.errors import NoEmailInUsername
35
38
def annotate_file(branch, rev_id, file_id, verbose=False, full=False,
39
to_file=None, show_ids=False):
37
40
if to_file is None:
38
41
to_file = sys.stdout
46
w = branch.repository.weave_store.get_weave(file_id,
47
branch.repository.get_transaction())
48
annotations = list(w.annotate_iter(rev_id))
49
max_origin_len = max(len(origin) for origin, text in annotations)
50
for origin, text in annotations:
51
if full or last_rev_id != origin:
55
to_file.write('%*s | %s' % (max_origin_len, this, text))
41
59
annotation = list(_annotate_file(branch, rev_id, file_id))
42
60
if len(annotation) == 0:
61
max_origin_len = max_revno_len = max_revid_len = 0
45
max_origin_len = max(len(origin) for origin in set(x[1] for x in annotation))
46
for (revno_str, author, date_str, line_rev_id, text ) in annotation:
63
max_origin_len = max(len(x[1]) for x in annotation)
64
max_revno_len = max(len(x[0]) for x in annotation)
65
max_revid_len = max(len(x[3]) for x in annotation)
68
max_revno_len = min(max_revno_len, 12)
69
max_revno_len = max(max_revno_len, 3)
71
for (revno_str, author, date_str, line_rev_id, text) in annotation:
48
anno = '%5s %-*s %8s ' % (revno_str, max_origin_len, author, date_str)
73
anno = '%-*s %-*s %8s ' % (max_revno_len, revno_str,
74
max_origin_len, author, date_str)
50
anno = "%5s %-7s " % ( revno_str, author[:7] )
76
if len(revno_str) > max_revno_len:
77
revno_str = revno_str[:max_revno_len-1] + '>'
78
anno = "%-*s %-7s " % (max_revno_len, revno_str, author[:7])
52
80
if anno.lstrip() == "" and full: anno = prevanno
53
81
print >>to_file, '%s| %s' % (anno, text)
56
85
def _annotate_file(branch, rev_id, file_id ):
86
"""Yield the origins for each line of a file.
88
This includes detailed information, such as the committer name, and
89
date string for the commit, rather than just the revision id.
58
92
rh = branch.revision_history()
59
w = branch.repository.weave_store.get_weave(file_id,
93
revision_graph = branch.repository.get_revision_graph(rev_id)
94
merge_sorted_revisions = tsort.merge_sort(
99
revision_id_to_revno = dict((rev_id, revno)
100
for seq_num, rev_id, depth, revno, end_of_merge
101
in merge_sorted_revisions)
102
w = branch.repository.weave_store.get_weave(file_id,
60
103
branch.repository.get_transaction())
61
104
last_origin = None
62
105
annotations = list(w.annotate_iter(rev_id))
74
117
if origin not in revisions:
75
118
(revno_str, author, date_str) = ('?','?','?')
78
revno_str = str(rh.index(origin) + 1)
120
revno_str = '.'.join(str(i) for i in
121
revision_id_to_revno[origin])
81
122
rev = revisions[origin]
82
123
tz = rev.timezone or 0
83
date_str = time.strftime('%Y%m%d',
124
date_str = time.strftime('%Y%m%d',
84
125
time.gmtime(rev.timestamp + tz))
85
126
# a lazy way to get something like the email address
86
127
# TODO: Get real email address
87
128
author = rev.committer
89
130
author = extract_email_address(author)
90
except NoEmailInUsername:
131
except errors.NoEmailInUsername:
91
132
pass # use the whole name
92
133
yield (revno_str, author, date_str, origin, text)