Git development
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Karthik Nayak <karthik.188@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/4] refs/reftable: don't write new table when expire is a no-op
Date: Wed, 18 Nov 2026 13:05:40 +0100	[thread overview]
Message-ID: <av2UlJLpSDOPKbua@pks.im> (raw)
In-Reply-To: <CAOLa=ZQGJkyVY=e94hJVmLa2fuPVUfC3uFRsQTeoa95sUe3UcA@mail.gmail.com>

On Wed, Nov 18, 2026 at 03:33:04AM -0800, Karthik Nayak wrote:
> Patrick Steinhardt <ps@pks.im> writes:
> > diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
> > index 4216a18684d..e2027bb9c02 100644
> > --- a/refs/reftable-backend.c
> > +++ b/refs/reftable-backend.c
> > @@ -2696,17 +2697,25 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
> >  				    logs[i].value.update.message,
> >  				    policy_cb_data)) {
> >  			dest->value_type = REFTABLE_LOG_DELETION;
> > +			has_changes = true;
> >  		} else {
> > -			if ((flags & EXPIRE_REFLOGS_REWRITE) && last_hash)
> > +			if ((flags & EXPIRE_REFLOGS_REWRITE) && last_hash &&
> > +			    memcmp(dest->value.update.old_hash, last_hash,
> > +				   ref_store->repo->hash_algo->rawsz)) {
> >  				memcpy(dest->value.update.old_hash, last_hash, GIT_MAX_RAWSZ);
> 
> We can skip this second copy.
> 
> > +				has_changes = true;
> > +			}
> >  			last_hash = logs[i].value.update.new_hash;
> >  		}
> >  	}
> >
> > -	if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash && !is_null_oid(&oid))
> > +	if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash && !is_null_oid(&oid)) {
> >  		oidread(&arg.update_oid, last_hash, ref_store->repo->hash_algo);
> > +		if (!oideq(&arg.update_oid, &oid))
> 
> We now check if its changed, makes sense.
> 
> > +			has_changes = true;
> > +	}
> >
> > -	if ((flags & EXPIRE_REFLOGS_DRY_RUN)) {
> > +	if (!has_changes || (flags & EXPIRE_REFLOGS_DRY_RUN)) {
> >  		ret = 0;
> >  		goto done;
> >  	}
> 
> Nit: it would be nice to mention that we exit early to skip writing any
> new tables.

Hm. I thought that this was obvious from the code itself, so I didn't
think there was much value in adding a comment. I wouldn't really know
what information to put here that doesn't just repeat the code exactly.

> > diff --git a/t/t0610-reftable-basics.sh b/t/t0610-reftable-basics.sh
> > index a7027458395..d808f1887f6 100755
> > --- a/t/t0610-reftable-basics.sh
> > +++ b/t/t0610-reftable-basics.sh
> > @@ -912,6 +912,36 @@ test_expect_success 'reflog: expiry empties reflog' '
> >  	)
> >  '
> >
> > +test_expect_success 'reflog: expiry without changes does not write tables' '
> > +	test_when_finished "rm -rf repo" &&
> > +	git init repo &&
> > +	(
> > +		cd repo &&
> > +
> > +		test_commit A &&
> > +		test_commit B &&
> > +		test_commit C &&
> > +		cp .git/reftable/tables.list expect &&
> > +
> > +		git reflog expire --all --expire=never --expire-unreachable=never &&
> > +		test_cmp expect .git/reftable/tables.list &&
> > +
> > +		git reflog expire --all --rewrite \
> > +			--expire=never --expire-unreachable=never &&
> > +		test_cmp expect .git/reftable/tables.list &&
> > +
> > +		git reflog expire --all --updateref \
> > +			--expire=never --expire-unreachable=never &&
> > +		test_cmp expect .git/reftable/tables.list &&
> > +
> > +		git reflog expire --all --dry-run --expire=all &&
> > +		test_cmp expect .git/reftable/tables.list &&
> > +
> > +		git reflog expire --all --expire=all &&
> > +		! test_cmp expect .git/reftable/tables.list
> > +	)
> > +'
> 
> Nice. Could we add a similar test for the previous patch too?

This test also exercises the preceding patch as we use "--dry-run" here.
I could've split this up across the two commits, but I was lazy and just
added it here.

Patrick

  reply	other threads:[~2026-11-18 12:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  9:30 [PATCH 0/4] Improve performance of reflog expiration Patrick Steinhardt
2026-11-18  9:31 ` [PATCH 1/4] refs/reftable: don't write new table on dry-run expire Patrick Steinhardt
2026-11-18 11:28   ` Karthik Nayak
2026-11-18 12:05     ` Patrick Steinhardt
2026-11-18 16:51   ` Junio C Hamano
2026-11-18  9:31 ` [PATCH 2/4] refs/reftable: don't write new table when expire is a no-op Patrick Steinhardt
2026-11-18 11:33   ` Karthik Nayak
2026-11-18 12:05     ` Patrick Steinhardt [this message]
2026-11-18 15:34   ` Toon Claes
2026-11-18  9:31 ` [PATCH 3/4] builtin/maintenance: only consider `gc.reflogExpire` for "--auto" Patrick Steinhardt
2026-11-18 15:52   ` Toon Claes
2026-11-18  9:31 ` [PATCH 4/4] Documentation/config: fix typo in "maintenance.reflog-expire.auto" Patrick Steinhardt
2026-11-18 15:54   ` Toon Claes
2026-11-18 15:56 ` [PATCH 0/4] Improve performance of reflog expiration Toon Claes

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=av2UlJLpSDOPKbua@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=karthik.188@gmail.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