Skip to content

fix: avoid buffering full diff for stats-only git_diff - #117

Open
Stephenxu000 wants to merge 1 commit into
rebel0789:mainfrom
Stephenxu000:fix/git-diff-stats-buffer
Open

Stephenxu000 wants to merge 1 commit into
rebel0789:mainfrom
Stephenxu000:fix/git-diff-stats-buffer

Conversation

@Stephenxu000

Copy link
Copy Markdown

Problem

git_diff(include_diff=false) is documented as a stats-only path, but it still materializes the full unified diff before discarding it. Large diffs can therefore exceed the Git child-process output buffer and return spawnSync git ENOBUFS even when raw diff output was explicitly disabled.

Fix

  • Use git diff --numstat for the stats-only path instead of generating the unified diff.
  • Preserve additions, deletions, changed state, path scoping, staged mode, and Git error diagnostics.
  • Keep the existing unified-diff path unchanged when include_diff=true.

Regression coverage

The smoke test creates an isolated Git repository with a diff larger than a 4 KB CODEXPRO_MAX_OUTPUT_BYTES limit. The test fails on the current upstream implementation with spawnSync git ENOBUFS and passes with this change while reporting the expected +600 / -600 stats and an empty raw diff.

Verification

  • npm run build
  • npm run smoke
  • git diff --check

Security impact: none expected. This remains a read-only Git operation and keeps the existing path guard and --no-ext-diff / --no-textconv restrictions.

This branch has not been deployed

No deployments
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