git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Jeff King <peff@peff.net>
Cc: Git List <git@vger.kernel.org>,
	Junio C Hamano <gitster@pobox.com>,
	"brian m. carlson" <sandals@crustytoothpaste.net>,
	Michael Haggerty <mhagger@alum.mit.edu>,
	Thomas Gummerer <t.gummerer@gmail.com>
Subject: Re: [PATCH 2/3] http-push: use hex_to_bytes()
Date: Wed, 1 Nov 2017 22:59:49 +0100	[thread overview]
Message-ID: <0e7f821a-94ae-3946-fb99-c508a06a6847@web.de> (raw)
In-Reply-To: <20171101195530.odscytks7jvgukbs@sigill.intra.peff.net>

Am 01.11.2017 um 20:55 schrieb Jeff King:
> On Tue, Oct 31, 2017 at 02:49:56PM +0100, René Scharfe wrote:
> 
>> 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.
> 
> I think the patch is correct, but I wonder if this approach will bite us
> later on when we start dealing with multiple lengths of hashes.
> 
> The hex_to_bytes() function requires that the caller make sure they have
> the right number of bytes. But for many callers, I think they'd want to
> say "parse this oid, which might be truncated; I can't tell what the
> length is supposed to be".

I'm confused by the word "many".  After this series there are three
callers of hex_to_bytes() and I don't expect that number to grow.

Would loose objects be stored at paths containing only a subset of their
new hash value?  If they won't then there will be two acceptable lengths
instead of the one we have today, which should be easy to handle.

> I.e., I wonder if the right primitive is really something like
> parse_oid_hex(), but with a flag to say "skip over interior slashes".

Hmm, ignoring any slashes is an interesting idea.  Is that too loose, I
wonder?  And I don't think it makes for a good primitive, as slashes
only need to be ignored in a single place so far (here in http-push.c).
Collecting special cases in a central place, guarded by flags, doesn't
reduce the overall complexity.

> We don't need to deal with that eventuality yet, but I'm on the fence on
> whether this patch is making that harder down the road or not. The
> current strategy of "stuff it into a buffer without slashes" would be
> easier to convert, I think.

How so?  If you have a buffer then you need to know the size of the
data to copy into it as well, or you'll learn it in the process.

The call sites of hex_to_bytes() have to be modified along with the
functions in hex.c to support longer hashes, with or without this
series.

René

  reply	other threads:[~2017-11-01 22:00 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 ` [PATCH 2/3] http-push: use hex_to_bytes() René Scharfe
2017-11-01 19:55   ` Jeff King
2017-11-01 21:59     ` René Scharfe [this message]
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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0e7f821a-94ae-3946-fb99-c508a06a6847@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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).