18
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
from paste.httpexceptions import HTTPServerError
24
from cherrypy import InternalError, session
27
26
from loggerhead import util
28
from loggerhead.controllers import TemplatedBranchView
31
class ChangeLogUI(TemplatedBranchView):
33
template_path = 'loggerhead.templates.changelog'
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))
29
class ChangeLogUI (object):
31
def __init__(self, branch):
36
@util.strip_whitespace
37
@turbogears.expose(html='loggerhead.templates.changelog')
38
def default(self, *args, **kw):
40
h = self._branch.get_history()
41
config = self._branch.config
44
revid = h.fix_revid(args[0])
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))
41
51
orig_start_revid = start_revid
42
pagesize = 20#int(config.get('pagesize', '20'))
52
pagesize = int(config.get('pagesize', '20'))
43
53
search_failed = False
45
if filter_file_id is None and path is not None:
46
filter_file_id = history.get_file_id(revid, path)
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)
56
revid, start_revid, revid_list = h.get_view(revid, start_revid, file_id, query)
57
kw['start_revid'] = start_revid
54
60
if (query is not None) and (len(revid_list) == 0):
55
61
search_failed = True
57
63
if len(revid_list) == 0:
58
64
scan_list = revid_list
60
if revid in revid_list: # XXX is this always true?
61
i = revid_list.index(revid)
64
scan_list = revid_list[i:]
65
change_list = scan_list[:pagesize]
66
changes = list(history.get_changes(change_list))
68
for i, c in enumerate(changes):
70
data[str(i)] = urllib.quote(urllib.quote(c.revid, safe=''))
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)
72
70
self.log.exception('Exception fetching changes')
73
raise HTTPServerError('Could not fetch changes')
71
raise InternalError('Could not fetch changes')
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)
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)
79
75
if query is not None:
80
76
navigation.query = query
81
util.fill_in_navigation(navigation)
83
# Directory Breadcrumbs
84
directory_breadcrumbs = (
85
util.directory_breadcrumbs(
86
self._branch.friendly_name,
91
for change in changes:
92
if change.tags is not None:
77
util.fill_in_navigation(h, navigation)
79
entries = list(entries)
80
# add parent & merge-point branch-nick info, in case it's useful
81
h.get_branch_nicks(entries)
97
84
'branch': self._branch,
99
'show_tag_col': show_tag_col,
100
'data': simplejson.dumps(data),
85
'changes': list(entries),
104
89
'navigation': navigation,
105
'filter_file_id': filter_file_id,
106
91
'start_revid': start_revid,
107
'viewing_from': (orig_start_revid is not None) and
108
(orig_start_revid != history.last_revid),
92
'viewing_from': (orig_start_revid is not None) and (orig_start_revid != h.last_revid),
110
94
'search_failed': search_failed,
111
'url': self._branch.context_url,
112
'directory_breadcrumbs': directory_breadcrumbs,
97
self.log.info('/changes %r: %r secs' % (revid, time.time() - z))