From: Junio C Hamano <gitster@pobox.com>
To: Laveesh Bansal <laveeshb@laveeshbansal.com>
Cc: git@vger.kernel.org, Patrick Steinhardt <ps@pks.im>,
Karthik Nayak <karthik.188@gmail.com>,
Sven Weiland <sven.weiland@tngtech.com>
Subject: Re: [PATCH] builtin/reflog: say "would prune" for named refs with --dry-run
Date: Sun, 25 Oct 2026 11:07:53 -0700 [thread overview]
Message-ID: <xmqqqzhdy7pi.fsf@gitster.g> (raw)
In-Reply-To: <20261024013850.66448-1-laveeshb@laveeshbansal.com> (Laveesh Bansal's message of "Fri, 23 Oct 2026 18:38:50 -0700")
Laveesh Bansal <laveeshb@laveeshbansal.com> writes:
> With --dry-run --verbose, "git reflog expire --all" reports the entries
> it would remove as "would prune", but when refs are named on the command
> line it reports them as "prune", which looks as if they were removed:
>
> $ git reflog expire --dry-run --verbose --expire=now HEAD
> prune commit (initial): first
>
> Nothing is removed in either case, only the label is wrong. This was
> reported at [1].
>
> fcd2c3d9d8 (reflog + refs-backend: move "verbose" out of the backend,
> 2021-12-22) added dry_run to struct expire_reflog_policy_cb and set it
> in the --all loop, but not in the loop for named refs. Set it there
> too.
> ...
> diff --git a/builtin/reflog.c b/builtin/reflog.c
> index 1211c58fa4..49e5453dd9 100644
> --- a/builtin/reflog.c
> +++ b/builtin/reflog.c
> @@ -279,7 +279,10 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
>
> for (i = 0; i < argc; i++) {
> char *ref;
> - struct expire_reflog_policy_cb cb = { .opts = opts };
> + struct expire_reflog_policy_cb cb = {
> + .opts = opts,
> + .dry_run = !!(flags & EXPIRE_REFLOGS_DRY_RUN),
> + };
This obviously mimics what happens in the "if (do_all)" side.
But I have to wonder why nobody finds it disgusting that what
happens inside the "for_each_string_list_item()" and the later "for
(i = 0; i < rgc; i++)" loop have striking similarity between them.
Would it make sense to retructure the code flow to
if (do_all) {
collect "all" to a strvec or string list
}
foreach arg in argv[]) {
add arg to the same strvec or string list
}
foreach ref in collected {
do the expiration of ref's reflog
}
That will help prevent a similar bug from ever happening again, as
there would be only a single place that sets up how the expiration
is called, instead of two we currently have.
next prev parent reply other threads:[~2026-10-25 18:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-24 1:38 [PATCH] builtin/reflog: say "would prune" for named refs with --dry-run Laveesh Bansal
2026-10-25 18:07 ` Junio C Hamano [this message]
2026-10-25 19:15 ` Laveesh Bansal
2026-10-26 1:16 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqqzhdy7pi.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=karthik.188@gmail.com \
--cc=laveeshb@laveeshbansal.com \
--cc=ps@pks.im \
--cc=sven.weiland@tngtech.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox