Skip to content

feat(gitter): add POST /commit-pack endpoint for shallow commit archives - #6431

Draft
another-rex wants to merge 3 commits into
google:masterfrom
another-rex:gitter-commit-pack
Draft

another-rex wants to merge 3 commits into
google:masterfrom
another-rex:gitter-commit-pack

Conversation

@another-rex

@another-rex another-rex commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Overview

(AI-assisted PR)

Split out from #6403 for easier review.

Adds a POST /commit-pack endpoint to gitter (and corresponding GetCommitPack method on go/internal/gitter.Client) that builds and returns a minimal, standalone shallow bare Git repository archive (.tar.zst) containing only the requested commit(s), their immediate parent(s), and the trees/blobs touched by each commit diff.

This enables downstream consumers (such as the upcoming Vanir sandbox in #6403) to extract commit diffs completely offline from gitter's cached repositories without transferring entire repository histories.

Details

  • Proto & Client (go/internal/gitter/):
    • Added CommitPackRequest (url, commits, ref_id) to repository.proto and regenerated repository.pb.go.
    • Added GetCommitPack, ErrPackTooLarge (413 Request Entity Too Large), and shared MaxCommitPackBytes (44 MiB) to go/internal/gitter.
    • Enforced 200 OK, non-empty body, Content-Length fail-fast, and io.LimitReader bounds in GetCommitPack; deduplicated error-detail wrapping in httpClient.do.
  • Server (go/cmd/gitter/):
    • Added POST /commit-pack (commitPackHandler) validating url via prepareURL, capping requests at 1..64 validated hex commit hashes, deduplicating hashes, bypassing 204 No Content entries cached by /tags, and setting Content-Length on responses.
    • Added an RLock freshness fast path in refreshRepo so concurrent /commit-pack readers on recently synced repos don't serialize behind repoLock.Lock().
    • Added resolveValidCommits (git cat-file --batch-check) to verify requested hashes are exact commit OIDs (rejecting missing commits, prefix abbreviations, and non-commit objects like annotated tags/blobs/trees).
    • Implemented CreateCommitPack + materializeDiffBlobs:
      • Holds repoLock.RLock() only during local reads without mutating the cached repo's .git/config by configuring remote.origin.uploadpack on the temporary bare clone (supporting --object-format=sha256 for 64-char hashes).
      • Fetches --filter=blob:none --depth=2 --no-tags, collects all touched blob OIDs across normal, root, and merge commits in one batched git diff-tree --stdin -r --raw --no-renames --no-commit-id -m --first-parent --root pass, and transfers them in a single git pack-objects | git index-pack --stdin --fix-thin stream.
      • Detaches remote.origin, enables uploadpack.allowFilter / uploadpack.allowAnySHA1InWant, drops hooks/ and FETCH_HEAD, and compresses with tar --zstd (matching ArchiveRepo, capped at MaxCommitPackBytes).
      • Retries with ForceUpdate: true (subject to a 1-minute cooldown) and partial-pack support when a requested commit is missing in the cached repo.
    • Moved GIT_TERMINAL_PROMPT=0 into prepareCmd for all git invocations and removed the redundant env parameter from prepareCmd/runCmd.

Testing

  • Added isolated subtests in go/cmd/gitter/commit_pack_test.go covering validation (400/413), missing commits & annotated tags (404), invalidRepoCache (204 bypass vs 404), cooldown suppression vs ForceUpdate refresh + partial pack extraction, standalone normal + merge + root + multi-commit packs after deleting source & cache repos (verifying unrelated 2 MiB blob exclusion and absence of hooks/FETCH_HEAD/remote.origin), and oversized archive 413.
  • Added TestGetCommitPack in go/internal/gitter/http_test.go covering 200, 400, 403, 404, 413 with body detail, 500, 204, empty 200, and oversized chunked 200 responses.
  • Verified locally:
    • cd go && go test -v -race -count=1 ./internal/gitter/... — PASS
    • cd go && go test -v -race -count=1 ./cmd/gitter -run TestCommitPackHandler — PASS (including isolated -run TestCommitPackHandler/cooldown)
    • cd go && go build ./... — PASS
    • ./tools/lint_and_format.sh — PASS (0 issues)

agy

@codecov-commenter

codecov-commenter commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.08469% with 55 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.89%. Comparing base (7a762d6) to head (73950c4).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
go/cmd/gitter/git.go 80.44% 35 Missing ⚠️
go/cmd/gitter/gitter.go 79.77% 18 Missing ⚠️
go/internal/gitter/http.go 91.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6431      +/-   ##
==========================================
+ Coverage   55.57%   55.89%   +0.32%     
==========================================
  Files         222      222              
  Lines       22919    23195     +276     
==========================================
+ Hits        12737    12965     +228     
- Misses      10179    10227      +48     
  Partials        3        3              
Flag Coverage Δ
go 59.60% <82.08%> (+0.40%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@another-rex
another-rex marked this pull request as ready for review November 24, 2026 02:18
@another-rex
another-rex requested a review from Ly-Joey November 24, 2026 02:18
@another-rex
another-rex marked this pull request as draft November 24, 2026 02:55
Comment thread go/cmd/gitter/git.go Fixed

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.

3 participants