RFR: Fix start of hunk range off-by-one error when parsing range string
JornVernee via github.com
duke at openjdk.java.net
Thu Aug 1 19:14:28 UTC 2019
I kept running into off-by-one errors in hunk headers when exporting a patch from a git repo, and then importing into a mercurial repo (for pushing, since git repos are currently read-only)
The problem seems to be that unified diffs report a line number 1 before the modified line if the line count is 0. For instance, if I just remove a few lines from a file, the hunk destination start line is one before the first deleted line. (similarly when only adding lines).
The problem is that when hunks are then coalesced together, the starting line, and computed line counts are off-by-one as well, and as a result, the generated patch fails to apply.
I noticed there was already some code dealing with this in HunkCoalescer, but this wasn't catching all the cases. I first made a version that patched the starting line in the missing cases, but it seemed cleaner to try and fix this at the source, i.e. when parsing the Range string from the unified diff. So, that is what I've done in this PR, as well as removing the previous patching code in HunkCoalescer, which was no longer needed.
If wanted I could also go the other route of patching the starting line in HunkCoalescer in the missing cases (there were 4 of these).
- 7a093687: Fixed some off-by-one errors caused by unified diff indicating the 'wrong' line when no lines were changes (in source or target)
git fetch https://github.com/openjdk/skara.git pull/34/head:pull/34
More information about the skara-dev