Repository navigation
fix(gitclone): include HEAD in local refs - #452
Conversation
An ensure-refs request for HEAD could never be satisfied, because GetLocalRefs used `git for-each-ref`, which only lists refs/... and so never reports HEAD. Every such request fell through to a full upstream fetch, and the response still had no SHA for HEAD. Clients that ask for HEAD on each clone paid for that fetch every time. List refs with `git show-ref --head` instead, so local refs include HEAD as the upstream ls-remote listing already does. Co-Authored-By: Claude Fable 5.2 <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: cac5c96816
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| output, err = cmd.CombinedOutput() | ||
| r.mu.RUnlock() | ||
|
|
||
| // show-ref exits 1 with no output when the repository has no refs. |
There was a problem hiding this comment.
Remove the new short-block explanatory comments
The new inline comment describes a three-line conditional, contrary to the root AGENTS.md requirement that non-documentation comments only accompany non-obvious blocks of at least 20 lines. The new comment above the five-line HEAD test has the same issue. Remove these two inline comments while retaining the required exported-method documentation.
AGENTS.md reference: AGENTS.md:L19-L22
Useful? React with 👍 / 👎.
`EnsureRefs` fetched from upstream whenever a request was unsatisfied, and it kept no record that a fetch had already failed to help. Any request the mirror could not satisfy even after fetching therefore cost a full upstream fetch on every call. #452 fixed one instance of this, `HEAD`. These cases remained: - A ref pinned to a SHA the mirror has moved past, because the check was exact equality. - An annotated tag pinned to its commit, because the mirror records the tag object's SHA. - A ref or commit that upstream does not have, such as a deleted branch, a misspelled name, or a commit removed by a force push. Separately, a ref requested with an empty SHA was satisfied as soon as it existed locally, so it never refreshed a stale mirror. That is not what callers asking for `HEAD` expect. The approach is to fetch only when upstream has something the mirror lacks: - A pinned ref is satisfied when its SHA is reachable from the ref. - An unsatisfied request compares the mirror's refs with `git ls-remote` and fetches only if they differ. This bypasses `RefCheckInterval`, so a commit pushed a moment ago is still found. - An entry upstream could not satisfy is remembered for `RefCheckInterval`, so a caller repeating a hopeless request makes no upstream call. - An empty SHA now also requires the ref to be current. For `HEAD` and branches this uses the existing cached check in `EnsureRefsUpToDate`, so frequent `HEAD` requests cost at most one `git ls-remote` per `RefCheckInterval`. That check compares only branches, so other refs, such as tags, are compared directly with upstream instead. Two behaviours change for callers. A request for a ref or commit that upstream lacks now returns `fetched=false`, with missing commits still listed. An empty-SHA request now fails if upstream cannot be reached, where before it succeeded from the mirror alone. The upstream comparison is shared with `EnsureRefsUpToDate` through a new `behindUpstream` method, which takes a filter for the refs to compare. Tests cover each case above, plus the memory of unsatisfiable entries. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
An
ensure-refsrequest forHEADcould never be satisfied.GetLocalRefsusedgit for-each-ref, which only listsrefs/...and never reportsHEAD. Every such request fell through to a full upstream fetch, and the response still had no SHA forHEAD. Clients that ask forHEADon each clone paid for that fetch every time. For large repositories that was several seconds per clone, plus an unnecessary fetch against upstream.GetLocalRefsnow lists refs withgit show-ref --head, so local refs includeHEAD, as the upstreamls-remotelisting already does.show-refexits 1 with no output when a repository has no refs, so that case returns an empty map. AHEADrequest with an empty SHA now follows the documented contract: the ref exists, at any SHA, so no fetch is needed.TestRepository_EnsureRefsnow asserts that aHEADrequest on an up-to-date mirror returnsfetched=falsewith the resolved SHA.Other requests that the mirror cannot satisfy even after fetching, such as a missing ref or commit, still fetch upstream on every call. That will be a separate fix.
🤖 Generated with Claude Code