From 7a04ab0943caf4cb0eab37df8bfcb474f0d8dc51 Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Wed, 13 Nov 2024 14:16:51 +0100 Subject: [PATCH 1/2] EDITME: cover title for 348-do-not-call-the-reference-transaction-hooks-for-reflogs # Describe the purpose of this series. The information you put here # will be used by the project maintainer to make a decision whether # your patches should be reviewed, and in what priority order. Please be # very detailed and link to any relevant discussions or sites that the # maintainer can review to better understand your proposed changes. If you # only have a single patch in your series, the contents of the cover # letter will be appended to the "under-the-cut" portion of the patch. # Lines starting with # will be removed from the cover letter. You can # use them to add notes or reminders to yourself. If you want to use # markdown headers in your cover letter, start the line with ">#". # You can add trailers to the cover letter. Any email addresses found in # these trailers will be added to the addresses specified/generated # during the b4 send stage. You can also run "b4 prep --auto-to-cc" to # auto-populate the To: and Cc: trailers based on the code being # modified. To: git@vger.kernel.org Signed-off-by: Karthik Nayak --- b4-submit-tracking --- # This section is used internally by b4 prep for tracking purposes. { "series": { "revision": 1, "change-id": "20241113-348-do-not-call-the-reference-transaction-hooks-for-reflogs-bb471a0b192f", "prefixes": [] } } -- GitLab From 914ec188a3c0cff5aca147c204225f47805a3506 Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Wed, 13 Nov 2024 14:27:25 +0100 Subject: [PATCH 2/2] refs: don't invoke reference-transaction hook for reflogs 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: - The hook is designed to work with reference updates and reflogs updates are different. - The hook doesn't have the required information to distinguish reference updates from reflog updates. This is particularly evident when the default branch (pointed by HEAD) is updated, we see that the hook also receives information about HEAD being changed. In reality, we only add a reflog update for HEAD, while HEAD's values remains the same. Signed-off-by: Karthik Nayak --- refs.c | 3 +++ t/t1416-ref-transaction-hooks.sh | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/refs.c b/refs.c index 5f729ed4124..7866cd7378d 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 5a812ca3c0b..262efec60e8 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 && -- GitLab