~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/changelog_ui.py

  • Committer: Michael Hudson-Doyle
  • Date: 2012-01-23 21:10:46 UTC
  • mfrom: (461.3.1 bug-390029)
  • Revision ID: michael.hudson@linaro.org-20120123211046-ec3rqt27goxfnxnq
fix a crash in comparing a revision to itself

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
 
2
# Copyright (C) 2008, 2009 Canonical Ltd.
2
3
# Copyright (C) 2006  Robey Pointer <robey@lag.net>
3
4
# Copyright (C) 2006  Goffredo Baroncelli <kreijack@inwind.it>
4
5
#
17
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19
#
19
20
 
20
 
import os
21
 
import time
22
 
 
23
 
import turbogears
24
 
from cherrypy import InternalError, session
 
21
import urllib
 
22
 
 
23
import simplejson
 
24
 
 
25
from paste.httpexceptions import HTTPServerError
25
26
 
26
27
from loggerhead import util
27
 
 
28
 
 
29
 
class ChangeLogUI (object):
30
 
    
31
 
    def __init__(self, branch):
32
 
        # BranchView object
33
 
        self._branch = branch
34
 
        self.log = branch.log
35
 
        
36
 
    @util.strip_whitespace
37
 
    @turbogears.expose(html='loggerhead.templates.changelog')
38
 
    def default(self, *args, **kw):
39
 
        z = time.time()
40
 
        h = self._branch.get_history()
41
 
        config = self._branch.config
42
 
        
43
 
        if len(args) > 0:
44
 
            revid = h.fix_revid(args[0])
45
 
        else:
46
 
            revid = None
47
 
 
48
 
        file_id = kw.get('file_id', None)
49
 
        query = kw.get('q', None)
50
 
        start_revid = h.fix_revid(kw.get('start_revid', None))
 
28
from loggerhead.controllers import TemplatedBranchView
 
29
 
 
30
 
 
31
class ChangeLogUI(TemplatedBranchView):
 
32
 
 
33
    template_path = 'loggerhead.templates.changelog'
 
34
 
 
35
    def get_values(self, path, kwargs, headers):
 
36
        history = self._history
 
37
        revid = self.get_revid()
 
38
        filter_file_id = kwargs.get('filter_file_id', None)
 
39
        query = kwargs.get('q', None)
 
40
        start_revid = history.fix_revid(kwargs.get('start_revid', None))
51
41
        orig_start_revid = start_revid
52
 
        pagesize = int(config.get('pagesize', '20'))
 
42
        pagesize = 20#int(config.get('pagesize', '20'))
53
43
        search_failed = False
54
 
        
 
44
 
 
45
        if filter_file_id is None and path is not None:
 
46
            filter_file_id = history.get_file_id(revid, path)
 
47
 
55
48
        try:
56
 
            revid, start_revid, revid_list = h.get_view(revid, start_revid, file_id, query)
57
 
            kw['start_revid'] = start_revid
58
 
            util.set_context(kw)
59
 
            
 
49
            revid, start_revid, revid_list = history.get_view(
 
50
                revid, start_revid, filter_file_id, query,
 
51
                extra_rev_count=pagesize+1)
 
52
            util.set_context(kwargs)
 
53
 
60
54
            if (query is not None) and (len(revid_list) == 0):
61
55
                search_failed = True
62
56
 
63
57
            if len(revid_list) == 0:
64
58
                scan_list = revid_list
65
59
            else:
66
 
                scan_list = revid_list[h.get_revid_sequence(revid_list, revid):]
67
 
            entry_list = scan_list[:pagesize]
68
 
            entries = h.get_changes(entry_list)
 
60
                if revid in revid_list: # XXX is this always true?
 
61
                    i = revid_list.index(revid)
 
62
                else:
 
63
                    i = None
 
64
                scan_list = revid_list[i:]
 
65
            change_list = scan_list[:pagesize]
 
66
            changes = list(history.get_changes(change_list))
 
67
            data = {}
 
68
            for i, c in enumerate(changes):
 
69
                c.index = i
 
70
                data[str(i)] = urllib.quote(urllib.quote(c.revid, safe=''))
69
71
        except:
70
72
            self.log.exception('Exception fetching changes')
71
 
            raise InternalError('Could not fetch changes')
 
73
            raise HTTPServerError('Could not fetch changes')
72
74
 
73
 
        navigation = util.Container(pagesize=pagesize, revid=revid, start_revid=start_revid, revid_list=revid_list,
74
 
                                    file_id=file_id, scan_url='/changes', branch=self._branch, feed=True)
 
75
        navigation = util.Container(
 
76
            pagesize=pagesize, revid=revid, start_revid=start_revid,
 
77
            revid_list=revid_list, filter_file_id=filter_file_id,
 
78
            scan_url='/changes', branch=self._branch, feed=True, history=history)
75
79
        if query is not None:
76
80
            navigation.query = query
77
 
        util.fill_in_navigation(h, navigation)
78
 
        
79
 
        entries = list(entries)
80
 
        # add parent & merge-point branch-nick info, in case it's useful
81
 
        h.get_branch_nicks(entries)
82
 
 
83
 
        vals = {
 
81
        util.fill_in_navigation(navigation)
 
82
 
 
83
        # Directory Breadcrumbs
 
84
        directory_breadcrumbs = (
 
85
            util.directory_breadcrumbs(
 
86
                self._branch.friendly_name,
 
87
                self._branch.is_root,
 
88
                'changes'))
 
89
 
 
90
        show_tag_col = False
 
91
        for change in changes:
 
92
            if change.tags is not None:
 
93
                show_tag_col = True
 
94
                break
 
95
 
 
96
        return {
84
97
            'branch': self._branch,
85
 
            'changes': list(entries),
 
98
            'changes': changes,
 
99
            'show_tag_col': show_tag_col,
 
100
            'data': simplejson.dumps(data),
86
101
            'util': util,
87
 
            'history': h,
 
102
            'history': history,
88
103
            'revid': revid,
89
104
            'navigation': navigation,
90
 
            'file_id': file_id,
 
105
            'filter_file_id': filter_file_id,
91
106
            'start_revid': start_revid,
92
 
            'viewing_from': (orig_start_revid is not None) and (orig_start_revid != h.last_revid),
 
107
            'viewing_from': (orig_start_revid is not None) and
 
108
                            (orig_start_revid != history.last_revid),
93
109
            'query': query,
94
110
            'search_failed': search_failed,
 
111
            'url': self._branch.context_url,
 
112
            'directory_breadcrumbs': directory_breadcrumbs,
95
113
        }
96
 
        h.flush_cache()
97
 
        self.log.info('/changes %r: %r secs' % (revid, time.time() - z))
98
 
        return vals