#include "common.h"
#include "git2/oid.h"
#include "repository.h"
+#include "global.h"
#include <string.h>
#include <limits.h>
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;
}
str = fmt_one(str, oid->id[i]);
}
+char *git_oid_tostr_s(const git_oid *oid)
+{
+ char *str = GIT_GLOBAL->oid_fmt;
+ git_oid_nfmt(str, GIT_OID_HEXSZ + 1, oid);
+ return str;
+}
+
char *git_oid_allocfmt(const git_oid *oid)
{
char *str = git__malloc(GIT_OID_HEXSZ + 1);
int git_oid_strcmp(const git_oid *oid_a, const char *str)
{
- const unsigned char *a = oid_a->id;
+ const unsigned char *a;
unsigned char strval;
int hexval;
static int resize_trie(git_oid_shorten *self, size_t new_size)
{
- self->nodes = git__realloc(self->nodes, new_size * sizeof(trie_node));
+ self->nodes = git__reallocarray(self->nodes, new_size, sizeof(trie_node));
GITERR_CHECK_ALLOC(self->nodes);
if (new_size > self->size) {