Skip to content

loopvec: label -d diffs with the file's path - #10

Merged
mauri870 merged 2 commits into
mauri870:masterfrom
thesyncim:diff-labels
Nov 3, 2026
Merged

mauri870 merged 2 commits into
mauri870:masterfrom
thesyncim:diff-labels

Conversation

@thesyncim

@thesyncim thesyncim commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

flag_diff.txt fails on macOS. The -d headers carry diff's timestamp, and BSD diff prints it differently from GNU diff (no fractional seconds, no zone). It's the timestamp of a temp file anyway, so it doesn't tell the reader anything.

This passes -L path for both sides (GNU, BSD and busybox diff all have it), so the headers are just --- path / +++ path like gofmt -d, and the filename replacement goes away. The four diff scripts now expect the path alone.

It's one of three small fixes to get the suite passing on macOS, along with #8 and #9, which I needed while trying loopvec on goav1.

-d ran diff -u on two temporary files and replaced their names with the
file's path, so each header still carried diff's timestamp. GNU diff
prints it as "2026-10-31 18:49:17.123456789 +0000" and BSD diff, the one
macOS ships, as "2026-10-31 18:49:17", which made flag_diff.txt fail on
macOS, and the timestamp of a temporary file says nothing about the
source.

diff now labels both sides with the path (-L, which GNU and BSD diff both
support), as gofmt -d does, so the headers are the same everywhere.
@mauri870
mauri870 enabled auto-merge (squash) November 3, 2026 20:34
@mauri870
mauri870 merged commit d8e8226 into mauri870:master Nov 3, 2026
2 checks passed
mauri870 added a commit that referenced this pull request Nov 3, 2026
`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](https://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.
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.

2 participants