Greatly improve filediff matching logic for interdiffs.

Review Request #8387 — Created Sept. 7, 2016 and submitted

Information

Review Board
release-2.5.x
8bd70ff...

Reviewers

When generating an interdiff, we need to match up files from the lists
of filediffs on both sides of an interdiff range. We used to do this by
comparing the source filenames, which worked in the common cases.
However, this didn't account for diffs that did something more complex,
like modify a file in diff 1 and then delete + re-introduce in diff 2,
or copy and modify twice, or other such operations. These were a lot
more rare, but could happen, particularly with Subversion.

This new logic works a lot harder to find the appropriate filediffs to
match, handling both simple and pathological cases. It starts out by
attempting to match all filediffs that have the same source filenames,
destination filenames, and new/deleted flags.

After that finishes, any remaining filediffs and interdiffs are matched
based on the source filename. A single source file on diff 1 can match
up with several on diff 2, handling the case where a file is copied to a
couple different places and modified. Any filediffs on diff 1 that fail
to match filediffs on diff 2 are shown as reverted.

Finally, any remaining filediffs on diff 2 that don't match diff 1 are
shown as new changes in the interdiff.

There are some other fixes around this as well. Sorting now takes into
account the destination filename (which is what we display as the
primary filename for the diff), prioritizing the interdiff filename.
This fixes sorting during renames, and for changes introduced in a newer
diff revision. Note that this does impact sort order of diffs, which might
impact the flow of text written on any in-progress reviews that are on diffs
containing several moved files going into different locations (which is
pretty unlikely, and a fixable issue), but it's definitely more correct.

It also fixes the display of "File Reverted" for files. We weren't
computing this correctly when generating the master list of files for an
interdiff, affecting the file index.

Unit tests were added for all these conditions, including those in a
pathological diff affecting one of our customers.

All unit tests pass.

Tested with some standard interdiffs I test against, comparing against
the renders without this change. They matched up.

Tested against a couple pathological diffs that outright broke the diff
viewer before. They now render these nearly nonsensical diffs properly.

Description From Last Updated

list comprehension redefines 'interfilediff' from line 341

reviewbotreviewbot

Col: 51 E127 continuation line over-indented for visual indent

reviewbotreviewbot

local variable 'interfilediff6' is assigned to but never used

reviewbotreviewbot
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/webapi/resources/filediff.py
        reviewboard/diffviewer/views.py
        reviewboard/diffviewer/tests.py
        reviewboard/diffviewer/diffutils.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/webapi/resources/filediff.py
        reviewboard/diffviewer/views.py
        reviewboard/diffviewer/tests.py
        reviewboard/diffviewer/diffutils.py
    
    
  2. reviewboard/diffviewer/diffutils.py (Diff revision 1)
     
     
    Show all issues
     list comprehension redefines 'interfilediff' from line 341
    
  3. reviewboard/diffviewer/diffutils.py (Diff revision 1)
     
     
    Show all issues
    Col: 51
     E127 continuation line over-indented for visual indent
    
  4. reviewboard/diffviewer/tests.py (Diff revision 1)
     
     
    Show all issues
     local variable 'interfilediff6' is assigned to but never used
    
  5. 
      
chipx86
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/webapi/resources/filediff.py
        reviewboard/diffviewer/views.py
        reviewboard/diffviewer/tests.py
        reviewboard/diffviewer/diffutils.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/webapi/resources/filediff.py
        reviewboard/diffviewer/views.py
        reviewboard/diffviewer/tests.py
        reviewboard/diffviewer/diffutils.py
    
    
  2. 
      
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-2.5.x (0e32ad8)