~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/revision_ui.py

  • Committer: Robey Pointer
  • Date: 2007-01-02 04:34:09 UTC
  • Revision ID: robey@lag.net-20070102043409-5slhxuzq5omtim2f
exponential backoff isn't really working for the lockfile, so keep it down
to 0.1 second pauses while trying to grab the lock.  also, flush the caches
at shutdown, and pause during cache rebuilding to give normal requests a
chance to get the lock.  (with threading.Lock, wakeups were automatic, but
with the file lock, there's a lot of sleeping going on.)

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
 
from paste.httpexceptions import HTTPServerError
 
20
import datetime
 
21
import logging
 
22
import os
 
23
import textwrap
 
24
import time
 
25
 
 
26
import turbogears
 
27
from cherrypy import HTTPRedirect, session
21
28
 
22
29
from loggerhead import util
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
 
 
 
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
    @turbogears.expose(html='loggerhead.templates.revision')
 
40
    def default(self, *args, **kw):
 
41
        z = time.time()
 
42
        h = self._branch.get_history()
 
43
        
35
44
        if len(args) > 0:
36
45
            revid = h.fix_revid(args[0])
37
46
        else:
38
47
            revid = None
39
 
 
40
 
        filter_file_id = kw.get('filter_file_id', None)
 
48
        
 
49
        file_id = kw.get('file_id', None)
41
50
        start_revid = h.fix_revid(kw.get('start_revid', None))
42
51
        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
 
 
 
52
        
46
53
        try:
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)
 
54
            revid, start_revid, revid_list = h.get_view(revid, start_revid, file_id, query)
 
55
        except Exception, x:
 
56
            self.log.error('Exception fetching changes: %s' % (x,))
 
57
            util.log_exception(self.log)
 
58
            raise HTTPRedirect(self._branch.url('/changes'))
 
59
        
 
60
        navigation = util.Container(revid_list=revid_list, revid=revid, start_revid=start_revid, file_id=file_id,
 
61
                                    pagesize=1, scan_url='/revision', branch=self._branch, feed=True)
56
62
        if query is not None:
57
63
            navigation.query = query
58
 
        util.fill_in_navigation(navigation)
 
64
        util.fill_in_navigation(h, navigation)
59
65
 
60
 
        change = h.get_change_with_diff(revid, compare_revid)
 
66
        change = h.get_changes([ revid ], get_diffs=True)[0]
61
67
        # add parent & merge-point branch-nick info, in case it's useful
62
68
        h.get_branch_nicks([ change ])
63
69
 
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
70
        # let's make side-by-side diff be the default
71
71
        side_by_side = not kw.get('unified', False)
72
72
        if side_by_side:
73
 
            h.add_side_by_side([ change ])
74
 
 
75
 
        return {
 
73
            h.make_side_by_side([ change ])
 
74
        
 
75
        vals = {
76
76
            'branch': self._branch,
77
77
            'revid': revid,
78
78
            'change': change,
79
79
            'start_revid': start_revid,
80
 
            'filter_file_id': filter_file_id,
 
80
            'file_id': file_id,
81
81
            'util': util,
82
82
            'history': h,
83
83
            'navigation': navigation,
84
84
            'query': query,
85
 
            'remember': remember,
86
 
            'compare_revid': compare_revid,
87
85
            '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
86
        }
 
87
        h.flush_cache()
 
88
        self.log.info('/revision: %r seconds' % (time.time() - z,))
 
89
        return vals