Commit 0c8efb38f9ffb1c4fffe620174669c51866eff79

Xavier L 2013-03-21T11:59:01

Added an oid function that accepts nul-terminated strings

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);