summaryrefslogtreecommitdiff
path: root/src/oid.c
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2011-12-28 20:24:58 +0100
committernulltoken <emeric.fermas@gmail.com>2011-12-28 20:25:29 +0100
commiteb8de7476b4d3caeac518ff9af459c49cfd78e35 (patch)
treef77a41b173b4b504591f230f287a0066a1c28ac2 /src/oid.c
parent06fcf057b6da37ffd388e4a31c2671b20d0dd21e (diff)
downloadlibgit2-eb8de7476b4d3caeac518ff9af459c49cfd78e35.tar.gz
util: add git__fromhex()
Diffstat (limited to 'src/oid.c')
-rw-r--r--src/oid.c28
1 files changed, 5 insertions, 23 deletions
diff --git a/src/oid.c b/src/oid.c
index 4b3080430..61bf6da8a 100644
--- a/src/oid.c
+++ b/src/oid.c
@@ -11,24 +11,6 @@
#include <string.h>
#include <limits.h>
-static signed char from_hex[] = {
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 00 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20 */
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 30 */
--1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 40 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 50 */
--1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 60 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 70 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 80 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 90 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* a0 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* b0 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* c0 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* d0 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* e0 */
--1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* f0 */
-};
static char to_hex[] = "0123456789abcdef";
int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
@@ -43,8 +25,8 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
length = GIT_OID_HEXSZ;
for (p = 0; p < length - 1; p += 2) {
- v = (from_hex[(unsigned char)str[p + 0]] << 4)
- | from_hex[(unsigned char)str[p + 1]];
+ v = (git__fromhex(str[p + 0]) << 4)
+ | git__fromhex(str[p + 1]);
if (v < 0)
return git__throw(GIT_ENOTOID, "Failed to generate sha1. Given string is not a valid sha1 hash");
@@ -53,7 +35,7 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
}
if (length % 2) {
- v = (from_hex[(unsigned char)str[p + 0]] << 4);
+ v = (git__fromhex(str[p + 0]) << 4);
if (v < 0)
return git__throw(GIT_ENOTOID, "Failed to generate sha1. Given string is not a valid sha1 hash");
@@ -346,7 +328,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
is_leaf = 0;
for (i = 0; i < GIT_OID_HEXSZ; ++i) {
- int c = from_hex[(int)text_oid[i]];
+ int c = git__fromhex(text_oid[i]);
trie_node *node;
if (c == -1)
@@ -360,7 +342,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
tail = node->tail;
node->tail = NULL;
- node = push_leaf(os, idx, from_hex[(int)tail[0]], &tail[1]);
+ node = push_leaf(os, idx, git__fromhex(tail[0]), &tail[1]);
if (node == NULL)
return GIT_ENOMEM;
}