From f218de8a7a20e45b52a75ee56cf840fc47d6f65c Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 2 Sep 2026 15:34:52 +0200 Subject: [PATCH] submodule-config: stop using `the_hash_algo` We have two uses of `the_hash_algo` in "submodule-config.c": - One trivial use in `gitmodules_cb`, which we can convert to use the hash algorithm of the repository that's already available in the caller's context. - One use where we compute the hashmap key of an object ID. We should only ever get valid, populated object IDs here, and consequently we can easily adapt that function to use the hash algorithm of the passed-in object ID. Adapt both sites accordingly. Safeguard us against the case where the passed-in object ID is _not_ properly initialized. While this case shouldn't ever happen, it doesn't hurt to be defensive. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- submodule-config.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/submodule-config.c b/submodule-config.c index f8c2cf7a93..7c73fa108b 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -133,7 +133,9 @@ void submodule_cache_free(struct submodule_cache *cache) static unsigned int hash_oid_string(const struct object_id *oid, const char *string) { - return memhash(oid->hash, the_hash_algo->rawsz) + strhash(string); + if (oid->algo == GIT_HASH_UNKNOWN) + BUG("hashing an object ID with unknown algorithm"); + return memhash(oid->hash, hash_algos[oid->algo].rawsz) + strhash(string); } static void cache_put_path(struct submodule_cache *cache, @@ -824,7 +826,7 @@ static int gitmodules_cb(const char *var, const char *value, parameter.cache = repo->submodule_cache; parameter.treeish_name = NULL; - parameter.gitmodules_oid = null_oid(the_hash_algo); + parameter.gitmodules_oid = null_oid(repo->hash_algo); parameter.overwrite = 1; return parse_config(var, value, ctx, ¶meter);