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>
This commit is contained in:
brian m. carlson
2019-02-19 00:05:17 +00:00
committed by Junio C Hamano
parent 9c9492e8aa
commit 95399788d1
2 changed files with 10 additions and 0 deletions

View File

@ -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