summaryrefslogtreecommitdiff
path: root/sha1-file.c
diff options
context:
space:
mode:
authorbrian m. carlson <sandals@crustytoothpaste.net>2018-10-22 02:43:32 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-10-22 03:59:08 (GMT)
commit2f90b9d9b4ba1f8e79318853301e8ef19ca02681 (patch)
tree76cc6f9d74fcc6153e9e2717f75194649ed6db4e /sha1-file.c
parent1ccf07cbb762b44746c49634e1c6fb945c9977df (diff)
downloadgit-2f90b9d9b4ba1f8e79318853301e8ef19ca02681.zip
git-2f90b9d9b4ba1f8e79318853301e8ef19ca02681.tar.gz
git-2f90b9d9b4ba1f8e79318853301e8ef19ca02681.tar.bz2
sha1-file: provide functions to look up hash algorithms
There are several ways we might refer to a hash algorithm: by name, such as in the config file; by format ID, such as in a pack; or internally, by a pointer to the hash_algos array. Provide functions to look up hash algorithms based on these various forms and return the internal constant used for them. If conversion to another form is necessary, this internal constant can be used to look up the proper data in the hash_algos array. 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.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/sha1-file.c b/sha1-file.c
index e29825f..3a75d51 100644
--- a/sha1-file.c
+++ b/sha1-file.c
@@ -122,6 +122,27 @@ const char *empty_blob_oid_hex(void)
return oid_to_hex_r(buf, the_hash_algo->empty_blob);
}
+int hash_algo_by_name(const char *name)
+{
+ int i;
+ if (!name)
+ return GIT_HASH_UNKNOWN;
+ for (i = 1; i < GIT_HASH_NALGOS; i++)
+ if (!strcmp(name, hash_algos[i].name))
+ return i;
+ return GIT_HASH_UNKNOWN;
+}
+
+int hash_algo_by_id(uint32_t format_id)
+{
+ int i;
+ for (i = 1; i < GIT_HASH_NALGOS; i++)
+ if (format_id == hash_algos[i].format_id)
+ return i;
+ return GIT_HASH_UNKNOWN;
+}
+
+
/*
* This is meant to hold a *small* number of objects that you would
* want read_sha1_file() to be able to return, but yet you do not want