Repository navigation
Bound git diff output while streaming - #146
Open
karansaini46 wants to merge 1 commit into
Open
karansaini46 wants to merge 1 commit into
karansaini46 wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Problem
Proofline rejects patches over 5 MiB (
MAX_PATCH_BYTES) and 3,000 files (MAX_PATCH_FILES), butdiff()insrc/git.rswas still callinggit_in(), which usestokio::process::Command::output().await. BecauseCommand::output()buffers all ofgit's stdout and stderr until EOF before returning, an oversized diff (such as generated fixtures, large assets, or huge refactors) gets read into memory in full before any size or file-count check runs.On a ~254 MiB (
25 × 10 MiB) multi-file staged diff locally, collecting fullgit diffstdout pushedVmHWMto ~525 MiB before failing. Even for patches within the 5 MiB limit,diff()also clonedpatch.to_vec()while validating UTF-8.What changed
git_in()alone: All metadata and index callers (resolve,named_files,line_in,git add,check_one_path) keep their existing behaviour.diff()incrementally: Added a dedicateddiff_output/diff_command_outputpath insrc/git.rsthat spawnsgitwith piped stdio and.kill_on_drop(true), drainingstdoutandstderrconcurrently withtokio::try_join!so neither pipe buffer can stall the child. (stderrretains up to 64 KiB for error messages and drains the rest to EOF.)read_diff_stdoutwalks the--raw -zheader records using the same status rules asdiff_paths()(one path forA/D/M/T, two paths forR/C). It aborts immediately past 3,000 entries and caps the metadata prefix at 32 MiB (enough for 3,000 renamed entries at POSIXPATH_MAX). Once the empty header separator ends metadata, the remaining bytes move into a separatepatchbuffer so--rawmetadata overhead never pushes a valid<= 5 MiBpatch over the limit, andString::from_utf8(patch)takes ownership withoutpatch.to_vec().gitprocesses: When a limit trips mid-stream,tokio::try_join!cancels stderr draining and drops the pipe ends, thenterminate_and_reapcallschild.start_kill()andchild.wait().awaitbefore returning the limit error.GitErrorsignatures intact:GitError::TooLarge(usize)andGitError::TooManyFiles(usize)keep their types, with display wording updated to"larger than {0} MiB"(5) and"more than {0} files"(3000) since early termination intentionally does not read the full unstreamed size.Testing & verification
Added unit tests in
src/git.rs(below, exact5 MiB,5 MiB + 1 B, and12 MiBpatches;3,000vs3,001changed files; 2,500 long-path files alongside a~3.75 MiBpatch; renames/copy-configs/submodules; chunked parser boundaries, corrupt metadata, stderr floods, and non-zero Git errors; plus a Unix test checking child kill and zombie reaping) and an end-to-end integration test intests/local_patch.rsverifying6 MiBlocal diffs exit locally with zero HTTP requests.Ran on Linux (
x86_64, Rust1.100.0):cargo test --locked --lib git::tests— 9 passedcargo test --locked --test local_patch— 16 passedcargo fmt --check,cargo clippy --locked --all-targets -- -D warnings,cargo deny check— all passed cleanlycargo test --locked— 174 passed, 0 failed, 1 upstream#[ignore](tests/hooks.rs, requirespre-commit >= 3.2.0onPATH)VmHWMon the~254 MiBmulti-file staged diff dropped from ~525.6 MiB (unbounded buffer) to ~20.2 MiB (21,920 KiBvia/usr/bin/time -v,0.08s)One note on open PR #132 (credential preflight on refused diffs): this change leaves
preflight::checkon accepted diffs unchanged and keeps(raw, patch)separate within5 MiB; if #132 lands alongside this, any preflight scan of refused oversized patches would be bounded to that captured prefix unless streamed. Runtime andpsreaping checks were executed on Linux; macOS and Windows (TerminateProcess) rely on Tokio's cross-platform child APIs and were not executed locally.