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

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

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.


Description From Last Updated

Could you attach screenshot(s) of the resulting e-mails?

daviddavid

Col: 80 E501 line too long (80 > 79 characters)

reviewbotreviewbot

Col: 80 E501 line too long (80 > 79 characters)

reviewbotreviewbot

Col: 80 E501 line too long (80 > 79 characters)

reviewbotreviewbot

"ranges"

brenniebrennie

Mind getting rid of the trailing whitespace? Or does that need to be there?

brenniebrennie
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/reviews/templatetags/tests.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/diffviewer/tests.py
        reviewboard/diffviewer/diffutils.py
    
    Ignored Files:
        reviewboard/templates/notifications/reply_email.txt
        reviewboard/templates/notifications/review_email.txt
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/reviews/templatetags/tests.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/diffviewer/tests.py
        reviewboard/diffviewer/diffutils.py
    
    Ignored Files:
        reviewboard/templates/notifications/reply_email.txt
        reviewboard/templates/notifications/review_email.txt
    
    
  2. reviewboard/diffviewer/diffutils.py (Diff revision 1)
     
     
    Show all issues
    Col: 80
     E501 line too long (80 > 79 characters)
    
  3. reviewboard/diffviewer/tests.py (Diff revision 1)
     
     
    Show all issues
    Col: 80
     E501 line too long (80 > 79 characters)
    
  4. reviewboard/diffviewer/tests.py (Diff revision 1)
     
     
    Show all issues
    Col: 80
     E501 line too long (80 > 79 characters)
    
  5. 
      
david
  1. 
      
  2. Show all issues

    Could you attach screenshot(s) of the resulting e-mails?

  3. 
      
chipx86
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/reviews/templatetags/tests.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/diffviewer/tests.py
        reviewboard/diffviewer/diffutils.py
    
    Ignored Files:
        reviewboard/templates/notifications/reply_email.txt
        reviewboard/templates/notifications/review_email.txt
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/reviews/templatetags/tests.py
        reviewboard/reviews/templatetags/reviewtags.py
        reviewboard/diffviewer/tests.py
        reviewboard/diffviewer/diffutils.py
    
    Ignored Files:
        reviewboard/templates/notifications/reply_email.txt
        reviewboard/templates/notifications/review_email.txt
    
    
  2. 
      
brennie
  1. 
      
  2. Show all issues

    "ranges"

  3. Show all issues

    Mind getting rid of the trailing whitespace? Or does that need to be there?

    1. They were added intentionally, once upon a time. I don't remember the details, whether we need them or not. I noticed this when self-reviewing, but decided not to risk changing it right now.

    2. If I remember correctly, some e-mail clients expected "quoted" text to be prefixed with "> " on each line, regardless of whether that line was empty or not.

    3. That sounds about right to me.

      Silly e-mail clients. I guess that's not the most ridiculous thing they do. (I'm looking at all of you, HTML renderers.)

  4. 
      
david
  1. Pending the docstring change that Barret pointed out, this looks good to me.

  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-2.5.x (cb96808)