summaryrefslogtreecommitdiff
path: root/sha1-file.c
diff options
context:
space:
mode:
authorbrian m. carlson <sandals@crustytoothpaste.net>2019-02-19 00:05:17 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-04-01 02:57:39 (GMT)
commit95399788d158e4628e25db20569d44af21a40906 (patch)
tree4051c49eddd71f891f7961fec6b251452af31f6b /sha1-file.c
parent9c9492e8aafdcc2ec464e9261b78619b05a835f8 (diff)
downloadgit-95399788d158e4628e25db20569d44af21a40906.zip
git-95399788d158e4628e25db20569d44af21a40906.tar.gz
git-95399788d158e4628e25db20569d44af21a40906.tar.bz2
hash: add a function to lookup hash algorithm by length
There are some cases, such as the dumb HTTP transport and bundles, where we can only determine the hash algorithm in use by the length of the object IDs. Provide a function that looks up the algorithm by length. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1-file.c')
-rw-r--r--sha1-file.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/sha1-file.c b/sha1-file.c
index 494606f..bcd9470 100644
--- a/sha1-file.c
+++ b/sha1-file.c
@@ -189,6 +189,14 @@ int hash_algo_by_id(uint32_t format_id)
return GIT_HASH_UNKNOWN;
}
+int hash_algo_by_length(int len)
+{
+ int i;
+ for (i = 1; i < GIT_HASH_NALGOS; i++)
+ if (len == hash_algos[i].rawsz)
+ return i;
+ return GIT_HASH_UNKNOWN;
+}
/*
* This is meant to hold a *small* number of objects that you would