Re: [RFC PATCH 5/6] object-name: use hexval
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 25, 2026, 16:19 UTC
- Message-ID
- <xmqqcxv6npf0.fsf@gitster.g>
- In-Reply-To
- <20260729233215.398654-6-sandals@crustytoothpaste.net>
"brian m. carlson" <sandals@crustytoothpaste.net> writes:
Show 37 quoted lines
> We've open-coded a different implementation of parsing hex values here
> when we already have a perfectly good one in hexval. This
> implementation will almost certainly be slower because it isn't
> table-driven, unlike the other one, and since it's not constant time it
> has no other advantages either. To tidy things up and prepare for
> future work, switch to hexval in this case.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
> object-name.c | 13 +++----------
> 1 file changed, 3 insertions(+), 10 deletions(-)
>
> diff --git a/object-name.c b/object-name.c
> index 83efba0ba6..d2d81b3511 100644
> --- a/object-name.c
> +++ b/object-name.c
> @@ -236,17 +236,10 @@ static int parse_oid_prefix(const char *name, int len,
> {
> for (int i = 0; i < len; i++) {
> unsigned char c = name[i];
> - unsigned char val;
> - if (c >= '0' && c <= '9') {
> - val = c - '0';
> - } else if (c >= 'a' && c <= 'f') {
> - val = c - 'a' + 10;
> - } else if (c >= 'A' && c <='F') {
> - val = c - 'A' + 10;
> - c -= 'A' - 'a';
> - } else {
> + int val = hexval(c, HEX_KIND_OID);
> +
> + if (val < 0)
> return -1;
> - }
>
> if (hex_out)
> hex_out[i] = c;When hex_out[] is given by the caller, they used to get a downcased version of object name. After your planned transition to forbid uppercase hex, they will get an error, which is exactly as you intend.
However, during transition, they will *not* get an error (as KIND_OID is still KIND_MIXED before the transition), and they will see the hex_out[] filled with object names in the original case, without canonicalization that the original code gave them.
While seemingly harmless, because repo_for_each_abbrev() doesn't seem to malfunction on uppercase string metadata for disambiguation), we may want to mention that this changes API contract (until we forbid uppercase input altogether).