]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs/reftable: refactor reflog expiry to use reftable backend
authorPatrick Steinhardt <ps@pks.im>
Tue, 26 Nov 2024 06:42:58 +0000 (07:42 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 26 Nov 2024 08:18:37 +0000 (17:18 +0900)
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>
refs/reftable-backend.c

index 2d06620ac8b1b7f07783cd5873dbe0fe67b84bd6..b6638d43028d11ae7621dcd4e0dbf1d3174743b7 100644 (file)
@@ -2444,14 +2444,15 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
                reftable_be_downcast(ref_store, REF_STORE_WRITE, "reflog_expire");
        struct reftable_log_record *logs = NULL;
        struct reftable_log_record *rewritten = NULL;
-       struct reftable_ref_record ref_record = {0};
        struct reftable_iterator it = {0};
        struct reftable_addition *add = NULL;
        struct reflog_expiry_arg arg = {0};
        struct reftable_backend *be;
        struct object_id oid = {0};
+       struct strbuf referent = STRBUF_INIT;
        uint8_t *last_hash = NULL;
        size_t logs_nr = 0, logs_alloc = 0, i;
+       unsigned int type = 0;
        int ret;
 
        if (refs->err < 0)
@@ -2473,12 +2474,9 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
        if (ret < 0)
                goto done;
 
-       ret = reftable_stack_read_ref(be->stack, refname, &ref_record);
+       ret = reftable_backend_read_ref(be, refname, &oid, &referent, &type);
        if (ret < 0)
                goto done;
-       if (reftable_ref_record_val1(&ref_record))
-               oidread(&oid, reftable_ref_record_val1(&ref_record),
-                       ref_store->repo->hash_algo);
        prepare_fn(refname, &oid, policy_cb_data);
 
        while (1) {
@@ -2545,8 +2543,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
                }
        }
 
-       if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash &&
-           reftable_ref_record_val1(&ref_record))
+       if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash && !is_null_oid(&oid))
                oidread(&arg.update_oid, last_hash, ref_store->repo->hash_algo);
 
        arg.refs = refs;
@@ -2571,11 +2568,11 @@ done:
                cleanup_fn(policy_cb_data);
        assert(ret != REFTABLE_API_ERROR);
 
-       reftable_ref_record_release(&ref_record);
        reftable_iterator_destroy(&it);
        reftable_addition_destroy(add);
        for (i = 0; i < logs_nr; i++)
                reftable_log_record_release(&logs[i]);
+       strbuf_release(&referent);
        free(logs);
        free(rewritten);
        return ret;