aboutsummaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorbrian m. carlson <sandals@crustytoothpaste.net>2026-02-07 20:04:36 +0000
committerJunio C Hamano <gitster@pobox.com>2026-02-07 17:41:01 -0800
commit9005b5bb72df521670db03eefeafe53c0a81f9a5 (patch)
tree196e267f9b5a4fce74898538987bc8b9b1a6f545 /hash.c
parente25c7c9393625df7f3f0596ebe79602afe3b5f7f (diff)
downloadgit-9005b5bb72df521670db03eefeafe53c0a81f9a5.tar.xz
hash: add a function to look up hash algo structs
In C, it's easy for us to look up a hash algorithm structure by its offset by simply indexing the hash_algos array. However, in Rust, we sometimes need a pointer to pass to a C function, but we have our own hash algorithm abstraction. To get one from the other, let's provide a simple function that looks up the C structure from the offset and expose it in Rust. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index 81b4f87027..97fd473607 100644
--- a/hash.c
+++ b/hash.c
@@ -241,6 +241,13 @@ const char *empty_tree_oid_hex(const struct git_hash_algo *algop)
return oid_to_hex_r(buf, algop->empty_tree);
}
+const struct git_hash_algo *hash_algo_ptr_by_number(uint32_t algo)
+{
+ if (algo >= GIT_HASH_NALGOS)
+ return NULL;
+ return &hash_algos[algo];
+}
+
uint32_t hash_algo_by_name(const char *name)
{
if (!name)