Conversation
In a unified diff a range with a count of 0 names the line before it, so "@@ -2,0 +3 @@" inserts after line 2. Both parsers took the start as the first affected line and both writers wrote it that way, so a zero-context diff from GNU diff or git was applied one line early, and GNU patch applied ours one line late.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In a unified diff, a range with a count of 0 names the line before it:
diff -U0andgit diff -U0write an insertion after line 2 as@@ -2,0 +3 @@. java-diff-utils reads and writes that start as the first affected line instead. Its own round trip agrees with itself, but patches exchanged with other tools land one line off:a,b,c->a,b,X,c:diff -U0output parsed byUnifiedDiffUtils.parseUnifiedDiff+applyTo[a, X, b, c][a, b, X, c]UnifiedDiffReader.parseUnifiedDiff[a, X, b, c][a, b, X, c]generateUnifiedDiff(..., 0)header@@ -3,0 +3,1 @@@@ -2,0 +3,1 @@patcha,b,c,Xa,b,X,cThe parsers already treat
-0,0this way (if (old_ln == 0) old_ln = 1), and the writers already emit@@ -0,0 +1,n @@for a new file; this extends the same rule to-N,0for N > 0. Diffs with context of 1 or more only have an empty range when a file is empty, so they are unaffected otherwise.Compatibility: zero-context patches generated by earlier versions of this library with a
-N,0or+N,0range (N > 0) will now be read one line later.Tests are added next to
testNewFileCreationinGenerateUnifiedDiffTest, next totestWriteWithNewFileinUnifiedDiffWriterTest, and inUnifiedDiffReaderTest; they fail on master.mvn -B packagepasses on JDK 8 (154 tests); an earlier run also passed on JDK 11 and for the core module on JDK 17. I also checked the table above against GNUdiffandpatch.Written with AI assistance (Claude); I have reviewed the change.