From: "René Scharfe" <l.s.r@web.de>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
"brian m. carlson" <sandals@crustytoothpaste.net>,
Michael Haggerty <mhagger@alum.mit.edu>,
Thomas Gummerer <t.gummerer@gmail.com>
Subject: [PATCH 2/3] http-push: use hex_to_bytes()
Date: Tue, 31 Oct 2017 14:49:56 +0100 [thread overview]
Message-ID: <31ce5c1c-cab3-80aa-623b-43f91ddd2162@web.de> (raw)
In-Reply-To: <508b1b3f-6b55-eee8-110a-c17d572ec27a@web.de>
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>
---
http-push.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/http-push.c b/http-push.c
index 493ee7d719..14435ab65d 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)
--
2.15.0
next prev parent reply other threads:[~2017-10-31 13:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-31 13:46 [PATCH 1/3] notes: move hex_to_bytes() to hex.c and export it René Scharfe
2017-10-31 13:49 ` René Scharfe [this message]
2017-11-01 19:55 ` [PATCH 2/3] http-push: use hex_to_bytes() Jeff King
2017-11-01 21:59 ` René Scharfe
2017-11-01 22:15 ` Jeff King
2017-11-04 9:05 ` René Scharfe
2017-10-31 13:50 ` [PATCH 3/3] sha1_file: " René Scharfe
2017-11-01 19:58 ` Jeff King
2017-11-05 2:56 ` [PATCH 1/3] notes: move hex_to_bytes() to hex.c and export it Kevin Daudt
2017-11-05 16:47 ` René Scharfe
2017-11-05 19:57 ` Kevin Daudt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=31ce5c1c-cab3-80aa-623b-43f91ddd2162@web.de \
--to=l.s.r@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mhagger@alum.mit.edu \
--cc=peff@peff.net \
--cc=sandals@crustytoothpaste.net \
--cc=t.gummerer@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).