git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] builtin/reflog: say "would prune" for named refs with --dry-run

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 25, 2026, 18:07 UTC
Message-ID
<xmqqqzhdy7pi.fsf@gitster.g>
In-Reply-To
<20261024013850.66448-1-laveeshb@laveeshbansal.com>
Laveesh Bansal <laveeshb@laveeshbansal.com> writes:
Show 28 quoted lines
> 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.

Previous: Laveesh BansalNext: Laveesh Bansal
Message 2 of 5 in “builtin/reflog: say "would prune" for named refs with --dry-run”
  1. builtin/reflog: say "would prune" for named refs with --dry-runLaveesh Bansal, Oct 24, 2026
  2. Junio C HamanoOct 25, 2026
  3. Laveesh BansalOct 25, 2026
  4. Junio C HamanoOct 26, 2026
  5. Patrick SteinhardtOct 29, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.