26
29
from loggerhead import util
31
log = logging.getLogger("loggerhead.controllers")
34
# just thinking out loud here...
36
# so, when browsing around, there are 3 pieces of context:
38
# the current beginning of navigation (navigation continues back to
39
# the original revision) -- this may not be along the primary revision
40
# path since the user may have navigated into a branch
42
# if navigating the revisions that touched a file
44
# current location along the navigation path (while browsing)
46
# current revid is given on the url path. 'path' and 'starting revid' are
47
# handed along as params.
31
50
class ChangeLogUI (object):
33
def __init__(self, branch):
38
@util.strip_whitespace
39
52
@turbogears.expose(html='loggerhead.templates.changelog')
40
53
def default(self, *args, **kw):
42
h = self._branch.get_history()
43
config = self._branch.config
55
h = util.get_history()
46
58
revid = h.fix_revid(args[0])
50
file_id = kw.get('file_id', None)
51
query = kw.get('q', None)
62
path = kw.get('path', None)
52
63
start_revid = h.fix_revid(kw.get('start_revid', None))
53
orig_start_revid = start_revid
54
pagesize = int(config.get('pagesize', '20'))
64
pagesize = int(util.get_config().get('pagesize', '20'))
58
revid, start_revid, revid_list = h.get_view(revid, start_revid, file_id, query)
59
kw['start_revid'] = start_revid
62
if (query is not None) and (len(revid_list) == 0):
65
if len(revid_list) == 0:
66
scan_list = revid_list
68
scan_list = revid_list[h.get_revid_sequence(revid_list, revid):]
69
entry_list = scan_list[:pagesize]
70
entries = h.get_changes(entry_list)
67
revlist, start_revid = h.get_navigation(start_revid, path)
70
if revid not in revlist:
71
# if the given revid is not in the revlist, use a revlist that
72
# starts at the given revid.
73
revlist, start_revid = h.get_navigation(revid, path)
74
entry_list = list(h.get_revids_from(revlist, revid))[:pagesize]
75
entries = h.get_changelist(entry_list)
71
76
except Exception, x:
72
self.log.error('Exception fetching changes: %s' % (x,))
73
util.log_exception(self.log)
74
raise HTTPRedirect(self._branch.url('/changes'))
77
log.error('Exception fetching changes: %r, %s' % (x, x))
78
raise HTTPRedirect(turbogears.url('/changes'))
76
navigation = util.Container(pagesize=pagesize, revid=revid, start_revid=start_revid, revid_list=revid_list,
77
file_id=file_id, scan_url='/changes', branch=self._branch, feed=True)
79
navigation.query = query
80
navigation = util.Container(pagesize=pagesize, revid=revid, start_revid=start_revid, revlist=revlist,
81
path=path, scan_url='/changes', feed=True)
80
82
util.fill_in_navigation(h, navigation)
82
84
entries = list(entries)
83
85
# add parent & merge-point branch-nick info, in case it's useful
84
h.get_branch_nicks(entries)
86
for change in entries:
87
for p in change.parents:
88
p.branch_nick = h.get_change(p.revid).branch_nick
89
for p in change.merge_points:
90
p.branch_nick = h.get_change(p.revid).branch_nick
87
'branch': self._branch,
93
'branch_name': util.get_config().get('branch_name'),
88
94
'changes': list(entries),
92
98
'navigation': navigation,
100
'last_revid': h.last_revid,
94
101
'start_revid': start_revid,
95
'viewing_from': (orig_start_revid is not None) and (orig_start_revid != h.last_revid),
97
'search_failed': search_failed,
100
self.log.info('/changes %r: %r secs' % (revid, time.time() - z))
104
log.info('/changes %r: %r secs' % (revid, time.time() - z))