Repository navigation
Conversation
After a fetch the local references were set to the ids the remote had advertised, whatever the pack held. A remote that answered with an empty pack, or one without a tree, a blob or a parent commit, left `refs/remotes/origin/main` on history that is not in the repository, and the fetch returned no error. git checks what it received before it updates a reference. Served such packs by a test server, git 2.54.0 failed each time with "did not send all necessary objects" and created no reference: for a tip commit without its tree, a missing parent commit, and a missing blob of the tip or of an older commit. The objects it did receive stayed in its object store. `Remote.Fetch` now does the same once a pack has been stored. It looks for every commit, tree and blob that the wanted objects reach and that the local references did not reach before the fetch, down to the shallow commits, and returns the new `ErrIncompleteFetch` if one is not in storage. No reference is updated then, and the shallow commits are put back to what they were. Objects already written stay in storage, unreferenced, as with git. The check follows the transport, so it holds for every protocol version, and for clone and pull, which fetch through `Remote`. Only an absent object is an incomplete fetch. Another failure to read what was fetched is returned as it is; no reference is updated in that case either. An object that merely is in storage proves nothing, as a fetch that failed leaves its objects behind. Only history under a local reference counts as held. Which commits are new is settled on the commit graph, as in a merge-base walk: commits are marked from the wanted objects and from the local references, the newest first, until every commit left to look at is marked from both sides. The commit a reference points at is recognised by its hash when the walk arrives there, so a fetch that continues a branch reads no other reference. The commits of the remaining references are read only once the walk has gone a sixteenth as many commits deep as there are references: when a fetched branch starts below every reference, or when a fetch brings that many commits. Of a new commit's tree, the entries that a held parent has under the same name are not read; trees are read as stored, without building an `object.Tree` for each. Two kinds of fetch leave objects out on purpose. With a depth, the walk ends at the shallow commits and does not stop at the local references, as deepening brings history below a commit a branch is already at. In a repository with a promisor remote, or on a fetch with a filter, only the wanted objects themselves are looked for: what they reach may be fetched later. Callers that fetched from a remote which serves incomplete history now get an error where they got broken references. `BenchmarkCheckFetched` measures the check on a packed repository of 30321 objects on disk: 43 ms and 23 MB allocated for the whole history; 1.5 ms for 50 fetched commits with one local reference and 2.0 ms with 10001, loose or packed, the difference being the set of their hashes; 13.5 ms when the fetched branch starts 3900 commits below the local one with no reference at or below that commit. On this repository's own history the whole of it, 29671 objects, takes 0.2 s, where a clone over the file transport takes 8.3 s. `TestFetchRefusesIncompletePack` fetches over HTTP, with protocol v0 and v2, from a server that sends packs with each kind of object left out: plain, shallow and deepening fetches, a shallow client, merges, tags, a directory used again in a new place, a commit left in storage by an earlier fetch, and a promisor remote. `TestFetchReturnsReadErrorOfTheCompletenessCheck` fetches into a storage that fails to read a commit. Assisted-by: Claude Fable 5.2 Signed-off-by: Hidde Beydals <hidde@entire.io>
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.
After a fetch,
Remote.Fetchset the local refs to the IDs the remote advertised, whatever the pack held. A remote that answered with an empty or incomplete pack leftrefs/remotes/origin/mainpointing at objects that are not in the repository, and the fetch returned no error.Git checks what it received before it updates a ref. Served such packs by a test server, Git 2.54.0 fails with “did not send all necessary objects” and creates no ref, whether the tip’s tree, a parent commit, or a blob of the tip or of an older commit is missing. go-git now does the same. Once the pack is stored and before any ref is updated, the fetch looks for every commit, tree, and blob that the fetched tips reach and the local refs did not reach before. If one is missing it returns the new
ErrIncompleteFetchand updates no ref. This covers protocol v0, v1, and v2, and clone and pull, which fetch throughRemote. Callers that fetched from a remote serving incomplete history now get an error where they got broken refs.Only an absent object counts as an incomplete fetch; a storage error during the check is returned as it is. An object that is merely in storage proves nothing, because a failed fetch leaves its objects behind, so only history under a local ref is taken as complete. A fetch with a depth ends the walk at the shallow commits. With a filter or a promisor remote, only the fetched tips themselves must exist, since what they reach may be fetched later. Objects written by a refused fetch stay in storage without a ref, as with Git. Git partial clone
The cost follows what was fetched and not the size of the repository. The check finds where new history joins old on the commit graph alone, and of a new commit’s tree it reads only the entries that differ from the parents the repository already had. On a packed repository of 30,321 objects,
BenchmarkCheckFetchedmeasures 1.5 ms for 50 fetched commits with one local ref and 2.0 ms with 10,001 refs. A whole history takes 43 ms and allocates 23 MB.TestFetchRefusesIncompletePackfetches over HTTP with protocol v0 and v2 from a server that leaves out each kind of object. It covers plain, shallow, and deepening fetches, a shallow client, merges, tags, a directory reused in a new place, a commit left in storage by an earlier fetch, and a promisor remote.TestFetchReturnsReadErrorOfTheCompletenessCheckcovers a storage that fails a read.This complements #2657, which stops the client from concluding there is nothing to fetch on the server’s word.