Commit

e4ad79fd9d8984827b2dc304f1ed99fa69e1ad11

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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt <ps@pks.im> · 2026-09-11 05:51 UTC · committed by Junio C Hamano

Browse files
1 file changed, +4 −2
modified submodule-config.c
@@ -133,7 +133,9 @@ void submodule_cache_free(struct submodule_cache *cache)
133 133 static unsigned int hash_oid_string(const struct object_id *oid,
134 134 const char *string)
135 135 {
136 - return memhash(oid->hash, the_hash_algo->rawsz) + strhash(string);
136 + if (oid->algo == GIT_HASH_UNKNOWN)
137 + BUG("hashing an object ID with unknown algorithm");
138 + return memhash(oid->hash, hash_algos[oid->algo].rawsz) + strhash(string);
137 139 }
138 140
139 141 static void cache_put_path(struct submodule_cache *cache,
@@ -824,7 +826,7 @@ static int gitmodules_cb(const char *var, const char *value,
824 826
825 827 parameter.cache = repo->submodule_cache;
826 828 parameter.treeish_name = NULL;
827 - parameter.gitmodules_oid = null_oid(the_hash_algo);
829 + parameter.gitmodules_oid = null_oid(repo->hash_algo);
828 830 parameter.overwrite = 1;
829 831
830 832 return parse_config(var, value, ctx, &parameter);