summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2022-01-21 19:37:53 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2022-01-26 15:25:11 -0500
commit6cb681822975b9e1efdb07b713d8712efcaf7288 (patch)
tree22adead64a418e89639f0444cd9d895888101143
parent2489e2d6884bcdb5d2cb83c3a7dcd5d4fae45173 (diff)
downloadlibgit2-6cb681822975b9e1efdb07b713d8712efcaf7288.tar.gz
oid: introduce `git_oid_raw_ncmp`
-rw-r--r--src/oid.c20
-rw-r--r--src/oid.h23
2 files changed, 24 insertions, 19 deletions
diff --git a/src/oid.c b/src/oid.c
index dbc5a5a90..054929e6a 100644
--- a/src/oid.c
+++ b/src/oid.c
@@ -196,25 +196,7 @@ int git_oid_equal(const git_oid *a, const git_oid *b)
int git_oid_ncmp(const git_oid *oid_a, const git_oid *oid_b, size_t len)
{
- const unsigned char *a = oid_a->id;
- const unsigned char *b = oid_b->id;
-
- if (len > GIT_OID_HEXSZ)
- len = GIT_OID_HEXSZ;
-
- while (len > 1) {
- if (*a != *b)
- return 1;
- a++;
- b++;
- len -= 2;
- };
-
- if (len)
- if ((*a ^ *b) & 0xf0)
- return 1;
-
- return 0;
+ return git_oid_raw_ncmp(oid_a->id, oid_b->id, len);
}
int git_oid_strcmp(const git_oid *oid_a, const char *str)
diff --git a/src/oid.h b/src/oid.h
index 302daedaa..ac87fc1b6 100644
--- a/src/oid.h
+++ b/src/oid.h
@@ -22,6 +22,29 @@
*/
char *git_oid_allocfmt(const git_oid *id);
+GIT_INLINE(int) git_oid_raw_ncmp(
+ const unsigned char *sha1,
+ const unsigned char *sha2,
+ size_t len)
+{
+ if (len > GIT_OID_HEXSZ)
+ len = GIT_OID_HEXSZ;
+
+ while (len > 1) {
+ if (*sha1 != *sha2)
+ return 1;
+ sha1++;
+ sha2++;
+ len -= 2;
+ };
+
+ if (len)
+ if ((*sha1 ^ *sha2) & 0xf0)
+ return 1;
+
+ return 0;
+}
+
GIT_INLINE(int) git_oid_raw_cmp(
const unsigned char *sha1,
const unsigned char *sha2)