Git development
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Laveesh Bansal <laveeshb@laveeshbansal.com>
Cc: git@vger.kernel.org, "Junio C Hamano" <gitster@pobox.com>,
	"Karthik Nayak" <karthik.188@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [PATCH v3 2/2] builtin/reflog: expire each reflog only once
Date: Tue, 1 Dec 2026 13:09:34 +0100	[thread overview]
Message-ID: <aw64_jhQf4a4JJQX@pks.im> (raw)
In-Reply-To: <3ac3a8fbba527fefeb331ae0334c4106a9806b5b.1795290319.git.laveeshb@laveeshbansal.com>

On Sat, Nov 21, 2026 at 11:53:17AM -0800, Laveesh Bansal wrote:
> "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.
> 
> With --updateref, naming a ref twice can also lose entries.  The first
> pass can move the ref to the last entry it kept, and the second pass
> then prunes entries that mention commits the new tip does not reach.
> 
> Skip a reflog that this run has already processed.  Add tests for the
> repeated output and for --updateref.
> 
> Signed-off-by: Laveesh Bansal <laveeshb@laveeshbansal.com>
> ---
> 
> Notes:
>     I kept the order in which reflogs are expired.  With --updateref,
>     expiring a branch can move it, and "HEAD" is checked against the tip of
>     every ref, so expiring "HEAD" before or after that branch can prune
>     different entries.  Sorting the names would change that order, so I
>     used a strset instead.

Makes sense, I guess. I wouldn't be surprised if there were users that
intentionally or accidentally rely on this behaviour.

>     This does not catch names that reach a reflog through a worktree
>     prefix, such as "HEAD" and "main-worktree/HEAD", or names that do not
>     exist.  Those are still processed or reported twice.

That's fair -- the change is already an improvement, there's no need for
the improvement to cover all known edge cases.

> diff --git a/builtin/reflog.c b/builtin/reflog.c
> index 42d37a3724..51a3d29505 100644
> --- a/builtin/reflog.c
> +++ b/builtin/reflog.c
> @@ -285,6 +287,11 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix,
>  		if (ref)
>  			refname = ref;
>  
> +		if (!strset_add(&seen, refname)) {
> +			free(ref);
> +			continue;
> +		}

Makes sense. If we cannot add the refname because we've already added
it then we know that we can skip it. I'd add a NEEDSWORK comment though
that mentions that this doesn't work for per-worktree refs so that this
limitation is documented.

Patrick

  reply	other threads:[~2026-12-01 12:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-08  1:22 [PATCH] builtin/reflog: expire --all and named refs in one loop Laveesh Bansal
2026-11-09  9:40 ` Patrick Steinhardt
2026-11-09 16:13   ` Laveesh Bansal
2026-11-10  7:09     ` Patrick Steinhardt
2026-11-09 20:04   ` Junio C Hamano
2026-11-10 15:26 ` [PATCH v2 0/2] builtin/reflog: expire each reflog only once Laveesh Bansal
2026-11-10 15:26   ` [PATCH v2 1/2] builtin/reflog: expire --all and named refs in one loop Laveesh Bansal
2026-11-10 15:26   ` [PATCH v2 2/2] builtin/reflog: expire each reflog only once Laveesh Bansal
2026-11-11 12:42     ` Patrick Steinhardt
2026-11-21 19:54       ` Laveesh Bansal
2026-11-21 19:53   ` [PATCH v3 0/2] " Laveesh Bansal
2026-11-21 19:53     ` [PATCH v3 1/2] builtin/reflog: expire --all and named refs in one loop Laveesh Bansal
2026-11-21 19:53     ` [PATCH v3 2/2] builtin/reflog: expire each reflog only once Laveesh Bansal
2026-12-01 12:09       ` Patrick Steinhardt [this message]
2026-12-01 15:43     ` [PATCH v4 0/2] " Laveesh Bansal
2026-12-01 15:43       ` [PATCH v4 1/2] builtin/reflog: expire --all and named refs in one loop Laveesh Bansal
2026-12-01 15:43       ` [PATCH v4 2/2] builtin/reflog: expire each reflog only once Laveesh Bansal

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=aw64_jhQf4a4JJQX@pks.im \
    --to=ps@pks.im \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=karthik.188@gmail.com \
    --cc=laveeshb@laveeshbansal.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