Repository navigation
feat(gix-ref): peel packed refs without object lookups where the header allows it - #3254
Sam Brightman (sambrightman) wants to merge 1 commit into
Conversation
…er allows it A `packed-refs` file written by `git pack-refs` starts with `# pack-refs with: peeled fully-peeled sorted`, promising that every annotated tag in it has its peeled object recorded on a `^` line below it. A ref without one is therefore not an annotated tag, and is its own peeled object. `git` relies on that (`packed-backend.c` marks such refs `REF_KNOWS_PEELED`), as it does for `refs/tags/` alone under the older `peeled` trait. `gix-ref` parsed the trait but didn't use it, so peeling any packed ref without a `^` line looked up and decoded its object only to learn it isn't a tag. Now the `Reference` made from a packed ref, when found or iterated, has its `peeled` set to its target where the header promises it, and `peel_to_id()` returns it without touching the object database. Motivated by `argus`, a multi-repository status tool built on `gix`, where peeling the 259 remote-tracking branches of an Emacs clone took about 2ms warm and up to 45ms with a cold disk cache, all of it reading commits whose ids were already the answer. Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 55bebb270c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".
| /// what `git` does as well: all references with `fully-peeled`, and those in `refs/tags/` with `peeled`. | ||
| pub(crate) fn set_known_peeled(&self, r: &mut crate::Reference) { | ||
| let knows_peeled = match self.peeled { | ||
| packed::decode::Peeled::Fully => true, |
There was a problem hiding this comment.
Preserve weaker peel guarantees during packed-ref rewrites
When a headerless packed file contains an annotated-tag record without a ^ line (or a peeled file contains one outside refs/tags/), a nonempty packed::Transaction::commit() writes the constant fully-peeled header even though write_packed_ref() copies unchanged records verbatim. After reload, this arm marks that retained record peeled to its tag-object ID, so peel_to_id() silently returns the tag ID instead of the ultimate target; preserve the input's weaker trait or actually peel carried records before enabling this shortcut.
AGENTS.md reference: AGENTS.md:L41-L41
Useful? React with 👍 / 👎.
| let header = packed::decode::header(&mut input).map_err(|()| { | ||
| corruption("The header could not be parsed, even though first line started with '#'").raise() | ||
| })?; | ||
| peeled = header.peeled; |
There was a problem hiding this comment.
Make fully-peeled dominate regardless of trait order
When a header lists capabilities as fully-peeled peeled (a valid order which Git still treats as fully peeled), header() overwrites Fully with Partial on the trailing token. Persisting that value here makes refs outside refs/tags/ perform an object lookup—and fail when objects are unavailable—even though the header vouches for their peeled state. Make Fully dominate Partial independent of token order.
AGENTS.md reference: AGENTS.md:L41-L41
Useful? React with 👍 / 👎.
Opened by Claude, an AI agent (Claude Opus 5.5), through the account holder's GitHub account at their request. This description is Claude's own.
A
packed-refsfile written bygit pack-refsstarts with# pack-refs with: peeled fully-peeled sorted: every annotated tag in it has its peeled object recorded on a^line, so a ref without one isn't an annotated tag and is its own peeled object. Git relies on this (packed-backend.cmarks such refsREF_KNOWS_PEELED), and on the olderpeeledtrait forrefs/tags/alone.gix-refparses the trait but doesn't use it, so peeling a packed ref with no^line looks up and decodes its object only to learn it isn't a tag. With this change, aReferencemade from a packed ref, whether found or iterated, haspeeledset to its target where the header promises it, andpeel_to_id()returns that without touching the object database. The parsedpacked::Referenceis unchanged, so the packed-refs writer doesn't start emitting^lines for every ref.Motivation: argus, a multi-repository status tool built on
gix, peels every remote-tracking branch to count commits not on any remote. Claude measured an Emacs clone with 259 of them, with a cold disk cache (sudo purge, macOS, three alternating runs):Part of the difference moves to the next step that reads objects, which now pays the one-off cost of opening the pack; the rest is gone. Warm, peeling went from about 2ms to under 1ms.
Tests: a fixture where
git pack-refswrites the file (asserting its header saysfully-peeled), plus copies with the olderpeeledheader and with none; archives for both hash kinds are included. Peeling withgix_object::find::Neversucceeds exactly for the refs the header vouches for, both when found and when iterated. Annotated tags still peel by their^line under every header.gix-ref's tests pass withsha1,sha256, andGIX_TEST_FIXTURE_HASH=sha256.