From 605f430efb23ce14ca11750368149acd38b8f1e4 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 20 Feb 2017 00:10:13 +0000 Subject: 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 Signed-off-by: Junio C Hamano --- hex.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'hex.c') diff --git a/hex.c b/hex.c index 845b01a874..eab7b626ee 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"; -- cgit v1.2.3