gitproto: use go-git's WithObjectSelector to stream materialized push

main

Commit

Soph4mo ago

Replaces the temp-file spool in PushObjects with the streaming approach unlocked by go-git PR #2142 (merged 2026-05-21):

  • Run packfile.DeltaSelector.ObjectsToPack synchronously up front, showing "selecting deltas, elapsed X" progress (no byte counter here — the selector is opaque, elapsed time is the only signal).
  • Construct a packfile.Encoder with WithObjectSelector pointing at a local precomputedSelector that returns the pre-selected []*ObjectToPack. Encoder.Encode then skips its own selection step and runs the write phase only.
  • Pipe encoder output through io.Pipe into sendReceivePack, which streams it to the receive-pack POST as chunked transfer encoding.

The mid-stream stall that originally caused "use of closed network connection" against Cloudflare's git frontend is gone because selection no longer happens between the request body opening and pack bytes flowing — it has already completed.

Removed:

  • SpooledBody, NewSpooledBody, (*SpooledBody).applyTo
  • postReceivePack helper (used to bypass sendReceivePack's body construction; no longer needed now that we hand sendReceivePack a streaming pipe again)
  • The SpooledBody type-assertion in PostRPCStreamBody

What we lose vs. the spool:

  • Content-Length on the request (chunked again)
  • req.GetBody-based retry
  • No more $TMPDIR requirement proportional to pack size

What we gain:

  • Pack bytes flow without ever landing on local disk
  • Materialized push is streaming end-to-end (within the constraint that the source object closure already has to be local)
  • Smaller surface in gitproto

Bumped go-git to a pseudo-version pinning the merge commit (v6.0.0-alpha.4.0.20260521151600-590487407c38). Will switch to a tagged release once one is cut.

TestPushObjectsBuffersBody → TestPushObjectsStreamsBody now asserts chunked encoding and Content-Length=-1 (unknown), the inverse of what we previously asserted.

Entire-Checkpoint: 680da8552908

Checkpoints

git-sync on  main [$!?] via 🐹 v1.26.2 on ☁️ (us-east-2) took 1m26s

Claude Code
View session
Checkpoint 1