~jameinel/loggerhead/less_work_for_head_716217

« back to all changes in this revision

Viewing changes to loggerhead/controllers/annotate_ui.py

  • Committer: John Arbash Meinel
  • Date: 2011-03-03 11:48:26 UTC
  • mfrom: (422.2.9 trunk-rich)
  • Revision ID: john@arbash-meinel.com-20110303114826-9xvuhwlwitfcgrdv
Merge trunk in, resolving merge conflicts.

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