Skip to content

Commit ffad994

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2ce8254 commit ffad994

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

refs/files-backend.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,8 @@ static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r)
11211121
if (check_refname_format(r->name, 0))
11221122
return;
11231123

1124-
transaction = ref_store_transaction_begin(&refs->base, 0, &err);
1124+
transaction = ref_store_transaction_begin(&refs->base,
1125+
REF_TRANSACTION_SKIP_HOOK, &err);
11251126
if (!transaction)
11261127
goto cleanup;
11271128
ref_transaction_add_update(
@@ -1192,7 +1193,8 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
11921193
struct strbuf err = STRBUF_INIT;
11931194
struct ref_transaction *transaction;
11941195

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);
11961198
if (!transaction)
11971199
return -1;
11981200

t/t1416-ref-transaction-hooks.sh

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,12 @@ test_expect_success 'hook does not get called on packing refs' '
150150
git pack-refs --all &&
151151
152152
# 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).
155154
cat >expect <<-EOF &&
156155
prepared
157156
$ZERO_OID $POST_OID refs/heads/unpacked-ref
158157
committed
159158
$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
168159
EOF
169160
170161
test_cmp expect actual

0 commit comments

Comments
 (0)