Skip to content

loopvec: compute -d diffs in process - #16

Merged
mauri870 merged 1 commit into
masterfrom
diff-in-process
Nov 3, 2026
Merged

mauri870 merged 1 commit into
masterfrom
diff-in-process

Conversation

@mauri870

@mauri870 mauri870 commented Nov 3, 2026

Copy link
Copy Markdown
Owner

printDiff wrote both sources to temporary files and ran the system diff. That made -d depend on the host. Windows has no diff. GNU and BSD diff printed different headers until #10 labeled them. And the error was ignored, so a missing or failing diff printed 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 exec call are gone. The library's own SplitLines adds an empty line after a final newline, which would show up as a context line past the end of the file, so printDiff splits 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 running loopvec -d std with the old and new code: all 17 files that get a diff apply with patch -F0 and give exactly the same source as GNU diff's patches. Since the output no longer depends on the machine, flag_diff.txt now checks it whole instead of line by line. Its patch also applies with patch -F0.

make ci passes.

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
mauri870 enabled auto-merge (squash) November 3, 2026 22:22
@mauri870
mauri870 merged commit 08b91dc into master Nov 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant