Repository navigation
fix(gix-protocol): only request deepen-relative in V0/V1 when relative deepening is asked for. - #3250
Open
sagi-qryptonite wants to merge 1 commit into
Open
sagi-qryptonite wants to merge 1 commit into
sagi-qryptonite wants to merge 1 commit into
Conversation
…ive deepening is asked for. Before protocol V2, `deepen-relative` is a capability that `git fetch-pack` adds to the first `want` only for `git fetch --deepen`. It is not an argument line (see `fetch-pack.c` and `receive_needs()` in `upload-pack.c`). `Arguments` got both of these wrong: - `Arguments::new()` put every advertised V0/V1 capability on the first `want`, so `deepen-relative` was requested whenever the server advertised it, which stock `git upload-pack` does. That made every `deepen` relative to the client's current shallow boundary. A shallow clone has no boundary yet, so the server sent no `shallow` lines and the whole history, which silently turned a `Shallow::DepthAtRemote(1)` clone into a full clone. - `Arguments::deepen_relative()` pushed `deepen-relative` as its own line, which `git upload-pack` rejects with "expected to get object ID", so `Shallow::Deepen` failed over V0/V1. Now `deepen-relative` isn't baked into the first `want` anymore, and `deepen_relative()` adds it as a capability in V0/V1 and as an argument in V2. `from_non_shallow_then_deepen_then_deepen_since_to_unshallow` now also runs with protocol V1 against `git upload-pack` and expects the same shallow boundaries as with V2.
Contributor
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Motivation
Found while reviewing #3248, which fixes shallow clones from Azure DevOps for a repository scanner built on
gix. That scanner fetches withShallow::DepthAtRemote(1). Against any V0/V1 server running stockgit upload-pack, those depth-1 clones turned into silent full clones.Root cause
Before protocol V2,
deepen-relativeis a capability.git fetch-packadds it to the firstwantonly forgit fetch --deepen(fetch-pack.c). Thedeepen-relativeargument line exists only in V2 (fetch-pack.c).Argumentsgot both of these wrong:Arguments::new()put every advertised V0/V1 capability on the firstwant, includingdeepen-relative. Stockgit upload-packadvertises it, so everydeepen Nbecame relative to the client's current shallow boundary. A fresh clone has no boundary yet, so the server sends noshallowlines and the full history, and the clone silently isn't shallow. On a repository that is already shallow,DepthAtRemote(n)instead deepens bynbeyond the existing boundary.Arguments::deepen_relative()pusheddeepen-relativeas a line. In V0/V1,receive_needs()dies on it with "expected to get object ID, not 'deepen-relative'" (upload-pack.c), soShallow::Deepenfails.V2 is not affected, and the e2e shallow tests (in
gix/tests/gix/remote/fetch.rs) run their shallow cases with V2 only, which is why this went unnoticed.Evidence
DepthAtRemote(1)clone ofhttps://github.com/octocat/Hello-World(3 commits) withprotocol.version=1:mainwant 7fd1a60… thin-pack side-band-64k ofs-delta shallow deepen-since deepen-not deepen-relative …want 7fd1a60… thin-pack side-band-64k ofs-delta shallow deepen-since deepen-not …The same happens against a local
git upload-pack(git 2.50.1). The server answersFLUSH,NAKwithout anyshallowline and sends the full pack.Change
Arguments::new()no longer putsdeepen-relativeon the firstwant, the same way it already treatsinclude-tag.Arguments::deepen_relative()adds it as a capability in V0/V1 (viaadd_feature()) and as an argument in V2. In V0/V1 it must therefore be called before the firstwant(), likeuse_include_tag().fetch()already does that.Tests
clone::blocking_io::from_non_shallow_then_deepen_then_deepen_since_to_unshallownow runs with protocol V1 and V2 againstgit upload-packand expects the same shallow boundaries for both. Most of its diff is re-indentation for the loop, so it's easier to read with whitespace changes hidden. Onmain, the V1 run fails at its first assertion (is_shallow()). With only the first fix, it fails onShallow::DeepenwithBroken pipeasupload-packdies.fetch::arguments::v1::haves_and_wants_for_fetch_statelessnow advertisesdeepen-relativeand checks it isn't requested.haves_and_wants_for_fetch_statefulchecks thatdeepen_relative()becomes a capability of the firstwantand not a line.fetch::response::v1::arguments::allencoded the old request with the separatedeepen-relativeline. It now expects the capability instead.cargo test -p gix-protocolpasses withblocking-clientandasync-client.cargo check -p gix-protocol --no-default-features --features sha1passes.cargo fmt --checkpasses, andcargo clippyreports nothing new.cargo test -p gix --features blocking-network-client --test gix -- remote:: clonepasses exceptfetch_and_checkout_honors_shared_repository_permissions, which fails the same way onmainon macOS.Note
This is independent of #3248. Both change the expected request in
fetch::response::v1::arguments::alland the V1 stateless test infetch/arguments.rs, so whichever lands second needs a small rebase. I'll do that.