Skip to content

Commit fbe73f6

Browse files
pks-tgitster
authored andcommitted
refs: allow passing flags when beginning transactions
We do not currently have any flags when creating reference transactions, but we'll add one to disable execution of the reference transaction hook in some cases. Allow passing flags to `ref_store_transaction_begin()` to prepare for this change. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 69840cc commit fbe73f6

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

refs.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,
800800
struct ref_transaction *transaction;
801801
struct strbuf err = STRBUF_INIT;
802802

803-
transaction = ref_store_transaction_begin(refs, &err);
803+
transaction = ref_store_transaction_begin(refs, 0, &err);
804804
if (!transaction ||
805805
ref_transaction_delete(transaction, refname, old_oid,
806806
flags, msg, &err) ||
@@ -1005,19 +1005,21 @@ int read_ref_at(struct ref_store *refs, const char *refname,
10051005
}
10061006

10071007
struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
1008+
unsigned int flags,
10081009
struct strbuf *err)
10091010
{
10101011
struct ref_transaction *tr;
10111012
assert(err);
10121013

10131014
CALLOC_ARRAY(tr, 1);
10141015
tr->ref_store = refs;
1016+
tr->flags = flags;
10151017
return tr;
10161018
}
10171019

10181020
struct ref_transaction *ref_transaction_begin(struct strbuf *err)
10191021
{
1020-
return ref_store_transaction_begin(get_main_ref_store(the_repository), err);
1022+
return ref_store_transaction_begin(get_main_ref_store(the_repository), 0, err);
10211023
}
10221024

10231025
void ref_transaction_free(struct ref_transaction *transaction)
@@ -1156,7 +1158,7 @@ int refs_update_ref(struct ref_store *refs, const char *msg,
11561158
struct strbuf err = STRBUF_INIT;
11571159
int ret = 0;
11581160

1159-
t = ref_store_transaction_begin(refs, &err);
1161+
t = ref_store_transaction_begin(refs, 0, &err);
11601162
if (!t ||
11611163
ref_transaction_update(t, refname, new_oid, old_oid, flags, msg,
11621164
&err) ||

refs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ char *repo_default_branch_name(struct repository *r, int quiet);
231231
* struct strbuf err = STRBUF_INIT;
232232
* int ret = 0;
233233
*
234-
* transaction = ref_store_transaction_begin(refs, &err);
234+
* transaction = ref_store_transaction_begin(refs, 0, &err);
235235
* if (!transaction ||
236236
* ref_transaction_update(...) ||
237237
* ref_transaction_create(...) ||
@@ -573,6 +573,7 @@ enum action_on_err {
573573
* be freed by calling ref_transaction_free().
574574
*/
575575
struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
576+
unsigned int flags,
576577
struct strbuf *err);
577578
struct ref_transaction *ref_transaction_begin(struct strbuf *err);
578579

refs/files-backend.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ 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, &err);
1124+
transaction = ref_store_transaction_begin(&refs->base, 0, &err);
11251125
if (!transaction)
11261126
goto cleanup;
11271127
ref_transaction_add_update(
@@ -1192,7 +1192,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
11921192
struct strbuf err = STRBUF_INIT;
11931193
struct ref_transaction *transaction;
11941194

1195-
transaction = ref_store_transaction_begin(refs->packed_ref_store, &err);
1195+
transaction = ref_store_transaction_begin(refs->packed_ref_store, 0, &err);
11961196
if (!transaction)
11971197
return -1;
11981198

@@ -1259,7 +1259,7 @@ static int files_delete_refs(struct ref_store *ref_store, const char *msg,
12591259
if (packed_refs_lock(refs->packed_ref_store, 0, &err))
12601260
goto error;
12611261

1262-
transaction = ref_store_transaction_begin(refs->packed_ref_store, &err);
1262+
transaction = ref_store_transaction_begin(refs->packed_ref_store, 0, &err);
12631263
if (!transaction)
12641264
goto error;
12651265

@@ -2774,7 +2774,7 @@ static int files_transaction_prepare(struct ref_store *ref_store,
27742774
*/
27752775
if (!packed_transaction) {
27762776
packed_transaction = ref_store_transaction_begin(
2777-
refs->packed_ref_store, err);
2777+
refs->packed_ref_store, 0, err);
27782778
if (!packed_transaction) {
27792779
ret = TRANSACTION_GENERIC_ERROR;
27802780
goto cleanup;
@@ -3045,7 +3045,7 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
30453045
&affected_refnames))
30463046
BUG("initial ref transaction called with existing refs");
30473047

3048-
packed_transaction = ref_store_transaction_begin(refs->packed_ref_store, err);
3048+
packed_transaction = ref_store_transaction_begin(refs->packed_ref_store, 0, err);
30493049
if (!packed_transaction) {
30503050
ret = TRANSACTION_GENERIC_ERROR;
30513051
goto cleanup;

refs/packed-backend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ static int packed_delete_refs(struct ref_store *ref_store, const char *msg,
15351535
* updates into a single transaction.
15361536
*/
15371537

1538-
transaction = ref_store_transaction_begin(ref_store, &err);
1538+
transaction = ref_store_transaction_begin(ref_store, 0, &err);
15391539
if (!transaction)
15401540
return -1;
15411541

refs/refs-internal.h

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

218219
/*

sequencer.c

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

3591-
transaction = ref_store_transaction_begin(refs, &err);
3591+
transaction = ref_store_transaction_begin(refs, 0, &err);
35923592
if (!transaction) {
35933593
error("%s", err.buf);
35943594
ret = -1;

0 commit comments

Comments
 (0)