refs: do not execute reference-transaction hook on packing refs
The reference-transaction hook is supposed to track logical changes to references, but it currently also gets executed when packing refs in a repository. This is unexpected and ultimately not all that useful: packing refs is not supposed to result in any user-visible change to the refs' state, and it ultimately is an implementation detail of how refs stores work. Fix this excessive execution of the hook when packing refs. Reported-by: Waleed Khan <me@waleedkhan.name> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Jan 17, 2022 at 09:12 UTC
ffad9941383465553bf26d88050f3243726f30df
2 files changed
+5
-12
refs/files-backend.c
+4
-2
@@ -1121,7 +1121,8 @@ static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r)
1121
if (check_refname_format(r->name, 0))
1122
return;
1123
1124
- transaction = ref_store_transaction_begin(&refs->base, 0, &err);
1124
+ transaction = ref_store_transaction_begin(&refs->base,
1125
+ REF_TRANSACTION_SKIP_HOOK, &err);
1126
if (!transaction)
1127
goto cleanup;
1128
ref_transaction_add_update(
@@ -1192,7 +1193,8 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
1193
struct strbuf err = STRBUF_INIT;
1194
struct ref_transaction *transaction;
1195
1195
- transaction = ref_store_transaction_begin(refs->packed_ref_store, 0, &err);
1196
+ transaction = ref_store_transaction_begin(refs->packed_ref_store,
1197
+ REF_TRANSACTION_SKIP_HOOK, &err);
1198
if (!transaction)
1199
return -1;
1200
t/t1416-ref-transaction-hooks.sh
+1
-10
@@ -150,21 +150,12 @@ test_expect_success 'hook does not get called on packing refs' '
150
git pack-refs --all &&
151
152
# We only expect a single hook invocation, which is the call to
153
- # git-update-ref(1). But currently, packing refs will also trigger the
154
- # hook.
153
+ # git-update-ref(1).
154
cat >expect <<-EOF &&
155
prepared
156
$ZERO_OID $POST_OID refs/heads/unpacked-ref
157
committed
158
$ZERO_OID $POST_OID refs/heads/unpacked-ref
160
- prepared
161
- $ZERO_OID $POST_OID refs/heads/unpacked-ref
162
- committed
163
- $ZERO_OID $POST_OID refs/heads/unpacked-ref
164
- prepared
165
- $POST_OID $ZERO_OID refs/heads/unpacked-ref
166
- committed
167
- $POST_OID $ZERO_OID refs/heads/unpacked-ref
159
EOF
160
161
test_cmp expect actual