Repository navigation
loopvec: compute -d diffs in process - #16
Merged
Merged
Conversation
printDiff wrote both sources to temporary files and ran the system diff command. That made -d depend on the host: Windows has no diff, the headers differed between GNU and BSD diff until #10 labeled them, and the error was ignored, so a missing or failing diff printed nothing while loopvec exited successfully. This change computes the unified diff with github.com/pmezard/go-difflib instead, with the same labels and three lines of context, and no temporary files or exec. Its SplitLines adds an empty line after a final newline, which would show up as context near the end of a file, so the lines are split here. go-difflib may align a hunk differently from GNU diff, placing an added line on the other side of an unchanged blank line or brace. The result is the same patch: over std, every file loopvec -d prints applies with patch -F0 and gives the same source as GNU diff's output. Since the output no longer depends on the machine, flag_diff.txt now checks it whole.
mauri870
enabled auto-merge (squash)
November 3, 2026 22:22
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.
printDiffwrote both sources to temporary files and ran the systemdiff. That made-ddepend on the host. Windows has nodiff. GNU and BSD diff printed different headers until #10 labeled them. And the error was ignored, so a missing or failingdiffprinted nothing while loopvec still exited 0.This change computes the unified diff in process with github.com/pmezard/go-difflib (BSD-3, about 1,300 importing packages, mostly through testify). The labels stay the same, with both sides named after the file path and three lines of context. The temporary files and the
execcall are gone. The library's ownSplitLinesadds an empty line after a final newline, which would show up as a context line past the end of the file, soprintDiffsplits the lines itself.go-difflib can align a hunk differently from GNU diff. For example, it may put an added line on the other side of an unchanged blank line or
}. The patches still apply the same way. I checked this by runningloopvec -d stdwith the old and new code: all 17 files that get a diff apply withpatch -F0and give exactly the same source as GNU diff's patches. Since the output no longer depends on the machine,flag_diff.txtnow checks it whole instead of line by line. Its patch also applies withpatch -F0.make cipasses.