17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
import json as simplejson
26
from paste.httpexceptions import HTTPServerError
27
from cherrypy import HTTPRedirect, session
28
29
from loggerhead import util
29
from loggerhead.controllers import TemplatedBranchView
30
from loggerhead.controllers.filediff_ui import diff_chunks_for_file
33
DEFAULT_LINE_COUNT_LIMIT = 3000
36
return urllib.quote(urllib.quote(p, safe=''))
39
class RevisionUI(TemplatedBranchView):
41
template_path = 'loggerhead.templates.revision'
43
def get_values(self, path, kwargs, headers):
45
revid = self.get_revid()
47
filter_file_id = kwargs.get('filter_file_id', None)
48
start_revid = h.fix_revid(kwargs.get('start_revid', None))
49
query = kwargs.get('q', None)
50
remember = h.fix_revid(kwargs.get('remember', None))
51
compare_revid = h.fix_revid(kwargs.get('compare_revid', None))
32
class RevisionUI (object):
34
def __init__(self, branch):
39
@util.strip_whitespace
40
@turbogears.expose(html='loggerhead.templates.revision')
41
def default(self, *args, **kw):
43
h = self._branch.get_history()
47
revid = h.fix_revid(args[0])
51
file_id = kw.get('file_id', None)
52
start_revid = h.fix_revid(kw.get('start_revid', None))
53
query = kw.get('q', None)
54
remember = kw.get('remember', None)
55
compare_revid = kw.get('compare_revid', None)
54
revid, start_revid, revid_list = h.get_view(revid,
59
self.log.exception('Exception fetching changes')
60
raise HTTPServerError('Could not fetch changes')
62
navigation = util.Container(
63
revid_list=revid_list, revid=revid, start_revid=start_revid,
64
filter_file_id=filter_file_id, pagesize=1,
65
scan_url='/revision', branch=self._branch, feed=True, history=h)
58
revid, start_revid, revid_list = h.get_view(revid, start_revid, file_id, query)
60
self.log.error('Exception fetching changes: %s' % (x,))
61
util.log_exception(self.log)
62
raise HTTPRedirect(self._branch.url('/changes'))
64
navigation = util.Container(revid_list=revid_list, revid=revid, start_revid=start_revid, file_id=file_id,
65
pagesize=1, scan_url='/revision', branch=self._branch, feed=True)
66
66
if query is not None:
67
67
navigation.query = query
68
util.fill_in_navigation(navigation)
70
change = h.get_changes([revid])[0]
72
if compare_revid is None:
73
file_changes = h.get_file_changes(change)
75
file_changes = h.file_changes_for_revision_ids(
76
compare_revid, change.revid)
84
item = [x for x in file_changes.text_changes if x.filename == path][0]
85
diff_chunks = diff_chunks_for_file(
86
self._history._branch.repository, item.file_id,
87
item.old_revision, item.new_revision)
90
for i, item in enumerate(file_changes.text_changes):
92
link_data['diff-' + str(i)] = '%s/%s/%s' % (
93
dq(item.new_revision), dq(item.old_revision), dq(item.file_id))
94
path_to_id[item.filename] = 'diff-' + str(i)
96
h.add_branch_nicks(change)
98
# Directory Breadcrumbs
99
directory_breadcrumbs = (
100
util.directory_breadcrumbs(
101
self._branch.friendly_name,
102
self._branch.is_root,
68
util.fill_in_navigation(h, navigation)
70
if compare_revid is not None:
71
change = h.get_diff(compare_revid, revid)
73
change = h.get_changes([ revid ], get_diffs=True)[0]
74
# add parent & merge-point branch-nick info, in case it's useful
75
h.get_branch_nicks([ change ])
77
# let's make side-by-side diff be the default
78
side_by_side = not kw.get('unified', False)
80
h.add_side_by_side([ change ])
106
83
'branch': self._branch,
109
'file_changes': file_changes,
110
'diff_chunks': diff_chunks,
111
'link_data': simplejson.dumps(link_data),
112
'specific_path': path,
113
'json_specific_path': simplejson.dumps(path),
114
'path_to_id': simplejson.dumps(path_to_id),
115
86
'start_revid': start_revid,
116
'filter_file_id': filter_file_id,
119
90
'navigation': navigation,
121
92
'remember': remember,
122
93
'compare_revid': compare_revid,
123
'url': self._branch.context_url,
124
'directory_breadcrumbs': directory_breadcrumbs,
94
'side_by_side': side_by_side,
97
self.log.info('/revision: %r seconds' % (time.time() - z,))