Added an oid function that accepts nul-terminated strings
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
diff --git a/include/git2/oid.h b/include/git2/oid.h
index 6be02da..d2f3f4a 100644
--- a/include/git2/oid.h
+++ b/include/git2/oid.h
@@ -47,6 +47,16 @@ typedef struct git_oid {
GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str);
/**
+ * Parse a hex formatted null-terminated string into a git_oid.
+ *
+ * @param out oid structure the result is written into.
+ * @param str input hex string; must be at least 4 characters
+ * long and null-terminated.
+ * @return 0 or an error code
+ */
+GIT_EXTERN(int) git_oid_fromstrp(git_oid *out, const char *str);
+
+/**
* Parse N characters of a hex formatted object id into a git_oid
*
* If N is odd, N-1 characters will be parsed instead.
diff --git a/src/oid.c b/src/oid.c
index 25c6fce..0a0a814 100644
--- a/src/oid.c
+++ b/src/oid.c
@@ -51,6 +51,11 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
return 0;
}
+int git_oid_fromstrp(git_oid *out, const char *str)
+{
+ return git_oid_fromstrn(out, str, min(strlen(str), GIT_OID_HEXSZ));
+}
+
int git_oid_fromstr(git_oid *out, const char *str)
{
return git_oid_fromstrn(out, str, GIT_OID_HEXSZ);