diff options
Diffstat (limited to 'src/oid.c')
| -rw-r--r-- | src/oid.c | 32 |
1 files changed, 17 insertions, 15 deletions
@@ -24,30 +24,24 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length) size_t p; int v; - if (length > GIT_OID_HEXSZ) - return oid_error_invalid("too long"); + assert(out && str); - for (p = 0; p < length - 1; p += 2) { - v = (git__fromhex(str[p + 0]) << 4) - | git__fromhex(str[p + 1]); + if (!length) + return oid_error_invalid("too short"); - if (v < 0) - return oid_error_invalid("contains invalid characters"); + if (length > GIT_OID_HEXSZ) + return oid_error_invalid("too long"); - out->id[p / 2] = (unsigned char)v; - } + memset(out->id, 0, GIT_OID_RAWSZ); - if (length % 2) { - v = (git__fromhex(str[p + 0]) << 4); + for (p = 0; p < length; p++) { + v = git__fromhex(str[p]); if (v < 0) return oid_error_invalid("contains invalid characters"); - out->id[p / 2] = (unsigned char)v; - p += 2; + out->id[p / 2] |= (unsigned char)(v << (p % 2 ? 0 : 4)); } - memset(out->id + p / 2, 0, (GIT_OID_HEXSZ - p) / 2); - return 0; } @@ -179,6 +173,11 @@ int git_oid_cmp(const git_oid *a, const git_oid *b) return git_oid__cmp(a, b); } +int git_oid_equal(const git_oid *a, const git_oid *b) +{ + return (git_oid__cmp(a, b) == 0); +} + int git_oid_ncmp(const git_oid *oid_a, const git_oid *oid_b, size_t len) { const unsigned char *a = oid_a->id; @@ -314,6 +313,9 @@ git_oid_shorten *git_oid_shorten_new(size_t min_length) void git_oid_shorten_free(git_oid_shorten *os) { + if (os == NULL) + return; + git__free(os->nodes); git__free(os); } |
