All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Karthik Nayak <karthik.188@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] refs: don't invoke reference-transaction hook for reflogs
Date: Fri, 15 Nov 2024 08:48:12 +0900	[thread overview]
Message-ID: <xmqqldxl5qdf.fsf@gitster.g> (raw)
In-Reply-To: <20241114-348-do-not-call-the-reference-transaction-hooks-for-reflogs-v1-1-ece7260ee3c1@gmail.com> (Karthik Nayak's message of "Thu, 14 Nov 2024 10:58:35 +0100")

Karthik Nayak <karthik.188@gmail.com> writes:

> The reference-transaction hook is invoked whenever there is a reference
> update being performed. For each state of the transaction, we iterate
> over the updates present and pass this information to the hook.
>
> The `ref_update` structure is used to hold these updates within a
> `transaction`. We use the same structure for holding reflog updates too.
> Which means that the reference transaction hook is also obtaining
> information about a reflog update. This is a bug, since:

Yeah, the transaction hook is deciding how the values of refs should
(or should not) change, and its decisions should be sufficient to
determine what should happen to corresponding reflog updates.  If an
update to the 'main' branch is let through, that update should result
in a new reflog record for that branch.  If such an update is blocked,
there is no update to the branch, and a reflog record would not be
created for such an update that did not happen.

One thing that the above argument does not capture is "stash",
especially "stash drop".  The way the subsystem abuses reflog
disconnects ref updates from reflog updates, so there _is_ a use
case for hooks to interfere with reflog updates.

However, the existing ref update transaction hook does not have to
be the mechanism to vet "git stash" operation.  If we really needed
to, we could add reflog transaction hook for that later, outside the
scope of this fix.

> diff --git a/refs.c b/refs.c
> index 5f729ed4124f7fe8fa9df7fd1f1ce951abefc585..7866cd7378da95b3cdd508500633958802d166d0 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -2185,6 +2185,9 @@ static int run_transaction_hook(struct ref_transaction *transaction,
>  	for (i = 0; i < transaction->nr; i++) {
>  		struct ref_update *update = transaction->updates[i];
>  
> +		if (update->flags & REF_LOG_ONLY)
> +			continue;
> +
>  		strbuf_reset(&buf);
>  
>  		if (!(update->flags & REF_HAVE_OLD))
> diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh
> index 5a812ca3c0b5d3f7de60dc999de6aafaf1f384a6..262efec60e85b7e00def18cce15d5ce15897836d 100755
> --- a/t/t1416-ref-transaction-hooks.sh
> +++ b/t/t1416-ref-transaction-hooks.sh
> @@ -53,7 +53,6 @@ test_expect_success 'hook gets all queued updates in prepared state' '
>  		fi
>  	EOF
>  	cat >expect <<-EOF &&
> -		$ZERO_OID $POST_OID HEAD
>  		$ZERO_OID $POST_OID refs/heads/main
>  	EOF
>  	git update-ref HEAD POST <<-EOF &&
> @@ -76,7 +75,6 @@ test_expect_success 'hook gets all queued updates in committed state' '
>  		fi
>  	EOF
>  	cat >expect <<-EOF &&
> -		$ZERO_OID $POST_OID HEAD
>  		$ZERO_OID $POST_OID refs/heads/main
>  	EOF
>  	git update-ref HEAD POST &&
>
> ---
> base-commit: b31fb630c0fc6869a33ed717163e8a1210460d94
> change-id: 20241113-348-do-not-call-the-reference-transaction-hooks-for-reflogs-bb471a0b192f
>
> Best regards,

  reply	other threads:[~2024-11-14 23:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-14  9:58 [PATCH] refs: don't invoke reference-transaction hook for reflogs Karthik Nayak
2024-11-14 23:48 ` Junio C Hamano [this message]
2024-11-15  7:01   ` Patrick Steinhardt

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=xmqqldxl5qdf.fsf@gitster.g \
    --to=gitster@pobox.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.