[PATCH 0/4] cat-file: do not die on reflog entries out of range
- From
- Caspar Duregger <caspar.duregger@gmail.com>
- Date
- Nov 13, 2026, 14:28 UTC
- Message-ID
- <20261113142804.7465-1-caspar.duregger@gmail.com>
- In-Reply-To
- <20260212040708.GA1894049@coredump.intra.peff.net>
Hi,
I necropost with a patch as I stumbled on this the other day.
I have one "git cat-file --batch-check" process per worktree, but it dies on "ref@{N}" past the end of the reflog. I work around by using the old "git rev-parse" for these but it's sad.
Passing GET_OID_GENTLY from cat-file is the obvious fix, but on its own it would change answers, not only failures:
- "ref@{N}" for a reflog with N entries and "ref@{<old date>}"
resolve today, but fail with GET_OID_GENTLY (patch 2, which picks
up a review question from the series that added the flag [1]); - "ref@{999999}^{tree}" would resolve to the current value of the
ref instead of dying, because after the peel fails get_oid_basic()
reads "999999}^{tree}" as an approxidate. The same bug already
makes "git rev-parse --verify 'HEAD@{1}^{blob}'" print a commit
(patch 1);- an emptied reflog still dies inside read_ref_at() (patch 3).
Patch 4 then flips the flag in cat-file. As Peff noted, this does not make batch lookups die-free: "HEAD@{999999}~1" and "@{upstream}" on a detached HEAD still die. The former needs get_parent() and get_nth_ancestor() to pass flags down, which I left for a separate series.
[1] https://lore.kernel.org/git/xmqqa5745ttw.fsf@gitster.g/
Caspar Duregger (4): object-name: do not read a peel suffix as a reflog selector object-name: let GET_OID_GENTLY affect only failing lookups refs: let read_ref_at() fail gently on an empty reflog cat-file: report out-of-range reflog entries as missing
builtin/cat-file.c | 1 + object-name.c | 28 +++++++++++++++++++--------- refs.c | 2 ++ refs.h | 4 ++++ t/t1006-cat-file.sh | 35 +++++++++++++++++++++++++++++++++++ t/t1508-at-combinations.sh | 4 ++++ t/t3903-stash.sh | 17 +++++++++++++++++ 7 files changed, 82 insertions(+), 9 deletions(-)
-- 2.56.1.windows.1