~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/changelog_ui.py

  • Committer: Robey Pointer
  • Date: 2006-12-24 06:54:42 UTC
  • Revision ID: robey@lag.net-20061224065442-my1tkqko1n02o8p1
sure, let's check in the tarballs too

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 os
20
21
import time
21
22
 
22
23
import turbogears
23
 
from cherrypy import InternalError
 
24
from cherrypy import HTTPRedirect, session
24
25
 
25
26
from loggerhead import util
26
27
 
27
28
 
 
29
# just thinking out loud here...
 
30
#
 
31
# so, when browsing around, there are 3 pieces of context:
 
32
#     - starting revid 
 
33
#         the current beginning of navigation (navigation continues back to
 
34
#         the original revision) -- this may not be along the primary revision
 
35
#         path since the user may have navigated into a branch
 
36
#     - file_id
 
37
#         if navigating the revisions that touched a file
 
38
#     - current revid
 
39
#         current location along the navigation path (while browsing)
 
40
#
 
41
# current revid is given on the url path.  'file_id' and 'starting revid' are
 
42
# handed along as params.
 
43
 
 
44
 
28
45
class ChangeLogUI (object):
29
46
    
30
47
    def __init__(self, branch):
32
49
        self._branch = branch
33
50
        self.log = branch.log
34
51
        
35
 
    @util.strip_whitespace
36
52
    @turbogears.expose(html='loggerhead.templates.changelog')
37
53
    def default(self, *args, **kw):
38
54
        z = time.time()
39
55
        h = self._branch.get_history()
40
56
        config = self._branch.config
 
57
        
 
58
        if len(args) > 0:
 
59
            revid = h.fix_revid(args[0])
 
60
        else:
 
61
            revid = None
41
62
 
42
 
        h._branch.lock_read()
 
63
        file_id = kw.get('file_id', None)
 
64
        query = kw.get('q', None)
 
65
        start_revid = h.fix_revid(kw.get('start_revid', None))
 
66
        orig_start_revid = start_revid
 
67
        pagesize = int(config.get('pagesize', '20'))
 
68
        search_failed = False
 
69
        
43
70
        try:
44
 
            if len(args) > 0:
45
 
                revid = h.fix_revid(args[0])
 
71
            revid, start_revid, revid_list = h.get_view(revid, start_revid, file_id, query)
 
72
            if (query is not None) and (len(revid_list) == 0):
 
73
                search_failed = True
 
74
 
 
75
            if len(revid_list) == 0:
 
76
                scan_list = revid_list
46
77
            else:
47
 
                revid = None
48
 
 
49
 
            file_id = kw.get('file_id', None)
50
 
            query = kw.get('q', None)
51
 
            start_revid = h.fix_revid(kw.get('start_revid', None))
52
 
            orig_start_revid = start_revid
53
 
            pagesize = int(config.get('pagesize', '20'))
54
 
            search_failed = False
55
 
 
56
 
            try:
57
 
                revid, start_revid, revid_list = h.get_view(revid, start_revid, file_id, query)
58
 
                kw['start_revid'] = start_revid
59
 
                util.set_context(kw)
60
 
 
61
 
                if (query is not None) and (len(revid_list) == 0):
62
 
                    search_failed = True
63
 
 
64
 
                if len(revid_list) == 0:
65
 
                    scan_list = revid_list
66
 
                else:
67
 
                    if revid in revid_list: # XXX is this always true?
68
 
                        i = revid_list.index(revid)
69
 
                    else:
70
 
                        i = None
71
 
                    scan_list = revid_list[i:]
72
 
                change_list = scan_list[:pagesize]
73
 
                changes = list(h.get_changes(change_list))
74
 
                h.add_changes(changes)
75
 
            except:
76
 
                self.log.exception('Exception fetching changes')
77
 
                raise InternalError('Could not fetch changes')
78
 
 
79
 
            navigation = util.Container(pagesize=pagesize, revid=revid, start_revid=start_revid, revid_list=revid_list,
80
 
                                        file_id=file_id, scan_url='/changes', branch=self._branch, feed=True)
81
 
            if query is not None:
82
 
                navigation.query = query
83
 
            util.fill_in_navigation(navigation)
84
 
 
85
 
            # add parent & merge-point branch-nick info, in case it's useful
86
 
            h.get_branch_nicks(changes)
87
 
 
88
 
            # does every change on this page have the same committer?  if so,
89
 
            # tell the template to show committer info in the "details block"
90
 
            # instead of on each line.
91
 
            all_same_author = True
92
 
 
93
 
            if changes:
94
 
                author = changes[0].author
95
 
                for e in changes[1:]:
96
 
                    if e.author != author:
97
 
                        all_same_author = False
98
 
                        break
99
 
 
100
 
            vals = {
101
 
                'branch': self._branch,
102
 
                'changes': changes,
103
 
                'util': util,
104
 
                'history': h,
105
 
                'revid': revid,
106
 
                'navigation': navigation,
107
 
                'file_id': file_id,
108
 
                'start_revid': start_revid,
109
 
                'viewing_from': (orig_start_revid is not None) and (orig_start_revid != h.last_revid),
110
 
                'query': query,
111
 
                'search_failed': search_failed,
112
 
                'all_same_author': all_same_author,
113
 
            }
114
 
            h.flush_cache()
115
 
            self.log.info('/changes %r: %r secs' % (revid, time.time() - z))
116
 
            return vals
117
 
        finally:
118
 
            h._branch.unlock()
 
78
                scan_list = revid_list[h.get_revid_sequence(revid_list, revid):]
 
79
            entry_list = scan_list[:pagesize]
 
80
            entries = h.get_changes(entry_list)
 
81
        except Exception, x:
 
82
            self.log.error('Exception fetching changes: %s' % (x,))
 
83
            util.log_exception(self.log)
 
84
            raise HTTPRedirect(self._branch.url('/changes'))
 
85
 
 
86
        navigation = util.Container(pagesize=pagesize, revid=revid, start_revid=start_revid, revid_list=revid_list,
 
87
                                    file_id=file_id, scan_url='/changes', feed=True)
 
88
        if query is not None:
 
89
            navigation.query = query
 
90
        util.fill_in_navigation(h, navigation)
 
91
        
 
92
        entries = list(entries)
 
93
        # add parent & merge-point branch-nick info, in case it's useful
 
94
        h.get_branch_nicks(entries)
 
95
 
 
96
        vals = {
 
97
            'branch': self._branch,
 
98
            'changes': list(entries),
 
99
            'util': util,
 
100
            'history': h,
 
101
            'revid': revid,
 
102
            'navigation': navigation,
 
103
            'file_id': file_id,
 
104
            'start_revid': start_revid,
 
105
            'viewing_from': (orig_start_revid is not None) and (orig_start_revid != h.last_revid),
 
106
            'query': query,
 
107
            'search_failed': search_failed,
 
108
        }
 
109
        h.flush_cache()
 
110
        self.log.info('/changes %r: %r secs' % (revid, time.time() - z))
 
111
        return vals