Skip to content

Commit d88e810

Browse files
calvin-wan-googlegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 94e83dc commit d88e810

File tree

10 files changed

+83
-75
lines changed

10 files changed

+83
-75
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,7 @@ LIB_OBJS += hash-lookup.o
10401040
LIB_OBJS += hashmap.o
10411041
LIB_OBJS += help.o
10421042
LIB_OBJS += hex.o
1043+
LIB_OBJS += hex-ll.o
10431044
LIB_OBJS += hook.o
10441045
LIB_OBJS += ident.o
10451046
LIB_OBJS += json-writer.o

color.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "color.h"
44
#include "editor.h"
55
#include "gettext.h"
6-
#include "hex.h"
6+
#include "hex-ll.h"
77
#include "pager.h"
88
#include "strbuf.h"
99

hex-ll.c

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
}

hex-ll.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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

hex.c

-47
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,6 @@
22
#include "hash.h"
33
#include "hex.h"
44

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-
525
static int get_hash_hex_algop(const char *hex, unsigned char *hash,
536
const struct git_hash_algo *algop)
547
{

hex.h

+1-23
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,7 @@
22
#define HEX_H
33

44
#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"
216

227
/*
238
* Try to read a hash (specified by the_hash_algo) in hexadecimal
@@ -34,13 +19,6 @@ int get_oid_hex(const char *hex, struct object_id *oid);
3419
/* Like get_oid_hex, but for an arbitrary hash algorithm. */
3520
int get_oid_hex_algop(const char *hex, struct object_id *oid, const struct git_hash_algo *algop);
3621

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-
4422
/*
4523
* Convert a binary hash in "unsigned char []" or an object name in
4624
* "struct object_id *" to its hex equivalent. The `_r` variant is reentrant,

mailinfo.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "git-compat-util.h"
22
#include "config.h"
33
#include "gettext.h"
4-
#include "hex.h"
4+
#include "hex-ll.h"
55
#include "utf8.h"
66
#include "strbuf.h"
77
#include "mailinfo.h"

strbuf.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "git-compat-util.h"
22
#include "gettext.h"
3-
#include "hex.h"
3+
#include "hex-ll.h"
44
#include "strbuf.h"
55
#include "string-list.h"
66
#include "utf8.h"

url.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "git-compat-util.h"
2-
#include "hex.h"
2+
#include "hex-ll.h"
33
#include "strbuf.h"
44
#include "url.h"
55

urlmatch.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "git-compat-util.h"
22
#include "gettext.h"
3-
#include "hex.h"
3+
#include "hex-ll.h"
44
#include "strbuf.h"
55
#include "urlmatch.h"
66

0 commit comments

Comments
 (0)