Article View: linux.kernel.git
Article #3067[PATCH 3/4] refs: let read_ref_at() fail gently on an empty reflog
From: Caspar Duregger
Date: Fri, 13 Nov 2026 14:28
Date: Fri, 13 Nov 2026 14:28
100 lines
14366 bytes
14366 bytes
When a reflog exists but has no entries, read_ref_at() can answer
"ref@{0}" with the current value of the ref. For any other request it
dies with "log for <ref> is empty", or exits silently with
GET_OID_QUIETLY, even when the caller asked for GET_OID_GENTLY. Such
reflogs are left behind by "git reflog expire --expire=all".
Return -1 in this case when GET_OID_GENTLY is given, and make
get_oid_basic() treat it as a failed lookup. "git stash export" on an
emptied stash reflog now reports "unable to find stash entry" instead
of exiting without a word.
Signed-off-by: Caspar Duregger <caspar.duregger@gmail.com>
---
object-name.c | 13 +++++++++----
refs.c | 2 ++
refs.h | 4 ++++
t/t3903-stash.sh | 8 ++++++++
4 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/object-name.c b/object-name.c
index c066a7d6a2..1d7cbd8a03 100644
--- a/object-name.c
+++ b/object-name.c
@@ -761,7 +761,7 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
warning(warn_msg, len, str);
if (reflog_len) {
- int nth, i;
+ int nth, i, ret;
timestamp_t at_time;
timestamp_t co_time;
int co_tz, co_cnt;
@@ -789,9 +789,14 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
return -1;
}
}
- if (read_ref_at(get_main_ref_store(r),
- real_ref, flags, at_time, nth, oid, NULL,
- &co_time, &co_tz, &co_cnt)) {
+ ret = read_ref_at(get_main_ref_store(r),
+ real_ref, flags, at_time, nth, oid, NULL,
+ &co_time, &co_tz, &co_cnt);
+ if (ret < 0) {
+ free(real_ref);
+ return -1;
+ }
+ if (ret) {
if (!len) {
if (!skip_prefix(real_ref, "refs/heads/", &str))
str = "HEAD";
diff --git a/refs.c b/refs.c
index 3f7458332e..b6ce62b12a 100644
--- a/refs.c
+++ b/refs.c
@@ -1227,6 +1227,8 @@ int read_ref_at(struct ref_store *refs, const char *refname,
set_read_ref_cutoffs(&cb, 0, 0, "empty reflog");
return 1;
}
+ if (flags & GET_OID_GENTLY)
+ return -1;
if (flags & GET_OID_QUIETLY)
exit(128);
else
diff --git a/refs.h b/refs.h
index ee3b8a62ef..25b8987ca9 100644
--- a/refs.h
+++ b/refs.h
@@ -603,6 +603,10 @@ int refs_create_reflog(struct ref_store *refs, const char *refname,
* that there is one important special case here! If the reflog was empty
* and the caller asked for the 0-th cnt, we will return "1" but leave the
* "oid" field untouched.
+ *
+ * If the reflog was empty and the caller asked for anything else, we die,
+ * or exit silently if "flags" contains GET_OID_QUIETLY. If "flags" contains
+ * GET_OID_GENTLY, we instead return -1.
**/
int read_ref_at(struct ref_store *refs,
const char *refname, unsigned int flags,
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 74ac66f22e..2c41cc2b3f 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -1566,6 +1566,14 @@ test_expect_success 'stash export resolves stash reflog selectors like rev-parse
test_grep "unable to find stash entry stash@{2}" err
'
+test_expect_success 'stash export reports entries of an empty stash reflog' '
+ git stash clear &&
+ git stash import refs/heads/bar &&
+ git reflog expire --expire=all refs/stash &&
+ test_must_fail git stash export --print stash@{1} 2>err &&
+ test_grep "unable to find stash entry stash@{1}" 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
Technical Details
Message-ID:
<20261113142804.7465-4-caspar.duregger@gmail.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-75385-linux-kernel-git=dewy.ruReferences:
<20260212040708.GA1894049@coredump.intra.peff.net>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-75385-linux-kernel-git=dewy.ru
From: caspar.duregger@gmail.com (Caspar Duregger)
Newsgroups: linux.kernel.git
Subject: [PATCH 3/4] refs: let read_ref_at() fail gently on an empty reflog
Date: Fri, 13 Nov 2026 15:28:03 +0100
Organization: Usenet Network
Message-ID: <20261113142804.7465-4-caspar.duregger@gmail.com>
References: <20260212040708.GA1894049@coredump.intra.peff.net>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1369563"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:z5u7K7UtdY6nvZxBiw7Y69hHNiQ= sha256:qcE5oKEH+ofrNDCaEr3mUE39TdKw5biCDkiJpVGCNPY=
sha1:r+xXrqzTRID3VJdshp8eSkEI1XQ= sha256:mNOVfeW8ylPSleGMoS0OKGdioUrPWoAoUr51LrZJBdE=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 7ADA5114574; Fri, 13 Nov 2026 18:08:08 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.148
X-Spam-Status: No, score=-3.148 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id 6jX-JsragzFV;
Fri, 13 Nov 2026 18:08:02 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=git+bounces-75385-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id 234A811455C; Fri, 13 Nov 2026 18:07:43 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sto.lore.kernel.org (Postfix) with ESMTP id 062846E0AC0; Fri, 13 Nov 2026 14:29:30 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1794580138;
b=aQGD6SSMBiiKVdMuzJWXzD5ww3VBHS6IOx6EER5SVM2XegybckL/Ylm2SdRv8Vody1Gb
Chy8tReiIPfq0TeoGzmUHaIcm1i5/rsnMKZ08qftWPn9l+1O/HhKCYqyZnNw88kCmQs7Z
TthPAzeprHy3CaBzFuNj5Iz+krpsUWLubwWp/SeASGy+uuSGFjWUDbCeudyYyp0CUBh09
DxMclXnshKh2rge0jYVPKgWGuA2GQeiBlOegqdDkTB+iMXDlqQyLAa/oVGMO9+l7TfoTX
4K8LVycev8zlDKy5UEgQl/KnKiCJOqKwC7d+KkqwJaIGsjgvfrk7fV4q78TCRtn8Qsg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794580138;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=nF4Cz6LkMZYxa1m8ZM9XEWREyq9i9s+0FgqtrzUNc3A=;
b=CRmLRQGEON4+/KwKNaX6VwRy4Er0xBDFvKqE3xh26y5iaZ7m6TdfnXrL7uNv5dDUt7nx
Ipjdb6bi1hm/eo1jPderbN2vYB9iJ3C7QHQO6pUjEvvxzn0CVGjGRXL/MWaku8L6DOyOi
iA/vC/lYg4q5RvMS70VPdKW0r9f+v8KVMYfRyJ+/1mjdnk9GPYeq/sMc0ZShf1ngc39PO
tOttiGD+D+ZOiq8owEfYwJMvleBbWeWiG0bLp62qFneL2uksN9kQHao8/jDfFQ07HJvT0
uxYFAdaF7Z0/HiuaMs72ubVa8ngR8Yb5QyjxSl7e4pnPurYjr7YfSdbufT3w0FxMJcA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="B+643xl/";
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id BADDB60A2616;
Fri, 13 Nov 2026 14:28:58 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=B+643xl/
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.42
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794580137;
b=YMAb7XhDJeRJJJ714DkzO4gCcb8u5kXrZlRzuJr8m3/ziDg+DAh61VgNQL+aV1rHHyJ4
yArIkJvZjgUzDCzyEnosiBHq60xt4PqiCzggM3G0WFwu5yMtgH/kfSSgJMReP14TrvqZ2
18TL/kcZ8vxurIZgLaESPa12T3uys07rup30HgK9p0aLkWp6FWf6JDSop0ugaAZCoB50P
NmwJCeyg1O7EAbdqdaifnBMChseu+2MnmnPVLZ1mYsREArEoYFztOEsH6tWqB/gTH7gS3
+64V1UBH0ENhDx4G8RC9JfjFSjw/Rj04x6k1saOZ8vk1dg7cowgw4w5nrtwEfXR/U3A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794580137;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
Content-Transfer-Encoding;
bh=nF4Cz6LkMZYxa1m8ZM9XEWREyq9i9s+0FgqtrzUNc3A=;
b=rmQDu7iZTECwSD+WJdk5+cSXqczwm8gzmM7BN1cc57yXdxSSw1Z9/8RqMGPpze8/ySbH
8ENZDMcMGNEqOxJIdu2Ior8ZqTbomkHoDF0JamKOH7r0SwpnRA+shtO/n1Vqq4pnIm8YC
G3gGwBa5Lm1y9jyfN6gvNQuPqvpa10xLzXIUiyc50UuVZeOX1w8WJk+sTRNKlVH1LOVkg
+myhxByM0qFJJ0H2LBW3ugYW9/a2FHILLHl4zCCYjEQR7tD06BLKfG9ZrQGuvXfQKmhEC
cJPElFvgpS4XETmzDlJGPsfT+Uk3++KkYmPOrqGUhPG4biGTiUfELwYNPFPdxkd+I0w==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="B+643xl/";
arc=none smtp.remote-ip=209.85.128.42
X-Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F5E960A260B
for <git@vger.kernel.org>; Fri, 13 Nov 2026 14:28:57 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8F5E960A260B
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4a60f9474c4so17080785e9.0
for <git@vger.kernel.org>; Fri, 13 Nov 2026 06:28:57 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1794580136; x=1795184936; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=nF4Cz6LkMZYxa1m8ZM9XEWREyq9i9s+0FgqtrzUNc3A=;
b=B+643xl/vU9hn0ANRNFjIPRaj4bW6laDrksNtZBXkr/ZgbEO/WjC6UifVrI0YkptE2
+44JFzlWULRHMvXSgZF5qsses9YMAylIiMCjarDRXVHxfe6+9ApNWpB59NBKPesFaitH
eYrZgN4OaDMJQdLL5XKdPKhtQtftoFwf2zrxtax5nklAbUAT9TMc8l9ZAt2ZFJCoHVSF
nh2p1tQX3vhYz+HdYv+7yUNVRh5tsVZoh2w3sg5+J3O6npzIefM5aqBTNMcVzNoUK1fy
/ylHWEfpxXfAKir+eeAT8Z0RAC3U6BoQO2KjpPNWDY0MbNUeSfNglCtwbK3JXUm/m2in
qguQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1794580136; x=1795184936;
h=content-transfer-encoding:mime-version:references:in-reply-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lE
r0Xis4nGtbs9x8/2OucenHsv4YfAxqCVh3gRtBX96nyHZA0pjfCfV8hi8R6Tu5DYC5eYyB/K6rk
bQcMZplzLFCWv6QiCN6T+K1YiRiSGPg4CFhK/0BcWmq64aBw9UNt1SShHAJRQE/XHzOWxdZWAz0
sqIdDN6OO+iAbu3gTH1L+Mtata1esFhCn2pqj5slUlrTIThY6UrZ18jhGBqYXmCqaapBAKm+25I
2q77iXPHD6OCk5RPq/wSK2tNReu/edw==
X-Received: by 2002:a05:600c:4e15:b0:4a2:1612:636e with SMTP id 5b1f17b1804b1-4bb55a4436cmr55070295e9.5.1794580135795;
Fri, 13 Nov 2026 06:28:55 -0800 (PST)
X-Received: from KURSA (ipservice-092-208-105-158.092.208.pools.vodafone-ip.de. [92.208.105.158])
by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb55ac1159sm60033285e9.4.2026.11.13.06.28.54
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Fri, 13 Nov 2026 06:28:55 -0800 (PST)
X-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>
X-Mailer: git-send-email 2.56.1.windows.1
X-In-Reply-To: <20260212040708.GA1894049@coredump.intra.peff.net>
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list