Skip to content

Commit 351f592

Browse files
pks-tgitster
authored andcommitted
refs/reftable: batch refname availability checks
Refactor the "reftable" backend to batch the availability check for refnames. This does not yet have an effect on performance as `refs_verify_refnames_available()` effectively still performs the availability check for each refname individually. But this will be optimized in subsequent commits, where we learn to optimize some parts of the logic when checking multiple refnames for availability. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2ff58de commit 351f592

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

refs/reftable-backend.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
10691069
reftable_be_downcast(ref_store, REF_STORE_WRITE|REF_STORE_MAIN, "ref_transaction_prepare");
10701070
struct strbuf referent = STRBUF_INIT, head_referent = STRBUF_INIT;
10711071
struct string_list affected_refnames = STRING_LIST_INIT_NODUP;
1072+
struct string_list refnames_to_check = STRING_LIST_INIT_NODUP;
10721073
struct reftable_transaction_data *tx_data = NULL;
10731074
struct reftable_backend *be;
10741075
struct object_id head_oid;
@@ -1224,12 +1225,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
12241225
* can output a proper error message instead of failing
12251226
* at a later point.
12261227
*/
1227-
ret = refs_verify_refname_available(ref_store, u->refname,
1228-
&affected_refnames, NULL,
1229-
transaction->flags & REF_TRANSACTION_FLAG_INITIAL,
1230-
err);
1231-
if (ret < 0)
1232-
goto done;
1228+
string_list_append(&refnames_to_check, u->refname);
12331229

12341230
/*
12351231
* There is no need to write the reference deletion
@@ -1379,6 +1375,12 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
13791375
}
13801376
}
13811377

1378+
ret = refs_verify_refnames_available(ref_store, &refnames_to_check, &affected_refnames, NULL,
1379+
transaction->flags & REF_TRANSACTION_FLAG_INITIAL,
1380+
err);
1381+
if (ret < 0)
1382+
goto done;
1383+
13821384
transaction->backend_data = tx_data;
13831385
transaction->state = REF_TRANSACTION_PREPARED;
13841386

@@ -1394,6 +1396,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
13941396
string_list_clear(&affected_refnames, 0);
13951397
strbuf_release(&referent);
13961398
strbuf_release(&head_referent);
1399+
string_list_clear(&refnames_to_check, 0);
13971400

13981401
return ret;
13991402
}

0 commit comments

Comments
 (0)