Git fork

hex-ll: separate out non-hash-algo functions

In order to further reduce all-in-one headers, separate out functions in
hex.h that do not operate on object hashes into its own file, hex-ll.h,
and update the include directives in the .c files that need only such
functions accordingly.

Signed-off-by: Calvin Wan <calvinwan@google.com>
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Calvin Wan and committed by
Junio C Hamano
d88e8106 94e83dcf

+83 -75
+1
Makefile
··· 1040 1040 LIB_OBJS += hashmap.o 1041 1041 LIB_OBJS += help.o 1042 1042 LIB_OBJS += hex.o 1043 + LIB_OBJS += hex-ll.o 1043 1044 LIB_OBJS += hook.o 1044 1045 LIB_OBJS += ident.o 1045 1046 LIB_OBJS += json-writer.o
+1 -1
color.c
··· 3 3 #include "color.h" 4 4 #include "editor.h" 5 5 #include "gettext.h" 6 - #include "hex.h" 6 + #include "hex-ll.h" 7 7 #include "pager.h" 8 8 #include "strbuf.h" 9 9
+49
hex-ll.c
··· 1 + #include "git-compat-util.h" 2 + #include "hex-ll.h" 3 + 4 + const signed char hexval_table[256] = { 5 + -1, -1, -1, -1, -1, -1, -1, -1, /* 00-07 */ 6 + -1, -1, -1, -1, -1, -1, -1, -1, /* 08-0f */ 7 + -1, -1, -1, -1, -1, -1, -1, -1, /* 10-17 */ 8 + -1, -1, -1, -1, -1, -1, -1, -1, /* 18-1f */ 9 + -1, -1, -1, -1, -1, -1, -1, -1, /* 20-27 */ 10 + -1, -1, -1, -1, -1, -1, -1, -1, /* 28-2f */ 11 + 0, 1, 2, 3, 4, 5, 6, 7, /* 30-37 */ 12 + 8, 9, -1, -1, -1, -1, -1, -1, /* 38-3f */ 13 + -1, 10, 11, 12, 13, 14, 15, -1, /* 40-47 */ 14 + -1, -1, -1, -1, -1, -1, -1, -1, /* 48-4f */ 15 + -1, -1, -1, -1, -1, -1, -1, -1, /* 50-57 */ 16 + -1, -1, -1, -1, -1, -1, -1, -1, /* 58-5f */ 17 + -1, 10, 11, 12, 13, 14, 15, -1, /* 60-67 */ 18 + -1, -1, -1, -1, -1, -1, -1, -1, /* 68-67 */ 19 + -1, -1, -1, -1, -1, -1, -1, -1, /* 70-77 */ 20 + -1, -1, -1, -1, -1, -1, -1, -1, /* 78-7f */ 21 + -1, -1, -1, -1, -1, -1, -1, -1, /* 80-87 */ 22 + -1, -1, -1, -1, -1, -1, -1, -1, /* 88-8f */ 23 + -1, -1, -1, -1, -1, -1, -1, -1, /* 90-97 */ 24 + -1, -1, -1, -1, -1, -1, -1, -1, /* 98-9f */ 25 + -1, -1, -1, -1, -1, -1, -1, -1, /* a0-a7 */ 26 + -1, -1, -1, -1, -1, -1, -1, -1, /* a8-af */ 27 + -1, -1, -1, -1, -1, -1, -1, -1, /* b0-b7 */ 28 + -1, -1, -1, -1, -1, -1, -1, -1, /* b8-bf */ 29 + -1, -1, -1, -1, -1, -1, -1, -1, /* c0-c7 */ 30 + -1, -1, -1, -1, -1, -1, -1, -1, /* c8-cf */ 31 + -1, -1, -1, -1, -1, -1, -1, -1, /* d0-d7 */ 32 + -1, -1, -1, -1, -1, -1, -1, -1, /* d8-df */ 33 + -1, -1, -1, -1, -1, -1, -1, -1, /* e0-e7 */ 34 + -1, -1, -1, -1, -1, -1, -1, -1, /* e8-ef */ 35 + -1, -1, -1, -1, -1, -1, -1, -1, /* f0-f7 */ 36 + -1, -1, -1, -1, -1, -1, -1, -1, /* f8-ff */ 37 + }; 38 + 39 + int hex_to_bytes(unsigned char *binary, const char *hex, size_t len) 40 + { 41 + for (; len; len--, hex += 2) { 42 + unsigned int val = (hexval(hex[0]) << 4) | hexval(hex[1]); 43 + 44 + if (val & ~0xff) 45 + return -1; 46 + *binary++ = val; 47 + } 48 + return 0; 49 + }
+27
hex-ll.h
··· 1 + #ifndef HEX_LL_H 2 + #define HEX_LL_H 3 + 4 + extern const signed char hexval_table[256]; 5 + static inline unsigned int hexval(unsigned char c) 6 + { 7 + return hexval_table[c]; 8 + } 9 + 10 + /* 11 + * Convert two consecutive hexadecimal digits into a char. Return a 12 + * negative value on error. Don't run over the end of short strings. 13 + */ 14 + static inline int hex2chr(const char *s) 15 + { 16 + unsigned int val = hexval(s[0]); 17 + return (val & ~0xf) ? val : (val << 4) | hexval(s[1]); 18 + } 19 + 20 + /* 21 + * Read `len` pairs of hexadecimal digits from `hex` and write the 22 + * values to `binary` as `len` bytes. Return 0 on success, or -1 if 23 + * the input does not consist of hex digits). 24 + */ 25 + int hex_to_bytes(unsigned char *binary, const char *hex, size_t len); 26 + 27 + #endif
-47
hex.c
··· 2 2 #include "hash.h" 3 3 #include "hex.h" 4 4 5 - const signed char hexval_table[256] = { 6 - -1, -1, -1, -1, -1, -1, -1, -1, /* 00-07 */ 7 - -1, -1, -1, -1, -1, -1, -1, -1, /* 08-0f */ 8 - -1, -1, -1, -1, -1, -1, -1, -1, /* 10-17 */ 9 - -1, -1, -1, -1, -1, -1, -1, -1, /* 18-1f */ 10 - -1, -1, -1, -1, -1, -1, -1, -1, /* 20-27 */ 11 - -1, -1, -1, -1, -1, -1, -1, -1, /* 28-2f */ 12 - 0, 1, 2, 3, 4, 5, 6, 7, /* 30-37 */ 13 - 8, 9, -1, -1, -1, -1, -1, -1, /* 38-3f */ 14 - -1, 10, 11, 12, 13, 14, 15, -1, /* 40-47 */ 15 - -1, -1, -1, -1, -1, -1, -1, -1, /* 48-4f */ 16 - -1, -1, -1, -1, -1, -1, -1, -1, /* 50-57 */ 17 - -1, -1, -1, -1, -1, -1, -1, -1, /* 58-5f */ 18 - -1, 10, 11, 12, 13, 14, 15, -1, /* 60-67 */ 19 - -1, -1, -1, -1, -1, -1, -1, -1, /* 68-67 */ 20 - -1, -1, -1, -1, -1, -1, -1, -1, /* 70-77 */ 21 - -1, -1, -1, -1, -1, -1, -1, -1, /* 78-7f */ 22 - -1, -1, -1, -1, -1, -1, -1, -1, /* 80-87 */ 23 - -1, -1, -1, -1, -1, -1, -1, -1, /* 88-8f */ 24 - -1, -1, -1, -1, -1, -1, -1, -1, /* 90-97 */ 25 - -1, -1, -1, -1, -1, -1, -1, -1, /* 98-9f */ 26 - -1, -1, -1, -1, -1, -1, -1, -1, /* a0-a7 */ 27 - -1, -1, -1, -1, -1, -1, -1, -1, /* a8-af */ 28 - -1, -1, -1, -1, -1, -1, -1, -1, /* b0-b7 */ 29 - -1, -1, -1, -1, -1, -1, -1, -1, /* b8-bf */ 30 - -1, -1, -1, -1, -1, -1, -1, -1, /* c0-c7 */ 31 - -1, -1, -1, -1, -1, -1, -1, -1, /* c8-cf */ 32 - -1, -1, -1, -1, -1, -1, -1, -1, /* d0-d7 */ 33 - -1, -1, -1, -1, -1, -1, -1, -1, /* d8-df */ 34 - -1, -1, -1, -1, -1, -1, -1, -1, /* e0-e7 */ 35 - -1, -1, -1, -1, -1, -1, -1, -1, /* e8-ef */ 36 - -1, -1, -1, -1, -1, -1, -1, -1, /* f0-f7 */ 37 - -1, -1, -1, -1, -1, -1, -1, -1, /* f8-ff */ 38 - }; 39 - 40 - int hex_to_bytes(unsigned char *binary, const char *hex, size_t len) 41 - { 42 - for (; len; len--, hex += 2) { 43 - unsigned int val = (hexval(hex[0]) << 4) | hexval(hex[1]); 44 - 45 - if (val & ~0xff) 46 - return -1; 47 - *binary++ = val; 48 - } 49 - return 0; 50 - } 51 - 52 5 static int get_hash_hex_algop(const char *hex, unsigned char *hash, 53 6 const struct git_hash_algo *algop) 54 7 {
+1 -23
hex.h
··· 2 2 #define HEX_H 3 3 4 4 #include "hash-ll.h" 5 - 6 - extern const signed char hexval_table[256]; 7 - static inline unsigned int hexval(unsigned char c) 8 - { 9 - return hexval_table[c]; 10 - } 11 - 12 - /* 13 - * Convert two consecutive hexadecimal digits into a char. Return a 14 - * negative value on error. Don't run over the end of short strings. 15 - */ 16 - static inline int hex2chr(const char *s) 17 - { 18 - unsigned int val = hexval(s[0]); 19 - return (val & ~0xf) ? val : (val << 4) | hexval(s[1]); 20 - } 5 + #include "hex-ll.h" 21 6 22 7 /* 23 8 * Try to read a hash (specified by the_hash_algo) in hexadecimal ··· 33 18 34 19 /* Like get_oid_hex, but for an arbitrary hash algorithm. */ 35 20 int get_oid_hex_algop(const char *hex, struct object_id *oid, const struct git_hash_algo *algop); 36 - 37 - /* 38 - * Read `len` pairs of hexadecimal digits from `hex` and write the 39 - * values to `binary` as `len` bytes. Return 0 on success, or -1 if 40 - * the input does not consist of hex digits). 41 - */ 42 - int hex_to_bytes(unsigned char *binary, const char *hex, size_t len); 43 21 44 22 /* 45 23 * Convert a binary hash in "unsigned char []" or an object name in
+1 -1
mailinfo.c
··· 1 1 #include "git-compat-util.h" 2 2 #include "config.h" 3 3 #include "gettext.h" 4 - #include "hex.h" 4 + #include "hex-ll.h" 5 5 #include "utf8.h" 6 6 #include "strbuf.h" 7 7 #include "mailinfo.h"
+1 -1
strbuf.c
··· 1 1 #include "git-compat-util.h" 2 2 #include "gettext.h" 3 - #include "hex.h" 3 + #include "hex-ll.h" 4 4 #include "strbuf.h" 5 5 #include "string-list.h" 6 6 #include "utf8.h"
+1 -1
url.c
··· 1 1 #include "git-compat-util.h" 2 - #include "hex.h" 2 + #include "hex-ll.h" 3 3 #include "strbuf.h" 4 4 #include "url.h" 5 5
+1 -1
urlmatch.c
··· 1 1 #include "git-compat-util.h" 2 2 #include "gettext.h" 3 - #include "hex.h" 3 + #include "hex-ll.h" 4 4 #include "strbuf.h" 5 5 #include "urlmatch.h" 6 6