17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
import json as simplejson
26
22
from paste.httpexceptions import HTTPServerError
23
from paste.request import path_info_pop
28
25
from loggerhead import util
29
from loggerhead.controllers import TemplatedBranchView
30
from loggerhead.controllers.filediff_ui import diff_chunks_for_file
26
from loggerhead.templatefunctions import templatefunctions
27
from turbosimpletal import TurboZpt
30
tt = t.load_template('loggerhead.templates.revision')
33
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))
36
class RevisionUI (object):
38
def __init__(self, branch):
43
def default(self, request, response):
45
h = self._branch.history
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)
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
if '.' in change.revno:
99
# Walk "up" though the merge-sorted graph until we find a
100
# revision with merge depth 0: this is the revision that merged
101
# this one to mainline.
102
ri = self._history._rev_info
103
i = self._history._rev_indices[change.revid]
104
while ri[i][0][2] > 0:
106
merged_in = ri[i][0][3]
110
# Directory Breadcrumbs
111
directory_breadcrumbs = (
112
util.directory_breadcrumbs(
113
self._branch.friendly_name,
114
self._branch.is_root,
118
'branch': self._branch,
121
'file_changes': file_changes,
122
'diff_chunks': diff_chunks,
123
'link_data': simplejson.dumps(link_data),
124
'specific_path': path,
125
'json_specific_path': simplejson.dumps(path),
126
'path_to_id': simplejson.dumps(path_to_id),
127
'start_revid': start_revid,
128
'filter_file_id': filter_file_id,
131
'merged_in': merged_in,
132
'navigation': navigation,
134
'remember': remember,
135
'compare_revid': compare_revid,
136
'url': self._branch.context_url,
137
'directory_breadcrumbs': directory_breadcrumbs,
53
arg = path_info_pop(request.environ)
59
revid = h.fix_revid(args[0])
63
filter_file_id = kw.get('filter_file_id', None)
64
start_revid = h.fix_revid(kw.get('start_revid', None))
65
query = kw.get('q', None)
66
remember = kw.get('remember', None)
67
compare_revid = kw.get('compare_revid', None)
70
revid, start_revid, revid_list = h.get_view(revid, start_revid, filter_file_id, query)
72
self.log.exception('Exception fetching changes')
73
raise HTTPServerError('Could not fetch changes')
75
navigation = util.Container(
76
revid_list=revid_list, revid=revid, start_revid=start_revid,
77
filter_file_id=filter_file_id, pagesize=1,
78
scan_url='/revision', branch=self._branch, feed=True)
80
navigation.query = query
81
util.fill_in_navigation(navigation)
83
change = h.get_change_with_diff(revid, compare_revid)
84
# add parent & merge-point branch-nick info, in case it's useful
85
h.get_branch_nicks([ change ])
87
line_count_limit = DEFAULT_LINE_COUNT_LIMIT
89
for file in change.changes.modified:
90
for chunk in file.chunks:
91
line_count += len(chunk.diff)
93
# let's make side-by-side diff be the default
94
side_by_side = not kw.get('unified', False)
96
h.add_side_by_side([ change ])
99
'branch': self._branch,
102
'start_revid': start_revid,
103
'filter_file_id': filter_file_id,
106
'navigation': navigation,
108
'remember': remember,
109
'compare_revid': compare_revid,
110
'side_by_side': side_by_side,
111
'url': self._branch.context_url,
112
'line_count': line_count,
113
'line_count_limit': line_count_limit,
114
'show_plain_diffs': line_count > line_count_limit,
116
vals.update(templatefunctions)
117
self.log.info('/revision: %r seconds' % (time.time() - z,))
118
response.headers['Content-Type'] = 'text/html'
119
tt.expand_(response, **vals)