summaryrefslogtreecommitdiff
path: root/hex.c
diff options
context:
space:
mode:
Diffstat (limited to 'hex.c')
-rw-r--r--hex.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/hex.c b/hex.c
index 10e24dc..da51e64 100644
--- a/hex.c
+++ b/hex.c
@@ -72,6 +72,20 @@ int get_oid_hex_algop(const char *hex, struct object_id *oid,
return get_hash_hex_algop(hex, oid->hash, algop);
}
+/*
+ * NOTE: This function relies on hash algorithms being in order from shortest
+ * length to longest length.
+ */
+int get_oid_hex_any(const char *hex, struct object_id *oid)
+{
+ int i;
+ for (i = GIT_HASH_NALGOS - 1; i > 0; i--) {
+ if (!get_hash_hex_algop(hex, oid->hash, &hash_algos[i]))
+ return i;
+ }
+ return GIT_HASH_UNKNOWN;
+}
+
int get_oid_hex(const char *hex, struct object_id *oid)
{
return get_oid_hex_algop(hex, oid, the_hash_algo);
@@ -87,6 +101,14 @@ int parse_oid_hex_algop(const char *hex, struct object_id *oid,
return ret;
}
+int parse_oid_hex_any(const char *hex, struct object_id *oid, const char **end)
+{
+ int ret = get_oid_hex_any(hex, oid);
+ if (ret)
+ *end = hex + hash_algos[ret].hexsz;
+ return ret;
+}
+
int parse_oid_hex(const char *hex, struct object_id *oid, const char **end)
{
return parse_oid_hex_algop(hex, oid, end, the_hash_algo);