Skip to content

Eliminate double file read in diff mode#78

Merged
campoy merged 2 commits intomasterfrom
eliminate-double-file-read
Feb 13, 2026
Merged

Eliminate double file read in diff mode#78
campoy merged 2 commits intomasterfrom
eliminate-double-file-read

Conversation

@campoy
Copy link
Owner

@campoy campoy commented Feb 12, 2026

Summary

  • Use io.TeeReader to capture original file content during the first read, instead of re-opening and reading the file a second time via readFile
  • Remove the now-unused readFile function
  • This follows the same pattern already used for stdin diffing (line 97)
  • Fixes a latent bug: the old code re-read through the same openFile function, but in test scenarios the reader was already exhausted, producing incorrect diffs (diffing empty string vs output instead of original vs output)

Test plan

  • go build ./... passes
  • go vet ./... passes
  • go test -run 'TestEmbedStreams|TestEmbedFiles' ./... passes
  • Test expectation updated to reflect the now-correct diff output

🤖 Generated with Claude Code

Francesc Campoy and others added 2 commits February 11, 2026 17:47
Use io.TeeReader to capture the original file content during the first
read instead of opening and reading the file a second time. This follows
the same pattern already used for stdin diffing. Remove the now-unused
readFile function.

The previous code re-opened the file via openFile for the diff, but in
practice the reader was already exhausted, producing incorrect diffs.
TeeReader captures the actual content that was processed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@campoy campoy merged commit 870991f into master Feb 13, 2026
3 checks passed
@campoy campoy deleted the eliminate-double-file-read branch February 13, 2026 17:21
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