summaryrefslogtreecommitdiff
path: root/http-push.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-10-31 13:49:56 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-11-01 01:35:39 (GMT)
commitc3bdc4e7795023863756cf6176c1ab32793459a1 (patch)
tree5494f784bb418e648755296a4598b0b69dbd7181 /http-push.c
parent0ec218656a02ea48e173262f7b80513feeb7f263 (diff)
downloadgit-c3bdc4e7795023863756cf6176c1ab32793459a1.zip
git-c3bdc4e7795023863756cf6176c1ab32793459a1.tar.gz
git-c3bdc4e7795023863756cf6176c1ab32793459a1.tar.bz2
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>
Diffstat (limited to 'http-push.c')
-rw-r--r--http-push.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/http-push.c b/http-push.c
index 493ee7d..14435ab 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1007,20 +1007,18 @@ static void remote_ls(const char *path, int flags,
void (*userFunc)(struct remote_ls_ctx *ls),
void *userData);
-/* extract hex from sharded "xx/x{40}" filename */
+/* extract hex from sharded "xx/x{38}" filename */
static int get_oid_hex_from_objpath(const char *path, struct object_id *oid)
{
- char hex[GIT_MAX_HEXSZ];
-
if (strlen(path) != GIT_SHA1_HEXSZ + 1)
return -1;
- memcpy(hex, path, 2);
+ if (hex_to_bytes(oid->hash, path, 1))
+ return -1;
path += 2;
path++; /* skip '/' */
- memcpy(hex + 2, path, GIT_SHA1_HEXSZ - 2);
- return get_oid_hex(hex, oid);
+ return hex_to_bytes(oid->hash + 1, path, GIT_SHA1_RAWSZ - 1);
}
static void process_ls_object(struct remote_ls_ctx *ls)