Repository navigation
fix(gix-ref): read loose refs that vanish while iterating from a fresh packed-refs - #3249
Open
Oleg Stotsky (OlegStotsky) wants to merge 1 commit into
Open
Oleg Stotsky (OlegStotsky) wants to merge 1 commit into
Oleg Stotsky (OlegStotsky) wants to merge 1 commit into
Conversation
…h `packed-refs` `LooseThenPacked` lists a directory of loose refs and opens each file later. If `git pack-refs --prune` runs in between, which `git gc --auto` does after pushes, a listed file is gone by the time it is opened. The ref still exists in `packed-refs`, but the iterator returned `Could not read reference` for it. A ref deleted in between failed the same way. Iterators from `file::Store::iter()` now read `packed-refs` afresh when a listed loose file is missing. Git writes `packed-refs` before it removes loose files, so the fresh file has the ref unless it was deleted, and a deleted ref is skipped. Loose-only iteration still reports the missing file. This was found in a server-side pre-receive hook that lists `refs/heads/` with `gix` while other pushes and `git gc --auto` run on the same repository. An unrelated push was refused because one branch was packed mid-listing. Assisted-by: Claude Code (claude-opus-5-5)
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.
This PR was written by Claude Code, an AI agent, working through Oleg Stotsky (@OlegStotsky)'s account.
Motivation
A service runs
gixinside a server-side pre-receive hook, and the hook listsrefs/heads/of the repository being pushed to. Other pushes land on the same repository at the same time, and receive-pack startsgit gc --autoafter them. One night the hook refused an unrelated push with:The branch was never deleted.
pack-refs --prunehad moved it intopacked-refsbetween the iterator listingrefs/heads/and opening the file.The change
LooseThenPackedreads a directory's entries and opens each loose file later. When that file is missing, iterators fromfile::Store::iter()(all()andprefixed()) now openpacked-refsafresh and look the ref up there:pack-refs --prunewritespacked-refsbefore it unlinks loose files, so a ref that was packed is always found.Other read errors are still returned.
loose_iter(),loose_iter_prefixed()andpseudo()keep reporting a missing file, since they don't list packed refs. Each missing file costs one read ofpacked-refs, which only happens while refs are packed or deleted under the iterator.The new test
overlay_iter_survives_refs_packed_and_deleted_while_iteratingreads the first ref ofrefs/heads/, runsgit pack-refs --all --pruneand deletes another branch, then reads the rest. Without the fix it fails withCould not read reference, path=…/refs/heads/d1.Not covered: refs packed before their directory is read
Platformtakes itspacked-refssnapshot when it is created, and the loose directories are read later. Ifpack-refs --prunefinishes in between, a ref that existed the whole time is in neither the stale snapshot nor the directory, and the iterator silently leaves it out. Git avoids this by reading the loose refs under the prefix before it checkspacked-refs(the comment infiles_ref_iterator_begin()inrefs/files-backend.c). Doing the same here would mean taking the snapshot after the loose walk instead of inPlatform, which changes the API, so it is left out of this PR. A follow-up can do it if you want that change.Checks run
By the agent, locally:
cargo test -p gix-refwith the default andGIX_TEST_FIXTURE_HASH=sha256fixtures,cargo fmt --check, andcargo clippy -p gix-ref --all-targets, which adds no new warnings.just testwas not run.