Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions diff-coverage-report.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,10 @@ def commit():
assert new_count == 0
file_data.changes = changes

prior_preprends = 0
for l in lines:
if l.startswith('--- '):
prior_preprends = 0
commit()
changes = []
old_line = -1
Expand All @@ -236,6 +238,7 @@ def commit():
old_file = fix_path(old_file.rstrip(), prefix_map)

elif l.startswith('+++ '):
prior_preprends = 0
_, new_file = l.split(' ', 1)
new_file = fix_path(new_file.rstrip(), prefix_map)
if old_file != new_file:
Expand All @@ -251,6 +254,7 @@ def commit():
# ignore this file, it doesn't have coverage

elif l.startswith('@@ '):
prior_preprends = 0
_, old_range, new_range, _ = l.split(' ', 3)
assert old_range[0] == '-'
assert new_range[0] == '+'
Expand All @@ -268,28 +272,34 @@ def commit():
new_count = 1

elif l.startswith(' '):
prior_preprends = 0
old_line += 1
new_line += 1
old_count -= 1
new_count -= 1

elif l.startswith('-'):
prior_preprends += 1
changes.append(('prepend', new_line, old_line, l[1:]))
old_line += 1
old_count -= 1

elif l.startswith('+'):
if changes and changes[-1][0] == 'prepend':
change = changes[-1]
changes[-1] = ('modify', change[1], change[2], change[3])
if prior_preprends:
assert prior_preprends > 0
change = changes[-prior_preprends]
assert change[0] == 'prepend'
changes[-prior_preprends] = (
'modify', new_line, change[2], change[3],
)
prior_preprends -= 1
else:
changes.append(('remove', new_line, old_line))
new_line += 1
new_count -= 1

else:
# ignore
pass
prior_preprends = 0

commit()
return result
Expand Down