Skip to content

Commit c6da34a

Browse files
committed
Revert "Merge branch 'ps/avoid-unnecessary-hook-invocation-with-packed-refs'"
This reverts commit 991b4d4, reversing changes made to bcd020f.
1 parent 1ac7422 commit c6da34a

File tree

8 files changed

+19
-114
lines changed

8 files changed

+19
-114
lines changed

refs.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,
794794
struct ref_transaction *transaction;
795795
struct strbuf err = STRBUF_INIT;
796796

797-
transaction = ref_store_transaction_begin(refs, 0, &err);
797+
transaction = ref_store_transaction_begin(refs, &err);
798798
if (!transaction ||
799799
ref_transaction_delete(transaction, refname, old_oid,
800800
flags, msg, &err) ||
@@ -999,21 +999,19 @@ int read_ref_at(struct ref_store *refs, const char *refname,
999999
}
10001000

10011001
struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
1002-
unsigned int flags,
10031002
struct strbuf *err)
10041003
{
10051004
struct ref_transaction *tr;
10061005
assert(err);
10071006

10081007
CALLOC_ARRAY(tr, 1);
10091008
tr->ref_store = refs;
1010-
tr->flags = flags;
10111009
return tr;
10121010
}
10131011

10141012
struct ref_transaction *ref_transaction_begin(struct strbuf *err)
10151013
{
1016-
return ref_store_transaction_begin(get_main_ref_store(the_repository), 0, err);
1014+
return ref_store_transaction_begin(get_main_ref_store(the_repository), err);
10171015
}
10181016

10191017
void ref_transaction_free(struct ref_transaction *transaction)
@@ -1152,7 +1150,7 @@ int refs_update_ref(struct ref_store *refs, const char *msg,
11521150
struct strbuf err = STRBUF_INIT;
11531151
int ret = 0;
11541152

1155-
t = ref_store_transaction_begin(refs, 0, &err);
1153+
t = ref_store_transaction_begin(refs, &err);
11561154
if (!t ||
11571155
ref_transaction_update(t, refname, new_oid, old_oid, flags, msg,
11581156
&err) ||
@@ -2074,9 +2072,6 @@ static int run_transaction_hook(struct ref_transaction *transaction,
20742072
const char *hook;
20752073
int ret = 0, i;
20762074

2077-
if (transaction->flags & REF_TRANSACTION_SKIP_HOOK)
2078-
return 0;
2079-
20802075
hook = find_hook("reference-transaction");
20812076
if (!hook)
20822077
return ret;

refs.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ char *repo_default_branch_name(struct repository *r, int quiet);
229229
* struct strbuf err = STRBUF_INIT;
230230
* int ret = 0;
231231
*
232-
* transaction = ref_store_transaction_begin(refs, 0, &err);
232+
* transaction = ref_store_transaction_begin(refs, &err);
233233
* if (!transaction ||
234234
* ref_transaction_update(...) ||
235235
* ref_transaction_create(...) ||
@@ -566,17 +566,11 @@ enum action_on_err {
566566
UPDATE_REFS_QUIET_ON_ERR
567567
};
568568

569-
/*
570-
* Skip executing the reference-transaction hook.
571-
*/
572-
#define REF_TRANSACTION_SKIP_HOOK (1 << 0)
573-
574569
/*
575570
* Begin a reference transaction. The reference transaction must
576571
* be freed by calling ref_transaction_free().
577572
*/
578573
struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
579-
unsigned int flags,
580574
struct strbuf *err);
581575
struct ref_transaction *ref_transaction_begin(struct strbuf *err);
582576

refs/files-backend.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,8 +1136,7 @@ static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r)
11361136
if (check_refname_format(r->name, 0))
11371137
return;
11381138

1139-
transaction = ref_store_transaction_begin(&refs->base,
1140-
REF_TRANSACTION_SKIP_HOOK, &err);
1139+
transaction = ref_store_transaction_begin(&refs->base, &err);
11411140
if (!transaction)
11421141
goto cleanup;
11431142
ref_transaction_add_update(
@@ -1208,8 +1207,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
12081207
struct strbuf err = STRBUF_INIT;
12091208
struct ref_transaction *transaction;
12101209

1211-
transaction = ref_store_transaction_begin(refs->packed_ref_store,
1212-
REF_TRANSACTION_SKIP_HOOK, &err);
1210+
transaction = ref_store_transaction_begin(refs->packed_ref_store, &err);
12131211
if (!transaction)
12141212
return -1;
12151213

@@ -1266,7 +1264,6 @@ static int files_delete_refs(struct ref_store *ref_store, const char *msg,
12661264
{
12671265
struct files_ref_store *refs =
12681266
files_downcast(ref_store, REF_STORE_WRITE, "delete_refs");
1269-
struct ref_transaction *transaction = NULL;
12701267
struct strbuf err = STRBUF_INIT;
12711268
int i, result = 0;
12721269

@@ -1276,15 +1273,10 @@ static int files_delete_refs(struct ref_store *ref_store, const char *msg,
12761273
if (packed_refs_lock(refs->packed_ref_store, 0, &err))
12771274
goto error;
12781275

1279-
transaction = ref_store_transaction_begin(refs->packed_ref_store,
1280-
REF_TRANSACTION_SKIP_HOOK, &err);
1281-
if (!transaction)
1282-
goto error;
1283-
1284-
result = packed_refs_delete_refs(refs->packed_ref_store,
1285-
transaction, msg, refnames, flags);
1286-
if (result)
1276+
if (refs_delete_refs(refs->packed_ref_store, msg, refnames, flags)) {
1277+
packed_refs_unlock(refs->packed_ref_store);
12871278
goto error;
1279+
}
12881280

12891281
packed_refs_unlock(refs->packed_ref_store);
12901282

@@ -1295,7 +1287,6 @@ static int files_delete_refs(struct ref_store *ref_store, const char *msg,
12951287
result |= error(_("could not remove reference %s"), refname);
12961288
}
12971289

1298-
ref_transaction_free(transaction);
12991290
strbuf_release(&err);
13001291
return result;
13011292

@@ -1312,7 +1303,6 @@ static int files_delete_refs(struct ref_store *ref_store, const char *msg,
13121303
else
13131304
error(_("could not delete references: %s"), err.buf);
13141305

1315-
ref_transaction_free(transaction);
13161306
strbuf_release(&err);
13171307
return -1;
13181308
}
@@ -2784,8 +2774,7 @@ static int files_transaction_prepare(struct ref_store *ref_store,
27842774
*/
27852775
if (!packed_transaction) {
27862776
packed_transaction = ref_store_transaction_begin(
2787-
refs->packed_ref_store,
2788-
REF_TRANSACTION_SKIP_HOOK, err);
2777+
refs->packed_ref_store, err);
27892778
if (!packed_transaction) {
27902779
ret = TRANSACTION_GENERIC_ERROR;
27912780
goto cleanup;
@@ -3056,8 +3045,7 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
30563045
&affected_refnames))
30573046
BUG("initial ref transaction called with existing refs");
30583047

3059-
packed_transaction = ref_store_transaction_begin(refs->packed_ref_store,
3060-
REF_TRANSACTION_SKIP_HOOK, err);
3048+
packed_transaction = ref_store_transaction_begin(refs->packed_ref_store, err);
30613049
if (!packed_transaction) {
30623050
ret = TRANSACTION_GENERIC_ERROR;
30633051
goto cleanup;

refs/packed-backend.c

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,10 +1522,15 @@ static int packed_initial_transaction_commit(struct ref_store *ref_store,
15221522
static int packed_delete_refs(struct ref_store *ref_store, const char *msg,
15231523
struct string_list *refnames, unsigned int flags)
15241524
{
1525+
struct packed_ref_store *refs =
1526+
packed_downcast(ref_store, REF_STORE_WRITE, "delete_refs");
15251527
struct strbuf err = STRBUF_INIT;
15261528
struct ref_transaction *transaction;
1529+
struct string_list_item *item;
15271530
int ret;
15281531

1532+
(void)refs; /* We need the check above, but don't use the variable */
1533+
15291534
if (!refnames->nr)
15301535
return 0;
15311536

@@ -1535,30 +1540,10 @@ static int packed_delete_refs(struct ref_store *ref_store, const char *msg,
15351540
* updates into a single transaction.
15361541
*/
15371542

1538-
transaction = ref_store_transaction_begin(ref_store, 0, &err);
1543+
transaction = ref_store_transaction_begin(ref_store, &err);
15391544
if (!transaction)
15401545
return -1;
15411546

1542-
ret = packed_refs_delete_refs(ref_store, transaction,
1543-
msg, refnames, flags);
1544-
1545-
ref_transaction_free(transaction);
1546-
return ret;
1547-
}
1548-
1549-
int packed_refs_delete_refs(struct ref_store *ref_store,
1550-
struct ref_transaction *transaction,
1551-
const char *msg,
1552-
struct string_list *refnames,
1553-
unsigned int flags)
1554-
{
1555-
struct strbuf err = STRBUF_INIT;
1556-
struct string_list_item *item;
1557-
int ret;
1558-
1559-
/* Assert that the ref store refers to a packed backend. */
1560-
packed_downcast(ref_store, REF_STORE_WRITE, "delete_refs");
1561-
15621547
for_each_string_list_item(item, refnames) {
15631548
if (ref_transaction_delete(transaction, item->string, NULL,
15641549
flags, msg, &err)) {
@@ -1578,6 +1563,7 @@ int packed_refs_delete_refs(struct ref_store *ref_store,
15781563
error(_("could not delete references: %s"), err.buf);
15791564
}
15801565

1566+
ref_transaction_free(transaction);
15811567
strbuf_release(&err);
15821568
return ret;
15831569
}

refs/packed-backend.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
struct repository;
55
struct ref_transaction;
6-
struct string_list;
76

87
/*
98
* Support for storing references in a `packed-refs` file.
@@ -28,12 +27,6 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
2827
void packed_refs_unlock(struct ref_store *ref_store);
2928
int packed_refs_is_locked(struct ref_store *ref_store);
3029

31-
int packed_refs_delete_refs(struct ref_store *ref_store,
32-
struct ref_transaction *transaction,
33-
const char *msg,
34-
struct string_list *refnames,
35-
unsigned int flags);
36-
3730
/*
3831
* Return true if `transaction` really needs to be carried out against
3932
* the specified packed_ref_store, or false if it can be skipped

refs/refs-internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ struct ref_transaction {
213213
size_t nr;
214214
enum ref_transaction_state state;
215215
void *backend_data;
216-
unsigned int flags;
217216
};
218217

219218
/*

sequencer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3584,7 +3584,7 @@ static int do_label(struct repository *r, const char *name, int len)
35843584
strbuf_addf(&ref_name, "refs/rewritten/%.*s", len, name);
35853585
strbuf_addf(&msg, "rebase (label) '%.*s'", len, name);
35863586

3587-
transaction = ref_store_transaction_begin(refs, 0, &err);
3587+
transaction = ref_store_transaction_begin(refs, &err);
35883588
if (!transaction) {
35893589
error("%s", err.buf);
35903590
ret = -1;

t/t1416-ref-transaction-hooks.sh

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -133,54 +133,4 @@ test_expect_success 'interleaving hook calls succeed' '
133133
test_cmp expect target-repo.git/actual
134134
'
135135

136-
test_expect_success 'hook does not get called on packing refs' '
137-
# Pack references first such that we are in a known state.
138-
git pack-refs --all &&
139-
140-
test_hook reference-transaction <<-\EOF &&
141-
echo "$@" >>actual
142-
cat >>actual
143-
EOF
144-
rm -f actual &&
145-
146-
git update-ref refs/heads/unpacked-ref $POST_OID &&
147-
git pack-refs --all &&
148-
149-
# We only expect a single hook invocation, which is the call to
150-
# git-update-ref(1).
151-
cat >expect <<-EOF &&
152-
prepared
153-
$ZERO_OID $POST_OID refs/heads/unpacked-ref
154-
committed
155-
$ZERO_OID $POST_OID refs/heads/unpacked-ref
156-
EOF
157-
158-
test_cmp expect actual
159-
'
160-
161-
test_expect_success 'deleting packed ref calls hook once' '
162-
# Create a reference and pack it.
163-
git update-ref refs/heads/to-be-deleted $POST_OID &&
164-
git pack-refs --all &&
165-
166-
test_hook reference-transaction <<-\EOF &&
167-
echo "$@" >>actual
168-
cat >>actual
169-
EOF
170-
rm -f actual &&
171-
172-
git update-ref -d refs/heads/to-be-deleted $POST_OID &&
173-
174-
# We only expect a single hook invocation, which is the logical
175-
# deletion.
176-
cat >expect <<-EOF &&
177-
prepared
178-
$POST_OID $ZERO_OID refs/heads/to-be-deleted
179-
committed
180-
$POST_OID $ZERO_OID refs/heads/to-be-deleted
181-
EOF
182-
183-
test_cmp expect actual
184-
'
185-
186136
test_done

0 commit comments

Comments
 (0)