~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/revision_ui.py

  • Committer: Martin Albisetti
  • Date: 2008-07-26 19:21:15 UTC
  • mfrom: (185.1.1 tmp-dir-name)
  • Revision ID: argentina@gmail.com-20080726192115-d8pof2or1omzpegr
Give the temp SQL cache directory a more descriptive name (Matt Nordhoff)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
#
19
19
 
20
 
import time
21
 
 
22
 
import turbogears
23
 
from cherrypy import InternalError
 
20
from paste.httpexceptions import HTTPServerError
24
21
 
25
22
from loggerhead import util
26
 
from loggerhead.templatefunctions import templatefunctions
 
23
from loggerhead.controllers import TemplatedBranchView
27
24
 
28
25
 
29
26
DEFAULT_LINE_COUNT_LIMIT = 3000
30
27
 
31
28
 
32
 
class RevisionUI (object):
33
 
 
34
 
    def __init__(self, branch):
35
 
        # BranchView object
36
 
        self._branch = branch
37
 
        self.log = branch.log
38
 
    
39
 
#    @util.lsprof
40
 
    @util.strip_whitespace
41
 
    @turbogears.expose(html='zpt:loggerhead.templates.revision')
42
 
    def default(self, *args, **kw):
43
 
        z = time.time()
44
 
        h = self._branch.get_history()
45
 
        util.set_context(kw)
46
 
        
47
 
        h._branch.lock_read()
 
29
class RevisionUI(TemplatedBranchView):
 
30
 
 
31
    template_path = 'loggerhead.templates.revision'
 
32
 
 
33
    def get_values(self, h, args, kw, headers):
 
34
 
 
35
        if len(args) > 0:
 
36
            revid = h.fix_revid(args[0])
 
37
        else:
 
38
            revid = None
 
39
 
 
40
        filter_file_id = kw.get('filter_file_id', None)
 
41
        start_revid = h.fix_revid(kw.get('start_revid', None))
 
42
        query = kw.get('q', None)
 
43
        remember = h.fix_revid(kw.get('remember', None))
 
44
        compare_revid = h.fix_revid(kw.get('compare_revid', None))
 
45
 
48
46
        try:
49
 
            if len(args) > 0:
50
 
                revid = h.fix_revid(args[0])
51
 
            else:
52
 
                revid = None
53
 
 
54
 
            filter_file_id = kw.get('filter_file_id', None)
55
 
            start_revid = h.fix_revid(kw.get('start_revid', None))
56
 
            query = kw.get('q', None)
57
 
            remember = kw.get('remember', None)
58
 
            compare_revid = kw.get('compare_revid', None)
59
 
 
60
 
            try:
61
 
                revid, start_revid, revid_list = h.get_view(revid, start_revid, filter_file_id, query)
62
 
            except:
63
 
                self.log.exception('Exception fetching changes')
64
 
                raise InternalError('Could not fetch changes')
65
 
 
66
 
            navigation = util.Container(
67
 
                revid_list=revid_list, revid=revid, start_revid=start_revid,
68
 
                filter_file_id=filter_file_id, pagesize=1,
69
 
                scan_url='/revision', branch=self._branch, feed=True)
70
 
            if query is not None:
71
 
                navigation.query = query
72
 
            util.fill_in_navigation(navigation)
73
 
 
74
 
            change = h.get_change_with_diff(revid, compare_revid)
75
 
            # add parent & merge-point branch-nick info, in case it's useful
76
 
            h.get_branch_nicks([ change ])
77
 
 
78
 
            line_count_limit = int(self._branch.get_config_item(
79
 
                'line_count_limit', DEFAULT_LINE_COUNT_LIMIT))
80
 
            line_count = 0
81
 
            for file in change.changes.modified:
82
 
                for chunk in file.chunks:
83
 
                    line_count += len(chunk.diff)
84
 
 
85
 
            # let's make side-by-side diff be the default
86
 
            side_by_side = not kw.get('unified', False)
87
 
            if side_by_side:
88
 
                h.add_side_by_side([ change ])
89
 
 
90
 
            def url(pathargs, **kw):
91
 
                return self._branch.url(pathargs, **util.get_context(**kw))
92
 
 
93
 
            vals = {
94
 
                'branch': self._branch,
95
 
                'revid': revid,
96
 
                'change': change,
97
 
                'start_revid': start_revid,
98
 
                'filter_file_id': filter_file_id,
99
 
                'util': util,
100
 
                'history': h,
101
 
                'navigation': navigation,
102
 
                'query': query,
103
 
                'remember': remember,
104
 
                'compare_revid': compare_revid,
105
 
                'side_by_side': side_by_side,
106
 
                'url': url,
107
 
                'line_count': line_count,
108
 
                'line_count_limit': line_count_limit,
109
 
                'show_plain_diffs': line_count > line_count_limit,
110
 
            }
111
 
            vals.update(templatefunctions)
112
 
            h.flush_cache()
113
 
            self.log.info('/revision: %r seconds' % (time.time() - z,))
114
 
            return vals
115
 
        finally:
116
 
            h._branch.unlock()
 
47
            revid, start_revid, revid_list = h.get_view(revid, start_revid, filter_file_id, query)
 
48
        except:
 
49
            self.log.exception('Exception fetching changes')
 
50
            raise HTTPServerError('Could not fetch changes')
 
51
 
 
52
        navigation = util.Container(
 
53
            revid_list=revid_list, revid=revid, start_revid=start_revid,
 
54
            filter_file_id=filter_file_id, pagesize=1,
 
55
            scan_url='/revision', branch=self._branch, feed=True, history=h)
 
56
        if query is not None:
 
57
            navigation.query = query
 
58
        util.fill_in_navigation(navigation)
 
59
 
 
60
        change = h.get_change_with_diff(revid, compare_revid)
 
61
        # add parent & merge-point branch-nick info, in case it's useful
 
62
        h.get_branch_nicks([ change ])
 
63
 
 
64
        line_count_limit = DEFAULT_LINE_COUNT_LIMIT
 
65
        line_count = 0
 
66
        for file in change.changes.modified:
 
67
            for chunk in file.chunks:
 
68
                line_count += len(chunk.diff)
 
69
 
 
70
        # let's make side-by-side diff be the default
 
71
        side_by_side = not kw.get('unified', False)
 
72
        if side_by_side:
 
73
            h.add_side_by_side([ change ])
 
74
 
 
75
        return {
 
76
            'branch': self._branch,
 
77
            'revid': revid,
 
78
            'change': change,
 
79
            'start_revid': start_revid,
 
80
            'filter_file_id': filter_file_id,
 
81
            'util': util,
 
82
            'history': h,
 
83
            'navigation': navigation,
 
84
            'query': query,
 
85
            'remember': remember,
 
86
            'compare_revid': compare_revid,
 
87
            'side_by_side': side_by_side,
 
88
            'url': self._branch.context_url,
 
89
            'line_count': line_count,
 
90
            'line_count_limit': line_count_limit,
 
91
            'show_plain_diffs': line_count > line_count_limit,
 
92
        }