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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Mar 12, 2025 at 16:56 UTC 351f592e1d6668f07529d30f05c04725a0a17b59
1 file changed +9 -6
refs/reftable-backend.c
+9 -6
@@ -1069,6 +1069,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
1069 reftable_be_downcast(ref_store, REF_STORE_WRITE|REF_STORE_MAIN, "ref_transaction_prepare");
1070 struct strbuf referent = STRBUF_INIT, head_referent = STRBUF_INIT;
1071 struct string_list affected_refnames = STRING_LIST_INIT_NODUP;
1072 + struct string_list refnames_to_check = STRING_LIST_INIT_NODUP;
1073 struct reftable_transaction_data *tx_data = NULL;
1074 struct reftable_backend *be;
1075 struct object_id head_oid;
@@ -1224,12 +1225,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
1225 * can output a proper error message instead of failing
1226 * at a later point.
1227 */
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);
1229
1230 /*
1231 * There is no need to write the reference deletion
@@ -1379,6 +1375,12 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
1375 }
1376 }
1377
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 +
1384 transaction->backend_data = tx_data;
1385 transaction->state = REF_TRANSACTION_PREPARED;
1386
@@ -1394,6 +1396,7 @@ done:
1396 string_list_clear(&affected_refnames, 0);
1397 strbuf_release(&referent);
1398 strbuf_release(&head_referent);
1399 + string_list_clear(&refnames_to_check, 0);
1400
1401 return ret;
1402 }