From: Caspar Duregger <caspar.duregger@gmail.com>
To: git@vger.kernel.org
Cc: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>,
Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
"brian m . carlson" <sandals@crustytoothpaste.net>,
Caspar Duregger <caspar.duregger@gmail.com>
Subject: [PATCH 2/4] object-name: let GET_OID_GENTLY affect only failing lookups
Date: Fri, 13 Nov 2026 15:28:02 +0100 [thread overview]
Message-ID: <20261113142804.7465-3-caspar.duregger@gmail.com> (raw)
In-Reply-To: <20260212040708.GA1894049@coredump.intra.peff.net>
393bbb21c9 (object-name: make get_oid quietly return an error,
2025-06-12) introduced GET_OID_GENTLY so that a caller can turn the
die() on an exhausted reflog into an error return. The check was
placed after the if/else cascade that decides whether the lookup
succeeded, though, so passing the flag also turns two successful
lookups into errors:
- "ref@{<date>}" older than the reflog;
- "ref@{N}" for a reflog with N entries.
This was questioned in review [1], but the code was merged as-is.
Make the check a branch of the cascade, just before the die(), so
that the flag changes only how a failing lookup fails. With the flag,
"ref@{<date>}" then resolves to the oldest known value and "ref@{N}"
to the "old" side of the oldest entry, as they do without it.
The only gentle caller so far is "git stash export", which can now
export "stash@{<date>}" like "git stash show" can show it. The oldest
entry of a stash reflog normally has a null "old" side, so
"stash@{N}" past the end keeps failing.
[1] https://lore.kernel.org/git/xmqqa5745ttw.fsf@gitster.g/
Signed-off-by: Caspar Duregger <caspar.duregger@gmail.com>
---
object-name.c | 9 ++++-----
t/t3903-stash.sh | 9 +++++++++
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/object-name.c b/object-name.c
index 13e4dc0f21..c066a7d6a2 100644
--- a/object-name.c
+++ b/object-name.c
@@ -812,17 +812,16 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
* still fill in the oid with the "old" value,
* which we can use.
*/
- } else if (!(flags & GET_OID_GENTLY)) {
+ } else if (flags & GET_OID_GENTLY) {
+ free(real_ref);
+ return -1;
+ } else {
if (flags & GET_OID_QUIETLY) {
exit(128);
}
die(_("log for '%.*s' only has %d entries"),
len, str, co_cnt);
}
- if (flags & GET_OID_GENTLY) {
- free(real_ref);
- return -1;
- }
}
}
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 70c6031958..74ac66f22e 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -1557,6 +1557,15 @@ test_expect_success 'stash export can accept specified stashes' '
test_line_count = 2 actual
'
+test_expect_success 'stash export resolves stash reflog selectors like rev-parse' '
+ git stash clear &&
+ git stash import refs/heads/bar &&
+ git stash export --to-ref refs/heads/oldest "stash@{1970-01-02}" &&
+ test_cmp_rev t-stash0 oldest^2 &&
+ test_must_fail git stash export --print stash@{2} 2>err &&
+ test_grep "unable to find stash entry stash@{2}" err
+'
+
test_expect_success 'stash export rejects invalid arguments' '
test_must_fail git stash export --print --to-ref refs/heads/invalid 2>err &&
test_grep "exactly one of --print and --to-ref is required" err &&
--
2.56.1.windows.1
next prev parent reply other threads:[~2026-11-13 14:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-11 23:13 cat-file: dies with --batch if reflog entry is out of bounds Kristoffer Haugsbakk
2026-02-11 23:40 ` Junio C Hamano
2026-02-12 4:07 ` Jeff King
2026-11-13 14:28 ` [PATCH 0/4] cat-file: do not die on reflog entries out of range Caspar Duregger
2026-11-13 14:28 ` [PATCH 1/4] object-name: do not read a peel suffix as a reflog selector Caspar Duregger
2026-11-13 14:28 ` Caspar Duregger [this message]
2026-11-13 14:28 ` [PATCH 3/4] refs: let read_ref_at() fail gently on an empty reflog Caspar Duregger
2026-11-13 14:28 ` [PATCH 4/4] cat-file: report out-of-range reflog entries as missing Caspar Duregger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261113142804.7465-3-caspar.duregger@gmail.com \
--to=caspar.duregger@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=kristofferhaugsbakk@fastmail.com \
--cc=peff@peff.net \
--cc=sandals@crustytoothpaste.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox