Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
At its core, getting suggestions from a patch involves looking for contiguous blocks of
either removes, or removes-then-adds. The former would be a suggestion to remove
some content, and the latter would be a suggestion to replace it.
The old version of this algorithm used line numbers to look for contiguous blocks: if
a line's number was the last line + 1, it was considered contiguous. This is wildly
incorrect since removed and added lines' numbers increment independently.
This was working fine, which made all our tests pass:
But this example breaks:
Notice how 4 (on the add side) should be considered as contiguous with 5 (on the
remove side). Obviously, looking for line numbers based on previous line numbers
won't work.
The new algorithm groups lines of equal type (add, remove, context)1 and also
considers an add immediately following a remove as equal. This turns a diff like
the above into the kind of groupings we'd visualize when looking for suggestions,
Once grouped, any group that has removes is a suggestion. If it also has adds, that's used
otherwise it's a suggested removal.
Footnotes
This, sadly, meant basically re-implementing
parse-git-patch
ourselves. ↩