• 
      

    Fix interdiffs for small files or changes near the top of the file.

    Review Request #5454 — Created Feb. 11, 2014 and submitted — Latest diff uploaded

    Information

    Review Board
    master
    d3590bf...

    Reviewers

    Fix interdiffs for small files or changes near the top of the file.

    The interdiff filtering code made some assumptions about the number of
    lines of context around changes in a diff chunk. This was believed to be
    mostly valid for a typical diff, but that was a bad assumption.

    Any changes near the top of the file (specifically, within those 3
    assumed lines of context) would be filtered out. If the file was fewer
    than 3 lines, it would flat-out break, due to an assumption of a length
    indicator in the chunk header that was missing. Even fixing that, since
    the file's total number of lines fell within the 3 lines of assumed
    context, the whole file would appear unchanged.

    Instead of assuming things, we now do a little more processing on the
    diff. We go through each line and look for the chunk headers, as we did
    before (previously using finditer). When we find one, we begin looking
    at the following lines for any line change indicator, and we count how
    many lines are unchanged. We can then use that to more accurately
    determine the context of the chunk.

    Tested with an interdiff for a 1-line file, which previously resulted in an error.
    Instead, I saw the interdiff with the appropriate highlighting.

    Tested with an interdiff changing one of the first lines in the file. It too passed.

    Tested with other interdiffs, and didn't see any problems.

    Unit tests pass.