17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
from paste.httpexceptions import HTTPServerError
27
from cherrypy import HTTPRedirect, session
22
29
from loggerhead import util
23
from loggerhead.controllers import TemplatedBranchView
26
DEFAULT_LINE_COUNT_LIMIT = 3000
29
class RevisionUI(TemplatedBranchView):
31
template_path = 'loggerhead.templates.revision'
33
def get_values(self, h, args, kw, headers):
32
class RevisionUI (object):
34
def __init__(self, branch):
39
@turbogears.expose(html='loggerhead.templates.revision')
40
def default(self, *args, **kw):
42
h = self._branch.get_history()
36
45
revid = h.fix_revid(args[0])
40
filter_file_id = kw.get('filter_file_id', None)
49
file_id = kw.get('file_id', None)
41
50
start_revid = h.fix_revid(kw.get('start_revid', None))
42
51
query = kw.get('q', None)
43
remember = h.fix_revid(kw.get('remember', None))
44
compare_revid = h.fix_revid(kw.get('compare_revid', None))
47
revid, start_revid, revid_list = h.get_view(revid, start_revid, filter_file_id, query)
49
self.log.exception('Exception fetching changes')
50
raise HTTPServerError('Could not fetch changes')
52
navigation = util.Container(
53
revid_list=revid_list, revid=revid, start_revid=start_revid,
54
filter_file_id=filter_file_id, pagesize=1,
55
scan_url='/revision', branch=self._branch, feed=True, history=h)
54
revid, start_revid, revid_list = h.get_view(revid, start_revid, file_id, query)
56
self.log.error('Exception fetching changes: %s' % (x,))
57
util.log_exception(self.log)
58
raise HTTPRedirect(self._branch.url('/changes'))
60
navigation = util.Container(revid_list=revid_list, revid=revid, start_revid=start_revid, file_id=file_id,
61
pagesize=1, scan_url='/revision', feed=True)
56
62
if query is not None:
57
63
navigation.query = query
58
util.fill_in_navigation(navigation)
64
util.fill_in_navigation(h, navigation)
60
change = h.get_change_with_diff(revid, compare_revid)
66
change = h.get_changes([ revid ], get_diffs=True)[0]
61
67
# add parent & merge-point branch-nick info, in case it's useful
62
68
h.get_branch_nicks([ change ])
64
line_count_limit = DEFAULT_LINE_COUNT_LIMIT
66
for file in change.changes.modified:
67
for chunk in file.chunks:
68
line_count += len(chunk.diff)
70
# let's make side-by-side diff be the default
71
side_by_side = not kw.get('unified', False)
73
h.add_side_by_side([ change ])
76
71
'branch': self._branch,
79
74
'start_revid': start_revid,
80
'filter_file_id': filter_file_id,
83
78
'navigation': navigation,
86
'compare_revid': compare_revid,
87
'side_by_side': side_by_side,
88
'url': self._branch.context_url,
89
'line_count': line_count,
90
'line_count_limit': line_count_limit,
91
'show_plain_diffs': line_count > line_count_limit,
82
self.log.info('/revision: %r seconds' % (time.time() - z,))