~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/revision_ui.py

  • Committer: Robey Pointer
  • Date: 2006-12-21 01:09:00 UTC
  • Revision ID: robey@lag.net-20061221010900-auqh80g9z7r8v5tu
use bzr.dev as the branch name now that it's okay

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', 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
 
 
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 {
 
69
        
 
70
        vals = {
76
71
            'branch': self._branch,
77
72
            'revid': revid,
78
73
            'change': change,
79
74
            'start_revid': start_revid,
80
 
            'filter_file_id': filter_file_id,
 
75
            'file_id': file_id,
81
76
            'util': util,
82
77
            'history': h,
83
78
            'navigation': navigation,
84
79
            '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
80
        }
 
81
        h.flush_cache()
 
82
        self.log.info('/revision: %r seconds' % (time.time() - z,))
 
83
        return vals