refs: remove the_hash_algo global state

refs.c uses the_hash_algo in multiple places, relying on global state for the object hash algorithm. Replace these uses with the appropriate repository-specific hash_algo. In transaction-related functions (ref_transaction_create, ref_transaction_delete, migrate_one_ref, and transaction_hook_feed_stdin), use transaction->ref_store->repo->hash_algo. In other cases, such as repo_get_submodule_ref_store(), use repo->hash_algo. Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> Acked-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shreyansh Paliwal committed Apr 4, 2026 at 19:28 UTC 9a03f165a41d708c672e18e69d43f69689981e7d
1 file changed +7 -6
refs.c
+7 -6
@@ -1472,7 +1472,7 @@ int ref_transaction_create(struct ref_transaction *transaction,
1472 return 1;
1473 }
1474 return ref_transaction_update(transaction, refname, new_oid,
1475 - null_oid(the_hash_algo), new_target, NULL, flags,
1475 + null_oid(transaction->ref_store->repo->hash_algo), new_target, NULL, flags,
1476 msg, err);
1477 }
1478
@@ -1491,7 +1491,7 @@ int ref_transaction_delete(struct ref_transaction *transaction,
1491 if (old_target && !(flags & REF_NO_DEREF))
1492 BUG("delete cannot operate on symrefs with deref mode");
1493 return ref_transaction_update(transaction, refname,
1494 - null_oid(the_hash_algo), old_oid,
1494 + null_oid(transaction->ref_store->repo->hash_algo), old_oid,
1495 NULL, old_target, flags,
1496 msg, err);
1497 }
@@ -2379,7 +2379,7 @@ struct ref_store *repo_get_submodule_ref_store(struct repository *repo,
2379 subrepo = xmalloc(sizeof(*subrepo));
2380
2381 if (repo_submodule_init(subrepo, repo, submodule,
2382 - null_oid(the_hash_algo))) {
2382 + null_oid(repo->hash_algo))) {
2383 free(subrepo);
2384 goto done;
2385 }
@@ -2571,14 +2571,14 @@ static int transaction_hook_feed_stdin(int hook_stdin_fd, void *pp_cb, void *pp_
2571 strbuf_reset(buf);
2572
2573 if (!(update->flags & REF_HAVE_OLD))
2574 - strbuf_addf(buf, "%s ", oid_to_hex(null_oid(the_hash_algo)));
2574 + strbuf_addf(buf, "%s ", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));
2575 else if (update->old_target)
2576 strbuf_addf(buf, "ref:%s ", update->old_target);
2577 else
2578 strbuf_addf(buf, "%s ", oid_to_hex(&update->old_oid));
2579
2580 if (!(update->flags & REF_HAVE_NEW))
2581 - strbuf_addf(buf, "%s ", oid_to_hex(null_oid(the_hash_algo)));
2581 + strbuf_addf(buf, "%s ", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));
2582 else if (update->new_target)
2583 strbuf_addf(buf, "ref:%s ", update->new_target);
2584 else
@@ -3146,6 +3146,7 @@ struct migration_data {
3146 static int migrate_one_ref(const struct reference *ref, void *cb_data)
3147 {
3148 struct migration_data *data = cb_data;
3149 + const struct git_hash_algo *hash_algo = data->transaction->ref_store->repo->hash_algo;
3150 struct strbuf symref_target = STRBUF_INIT;
3151 int ret;
3152
@@ -3154,7 +3155,7 @@ static int migrate_one_ref(const struct reference *ref, void *cb_data)
3155 if (ret < 0)
3156 goto done;
3157
3157 - ret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(the_hash_algo),
3158 + ret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(hash_algo),
3159 symref_target.buf, NULL,
3160 REF_SKIP_CREATE_REFLOG | REF_NO_DEREF, NULL, data->errbuf);
3161 if (ret < 0)