~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/revision_ui.py

  • Committer: Michael Hudson
  • Date: 2008-07-01 04:04:03 UTC
  • mfrom: (179.1.16 dont-hold-branches-open)
  • Revision ID: michael.hudson@canonical.com-20080701040403-payspbvmsfmp4e84
refactor things to avoid keeping branches open when they are not being viewed.
history objects are now ephemeral wrappers around branches, with the
expensive-to-calculate whole history data being cached elsewhere, in a
LRUCache.
also fixes a logging setup regression and deletes some dead code.

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 datetime
21
 
import logging
22
 
import os
23
 
import textwrap
24
 
import time
25
 
 
26
 
import turbogears
27
 
from cherrypy import InternalError, session
 
20
from paste.httpexceptions import HTTPServerError
28
21
 
29
22
from loggerhead import util
30
 
 
31
 
 
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='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()
 
23
from loggerhead.controllers import TemplatedBranchView
 
24
 
 
25
 
 
26
DEFAULT_LINE_COUNT_LIMIT = 3000
 
27
 
 
28
 
 
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
 
            file_id = kw.get('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, file_id, query)
62
 
            except:
63
 
                self.log.exception('Exception fetching changes')
64
 
                raise InternalError('Could not fetch changes')
65
 
 
66
 
            navigation = util.Container(revid_list=revid_list, revid=revid, start_revid=start_revid, file_id=file_id,
67
 
                                        pagesize=1, scan_url='/revision', branch=self._branch, feed=True)
68
 
            if query is not None:
69
 
                navigation.query = query
70
 
            util.fill_in_navigation(navigation)
71
 
 
72
 
            change = h.get_change_with_diff(revid, compare_revid)
73
 
            # add parent & merge-point branch-nick info, in case it's useful
74
 
            h.get_branch_nicks([ change ])
75
 
 
76
 
            # let's make side-by-side diff be the default
77
 
            side_by_side = not kw.get('unified', False)
78
 
            if side_by_side:
79
 
                h.add_side_by_side([ change ])
80
 
 
81
 
            vals = {
82
 
                'branch': self._branch,
83
 
                'revid': revid,
84
 
                'change': change,
85
 
                'start_revid': start_revid,
86
 
                'file_id': file_id,
87
 
                'util': util,
88
 
                'history': h,
89
 
                'navigation': navigation,
90
 
                'query': query,
91
 
                'remember': remember,
92
 
                'compare_revid': compare_revid,
93
 
                'side_by_side': side_by_side,
94
 
            }
95
 
            h.flush_cache()
96
 
            self.log.info('/revision: %r seconds' % (time.time() - z,))
97
 
            return vals
98
 
        finally:
99
 
            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
        }