summaryrefslogtreecommitdiff
path: root/include/git2/oid.h
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-04-29 08:59:46 -0700
committerRussell Belfer <rb@github.com>2013-04-29 08:59:46 -0700
commitaa8f010120577e61715f3ae1286a03055815f9c3 (patch)
treec6e8f4c96797675040e45e4b420705f5f3c21454 /include/git2/oid.h
parent8564a0224abe09beaacb2d2e7a54b16f8fcea7d1 (diff)
downloadlibgit2-aa8f010120577e61715f3ae1286a03055815f9c3.tar.gz
Add git_oid_strcmp and use it for git_oid_streq
Add a new git_oid_strcmp that compares a string OID with a hex oid for sort order, and then reimplement git_oid_streq using it. This actually should speed up git_oid_streq because it only reads as far into the string as it needs to, whereas previously it would convert the whole string into an OID and then use git_oid_cmp.
Diffstat (limited to 'include/git2/oid.h')
-rw-r--r--include/git2/oid.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/include/git2/oid.h b/include/git2/oid.h
index c35acdcdc..8d93e79cf 100644
--- a/include/git2/oid.h
+++ b/include/git2/oid.h
@@ -202,6 +202,16 @@ GIT_EXTERN(int) git_oid_ncmp(const git_oid *a, const git_oid *b, size_t len);
GIT_EXTERN(int) git_oid_streq(const git_oid *id, const char *str);
/**
+ * Compare an oid to an hex formatted object id.
+ *
+ * @param id oid structure.
+ * @param str input hex string of an object id.
+ * @return -1 if str is not valid, <0 if id sorts before str,
+ * 0 if id matches str, >0 if id sorts after str.
+ */
+GIT_EXTERN(int) git_oid_strcmp(const git_oid *id, const char *str);
+
+/**
* Check is an oid is all zeros.
*
* @return 1 if all zeros, 0 otherwise.