diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cache.h | 5 | ||||
-rw-r--r-- | src/errors.c | 1 | ||||
-rw-r--r-- | src/oid.c | 20 | ||||
-rw-r--r-- | src/oid.h | 7 |
4 files changed, 33 insertions, 0 deletions
diff --git a/src/cache.h b/src/cache.h index 4794dea3a..3038030f4 100644 --- a/src/cache.h +++ b/src/cache.h @@ -42,6 +42,11 @@ GIT_INLINE(int) git_cached_obj_compare(git_cached_obj *obj, const git_oid *oid) return git_oid_cmp(&obj->oid, oid); } +GIT_INLINE(int) git_cached_obj_match(unsigned int len, git_cached_obj *obj, const git_oid *oid) +{ + return git_oid_match(len, &obj->oid, oid); +} + GIT_INLINE(void) git_cached_obj_incref(git_cached_obj *obj) { git_atomic_inc(&obj->refcount); diff --git a/src/errors.c b/src/errors.c index 1fb68ee65..7da02b4f7 100644 --- a/src/errors.c +++ b/src/errors.c @@ -61,6 +61,7 @@ static struct { {GIT_EEXISTS, "A reference with this name already exists"}, {GIT_EOVERFLOW, "The given integer literal is too large to be parsed"}, {GIT_ENOTNUM, "The given literal is not a valid number"}, + {GIT_EAMBIGUOUSOIDPREFIX, "The given oid prefix is ambiguous"}, }; const char *git_strerror(int num) @@ -173,6 +173,26 @@ int git_oid_cmp(const git_oid *a, const git_oid *b) } +int git_oid_match_raw(unsigned int len, const unsigned char *a, const unsigned char *b) +{ + do { + if (*a != *b) + return 0; + a++; + b++; + len -= 2; + } while (len > 1); + if (len) + if ((*a ^ *b) & 0xf0) + return 0; + return 1; +} + +int gid_oid_match(unsigned int len, git_oid *a, git_oid *b) +{ + return git_oid_match_raw(len, a->id, b->id); +} + typedef short node_index; typedef union { diff --git a/src/oid.h b/src/oid.h new file mode 100644 index 000000000..79f5b6507 --- /dev/null +++ b/src/oid.h @@ -0,0 +1,7 @@ +#ifndef INCLUDE_oid_h__ +#define INCLUDE_oid_h__ + +/* This can be useful for internal use */ +int git_oid_match_raw(unsigned int len, const unsigned char *a, const unsigned char *b); + +#endif |