Skip to content

Commit

Permalink
http-push: use hex_to_bytes()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rscharfe authored and gitster committed Nov 1, 2017
1 parent 0ec2186 commit c3bdc4e
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions http-push.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c3bdc4e

Please sign in to comment.