summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-10-31 13:46:49 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-11-01 01:35:35 (GMT)
commit0ec218656a02ea48e173262f7b80513feeb7f263 (patch)
tree7cd0bbbbd2a1bccd5873c0c962d40040c2a7e504
parentcb5918aa0d50f50e83787f65c2ddc3dcb10159fe (diff)
downloadgit-0ec218656a02ea48e173262f7b80513feeb7f263.zip
git-0ec218656a02ea48e173262f7b80513feeb7f263.tar.gz
git-0ec218656a02ea48e173262f7b80513feeb7f263.tar.bz2
notes: move hex_to_bytes() to hex.c and export it
Make the function for converting pairs of hexadecimal digits to binary available to other call sites. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--cache.h7
-rw-r--r--hex.c12
-rw-r--r--notes.c17
3 files changed, 19 insertions, 17 deletions
diff --git a/cache.h b/cache.h
index 6440e2b..f06bfba 100644
--- a/cache.h
+++ b/cache.h
@@ -1318,6 +1318,13 @@ extern int get_sha1_hex(const char *hex, unsigned char *sha1);
extern int get_oid_hex(const char *hex, struct object_id *sha1);
/*
+ * Read `len` pairs of hexadecimal digits from `hex` and write the
+ * values to `binary` as `len` bytes. Return 0 on success, or -1 if
+ * the input does not consist of hex digits).
+ */
+extern int hex_to_bytes(unsigned char *binary, const char *hex, size_t len);
+
+/*
* Convert a binary sha1 to its hex equivalent. The `_r` variant is reentrant,
* and writes the NUL-terminated output to the buffer `out`, which must be at
* least `GIT_SHA1_HEXSZ + 1` bytes, and returns a pointer to out for
diff --git a/hex.c b/hex.c
index 28b4411..8df2d63 100644
--- a/hex.c
+++ b/hex.c
@@ -35,6 +35,18 @@ const signed char hexval_table[256] = {
-1, -1, -1, -1, -1, -1, -1, -1, /* f8-ff */
};
+int hex_to_bytes(unsigned char *binary, const char *hex, size_t len)
+{
+ for (; len; len--, hex += 2) {
+ unsigned int val = (hexval(hex[0]) << 4) | hexval(hex[1]);
+
+ if (val & ~0xff)
+ return -1;
+ *binary++ = val;
+ }
+ return 0;
+}
+
int get_sha1_hex(const char *hex, unsigned char *sha1)
{
int i;
diff --git a/notes.c b/notes.c
index 5c62862..04f8c86 100644
--- a/notes.c
+++ b/notes.c
@@ -334,23 +334,6 @@ static void note_tree_free(struct int_node *tree)
}
}
-/*
- * Read `len` pairs of hexadecimal digits from `hex` and write the
- * values to `binary` as `len` bytes. Return 0 on success, or -1 if
- * the input does not consist of hex digits).
- */
-static int hex_to_bytes(unsigned char *binary, const char *hex, size_t len)
-{
- for (; len; len--, hex += 2) {
- unsigned int val = (hexval(hex[0]) << 4) | hexval(hex[1]);
-
- if (val & ~0xff)
- return -1;
- *binary++ = val;
- }
- return 0;
-}
-
static int non_note_cmp(const struct non_note *a, const struct non_note *b)
{
return strcmp(a->path, b->path);