Article View: linux.kernel.git
Article #4201[PATCH v4 1/2] builtin/reflog: expire --all and named refs in one loop
From: Laveesh Bansal
Date: Tue, 01 Dec 2026 15:43
Date: Tue, 01 Dec 2026 15:43
110 lines
13234 bytes
13234 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.1796138650.git.laveeshb@laveeshbansal.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76793-linux-kernel-git=dewy.ruReferences:
<cover.1795290319.git.laveeshb@laveeshbansal.com> <cover.1796138650.git.laveeshb@laveeshbansal.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76793-linux-kernel-git=dewy.ru From: laveeshb@laveeshbansal.com (Laveesh Bansal) Newsgroups: linux.kernel.git Subject: [PATCH v4 1/2] builtin/reflog: expire --all and named refs in one loop Date: Tue, 1 Dec 2026 07:43:04 -0800 Organization: Usenet Network Message-ID: <5878cbe0ebc18b9c61cce37587fcd3a211e8d354.1796138650.git.laveeshb@laveeshbansal.com> References: <cover.1795290319.git.laveeshb@laveeshbansal.com> <cover.1796138650.git.laveeshb@laveeshbansal.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1751704"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:vGa8ChH/jqjky2gfbIeSztV/21A= sha256:rcgykjkD9JGnDhJuDH70djJRu86bvyES6ybK3F5zlhY= sha1:sEkHmC8Qi+SczmeqFsdJVL48zG0= sha256:dCkH0/i5B6DpfD9rQzqTeX92ggfPAT0k6d5lN0xg7f0= 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 68C90117407; Tue, 1 Dec 2026 18:43:47 +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 wAAhaRrea6-P; Tue, 1 Dec 2026 18:43:44 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-76793-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 F1D1E117405; Tue, 1 Dec 2026 18:43:35 +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 EF13D28A9E; Tue, 1 Dec 2026 15:43:33 +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=1796139813; b=G84j99wf1UCs7ekeaGfM2TKxz6d21jBJYwd0d/qF8a4p3GrWHuzcpzfH2e2kdJvGdfWR byZr/ks+VmCSmsnMqzfhI8EV9xmxb5O8SQgiXQpIYPgUsANDJQ6EvLMWt1rcNME1whdAF n8Uqrx+IiicSWvXiikFja3Irmm25hQkUhxUZSI8cvl4R+qHjBtSdTogI99r766awfx0lQ QAarJ/eaY214hocpIwkFl8h0IjLAOYR+vgGQLMhp7S2AUN7Knb419cz0hZqIB2YprJ8jX T118DFvTVQwFx6agWL2KOkdPZSRQpV8djSiSswcSftAM1+wkpeQ4H8i457Ft+zSSpMw== X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796139813; 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=f2B+PC8Cg56yWGZ9CXyWV3CnVEI6fLOLXnawSworvrwVEoBCThoBC/WTQEXkd3FLVuuk vFx1h1WcFRW/+0v5FNY4b0Tw0jAY1mHssH/I/CgKmUNf7f1TDX1+Fia7R9GMomT8bDnvC +HCJS3qy8OyI3be45wABYYQ3hbl+FgXv2lyzdoBfCWrN32bjktCeQgD5VJV2+jC9zI48x chguIpUg4C1BSHNw941vVTjHPHv1scYxCrUnhvcDGXFQF3wJpo8SSBT/SL6GvyxEwegVo RKm6H/C5Pc3EG7pSoEuIwIm2mtFqaOUwV4pvSdjoWEWnXo1D1urQ7yVsVXv96fj2AFQ== 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=AUbKYeks; 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 8C8F7606A331; Tue, 1 Dec 2026 15:43:33 +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=AUbKYeks X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.180.16 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796139812; b=Ct6cc8Lxwh81yq06eSp9RHYgnTYKzN5y8vGAjicwNdT9lGpPckmR2fwa1NxTFjvWGBhK 5lELVHVDedbcpwOTnPUIzate2YyVow0+fLKBFL+bOJ95YNnvwxBX9P9HRdUnjmYh3hrtH m6sdbwPTfdkcNKjr5kOuvBJPr81uclsTbQsrnagWxo11pCDGIjwDZBPDwixjrqGyZM9BZ jBWLhTeY8ztudYoNSpRhaIJY2sfG6HmedicKnqNd/E5KKDAB5agXp62SZ6oqD0cSUDzqt IDk7oATKI0PoN4ksW1KCP4+wP6UpUSk7O2yT05nTPXifqg2jOZg5dU9Xs40f4K4GPkQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796139812; 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=27yOyenGJV2GjjU0IGRM5brsW9wq5CQwLdNKskRuP/NMEq9xIbiipozLtq+Vgs7AiY9v STt9E8pUUNWAKqR6jCszebLDR0jsC22bH6rsR7/VFEqFlT9il1THe9u+Nhep5FXHZe/H+ ybpZ7cgVNUE7iBHmYLbcynCt2zHmh9tqc4WHfiYGNmaLb1TtWwthvD4Dx0/QJUGY3xNpF lEnt/8OqBfjuraB43V0NCttDYcyiWKXOEGERSHMHm+bFDFjrAAyTomUDlQrUfaYyzPJ03 ZF77RWMp2S41ctltY/EZwbTqWDeE+4u8CycdTwJtLxG7dg4Ykn+BhKVi7zPyssJM3Iw== 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=AUbKYeks; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.180.16 X-Received: from sender6-op-o16.zoho.com (sender6-op-o16.zoho.com [165.173.180.16]) (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 58BF8606A327 for <git@vger.kernel.org>; Tue, 1 Dec 2026 15:43:32 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 58BF8606A327 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=1796139800; cv=none; d=zohomail.com; s=zohoarc; b=YErSXhyq0fs9JTxGP9pvhoITE+GMY+KJUsb+xyZBpuylPbbqc+vxkOF9tr0ApTn8IRIFsQVJi8dsI8cY5EGk1BCvjy9vpDDv0tc+sVrmHNWXlp6na9xMxGE6d6hpIeTLBjJSXatJHg0vyJCV2TGA0w/XGmbEjFxEh0iqhDhJYRE= X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1796139800; 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=Vt94d2qG9af860M/vh5K7wsTRauqVV5xg3y6nzFkP04qZHxKk4gdN9jDw3Golg06ReXhUwvIaRay4mJ7UvQMxU9iG+G8RyBfhRGUi4LN84iF9Tal3G5juSVLNKiHkpR/UN0I6EyG17ZvUhVqa0udU6HJityMD49mD2xG4VxTg6U= 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=AUbKYeksqTIX2ylaFYFHSVBUBaDHsiIiiPG/s+aGGAIGLEajx14dTi9Z7/TKVZLOhb0bfBIEDRXVgQ69JxEOAQIJ600HYOMp0TfrRSkdleZDNwWr/Zg74Ed3xvQVNcopzNQaBOzar7fJzzHvLB0o0AbsCexb0K6HrksuK0KtmEM=; 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 1796139796001489.87432084975296; Tue, 1 Dec 2026 07:43:16 -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.1796138650.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