~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/annotate_ui.py

  • Committer: Max Kanat-Alexander
  • Date: 2010-12-01 08:30:02 UTC
  • mto: (157.1.21 devel)
  • mto: This revision was merged to the branch mainline in revision 423.
  • Revision ID: mkanat@bugzilla.org-20101201083002-tum61bojpypc9a7b
Merge in a cherrypick of the "view" controller, to help performance on
Launchpad.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Copyright (C) 2010 Canonical Ltd.
 
3
#
 
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.
 
8
#
 
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.
 
13
#
 
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
 
17
#
 
18
 
 
19
from loggerhead.controllers.view_ui import ViewUI
 
20
from loggerhead import util
 
21
 
 
22
class AnnotateUI(ViewUI):
 
23
 
 
24
    def annotate_file(self, info):
 
25
        file_id = info['file_id']
 
26
        revid = info['change'].revid
 
27
        
 
28
        tree = self.tree_for(file_id, revid)
 
29
        
 
30
        change_cache = {}
 
31
        last_line_revid = None
 
32
        parity = 1
 
33
        for line_revid, text in tree.annotate_iter(file_id):
 
34
            if line_revid == last_line_revid:
 
35
                # remember which lines have a new revno and which don't
 
36
                new_rev = False
 
37
            else:
 
38
                new_rev = True
 
39
                parity ^= 1
 
40
                last_line_revid = line_revid
 
41
                if line_revid in change_cache:
 
42
                    change = change_cache[line_revid]
 
43
                else:
 
44
                    change = self._history.get_changes([line_revid])[0]
 
45
                    change_cache[line_revid] = change
 
46
 
 
47
            yield util.Container(
 
48
                parity=parity, new_rev=new_rev, change=change)
 
49
            
 
50
    def get_values(self, path, kwargs, headers):
 
51
        values = super(AnnotateUI, self).get_values(path, kwargs, headers)
 
52
        values['annotated'] = self.annotate_file(values)
 
53
        
 
54
        return values