fix(refs): attach refdb owner to loose pseudorefs - #7227
Merged
Conversation
b17ecb2 changed pseudoref lookup to read loose refs directly, bypassing refdb lookup. This documents the resulting buggy behavior: a looked-up `FETCH_HEAD` pseudoref has no owning refdb attached.
Pseudoref lookup now reads `FETCH_HEAD` directly as a loose ref, but callers still expect looked-up references to know their owning repository. Attach the repo's refdb after the loose pseudoref is read so owner-dependent ops such as peeling can safely resolve objects.
The loose ref lookup helper was exposed by 7f35dc5 and then used by b17ecb2 directly for pseudoref lookup. While investigating the pseudoref owner regression, I found that the helper also returns success with a NULL output reference when `git_reference__alloc()` or `git_reference__alloc_symbolic()` failed. This fixes it by reporting allocation failures inside `git_reference__lookup_loose`.
weihanglo
added a commit
to weihanglo/git2-rs
that referenced
this pull request
Apr 22, 2026
weihanglo
added a commit
to weihanglo/git2-rs
that referenced
this pull request
Apr 22, 2026
Member
|
Good catch - thanks! |
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.
What is the bug
b17ecb2 changed pseudoref lookup to read loose refs directly, bypassing refdb lookup. It introduced a bug that a looked-up
FETCH_HEADpseudoref has no owning refdb attached.The test in c0a5341 shows that caller may still expect
ref->dbto have an associated db, hencegit_reference_peelfailed and gave us a segmentation fault.This was found this during the integration of Cargo with SHA256 support. In Cargo test suite we have things like this that peels FETCH_HEAD to a commit
The fix
Attach the repo's refdb after the loose pseudoref is read so
owner-dependent ops such as peeling can safely resolve objects.
Also found a bug in
git_reference__lookup_loosethat it didn't check allocation error before.How to reviews
This PR is best reviewed commit by commit, and is bisect-friendly.