int parse_oid_hex_algop(const char *hex, struct object_id *oid, const char **end,
const struct git_hash_algo *algo);
+
+/*
+ * These functions work like get_oid_hex and parse_oid_hex, but they will parse
+ * a hex value for any algorithm. The algorithm is detected based on the length
+ * and the algorithm in use is returned. If this is not a hex object ID in any
+ * algorithm, returns GIT_HASH_UNKNOWN.
+ */
+int get_oid_hex_any(const char *hex, struct object_id *oid);
+int parse_oid_hex_any(const char *hex, struct object_id *oid, const char **end);
+
/*
* This reads short-hand syntax that not only evaluates to a commit
* object name, but also can act as if the end user spelled the name
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);
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);