Skip to content

Commit 3ec8022

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c9f76fc commit 3ec8022

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

refs/reftable-backend.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,7 @@ static void fill_reftable_log_record(struct reftable_log_record *log, const stru
243243
log->value.update.tz_offset = sign * atoi(tz_begin);
244244
}
245245

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,
248247
const char *refname,
249248
struct object_id *oid,
250249
struct strbuf *referent,
@@ -262,8 +261,21 @@ static int read_ref_without_reload(struct reftable_ref_store *refs,
262261
strbuf_addstr(referent, ref.value.symref);
263262
*type |= REF_ISSYMREF;
264263
} 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+
265277
oidread(oid, reftable_ref_record_val1(&ref),
266-
refs->base.repo->hash_algo);
278+
&hash_algos[hash_id]);
267279
} else {
268280
/* We got a tombstone, which should not happen. */
269281
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,
855867
if (ret)
856868
return ret;
857869

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);
859871
if (ret < 0)
860872
return ret;
861873
if (ret > 0) {
@@ -1091,7 +1103,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
10911103
if (ret)
10921104
goto done;
10931105

1094-
ret = read_ref_without_reload(refs, be->stack, "HEAD",
1106+
ret = read_ref_without_reload(be->stack, "HEAD",
10951107
&head_oid, &head_referent, &head_type);
10961108
if (ret < 0)
10971109
goto done;
@@ -1167,7 +1179,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
11671179
string_list_insert(&affected_refnames, new_update->refname);
11681180
}
11691181

1170-
ret = read_ref_without_reload(refs, be->stack, rewritten_ref,
1182+
ret = read_ref_without_reload(be->stack, rewritten_ref,
11711183
&current_oid, &referent, &u->type);
11721184
if (ret < 0)
11731185
goto done;
@@ -1733,7 +1745,7 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data)
17331745
memcpy(logs[logs_nr].value.update.old_hash, old_ref.value.val1, GIT_MAX_RAWSZ);
17341746
logs_nr++;
17351747

1736-
ret = read_ref_without_reload(arg->refs, arg->stack, "HEAD", &head_oid,
1748+
ret = read_ref_without_reload(arg->stack, "HEAD", &head_oid,
17371749
&head_referent, &head_type);
17381750
if (ret < 0)
17391751
goto done;

0 commit comments

Comments
 (0)