http-push: use hex_to_bytes()
The path of a loose object contains its hash value encoded into two substrings of hexadecimal digits, separated by a slash. The current code copies the pieces into a temporary buffer to get rid of the slash and then uses get_oid_hex() to decode the hash value. Avoid the copy by using hex_to_bytes() directly on the substrings. That's shorter and easier. While at it correct the length of the second substring in a comment. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Oct 31, 2017 at 14:49 UTC
c3bdc4e7795023863756cf6176c1ab32793459a1
1 file changed
+4
-6
http-push.c
+4
-6
@@ -1007,20 +1007,18 @@ static void remote_ls(const char *path, int flags,
1007
void (*userFunc)(struct remote_ls_ctx *ls),
1008
void *userData);
1009
1010
-/* extract hex from sharded "xx/x{40}" filename */
1010
+/* extract hex from sharded "xx/x{38}" filename */
1011
static int get_oid_hex_from_objpath(const char *path, struct object_id *oid)
1012
{
1013
- char hex[GIT_MAX_HEXSZ];
1014
-
1013
if (strlen(path) != GIT_SHA1_HEXSZ + 1)
1014
return -1;
1015
1018
- memcpy(hex, path, 2);
1016
+ if (hex_to_bytes(oid->hash, path, 1))
1017
+ return -1;
1018
path += 2;
1019
path++; /* skip '/' */
1021
- memcpy(hex + 2, path, GIT_SHA1_HEXSZ - 2);
1020
1023
- return get_oid_hex(hex, oid);
1021
+ return hex_to_bytes(oid->hash + 1, path, GIT_SHA1_RAWSZ - 1);
1022
}
1023
1024
static void process_ls_object(struct remote_ls_ctx *ls)