2
# Copyright (C) 2010 Canonical Ltd.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
from loggerhead.controllers.view_ui import ViewUI
22
from loggerhead import util
24
class AnnotateUI(ViewUI):
26
def annotate_file(self, info):
27
file_id = info['file_id']
28
revid = info['change'].revid
30
tree = self.tree_for(file_id, revid)
33
last_line_revid = None
40
for (line_revid, text), lineno in zip(tree.annotate_iter(file_id), itertools.count(1)):
41
if line_revid != last_line_revid:
42
last_line_revid = line_revid
44
change = change_cache.get(line_revid, None)
46
change = self._history.get_changes([line_revid])[0]
47
change_cache[line_revid] = change
50
message = change.comment.splitlines()[0]
52
# Comment not present for this revision
56
# The revspan is of lines between the last revision and this one.
57
# We set the one for the previous revision when we're creating the current revision.
58
revisions[last_lineno].revspan = lineno - last_lineno
60
revisions[lineno] = util.Container(change=change, message=message)
63
last_line_revid = line_revid
65
# Zero-size file. Return empty revisions.
66
if last_lineno is None:
69
# We never set a revspan for the last revision during the loop above, so set it here.
70
revisions[last_lineno].revspan = lineno - last_lineno + 1
74
def get_values(self, path, kwargs, headers):
75
values = super(AnnotateUI, self).get_values(path, kwargs, headers)
76
values['annotated'] = self.annotate_file(values)