Fix and improve the line range indicators in text-only e-mails.

Review Request #8242 — Created June 13, 2016 and submitted — Latest diff uploaded

Information

Review Board
release-2.5.x
e16b541...

Reviewers

Some work was done for Review Board 2.5 to add line range indication to
text-only review e-mails, in order to give users who prefer plain text
e-mails some indication of where a comment was made. This work ended up
having some problems with the accuracy of the line ranges, the
usefulness of the ranges (it only showed the patched/modified ranges,
not those on the original file), the consistency (reply e-mails did not
show the same information), and reliability (it sometimes crashed).

This change completely redoes how these line ranges works, and does so
in a way where the line range calculations can be easily reused by other
parts of the codebase.

A new function, get_displayed_diff_line_ranges(), takes a list of
chunks and a virtual line range (indexes into a side-by-side diff table)
and returns a series of information about the human-readable displayed
ranges. The information covers the line numbers shown in the diff
viewer (limiting to compatible chunks where lines could occur), the
virtual line ranges that match those, and the beginning/ending chunks
for the range.

The template tag used for e-mail now uses this to more easily render
the line ranges. It's been updated to show both the original and patched
line ranges, where applicable. It also handles the case of a comment
that spans the entire file (something we document internally supporting,
but do not expose yet), which the old code would not be able to cope
with.

Last, but not least, the reply e-mails are now using the same template
tag to show a quoted response with the correct line information, instead
of the old behavior of showing a virtual line range.

Unit tests pass.

Verified the plain text e-mails for both reviews and replies against a
bunch of reviews I had on my dev server, testing various combinations of
chunks and ranges, and saw that the line numbers were matching up in all
cases.