summaryrefslogtreecommitdiff
path: root/hex.c
diff options
context:
space:
mode:
authorbrian m. carlson <sandals@crustytoothpaste.net>2017-02-20 00:10:13 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-02-20 09:11:26 (GMT)
commit605f430efb23ce14ca11750368149acd38b8f1e4 (patch)
treeb9e9593022ca7c0258f0a940eab301b4a0d3bbdc /hex.c
parent5588dbffbd61e4906e453808c6ad32f792fea521 (diff)
downloadgit-605f430efb23ce14ca11750368149acd38b8f1e4.zip
git-605f430efb23ce14ca11750368149acd38b8f1e4.tar.gz
git-605f430efb23ce14ca11750368149acd38b8f1e4.tar.bz2
hex: introduce parse_oid_hex
Introduce a function, parse_oid_hex, which parses a hexadecimal object ID and if successful, sets a pointer to just beyond the last character. This allows for simpler, more robust parsing without needing to hard-code integer values throughout the codebase. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'hex.c')
-rw-r--r--hex.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/hex.c b/hex.c
index 845b01a..eab7b62 100644
--- a/hex.c
+++ b/hex.c
@@ -53,6 +53,14 @@ int get_oid_hex(const char *hex, struct object_id *oid)
return get_sha1_hex(hex, oid->hash);
}
+int parse_oid_hex(const char *hex, struct object_id *oid, const char **end)
+{
+ int ret = get_oid_hex(hex, oid);
+ if (!ret)
+ *end = hex + GIT_SHA1_HEXSZ;
+ return ret;
+}
+
char *sha1_to_hex_r(char *buffer, const unsigned char *sha1)
{
static const char hex[] = "0123456789abcdef";