31
36
template_path = 'loggerhead.templates.revision'
33
def get_values(self, h, args, kw, headers):
36
revid = h.fix_revid(args[0])
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))
38
def _process_diff(self, diff):
39
# doesn't really need to be a method; could be static.
42
for line in diff.splitlines():
45
if line.startswith('+++ ') or line.startswith('--- '):
47
if line.startswith('@@ '):
51
chunk = util.Container()
53
split_lines = line.split(' ')[1:3]
54
lines = [int(x.split(',')[0][1:]) for x in split_lines]
57
elif line.startswith(' '):
58
chunk.diff.append(util.Container(old_lineno=old_lineno,
59
new_lineno=new_lineno,
64
elif line.startswith('+'):
65
chunk.diff.append(util.Container(old_lineno=None,
66
new_lineno=new_lineno,
67
type='insert', line=line[1:]))
69
elif line.startswith('-'):
70
chunk.diff.append(util.Container(old_lineno=old_lineno,
72
type='delete', line=line[1:]))
75
chunk.diff.append(util.Container(old_lineno=None,
83
def _parse_diffs(self, old_tree, new_tree, delta):
85
Return a list of processed diffs, in the format::
94
type: str('context', 'delete', or 'insert'),
103
for old_path, new_path, fid, \
104
kind, text_modified, meta_modified in delta.renamed:
106
process.append((old_path, new_path, fid, kind))
107
for path, fid, kind, text_modified, meta_modified in delta.modified:
108
process.append((path, path, fid, kind))
110
for old_path, new_path, fid, kind in process:
111
old_lines = old_tree.get_file_lines(fid)
112
new_lines = new_tree.get_file_lines(fid)
114
if old_lines != new_lines:
116
bzrlib.diff.internal_diff(old_path, old_lines,
117
new_path, new_lines, buffer)
118
except bzrlib.errors.BinaryFile:
121
diff = buffer.getvalue()
124
out.append(util.Container(
125
filename=rich_filename(new_path, kind),
127
chunks=self._process_diff(diff),
132
def get_change_with_diff(self, revid, compare_revid):
134
change = h.get_changes([revid])[0]
136
if compare_revid is None:
138
compare_revid = change.parents[0].revid
140
compare_revid = 'null:'
142
rev_tree1 = h._branch.repository.revision_tree(compare_revid)
143
rev_tree2 = h._branch.repository.revision_tree(revid)
144
delta = rev_tree2.changes_from(rev_tree1)
146
change.changes = h.parse_delta(delta)
147
change.changes.modified = self._parse_diffs(rev_tree1,
153
def get_values(self, path, kwargs, headers):
155
revid = self.get_revid()
157
filter_file_id = kwargs.get('filter_file_id', None)
158
start_revid = h.fix_revid(kwargs.get('start_revid', None))
159
query = kwargs.get('q', None)
160
remember = h.fix_revid(kwargs.get('remember', None))
161
compare_revid = h.fix_revid(kwargs.get('compare_revid', None))
47
revid, start_revid, revid_list = h.get_view(revid, start_revid, filter_file_id, query)
164
revid, start_revid, revid_list = h.get_view(revid,
49
169
self.log.exception('Exception fetching changes')
50
170
raise HTTPServerError('Could not fetch changes')