~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/revision_ui.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2008-02-29 04:43:52 UTC
  • mfrom: (146.1.5 release-prep)
  • Revision ID: launchpad@pqm.canonical.com-20080229044352-zoweuygtkq7uwo37
[r=jml] updates to README.txt and NEWS before release

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 time
 
21
 
 
22
import turbogears
 
23
from cherrypy import InternalError
21
24
 
22
25
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, revid, path, kwargs, headers):
34
 
 
35
 
        filter_file_id = kwargs.get('filter_file_id', None)
36
 
        start_revid = h.fix_revid(kwargs.get('start_revid', None))
37
 
        query = kwargs.get('q', None)
38
 
        remember = h.fix_revid(kwargs.get('remember', None))
39
 
        compare_revid = h.fix_revid(kwargs.get('compare_revid', None))
40
 
 
 
26
 
 
27
 
 
28
class RevisionUI (object):
 
29
 
 
30
    def __init__(self, branch):
 
31
        # BranchView object
 
32
        self._branch = branch
 
33
        self.log = branch.log
 
34
    
 
35
#    @util.lsprof
 
36
    @util.strip_whitespace
 
37
    @turbogears.expose(html='loggerhead.templates.revision')
 
38
    def default(self, *args, **kw):
 
39
        z = time.time()
 
40
        h = self._branch.get_history()
 
41
        util.set_context(kw)
 
42
        
 
43
        h._branch.lock_read()
41
44
        try:
42
 
            revid, start_revid, revid_list = h.get_view(revid,
43
 
                                                        start_revid,
44
 
                                                        filter_file_id,
45
 
                                                        query)
46
 
        except:
47
 
            self.log.exception('Exception fetching changes')
48
 
            raise HTTPServerError('Could not fetch changes')
49
 
 
50
 
        navigation = util.Container(
51
 
            revid_list=revid_list, revid=revid, start_revid=start_revid,
52
 
            filter_file_id=filter_file_id, pagesize=1,
53
 
            scan_url='/revision', branch=self._branch, feed=True, history=h)
54
 
        if query is not None:
55
 
            navigation.query = query
56
 
        util.fill_in_navigation(navigation)
57
 
 
58
 
        change = h.get_change_with_diff(revid, compare_revid)
59
 
        # add parent & merge-point branch-nick info, in case it's useful
60
 
        h.get_branch_nicks([change])
61
 
 
62
 
        line_count_limit = DEFAULT_LINE_COUNT_LIMIT
63
 
        line_count = 0
64
 
        for file in change.changes.modified:
65
 
            for chunk in file.chunks:
66
 
                line_count += len(chunk.diff)
67
 
 
68
 
        # let's make side-by-side diff be the default
69
 
        # FIXME: not currently in use. Should be
70
 
        side_by_side = not kwargs.get('unified', False)
71
 
        if side_by_side:
72
 
            h.add_side_by_side([change])
73
 
 
74
 
        # Directory Breadcrumbs
75
 
        directory_breadcrumbs = (
76
 
            util.directory_breadcrumbs(
77
 
                self._branch.friendly_name,
78
 
                self._branch.is_root,
79
 
                'changes'))
80
 
 
81
 
        return {
82
 
            'branch': self._branch,
83
 
            'revid': revid,
84
 
            'change': change,
85
 
            'start_revid': start_revid,
86
 
            'filter_file_id': filter_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
 
            'url': self._branch.context_url,
95
 
            'line_count': line_count,
96
 
            'line_count_limit': line_count_limit,
97
 
            'show_plain_diffs': line_count > line_count_limit,
98
 
            'directory_breadcrumbs': directory_breadcrumbs,
99
 
        }
 
45
            if len(args) > 0:
 
46
                revid = h.fix_revid(args[0])
 
47
            else:
 
48
                revid = None
 
49
 
 
50
            file_id = kw.get('file_id', None)
 
51
            start_revid = h.fix_revid(kw.get('start_revid', None))
 
52
            query = kw.get('q', None)
 
53
            remember = kw.get('remember', None)
 
54
            compare_revid = kw.get('compare_revid', None)
 
55
 
 
56
            try:
 
57
                revid, start_revid, revid_list = h.get_view(revid, start_revid, file_id, query)
 
58
            except:
 
59
                self.log.exception('Exception fetching changes')
 
60
                raise InternalError('Could not fetch changes')
 
61
 
 
62
            navigation = util.Container(revid_list=revid_list, revid=revid, start_revid=start_revid, file_id=file_id,
 
63
                                        pagesize=1, scan_url='/revision', branch=self._branch, feed=True)
 
64
            if query is not None:
 
65
                navigation.query = query
 
66
            util.fill_in_navigation(navigation)
 
67
 
 
68
            change = h.get_change_with_diff(revid, compare_revid)
 
69
            # add parent & merge-point branch-nick info, in case it's useful
 
70
            h.get_branch_nicks([ change ])
 
71
 
 
72
            # let's make side-by-side diff be the default
 
73
            side_by_side = not kw.get('unified', False)
 
74
            if side_by_side:
 
75
                h.add_side_by_side([ change ])
 
76
 
 
77
            vals = {
 
78
                'branch': self._branch,
 
79
                'revid': revid,
 
80
                'change': change,
 
81
                'start_revid': start_revid,
 
82
                'file_id': file_id,
 
83
                'util': util,
 
84
                'history': h,
 
85
                'navigation': navigation,
 
86
                'query': query,
 
87
                'remember': remember,
 
88
                'compare_revid': compare_revid,
 
89
                'side_by_side': side_by_side,
 
90
            }
 
91
            h.flush_cache()
 
92
            self.log.info('/revision: %r seconds' % (time.time() - z,))
 
93
            return vals
 
94
        finally:
 
95
            h._branch.unlock()