17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
20
from paste.httpexceptions import HTTPServerError
25
22
from loggerhead import util
26
23
from loggerhead.controllers import TemplatedBranchView
27
from loggerhead.controllers.filediff_ui import diff_chunks_for_file
30
26
DEFAULT_LINE_COUNT_LIMIT = 3000
33
return urllib.quote(urllib.quote(p, safe=''))
36
29
class RevisionUI(TemplatedBranchView):
38
31
template_path = 'loggerhead.templates.revision'
40
def get_values(self, path, kwargs, headers):
42
revid = self.get_revid()
33
def get_values(self, h, revid, path, kwargs, headers):
44
35
filter_file_id = kwargs.get('filter_file_id', None)
45
36
start_revid = h.fix_revid(kwargs.get('start_revid', None))
64
55
navigation.query = query
65
56
util.fill_in_navigation(navigation)
67
change = h.get_changes([revid])[0]
69
if compare_revid is None:
70
file_changes = h.get_file_changes(change)
72
file_changes = h.file_changes_for_revision_ids(
73
compare_revid, change.revid)
81
item = [x for x in file_changes.text_changes if x.filename == path][0]
82
diff_chunks = diff_chunks_for_file(
83
self._history._branch.repository, item.file_id,
84
item.old_revision, item.new_revision)
87
for i, item in enumerate(file_changes.text_changes):
89
link_data['diff-' + str(i)] = '%s/%s/%s' % (
90
dq(item.new_revision), dq(item.old_revision), dq(item.file_id))
91
path_to_id[item.filename] = 'diff-' + str(i)
93
h.add_branch_nicks(change)
95
if '.' in change.revno:
96
# Walk "up" though the merge-sorted graph until we find a
97
# revision with merge depth 0: this is the revision that merged
98
# this one to mainline.
99
ri = self._history._rev_info
100
i = self._history._rev_indices[change.revid]
101
while ri[i][0][2] > 0:
103
merged_in = ri[i][0][3]
58
change = h.get_change_with_diff(revid, compare_revid)
59
# add parent & merge-point branch-nick info, in case it's useful
60
h.get_branch_nicks([change])
62
line_count_limit = DEFAULT_LINE_COUNT_LIMIT
64
for file in change.changes.modified:
65
for chunk in file.chunks:
66
line_count += len(chunk.diff)
68
# let's make side-by-side diff be the default
69
# FIXME: not currently in use. Should be
70
side_by_side = not kwargs.get('unified', False)
72
h.add_side_by_side([change])
107
74
# Directory Breadcrumbs
108
75
directory_breadcrumbs = (
110
77
self._branch.friendly_name,
111
78
self._branch.is_root,
113
can_export = self._branch.export_tarballs
115
82
'branch': self._branch,
118
'file_changes': file_changes,
119
'diff_chunks': diff_chunks,
120
'link_data': simplejson.dumps(link_data),
121
'specific_path': path,
122
'json_specific_path': simplejson.dumps(path),
123
'path_to_id': simplejson.dumps(path_to_id),
124
85
'start_revid': start_revid,
125
86
'filter_file_id': filter_file_id,
128
'merged_in': merged_in,
129
89
'navigation': navigation,
131
91
'remember': remember,
132
92
'compare_revid': compare_revid,
93
'side_by_side': side_by_side,
133
94
'url': self._branch.context_url,
95
'line_count': line_count,
96
'line_count_limit': line_count_limit,
97
'show_plain_diffs': line_count > line_count_limit,
134
98
'directory_breadcrumbs': directory_breadcrumbs,
135
'can_export': can_export,