Thread (37 messages) flat view 37 messages, 4 authors, 18h ago
HOTtoday

Revision v2 of 2 in this series.

Revisions (2)
  1. v1 [diff vs current]
  2. v2 current

[PATCH v2 04/13] submodule-config: stop using `the_hash_algo`

From: Patrick Steinhardt <hidden>
Date: 2026-09-02 13:35:11
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
---
 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, &parameter);
-- 
2.55.0.979.g7e5102b832.dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help