37
31
template_path = 'loggerhead.templates.revision'
39
def _process_diff(self, diff):
40
# doesn't really need to be a method; could be static.
43
for line in diff.splitlines():
46
if line.startswith('+++ ') or line.startswith('--- '):
48
if line.startswith('@@ '):
52
chunk = util.Container()
54
split_lines = line.split(' ')[1:3]
55
lines = [int(x.split(',')[0][1:]) for x in split_lines]
58
elif line.startswith(' '):
59
chunk.diff.append(util.Container(old_lineno=old_lineno,
60
new_lineno=new_lineno,
65
elif line.startswith('+'):
66
chunk.diff.append(util.Container(old_lineno=None,
67
new_lineno=new_lineno,
68
type='insert', line=line[1:]))
70
elif line.startswith('-'):
71
chunk.diff.append(util.Container(old_lineno=old_lineno,
73
type='delete', line=line[1:]))
76
chunk.diff.append(util.Container(old_lineno=None,
84
def _parse_diffs(self, old_tree, new_tree, delta, specific_path):
86
Return a list of processed diffs, in the format::
95
type: str('context', 'delete', or 'insert'),
104
def include_specific_path(path):
105
return specific_path == path
106
def include_all_paths(path):
109
include_path = include_specific_path
33
def get_values(self, h, args, kw, response):
36
revid = h.fix_revid(args[0])
111
include_path = include_all_paths
113
for old_path, new_path, fid, \
114
kind, text_modified, meta_modified in delta.renamed:
115
if text_modified and include_path(new_path):
116
process.append((old_path, new_path, fid, kind))
117
for path, fid, kind, text_modified, meta_modified in delta.modified:
118
if include_path(path):
119
process.append((path, path, fid, kind))
120
for path, fid, kind in delta.added:
121
if file == 'kind' and include_path(path):
122
process.append((path, path, fid, kind))
123
for path, fid, kind in delta.removed:
124
if file == 'kind' and include_path(path):
125
process.append((path, path, fid, kind))
127
process.sort(key=lambda x:x[1])
129
for old_path, new_path, fid, kind in process:
131
old_lines = old_tree.get_file_lines(fid)
132
except errors.NoSuchId:
135
new_lines = new_tree.get_file_lines(fid)
136
except errors.NoSuchId:
139
if old_lines != new_lines:
141
bzrlib.diff.internal_diff(old_path, old_lines,
142
new_path, new_lines, buffer)
143
except bzrlib.errors.BinaryFile:
146
diff = buffer.getvalue()
149
out.append(util.Container(
150
filename=rich_filename(new_path, kind), file_id=fid,
151
chunks=self._process_diff(diff)))
155
def get_changes_with_diff(self, change, compare_revid, specific_path):
157
if compare_revid is None:
159
compare_revid = change.parents[0].revid
161
compare_revid = 'null:'
163
rev_tree1 = h._branch.repository.revision_tree(compare_revid)
164
rev_tree2 = h._branch.repository.revision_tree(change.revid)
165
delta = rev_tree2.changes_from(rev_tree1)
167
changes = h.parse_delta(delta)
169
return changes, self._parse_diffs(
170
rev_tree1, rev_tree2, delta, specific_path)
172
def get_values(self, path, kwargs, headers):
174
revid = self.get_revid()
176
filter_file_id = kwargs.get('filter_file_id', None)
177
start_revid = h.fix_revid(kwargs.get('start_revid', None))
178
query = kwargs.get('q', None)
179
remember = h.fix_revid(kwargs.get('remember', None))
180
compare_revid = h.fix_revid(kwargs.get('compare_revid', None))
40
filter_file_id = kw.get('filter_file_id', None)
41
start_revid = h.fix_revid(kw.get('start_revid', None))
42
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))
183
revid, start_revid, revid_list = h.get_view(revid,
47
revid, start_revid, revid_list = h.get_view(revid, start_revid, filter_file_id, query)
188
49
self.log.exception('Exception fetching changes')
189
50
raise HTTPServerError('Could not fetch changes')
191
52
navigation = util.Container(
192
53
revid_list=revid_list, revid=revid, start_revid=start_revid,
193
54
filter_file_id=filter_file_id, pagesize=1,
194
scan_url='/revision', branch=self._branch, feed=True, history=h)
55
scan_url='/revision', branch=self._branch, feed=True)
195
56
if query is not None:
196
57
navigation.query = query
197
58
util.fill_in_navigation(navigation)
199
change = h.get_changes([revid])[0]
200
if path in ('', '/'):
202
change.changes, diffs = self.get_changes_with_diff(change, compare_revid, path)
60
change = h.get_change_with_diff(revid, compare_revid)
203
61
# add parent & merge-point branch-nick info, in case it's useful
204
h.get_branch_nicks([change])
206
# Directory Breadcrumbs
207
directory_breadcrumbs = (
208
util.directory_breadcrumbs(
209
self._branch.friendly_name,
210
self._branch.is_root,
62
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 ])
214
76
'branch': self._branch,
218
'specific_path': path,
219
79
'start_revid': start_revid,
220
80
'filter_file_id': filter_file_id,