summaryrefslogtreecommitdiff
path: root/cache.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-09-12 22:34:36 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-09-12 22:34:36 (GMT)
commite4ec05ed93bede22b0d79ab58997f0fc170929e9 (patch)
treef2e445694b466952e89b616977832a641432db9b /cache.h
parent27853a85edce65afd73c8bb0ca7adf0a4468def3 (diff)
parentd23309733a5b2a9e1adc304ee50c5a5ed7a087c2 (diff)
downloadgit-e4ec05ed93bede22b0d79ab58997f0fc170929e9.zip
git-e4ec05ed93bede22b0d79ab58997f0fc170929e9.tar.gz
git-e4ec05ed93bede22b0d79ab58997f0fc170929e9.tar.bz2
Merge branch 'rs/hex2chr'
* rs/hex2chr: introduce hex2chr() for converting two hexadecimal digits to a character
Diffstat (limited to 'cache.h')
-rw-r--r--cache.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/cache.h b/cache.h
index aac38a6..3556326 100644
--- a/cache.h
+++ b/cache.h
@@ -1156,6 +1156,16 @@ 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)
+{
+ int val = hexval(s[0]);
+ return (val < 0) ? val : (val << 4) | hexval(s[1]);
+}
+
/* Convert to/from hex/sha1 representation */
#define MINIMUM_ABBREV minimum_abbrev
#define DEFAULT_ABBREV default_abbrev