refs/reftable: stop using `the_repository`

Convert the reftable ref backend to stop using `the_repository` in favor of the repo that gets passed in via `struct ref_store`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jul 30, 2024 at 07:23 UTC 9d36dbd1ff6e216abb961bfbc970d266a7826779
1 file changed +26 -25
refs/reftable-backend.c
+26 -25
@@ -1,5 +1,3 @@
1 -#define USE_THE_REPOSITORY_VARIABLE
2 -
1 #include "../git-compat-util.h"
2 #include "../abspath.h"
3 #include "../chdir-notify.h"
@@ -201,7 +199,8 @@ static void fill_reftable_log_record(struct reftable_log_record *log, const stru
199 log->value.update.tz_offset = sign * atoi(tz_begin);
200 }
201
204 -static int read_ref_without_reload(struct reftable_stack *stack,
202 +static int read_ref_without_reload(struct reftable_ref_store *refs,
203 + struct reftable_stack *stack,
204 const char *refname,
205 struct object_id *oid,
206 struct strbuf *referent,
@@ -220,7 +219,7 @@ static int read_ref_without_reload(struct reftable_stack *stack,
219 *type |= REF_ISSYMREF;
220 } else if (reftable_ref_record_val1(&ref)) {
221 oidread(oid, reftable_ref_record_val1(&ref),
223 - the_repository->hash_algo);
222 + refs->base.repo->hash_algo);
223 } else {
224 /* We got a tombstone, which should not happen. */
225 BUG("unhandled reference value type %d", ref.value_type);
@@ -487,16 +486,16 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator)
486 switch (iter->ref.value_type) {
487 case REFTABLE_REF_VAL1:
488 oidread(&iter->oid, iter->ref.value.val1,
490 - the_repository->hash_algo);
489 + refs->base.repo->hash_algo);
490 break;
491 case REFTABLE_REF_VAL2:
492 oidread(&iter->oid, iter->ref.value.val2.value,
494 - the_repository->hash_algo);
493 + refs->base.repo->hash_algo);
494 break;
495 case REFTABLE_REF_SYMREF:
496 if (!refs_resolve_ref_unsafe(&iter->refs->base, iter->ref.refname,
497 RESOLVE_REF_READING, &iter->oid, &flags))
499 - oidclr(&iter->oid, the_repository->hash_algo);
498 + oidclr(&iter->oid, refs->base.repo->hash_algo);
499 break;
500 default:
501 BUG("unhandled reference value type %d", iter->ref.value_type);
@@ -508,7 +507,7 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator)
507 if (check_refname_format(iter->ref.refname, REFNAME_ALLOW_ONELEVEL)) {
508 if (!refname_is_safe(iter->ref.refname))
509 die(_("refname is dangerous: %s"), iter->ref.refname);
511 - oidclr(&iter->oid, the_repository->hash_algo);
510 + oidclr(&iter->oid, refs->base.repo->hash_algo);
511 flags |= REF_BAD_NAME | REF_ISBROKEN;
512 }
513
@@ -551,7 +550,7 @@ static int reftable_ref_iterator_peel(struct ref_iterator *ref_iterator,
550
551 if (iter->ref.value_type == REFTABLE_REF_VAL2) {
552 oidread(peeled, iter->ref.value.val2.target_value,
554 - the_repository->hash_algo);
553 + iter->refs->base.repo->hash_algo);
554 return 0;
555 }
556
@@ -659,7 +658,7 @@ static int reftable_be_read_raw_ref(struct ref_store *ref_store,
658 if (ret)
659 return ret;
660
662 - ret = read_ref_without_reload(stack, refname, oid, referent, type);
661 + ret = read_ref_without_reload(refs, stack, refname, oid, referent, type);
662 if (ret < 0)
663 return ret;
664 if (ret > 0) {
@@ -868,8 +867,8 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
867 goto done;
868 }
869
871 - ret = read_ref_without_reload(stack_for(refs, "HEAD", NULL), "HEAD", &head_oid,
872 - &head_referent, &head_type);
870 + ret = read_ref_without_reload(refs, stack_for(refs, "HEAD", NULL), "HEAD",
871 + &head_oid, &head_referent, &head_type);
872 if (ret < 0)
873 goto done;
874 ret = 0;
@@ -936,7 +935,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
935 string_list_insert(&affected_refnames, new_update->refname);
936 }
937
939 - ret = read_ref_without_reload(stack, rewritten_ref,
938 + ret = read_ref_without_reload(refs, stack, rewritten_ref,
939 &current_oid, &referent, &u->type);
940 if (ret < 0)
941 goto done;
@@ -1500,7 +1499,8 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data)
1499 memcpy(logs[logs_nr].value.update.old_hash, old_ref.value.val1, GIT_MAX_RAWSZ);
1500 logs_nr++;
1501
1503 - ret = read_ref_without_reload(arg->stack, "HEAD", &head_oid, &head_referent, &head_type);
1502 + ret = read_ref_without_reload(arg->refs, arg->stack, "HEAD", &head_oid,
1503 + &head_referent, &head_type);
1504 if (ret < 0)
1505 goto done;
1506 append_head_reflog = (head_type & REF_ISSYMREF) && !strcmp(head_referent.buf, arg->oldname);
@@ -1790,15 +1790,16 @@ static struct ref_iterator *reftable_be_reflog_iterator_begin(struct ref_store *
1790 ref_iterator_select, NULL);
1791 }
1792
1793 -static int yield_log_record(struct reftable_log_record *log,
1793 +static int yield_log_record(struct reftable_ref_store *refs,
1794 + struct reftable_log_record *log,
1795 each_reflog_ent_fn fn,
1796 void *cb_data)
1797 {
1798 struct object_id old_oid, new_oid;
1799 const char *full_committer;
1800
1800 - oidread(&old_oid, log->value.update.old_hash, the_repository->hash_algo);
1801 - oidread(&new_oid, log->value.update.new_hash, the_repository->hash_algo);
1801 + oidread(&old_oid, log->value.update.old_hash, refs->base.repo->hash_algo);
1802 + oidread(&new_oid, log->value.update.new_hash, refs->base.repo->hash_algo);
1803
1804 /*
1805 * When both the old object ID and the new object ID are null
@@ -1841,7 +1842,7 @@ static int reftable_be_for_each_reflog_ent_reverse(struct ref_store *ref_store,
1842 break;
1843 }
1844
1844 - ret = yield_log_record(&log, fn, cb_data);
1845 + ret = yield_log_record(refs, &log, fn, cb_data);
1846 if (ret)
1847 break;
1848 }
@@ -1886,7 +1887,7 @@ static int reftable_be_for_each_reflog_ent(struct ref_store *ref_store,
1887 }
1888
1889 for (i = logs_nr; i--;) {
1889 - ret = yield_log_record(&logs[i], fn, cb_data);
1890 + ret = yield_log_record(refs, &logs[i], fn, cb_data);
1891 if (ret)
1892 goto done;
1893 }
@@ -2200,7 +2201,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
2201 goto done;
2202 if (reftable_ref_record_val1(&ref_record))
2203 oidread(&oid, reftable_ref_record_val1(&ref_record),
2203 - the_repository->hash_algo);
2204 + ref_store->repo->hash_algo);
2205 prepare_fn(refname, &oid, policy_cb_data);
2206
2207 while (1) {
@@ -2216,9 +2217,9 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
2217 }
2218
2219 oidread(&old_oid, log.value.update.old_hash,
2219 - the_repository->hash_algo);
2220 + ref_store->repo->hash_algo);
2221 oidread(&new_oid, log.value.update.new_hash,
2221 - the_repository->hash_algo);
2222 + ref_store->repo->hash_algo);
2223
2224 /*
2225 * Skip over the reflog existence marker. We will add it back
@@ -2250,9 +2251,9 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
2251
2252 *dest = logs[i];
2253 oidread(&old_oid, logs[i].value.update.old_hash,
2253 - the_repository->hash_algo);
2254 + ref_store->repo->hash_algo);
2255 oidread(&new_oid, logs[i].value.update.new_hash,
2255 - the_repository->hash_algo);
2256 + ref_store->repo->hash_algo);
2257
2258 if (should_prune_fn(&old_oid, &new_oid, logs[i].value.update.email,
2259 (timestamp_t)logs[i].value.update.time,
@@ -2269,7 +2270,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
2270
2271 if (flags & EXPIRE_REFLOGS_UPDATE_REF && last_hash &&
2272 reftable_ref_record_val1(&ref_record))
2272 - oidread(&arg.update_oid, last_hash, the_repository->hash_algo);
2273 + oidread(&arg.update_oid, last_hash, ref_store->repo->hash_algo);
2274
2275 arg.refs = refs;
2276 arg.records = rewritten;