Skip to content

feat(gix-ref): peel packed refs without object lookups where the header allows it - #3254

Open
Sam Brightman (sambrightman) wants to merge 1 commit into
GitoxideLabs:mainfrom
sambrightman:peel-fully-peeled-packed-refs
Open

Sam Brightman (sambrightman) wants to merge 1 commit into
GitoxideLabs:mainfrom
sambrightman:peel-fully-peeled-packed-refs

Conversation

@sambrightman

Copy link
Copy Markdown

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-refs file written by git pack-refs starts 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.c marks such refs REF_KNOWS_PEELED), and on the older peeled trait for refs/tags/ alone.

gix-ref parses 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, a Reference made from a packed ref, whether found or iterated, has peeled set to its target where the header promises it, and peel_to_id() returns that without touching the object database. The parsed packed::Reference is 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):

peeling remote branches whole repo status
before 52, 53, 68 ms 122, 129, 170 ms
after 1, 1, 1 ms 91, 84, 111 ms

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-refs writes the file (asserting its header says fully-peeled), plus copies with the older peeled header and with none; archives for both hash kinds are included. Peeling with gix_object::find::Never succeeds 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 with sha1, sha256, and GIX_TEST_FIXTURE_HASH=sha256.

…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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T07:25:37.905683Z 55bebb2 PR opened
ℹ️ About Codex in GitHub

Your 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant