git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/4] object-name: let GET_OID_GENTLY affect only failing lookups

From
CDCaspar Duregger <caspar.duregger@gmail.com>
Date
Nov 13, 2026, 14:28 UTC
Message-ID
<20261113142804.7465-3-caspar.duregger@gmail.com>
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
Previous: Caspar DureggerNext: Caspar Duregger
Message 6 of 8 in “cat-file: dies with --batch if reflog entry is out of bounds”
  1. Kristoffer HaugsbakkFeb 11, 2026
  2. Junio C HamanoFeb 11, 2026
  3. Jeff KingFeb 12, 2026
  4. 0/4 cat-file: do not die on reflog entries out of rangeCaspar Duregger, Nov 13, 2026
  5. 1/4 object-name: do not read a peel suffix as a reflog selectorCaspar Duregger, Nov 13, 2026
  6. 2/4 object-name: let GET_OID_GENTLY affect only failing lookupsCaspar Duregger, Nov 13, 2026
  7. 3/4 refs: let read_ref_at() fail gently on an empty reflogCaspar Duregger, Nov 13, 2026
  8. 4/4 cat-file: report out-of-range reflog entries as missingCaspar Duregger, Nov 13, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.