]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs: remove the_hash_algo global state
authorShreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
Sat, 4 Apr 2026 13:58:39 +0000 (19:28 +0530)
committerJunio C Hamano <gitster@pobox.com>
Wed, 8 Apr 2026 16:58:10 +0000 (09:58 -0700)
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>
refs.c

diff --git a/refs.c b/refs.c
index 4ab746a3cb555c65b79050ac91fa83546e1a0463..d13ca9a37c63e36c967ad08a784732306983cc90 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1472,7 +1472,7 @@ int ref_transaction_create(struct ref_transaction *transaction,
                return 1;
        }
        return ref_transaction_update(transaction, refname, new_oid,
-                                     null_oid(the_hash_algo), new_target, NULL, flags,
+                                     null_oid(transaction->ref_store->repo->hash_algo), new_target, NULL, flags,
                                      msg, err);
 }
 
@@ -1491,7 +1491,7 @@ int ref_transaction_delete(struct ref_transaction *transaction,
        if (old_target && !(flags & REF_NO_DEREF))
                BUG("delete cannot operate on symrefs with deref mode");
        return ref_transaction_update(transaction, refname,
-                                     null_oid(the_hash_algo), old_oid,
+                                     null_oid(transaction->ref_store->repo->hash_algo), old_oid,
                                      NULL, old_target, flags,
                                      msg, err);
 }
@@ -2379,7 +2379,7 @@ struct ref_store *repo_get_submodule_ref_store(struct repository *repo,
        subrepo = xmalloc(sizeof(*subrepo));
 
        if (repo_submodule_init(subrepo, repo, submodule,
-                               null_oid(the_hash_algo))) {
+                               null_oid(repo->hash_algo))) {
                free(subrepo);
                goto done;
        }
@@ -2571,14 +2571,14 @@ static int transaction_hook_feed_stdin(int hook_stdin_fd, void *pp_cb, void *pp_
        strbuf_reset(buf);
 
        if (!(update->flags & REF_HAVE_OLD))
-               strbuf_addf(buf, "%s ", oid_to_hex(null_oid(the_hash_algo)));
+               strbuf_addf(buf, "%s ", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));
        else if (update->old_target)
                strbuf_addf(buf, "ref:%s ", update->old_target);
        else
                strbuf_addf(buf, "%s ", oid_to_hex(&update->old_oid));
 
        if (!(update->flags & REF_HAVE_NEW))
-               strbuf_addf(buf, "%s ", oid_to_hex(null_oid(the_hash_algo)));
+               strbuf_addf(buf, "%s ", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));
        else if (update->new_target)
                strbuf_addf(buf, "ref:%s ", update->new_target);
        else
@@ -3146,6 +3146,7 @@ struct migration_data {
 static int migrate_one_ref(const struct reference *ref, void *cb_data)
 {
        struct migration_data *data = cb_data;
+       const struct git_hash_algo *hash_algo = data->transaction->ref_store->repo->hash_algo;
        struct strbuf symref_target = STRBUF_INIT;
        int ret;
 
@@ -3154,7 +3155,7 @@ static int migrate_one_ref(const struct reference *ref, void *cb_data)
                if (ret < 0)
                        goto done;
 
-               ret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(the_hash_algo),
+               ret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(hash_algo),
                                             symref_target.buf, NULL,
                                             REF_SKIP_CREATE_REFLOG | REF_NO_DEREF, NULL, data->errbuf);
                if (ret < 0)