refs/reftable: refactor reflog expiry to use reftable backend

Refactor the callback function that expires reflog entries in the reftable backend to use `reftable_backend_read_ref()` instead of accessing the reftable stack directly. This ensures that the function will benefit from the new caching layer that we're about to introduce. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Nov 26, 2024 at 07:42 UTC 96e7cb83b65622c8189678ea52d469786bdf0240
1 file changed +5 -8
refs/reftable-backend.c
+5 -8
@@ -2444,14 +2444,15 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
2444 reftable_be_downcast(ref_store, REF_STORE_WRITE, "reflog_expire");
2445 struct reftable_log_record *logs = NULL;
2446 struct reftable_log_record *rewritten = NULL;
2447 - struct reftable_ref_record ref_record = {0};
2447 struct reftable_iterator it = {0};
2448 struct reftable_addition *add = NULL;
2449 struct reflog_expiry_arg arg = {0};
2450 struct reftable_backend *be;
2451 struct object_id oid = {0};
2452 + struct strbuf referent = STRBUF_INIT;
2453 uint8_t *last_hash = NULL;
2454 size_t logs_nr = 0, logs_alloc = 0, i;
2455 + unsigned int type = 0;
2456 int ret;
2457
2458 if (refs->err < 0)
@@ -2473,12 +2474,9 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
2474 if (ret < 0)
2475 goto done;
2476
2476 - ret = reftable_stack_read_ref(be->stack, refname, &ref_record);
2477 + ret = reftable_backend_read_ref(be, refname, &oid, &referent, &type);
2478 if (ret < 0)
2479 goto done;
2479 - if (reftable_ref_record_val1(&ref_record))
2480 - oidread(&oid, reftable_ref_record_val1(&ref_record),
2481 - ref_store->repo->hash_algo);
2480 prepare_fn(refname, &oid, policy_cb_data);
2481
2482 while (1) {
@@ -2545,8 +2543,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
2543 }
2544 }
2545
2548 - if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash &&
2549 - reftable_ref_record_val1(&ref_record))
2546 + if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash && !is_null_oid(&oid))
2547 oidread(&arg.update_oid, last_hash, ref_store->repo->hash_algo);
2548
2549 arg.refs = refs;
@@ -2571,11 +2568,11 @@ done:
2568 cleanup_fn(policy_cb_data);
2569 assert(ret != REFTABLE_API_ERROR);
2570
2574 - reftable_ref_record_release(&ref_record);
2571 reftable_iterator_destroy(&it);
2572 reftable_addition_destroy(add);
2573 for (i = 0; i < logs_nr; i++)
2574 reftable_log_record_release(&logs[i]);
2575 + strbuf_release(&referent);
2576 free(logs);
2577 free(rewritten);
2578 return ret;