mirror of
https://github.com/git/git
synced 2024-11-04 16:17:49 +00:00
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>
This commit is contained in:
parent
94e83dcf5b
commit
d88e8106e8
10 changed files with 83 additions and 75 deletions
1
Makefile
1
Makefile
|
@ -1040,6 +1040,7 @@ LIB_OBJS += hash-lookup.o
|
|||
LIB_OBJS += hashmap.o
|
||||
LIB_OBJS += help.o
|
||||
LIB_OBJS += hex.o
|
||||
LIB_OBJS += hex-ll.o
|
||||
LIB_OBJS += hook.o
|
||||
LIB_OBJS += ident.o
|
||||
LIB_OBJS += json-writer.o
|
||||
|
|
2
color.c
2
color.c
|
@ -3,7 +3,7 @@
|
|||
#include "color.h"
|
||||
#include "editor.h"
|
||||
#include "gettext.h"
|
||||
#include "hex.h"
|
||||
#include "hex-ll.h"
|
||||
#include "pager.h"
|
||||
#include "strbuf.h"
|
||||
|
||||
|
|
49
hex-ll.c
Normal file
49
hex-ll.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include "git-compat-util.h"
|
||||
#include "hex-ll.h"
|
||||
|
||||
const signed char hexval_table[256] = {
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 00-07 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 08-0f */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 10-17 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 18-1f */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 20-27 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 28-2f */
|
||||
0, 1, 2, 3, 4, 5, 6, 7, /* 30-37 */
|
||||
8, 9, -1, -1, -1, -1, -1, -1, /* 38-3f */
|
||||
-1, 10, 11, 12, 13, 14, 15, -1, /* 40-47 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 48-4f */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 50-57 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 58-5f */
|
||||
-1, 10, 11, 12, 13, 14, 15, -1, /* 60-67 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 68-67 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 70-77 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 78-7f */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 80-87 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-8f */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 90-97 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 98-9f */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* a0-a7 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* a8-af */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* b0-b7 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* b8-bf */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* c0-c7 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* c8-cf */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* d0-d7 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* d8-df */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* e0-e7 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* e8-ef */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* f0-f7 */
|
||||
-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;
|
||||
}
|
27
hex-ll.h
Normal file
27
hex-ll.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#ifndef HEX_LL_H
|
||||
#define HEX_LL_H
|
||||
|
||||
extern const signed char hexval_table[256];
|
||||
static inline unsigned int hexval(unsigned char c)
|
||||
{
|
||||
return hexval_table[c];
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert two consecutive hexadecimal digits into a char. Return a
|
||||
* negative value on error. Don't run over the end of short strings.
|
||||
*/
|
||||
static inline int hex2chr(const char *s)
|
||||
{
|
||||
unsigned int val = hexval(s[0]);
|
||||
return (val & ~0xf) ? val : (val << 4) | hexval(s[1]);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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).
|
||||
*/
|
||||
int hex_to_bytes(unsigned char *binary, const char *hex, size_t len);
|
||||
|
||||
#endif
|
47
hex.c
47
hex.c
|
@ -2,53 +2,6 @@
|
|||
#include "hash.h"
|
||||
#include "hex.h"
|
||||
|
||||
const signed char hexval_table[256] = {
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 00-07 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 08-0f */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 10-17 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 18-1f */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 20-27 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 28-2f */
|
||||
0, 1, 2, 3, 4, 5, 6, 7, /* 30-37 */
|
||||
8, 9, -1, -1, -1, -1, -1, -1, /* 38-3f */
|
||||
-1, 10, 11, 12, 13, 14, 15, -1, /* 40-47 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 48-4f */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 50-57 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 58-5f */
|
||||
-1, 10, 11, 12, 13, 14, 15, -1, /* 60-67 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 68-67 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 70-77 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 78-7f */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 80-87 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 88-8f */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 90-97 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* 98-9f */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* a0-a7 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* a8-af */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* b0-b7 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* b8-bf */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* c0-c7 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* c8-cf */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* d0-d7 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* d8-df */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* e0-e7 */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* e8-ef */
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, /* f0-f7 */
|
||||
-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;
|
||||
}
|
||||
|
||||
static int get_hash_hex_algop(const char *hex, unsigned char *hash,
|
||||
const struct git_hash_algo *algop)
|
||||
{
|
||||
|
|
24
hex.h
24
hex.h
|
@ -2,22 +2,7 @@
|
|||
#define HEX_H
|
||||
|
||||
#include "hash-ll.h"
|
||||
|
||||
extern const signed char hexval_table[256];
|
||||
static inline unsigned int hexval(unsigned char c)
|
||||
{
|
||||
return hexval_table[c];
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert two consecutive hexadecimal digits into a char. Return a
|
||||
* negative value on error. Don't run over the end of short strings.
|
||||
*/
|
||||
static inline int hex2chr(const char *s)
|
||||
{
|
||||
unsigned int val = hexval(s[0]);
|
||||
return (val & ~0xf) ? val : (val << 4) | hexval(s[1]);
|
||||
}
|
||||
#include "hex-ll.h"
|
||||
|
||||
/*
|
||||
* 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);
|
|||
/* Like get_oid_hex, but for an arbitrary hash algorithm. */
|
||||
int get_oid_hex_algop(const char *hex, struct object_id *oid, const struct git_hash_algo *algop);
|
||||
|
||||
/*
|
||||
* 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).
|
||||
*/
|
||||
int hex_to_bytes(unsigned char *binary, const char *hex, size_t len);
|
||||
|
||||
/*
|
||||
* Convert a binary hash in "unsigned char []" or an object name in
|
||||
* "struct object_id *" to its hex equivalent. The `_r` variant is reentrant,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "git-compat-util.h"
|
||||
#include "config.h"
|
||||
#include "gettext.h"
|
||||
#include "hex.h"
|
||||
#include "hex-ll.h"
|
||||
#include "utf8.h"
|
||||
#include "strbuf.h"
|
||||
#include "mailinfo.h"
|
||||
|
|
2
strbuf.c
2
strbuf.c
|
@ -1,6 +1,6 @@
|
|||
#include "git-compat-util.h"
|
||||
#include "gettext.h"
|
||||
#include "hex.h"
|
||||
#include "hex-ll.h"
|
||||
#include "strbuf.h"
|
||||
#include "string-list.h"
|
||||
#include "utf8.h"
|
||||
|
|
2
url.c
2
url.c
|
@ -1,5 +1,5 @@
|
|||
#include "git-compat-util.h"
|
||||
#include "hex.h"
|
||||
#include "hex-ll.h"
|
||||
#include "strbuf.h"
|
||||
#include "url.h"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "git-compat-util.h"
|
||||
#include "gettext.h"
|
||||
#include "hex.h"
|
||||
#include "hex-ll.h"
|
||||
#include "strbuf.h"
|
||||
#include "urlmatch.h"
|
||||
|
||||
|
|
Loading…
Reference in a new issue