🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #2841

[PATCH v2 2/2] builtin/reflog: expire each reflog only once

#2841
From: Laveesh Bansal
Date: Tue, 10 Nov 2026 15:26
85 lines
12287 bytes
"git reflog expire" processes a reflog once for every time it is named,
and reports it every time:

    $ git reflog expire --dry-run --verbose --expire=now main main
    would prune commit (initial): one
    would prune commit (initial): one

The same happens for two names of the same ref, such as "main" and
"refs/heads/main", and for a name that --all already covers.

Skip a reflog that this run has already processed.

Signed-off-by: Laveesh Bansal <laveeshb@laveeshbansal.com>
---

Notes:
    With --updateref, the first pass can move the ref, so a second pass
    over the same reflog could prune entries that the new tip no longer
    reaches.  It now ends as if the name had been given once.

 builtin/reflog.c  |  8 ++++++++
 t/t1410-reflog.sh | 14 ++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/builtin/reflog.c b/builtin/reflog.c
index 42d37a3724..4221136298 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -190,6 +190,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
 	struct worktree_reflogs collected = {
 		.reflogs = STRING_LIST_INIT_DUP,
 	};
+	struct string_list seen = STRING_LIST_INIT_DUP;
 	struct string_list_item *item;
 	const struct option options[] = {
 		OPT_BIT('n', "dry-run", &flags, N_("do not actually prune any entries"),
@@ -285,6 +286,12 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
 		if (ref)
 			refname = ref;
 
+		if (string_list_has_string(&seen, refname)) {
+			free(ref);
+			continue;
+		}
+		string_list_insert(&seen, refname);
+
 		reflog_expire_options_set_refname(&cb.opts, refname);
 		status |= refs_reflog_expire(get_main_ref_store(the_repository),
 					     refname, flags,
@@ -295,6 +302,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
 		free(ref);
 	}
 	string_list_clear(&collected.reflogs, 0);
+	string_list_clear(&seen, 0);
 
 	reflog_clear_expire_config(&opts);
 
diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh
index 998a7e8667..d22216c36d 100755
--- a/t/t1410-reflog.sh
+++ b/t/t1410-reflog.sh
@@ -274,6 +274,20 @@ test_expect_success 'reflog expire --dry-run --verbose --all' '
 	test_cmp before after
 '
 
+test_expect_success 'reflog expire does not process a reflog twice' '
+	git reflog expire --dry-run --verbose \
+		--expire=$(($test_tick - 10000)) \
+		--expire-unreachable=$(($test_tick - 10000)) \
+		--stale-fix \
+		--all >once &&
+	git reflog expire --dry-run --verbose \
+		--expire=$(($test_tick - 10000)) \
+		--expire-unreachable=$(($test_tick - 10000)) \
+		--stale-fix \
+		--all main refs/heads/main main >twice &&
+	test_cmp once twice
+'
+
 test_expect_success 'reflog expire' '
 
 	git reflog expire --verbose \
-- 
2.54.0
Technical Details
Message-ID: <0e5d78f552deaf3bd0ba2ec70666cebc2957c9e4.1794324064.git.laveeshb@laveeshbansal.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-75083-linux-kernel-git=dewy.ru
References: <20261108012213.89468-1-laveeshb@laveeshbansal.com> <cover.1794324064.git.laveeshb@laveeshbansal.com>

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-75083-linux-kernel-git=dewy.ru
From: laveeshb@laveeshbansal.com (Laveesh Bansal)
Newsgroups: linux.kernel.git
Subject: [PATCH v2 2/2] builtin/reflog: expire each reflog only once
Date: Tue, 10 Nov 2026 07:26:41 -0800
Organization: Usenet Network
Message-ID: <0e5d78f552deaf3bd0ba2ec70666cebc2957c9e4.1794324064.git.laveeshb@laveeshbansal.com>
References: <20261108012213.89468-1-laveeshb@laveeshbansal.com> <cover.1794324064.git.laveeshb@laveeshbansal.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="639218"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:heKx/vYA12z6eo8wR4bNVnXwCQ4= sha256:72C3zlOrLQcAivYDB0Ul2M7i9zI/XEZsMKjcfJREoZk=
	sha1:yzfCFnFNdAOFQGxX0tZqwMl5ZgA= sha256:EPfCt31/p5DV26lmmaOkHRUHT2GFBFGPC/fPDUSvTuw=
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 F300C113C21; Tue, 10 Nov 2026 18:35:28 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.75
X-Spam-Status: No, score=-2.75 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_INVALID=0.1, DKIM_SIGNED=0.1,
	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=fail (1024-bit key)
	reason="fail (message has been altered)" header.d=laveeshbansal.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 Nj9boS_3FcHY;
	Tue, 10 Nov 2026 18:35:25 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-75083-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=laveeshbansal.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 57BCC113C1E; Tue, 10 Nov 2026 18:35:17 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id BBE0A1264B4; Tue, 10 Nov 2026 15:28:06 +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=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794324485;
	b=HdormfjOZcMolx40H/4KLI9revrBaopAHHF7AfkMp/pseP5ODZeZe7UPava6do9/mRLL
	 0KX7rp3xaRPBtsNSeSABwOog/cmUuqLEva6HqtXi3vOUOTxykIuFHAN8GbauULN5yYtw0
	 FtkbKAQXpw1QOQRrkXc1r8N5BqZXinBsXVrOpD6ErnfSTuV6IY+a9bwCGm2sg55pdFaYx
	 oGNp2PJtvm5cXYCIGlH6kIo/1+hwk6Fsl8GJckezJvEb43ITWr7/pF2U388gEI17+QHuk
	 dljgtPBlP0ffuriFi7RIRar0FYOsIr+U4GzjqxP+jI6QIgEl8Mla8AZ7xBt7Y/GoynQ==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794324485;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature: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:X-ZohoMailClient;
	bh=PUrAxMb2ByCAIFwLuGY7ACRDlSD9UXydzFIYbITAK8E=;
	b=pXemkW7THfsv4keXKYRI8JBneWqkxez8yQfBL0vuBEiM2Mms54ma3AXVeTO7qAWquUYQ
	 TVHnK3cqSMlq5opgQWSN7FRigRYi/oD4NohkgS+h1hdjpazB2VodlP71nhx795uGaYqve
	 sDoDbcGMY2rjiX7UZ7Xp4V7nf/j+kXcIihzp6HewqkrUjvv260d0QrkjJPRtB0lzdc7Ta
	 5kBXGuyxu6Q87oAwcAYItWGI2mWF++GSemeIvjRuuOxKcSzLhn9MzR/zcIVrRAEetTHLA
	 s3W/OrvU6mQ5r/7Sc/bg+w6TBK/TJrSH2bBA/CnHP6hMr8l5wSaDMOlH7n0GbWIEEdw==
X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; 
	dkim=fail reason="signature verification failed" header.d=laveeshbansal.com header.i=@laveeshbansal.com header.a=rsa-sha256 header.s=zoho header.b=cbgCiVND;
	dmarc=none header.from=laveeshbansal.com;
	spf=pass smtp.mailfrom=laveeshbansal.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 584AD606A32A;
	Tue, 10 Nov 2026 15:28:05 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=fail reason="signature verification failed" (1024-bit key) header.d=laveeshbansal.com header.i=@laveeshbansal.com header.a=rsa-sha256 header.s=zoho header.b=cbgCiVND
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.182.15
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794324484;
	b=puAGTT2QLR5oeSoLf9bAu2kg5NS9tNT1TM6GaJ9oRZ/tWJavQ++YgNzEs4IpXAjDJu7W
	 SHxVusyeJ/bltQSpbpSXUJEvawS2IWN/EUt5tWYqS93L26UuCbU+3I3iBkFUvhjpIpOkN
	 4MKtjra1Hl2yFX9/xy+61fu7HxhIHoehyA5LYKdGIrBWk7iN60QfYaBiP+IU0GZzASLsi
	 MqBSrPPgKr2ja3JfIjje3E63Gc2udkTVevhEd5JZKBSOHLL+MdtqzmLwORfhSVmilbIXb
	 WI/6DczO3blZ+er1F6hvZ8Ons+C3j+E/YUqt5UzPNAWeBy6emMhY2HAuuKi8jtpEBqw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794324484;
	h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date:
	 Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding:X-ZohoMailClient;
	bh=PUrAxMb2ByCAIFwLuGY7ACRDlSD9UXydzFIYbITAK8E=;
	b=XTayUVTlY7mS1D0ecVlfNp91suu6ue51qp3XOtX8A0pQpiaumbfqPuC4YtRWUNxp0DIb
	 S2MC95H7lCyi84TP5S4ZH7CdshuSjA1g/vETlJfsn/yYyGHYgxzcxkeBN3IyH14M9DEio
	 NMDwaiRyjv6UD1+CHGEbzfGQ8Wi/WAiBDJ5nMkPGQdNxVp98XIn+e8S3u3xi0thZUclWo
	 0AbvceY6YP/shO6DkQfvJGT+dmcZQlVqSGDflcsQ1hUF+OrdZOPtZ0ZK9bdxWxANsDplY
	 9Nyb9JYVYmaR/iQ/7rrKJp8wveSAOQ4hLkaFR+VhHj/F3B//RBKX4llr0/DMEl+ItPw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dmarc=none header.from=laveeshbansal.com;
	spf=pass smtp.mailfrom=laveeshbansal.com;
	dkim=pass header.d=laveeshbansal.com header.i=@laveeshbansal.com header.a=rsa-sha256 header.s=zoho header.b=cbgCiVND;
	arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.182.15
X-Received: from sender5-op-o15.zoho.com (sender5-op-o15.zoho.com [165.173.182.15])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A82E606A31C
	for <git@vger.kernel.org>; Tue, 10 Nov 2026 15:28:03 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6A82E606A31C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=laveeshbansal.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=laveeshbansal.com
X-ARC-Seal: i=1; a=rsa-sha256; t=1794324436; cv=none; 
	d=zohomail.com; s=zohoarc; 
	b=V/J8L47iQOx2K0BCtdNw55PVhDA28IG2wizWlDwoJ8HJP4Vmq9pep3urv4UbcMaj6Y/yGaffBmBpl3Cj6Elm0Stqf6JZ/wMdFRM5eeJXvMIqAlxokGi2s7gAx1oxK+ghp6X23gKJCQrGJiLVNhoQOp4j5+0PgyHBZPxOCyYBoMw=
X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; 
	t=1794324436; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; 
	bh=PUrAxMb2ByCAIFwLuGY7ACRDlSD9UXydzFIYbITAK8E=; 
	b=DFmPOYyJEyCqJtxZJsk01OR0TiemL8ulLTYTJQexED8A5ObPEoYjB93Czp4xUGuu+STjKPt0Duc/ffdEd3c/GOFxG2oIxgShd7OITgffrt66TwNMkJjqCpKnW+sMOS87PS8dpmkvlvpDN+HYqkw0yV/XmLfhGDd6+VElBJCOPyU=
X-ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass  header.i=laveeshbansal.com;
	spf=pass  smtp.mailfrom=laveeshb@laveeshbansal.com;
	dmarc=pass header.from=<laveeshb@laveeshbansal.com>
X-DKIM-Signature: a=rsa-sha256; b=cbgCiVNDOjSCJ+JUFpqf583fGTo2VQn5DelEaR+qDa4KeP1T7YLjwO+NpXsekMh95fg2GGeAjNgpx/sT6yllpFYifUpvICUSvkaXchnqQ6mSj5CWnJzRt4jlj0PzrjcscciVTCbq/I9VPFPMew4UlxKsazzaiZBEbY5jAKfj2jI=; c=relaxed/relaxed; s=zoho; d=laveeshbansal.com; v=1; bh=PUrAxMb2ByCAIFwLuGY7ACRDlSD9UXydzFIYbITAK8E=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc;
X-Received: by smtp.zohomail.com with SMTPS id 1794324426753698.0345998147542;
	Tue, 10 Nov 2026 07:27:06 -0800 (PST)
X-Cc: Junio C Hamano <gitster@pobox.com>,
	Patrick Steinhardt <ps@pks.im>,
	Karthik Nayak <karthik.188@gmail.com>,
	Ævar Arnfjörð Bjarmason <avarab@gmail.com>
X-Mailer: git-send-email 2.54.0
X-In-Reply-To: <cover.1794324064.git.laveeshb@laveeshbansal.com>
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
X-ZohoMailClient: External