Skip to content

plumbing: transport, Align flush size with upstream git#2000

Merged
pjbgf merged 4 commits into
mainfrom
align-fetch
May 6, 2026
Merged

plumbing: transport, Align flush size with upstream git#2000
pjbgf merged 4 commits into
mainfrom
align-fetch

Conversation

@pjbgf
Copy link
Copy Markdown
Member

@pjbgf pjbgf commented Apr 15, 2026

Previously go-git flush size was hard-coded to 32, which could be rather inefficient for very
large negotiations. This change aligns the behaviour with upstream, growing exponentially that
number when it is safe to do so, as per next_flush().

The initial flush size is now 16 - which is also aligned with upstream.

Copilot AI review requested due to automatic review settings April 15, 2026 13:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Aligns go-git pack negotiation “flush” behavior with upstream git to reduce inefficiency on large negotiations, and updates tests to validate multi-round stateless RPC behavior.

Changes:

  • Introduces a nextFlush growth strategy and replaces the fixed flush size of 32 with an adaptive flushAt starting at 16.
  • Adds unit tests for nextFlush behavior in stateless vs stateful modes.
  • Replaces the prior HTTP negotiator regression test with a higher-level smart fetch test that asserts multiple stateless RPC POST rounds occur.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
plumbing/transport/negotiate.go Adds adaptive flush sizing (nextFlush) and uses it in the negotiation loop.
plumbing/transport/negotiate_test.go Adds unit coverage for nextFlush growth rules.
plumbing/transport/http/handshake_test.go Adds an integration-style regression test to confirm multi-round stateless RPC fetch behavior and records POST bodies via a reverse proxy.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plumbing/transport/negotiate.go
Comment thread plumbing/transport/http/handshake_test.go Outdated
@pjbgf pjbgf force-pushed the align-fetch branch 3 times, most recently from 52bbf4b to 950ddd7 Compare April 15, 2026 16:53
@pjbgf pjbgf requested a review from aymanbagabas April 15, 2026 16:59
aymanbagabas
aymanbagabas previously approved these changes Apr 16, 2026
Copy link
Copy Markdown
Member

@aymanbagabas aymanbagabas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

base, backend := setupSmartServer(t)
remoteFS := prepareRepo(t, fixture, base, "packfile.git")
remotePath := remoteFS.Root()
remoteStorage := filesystem.NewStorage(osfs.New(remotePath), cache.NewObjectLRUDefault())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
remoteStorage := filesystem.NewStorage(osfs.New(remotePath), cache.NewObjectLRUDefault())
remoteStorage := filesystem.NewStorage(osfs.New(remotePath), cache.NewObjectLRUDefault())
defer func() { _ = remoteStorage.Close() }()

seedRef := plumbing.ReferenceName("refs/heads/seed-old")
require.NoError(t, remoteStorage.SetReference(plumbing.NewHashReference(seedRef, oldCommit)))
seedPath := filepath.Join(t.TempDir(), "seed.git")
seedStorage := initBareStorage(t, seedPath)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
seedStorage := initBareStorage(t, seedPath)
seedStorage := initBareStorage(t, seedPath)
defer func() { _ = seedStorage.Close() }()

neg := &httpNegotiator{session: session, ctx: context.Background()}
defer neg.closeResponse()
clientPath := filepath.Join(t.TempDir(), "client.git")
clientStorage := initBareStorage(t, clientPath)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
clientStorage := initBareStorage(t, clientPath)
clientStorage := initBareStorage(t, clientPath)
defer func() { _ = clientStorage.Close() }()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that @AriehSchneier, added the three instances to the final change. 🙇

pjbgf added 4 commits May 6, 2026 14:49
Previously go-git flush size was hard-coded to 32, which could be rather inefficient for very
large negotiations. This change aligns the behaviour with upstream, growing exponentially that
number when it is safe to do so, as per next_flush() (fetch-pack.c:277-291).

The initial flush size is now 16 - which is also aligned with upstream.

ref: https://github.com/git/git/blob/9f223ef1c026d91c7ac68cc0211bde255dda6199/fetch-pack.c
Signed-off-by: Paulo Gomes <[email protected]>
… git

Add applyServerACKs to properly handle multi-ack-detailed responses:
- Reset in_vain on ACK_continue and ACK_ready (fetch-pack.c:550-552)
- Re-queue ACK_common haves for stateless RPC rounds (fetch-pack.c:533-542)
- Suppress duplicate ACK_common to avoid re-queuing already-known objects
- Track ACK_ready and stop negotiation early (fetch-pack.c:555-556, 569-570)
- Send a terminal done round after ACK_ready (fetch-pack.c:577-579)
- Clamp batch size to remaining in-vein budget after got_continue

Assisted-by: Claude Opus 4.6 <[email protected]>
Signed-off-by: Paulo Gomes <[email protected]>
@pjbgf pjbgf merged commit ecd8a38 into main May 6, 2026
28 of 34 checks passed
@pjbgf pjbgf deleted the align-fetch branch May 6, 2026 14:32
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.

4 participants