refs/reftable: figure out hash via `reftable_stack`

The function `read_ref_without_reload()` accepts a ref store as input only so that we can figure out the hash function used by it. This is duplicate information though because the reftable stack knows about its hash function, too. Drop the superfluous parameter to simplify the calling convention a bit. 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 3ec8022bb0bd20da40e9d4a173331ac864d1bd28
1 file changed +19 -7
refs/reftable-backend.c
+19 -7
@@ -243,8 +243,7 @@ static void fill_reftable_log_record(struct reftable_log_record *log, const stru
243 log->value.update.tz_offset = sign * atoi(tz_begin);
244 }
245
246 -static int read_ref_without_reload(struct reftable_ref_store *refs,
247 - struct reftable_stack *stack,
246 +static int read_ref_without_reload(struct reftable_stack *stack,
247 const char *refname,
248 struct object_id *oid,
249 struct strbuf *referent,
@@ -262,8 +261,21 @@ static int read_ref_without_reload(struct reftable_ref_store *refs,
261 strbuf_addstr(referent, ref.value.symref);
262 *type |= REF_ISSYMREF;
263 } else if (reftable_ref_record_val1(&ref)) {
264 + unsigned int hash_id;
265 +
266 + switch (reftable_stack_hash_id(stack)) {
267 + case REFTABLE_HASH_SHA1:
268 + hash_id = GIT_HASH_SHA1;
269 + break;
270 + case REFTABLE_HASH_SHA256:
271 + hash_id = GIT_HASH_SHA256;
272 + break;
273 + default:
274 + BUG("unhandled hash ID %d", reftable_stack_hash_id(stack));
275 + }
276 +
277 oidread(oid, reftable_ref_record_val1(&ref),
266 - refs->base.repo->hash_algo);
278 + &hash_algos[hash_id]);
279 } else {
280 /* We got a tombstone, which should not happen. */
281 BUG("unhandled reference value type %d", ref.value_type);
@@ -855,7 +867,7 @@ static int reftable_be_read_raw_ref(struct ref_store *ref_store,
867 if (ret)
868 return ret;
869
858 - ret = read_ref_without_reload(refs, be->stack, refname, oid, referent, type);
870 + ret = read_ref_without_reload(be->stack, refname, oid, referent, type);
871 if (ret < 0)
872 return ret;
873 if (ret > 0) {
@@ -1091,7 +1103,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
1103 if (ret)
1104 goto done;
1105
1094 - ret = read_ref_without_reload(refs, be->stack, "HEAD",
1106 + ret = read_ref_without_reload(be->stack, "HEAD",
1107 &head_oid, &head_referent, &head_type);
1108 if (ret < 0)
1109 goto done;
@@ -1167,7 +1179,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
1179 string_list_insert(&affected_refnames, new_update->refname);
1180 }
1181
1170 - ret = read_ref_without_reload(refs, be->stack, rewritten_ref,
1182 + ret = read_ref_without_reload(be->stack, rewritten_ref,
1183 &current_oid, &referent, &u->type);
1184 if (ret < 0)
1185 goto done;
@@ -1733,7 +1745,7 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data)
1745 memcpy(logs[logs_nr].value.update.old_hash, old_ref.value.val1, GIT_MAX_RAWSZ);
1746 logs_nr++;
1747
1736 - ret = read_ref_without_reload(arg->refs, arg->stack, "HEAD", &head_oid,
1748 + ret = read_ref_without_reload(arg->stack, "HEAD", &head_oid,
1749 &head_referent, &head_type);
1750 if (ret < 0)
1751 goto done;