🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #2843

[PATCH v2 1/2] builtin/reflog: expire --all and named refs in one loop

#2843
From: Laveesh Bansal
Date: Tue, 10 Nov 2026 15:26
110 lines
13279 bytes
"git reflog expire" calls refs_reflog_expire() from two places, one
for --all and one for the refs named on the command line, each with
its own copy of the callback setup. The copies can drift apart:
d1536ac3e2 (builtin/reflog: say "would prune" for named refs with
--dry-run, 2026-10-23) fixed a copy that was missing dry_run.

Collect the reflogs from both sources into one list and expire them
in a single loop, so the call is set up in one place. The names given
on the command line are still looked up in that loop, so the output
and the exit status stay the same.

Signed-off-by: Laveesh Bansal <laveeshb@laveeshbansal.com>
---
 builtin/reflog.c | 50 +++++++++++++++++++++++-------------------------
 1 file changed, 24 insertions(+), 26 deletions(-)

diff --git a/builtin/reflog.c b/builtin/reflog.c
index 49e5453dd9..42d37a3724 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -187,6 +187,10 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
 	unsigned int flags = 0;
 	int verbose = 0;
 	reflog_expiry_should_prune_fn *should_prune_fn = should_expire_reflog_ent;
+	struct worktree_reflogs collected = {
+		.reflogs = 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"),
 			EXPIRE_REFLOGS_DRY_RUN),
@@ -244,10 +248,6 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
 	}
 
 	if (do_all) {
-		struct worktree_reflogs collected = {
-			.reflogs = STRING_LIST_INIT_DUP,
-		};
-		struct string_list_item *item;
 		struct worktree **worktrees, **p;
 
 		worktrees = get_worktrees(the_repository);
@@ -259,44 +259,42 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
 					     collect_reflog, &collected);
 		}
 		free_worktrees(worktrees);
-
-		for_each_string_list_item(item, &collected.reflogs) {
-			struct expire_reflog_policy_cb cb = {
-				.opts = opts,
-				.dry_run = !!(flags & EXPIRE_REFLOGS_DRY_RUN),
-			};
-
-			reflog_expire_options_set_refname(&cb.opts,  item->string);
-			status |= refs_reflog_expire(get_main_ref_store(the_repository),
-						     item->string, flags,
-						     reflog_expiry_prepare,
-						     should_prune_fn,
-						     reflog_expiry_cleanup,
-						     &cb);
-		}
-		string_list_clear(&collected.reflogs, 0);
 	}
 
+	/* util marks the names that still have to be looked up */
 	for (i = 0; i < argc; i++) {
-		char *ref;
+		item = string_list_append(&collected.reflogs, argv[i]);
+		item->util = (void *)1;
+	}
+
+	for_each_string_list_item(item, &collected.reflogs) {
 		struct expire_reflog_policy_cb cb = {
 			.opts = opts,
 			.dry_run = !!(flags & EXPIRE_REFLOGS_DRY_RUN),
 		};
-
-		if (!repo_dwim_log(the_repository, argv[i], strlen(argv[i]), NULL, &ref)) {
-			status |= error(_("reflog could not be found: '%s'"), argv[i]);
+		const char *refname = item->string;
+		char *ref = NULL;
+
+		if (item->util &&
+		    !repo_dwim_log(the_repository, item->string,
+				   strlen(item->string), NULL, &ref)) {
+			status |= error(_("reflog could not be found: '%s'"),
+					item->string);
 			continue;
 		}
-		reflog_expire_options_set_refname(&cb.opts, ref);
+		if (ref)
+			refname = ref;
+
+		reflog_expire_options_set_refname(&cb.opts, refname);
 		status |= refs_reflog_expire(get_main_ref_store(the_repository),
-					     ref, flags,
+					     refname, flags,
 					     reflog_expiry_prepare,
 					     should_prune_fn,
 					     reflog_expiry_cleanup,
 					     &cb);
 		free(ref);
 	}
+	string_list_clear(&collected.reflogs, 0);
 
 	reflog_clear_expire_config(&opts);
 
-- 
2.54.0
Technical Details
Message-ID: <5878cbe0ebc18b9c61cce37587fcd3a211e8d354.1794324064.git.laveeshb@laveeshbansal.com>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!git+bounces-75082-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!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!git+bounces-75082-linux-kernel-git=dewy.ru
From: laveeshb@laveeshbansal.com (Laveesh Bansal)
Newsgroups: linux.kernel.git
Subject: [PATCH v2 1/2] builtin/reflog: expire --all and named refs in one loop
Date: Tue, 10 Nov 2026 07:26:40 -0800
Organization: Usenet Network
Message-ID: <5878cbe0ebc18b9c61cce37587fcd3a211e8d354.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="639412"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:pVaXmWyctbJ5BWLTgA9WHLnAKLU= sha256:XqWK55sVZgjRvdG2hpc5MFnK0+Fz5ZDBtHzQ11Qqb0M=
	sha1:M43dY86sCU8pO9c9pRToUVOVT38= sha256:v8kCXtppZBiiexU20RtZmtAdLdlvtOHoEy9lEoJDZaM=
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 8408A113C27; Tue, 10 Nov 2026 18:36:18 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.65
X-Spam-Status: No, score=-1.65 tagged_above=-9999 required=6.31
	tests=[DCC_CHECK=1.1, 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 lckHvLuNHEXH;
	Tue, 10 Nov 2026 18:36:15 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-75082-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 4D5D0113C03; Tue, 10 Nov 2026 18:36:07 +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 C3190123822; Tue, 10 Nov 2026 15:27:53 +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=1794324469;
	b=YzenUAXiibQqUppO/fmReiiFoI4FiTFa+iZ3jU66gt1GV0n2TJDcp+8UfYOZAUcStWpX
	 OzBN/ji3xxSRagsbZAJ8xL1qBnaoCiIddfbG2qkxfYmvm7FreNcbIeHjIx2DzIjjpeII+
	 6mYlkfsMlart+6hrnNnFmCL4nLzeQHjAc09kTd2ePUzXkmySNOgDps9Pt7XC9dj4xWXx5
	 Jssy0W0fUoI8DVqZygs3a+eYjdw/NRe9TSuUvsAqweQ5hva8ufFKFpHM31k0n8pPD0lyW
	 WIOodvj9WIXjNov0rfKc4iOAiCdZlFaWPnx6EUZhf3ZER61c8iNSxUvKM5LYVbGhx0g==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794324469;
	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=OHnUFWX/cwH+DxnElTb6KzwisoaX76UAXk9ICG5u/DE=;
	b=Zg3BM/UW0iFGB8QKS2CHDXIAHQRpboI3ymg3OXiLd+A3r4YpLY/Br2NMFhBq9k4Tp2i2
	 KAKfccI1mIjq83ZgGoAGPqm6LbY1TMBtdTxOHjWvBRfZx8V3GL9sG8zxNd3CeeW7Jj1p9
	 v5yu976bVZngabDxHp2xoWjArqjAYKNmjpTqCfXbmtZS69RMA1W5eodqctQVmKySkvYHo
	 b0W9IhBM/wJmyl/flpDMyqLAKTuwFSTFmsf78nMdjqVimuw2tlSaHd3saE8+twTj0AQqv
	 TLtYzVGtt5kgq1vDDiwXLqBsIHL/TxiXI/btrugR+csJBa2gYMx+pACyaBHwiAgvBMw==
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=Xrr8D2SL;
	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 0A0CB606A338;
	Tue, 10 Nov 2026 15:27:49 +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=Xrr8D2SL
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=1794324468;
	b=3KJ2Mn7K8GNwv2kd3HKZoIlkp2M0MAGb+56Q2ZKAX7hzGQ0HT1f/gvtOZ490vScIUhr7
	 QzJuPLnFVgbhFM/UVBPtK6Vw6oHzjU8nsUJ0F4PXOcVWMQhgPG4X+xbA/dtJQ4UPMo9/5
	 5FZKw37aFi6C8+FdY0yOij90/cWkh0lSJOjhc//uwB/FjOoKJzaJo7xoV1WndzsmMiaFr
	 jSq7hEa15imk2fjBdgF+JIuwj7s6QYom6/StNlgruwun3SbfGSy/x+d+hhDJ4D5gJUIXh
	 5kydLcF1UIlAeNF5RVmuUeBuMasKs9/oTNrQp+n4RxqHOShx6G1PeDXwU7wUKqKaZYA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794324468;
	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=OHnUFWX/cwH+DxnElTb6KzwisoaX76UAXk9ICG5u/DE=;
	b=Prh7wqYxITsDBT+WesyKpIhPO5rb/sybPmerTaEUm1wUNp468YXlFw75BLgcEIHmsz71
	 mDI2dElNUqXfPY7VIGp0s9obCfUIdxuU0vAvewWQgVT5wyKynigcNFY3CQvulcNAL6Ksu
	 lCiTMjB2Xjg59zCwzXiz/pZtnuJJHUjZ7EkZKdjcoCbNPhf9fBLwJdb+bKmuXdm7x/Bw4
	 0A61D5YfGcy7hhDU7P2YAnmlRyfvx6KNn+uMvHn3BI0E8t65nuxnz4zSXSuKDFaKUIkpR
	 /cQODpZ1t3qpVAE9gKsrKLoys9jYpjqJehoTN+lWt+vGPWwKZ1HgukTkprs8IJVxPsA==
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=Xrr8D2SL;
	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))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5D37606A331
	for <git@vger.kernel.org>; Tue, 10 Nov 2026 15:27:46 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E5D37606A331
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=ftSlPf4xYCfYxtIGED85vMRwGPLdbAju0kEogiMYnXh1wCzPp1JR7ghagVFJe3awbFGrrD/7lZ/MOGcq4s2NePC3KIRRxKN5xDEiLwp/dw8G1N8hlXYSqKNPkYQY8K2ldpDMfvjJ4OfYYSnFvCNoxqv/qbRjdMx2T0F+bGzroAk=
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=OHnUFWX/cwH+DxnElTb6KzwisoaX76UAXk9ICG5u/DE=; 
	b=ZtnHLMVhxYi8reYtz6ShHcXVV0sEfK1zNTQVRnFofppfUXv2wBmdOKIVSy5caHHTHX2jXakR9DTafyLbscgahRFxKr9BwJSjanIq7K8GIzI9YDw2CdXMBfIcxE6Z+VeTBFOlyuCuAdGZ7dHhXj7l4qtcmgtd2URHw0olm+J6tj0=
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=Xrr8D2SLzhb/sSbFJkmXaQNDxnyQCdqdLF0zdHC4gFfFmvaQwQ0bkDH86SYSKUIEveFQ3NRLlzDa1lYl0yeElznyFcczh5oW7OXKgEB/vrTcFvABkN8GRtmWlCtHb/VBvggP2iFb04vP0bChc0TwJG2b1nfaT+zitkOIC+i0qdo=; c=relaxed/relaxed; s=zoho; d=laveeshbansal.com; v=1; bh=OHnUFWX/cwH+DxnElTb6KzwisoaX76UAXk9ICG5u/DE=; 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 1794324425319358.5292775269211;
	Tue, 10 Nov 2026 07:27:05 -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