Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hash.h2
-rw-r--r--sha1-file.c8
2 files changed, 10 insertions, 0 deletions
diff --git a/hash.h b/hash.h
index adde708cf2..661c9f2281 100644
--- a/hash.h
+++ b/hash.h
@@ -131,6 +131,8 @@ extern const struct git_hash_algo hash_algos[GIT_HASH_NALGOS];
int hash_algo_by_name(const char *name);
/* Identical, except based on the format ID. */
int hash_algo_by_id(uint32_t format_id);
+/* Identical, except based on the length. */
+int hash_algo_by_length(int len);
/* Identical, except for a pointer to struct git_hash_algo. */
static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
{
diff --git a/sha1-file.c b/sha1-file.c
index 494606f771..bcd9470bce 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