From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: git@vger.kernel.org, Jon Forrest <nobozo@gmail.com>,
Derrick Stolee <stolee@gmail.com>
Subject: Re: [PATCH v2] abbrev: allow extending beyond 20 chars to disambiguate
Date: Tue, 12 Aug 2025 08:17:58 -0700 [thread overview]
Message-ID: <xmqqwm78vaah.fsf@gitster.g> (raw)
In-Reply-To: <9ae4a718-b00d-4435-8739-cf87b2c9df7d@web.de> ("René Scharfe"'s message of "Tue, 12 Aug 2025 16:58:14 +0200")
René Scharfe <l.s.r@web.de> writes:
>> while (mad->hex[i] && mad->hex[i] == get_hex_char_from_oid(oid, i))
>> i++;
>>
>> - if (i < GIT_MAX_RAWSZ && i >= mad->cur_len)
>> + if (mad->cur_len <= i && i < mad->max_len)
>> mad->cur_len = i + 1;
>
> This combines two checks: Whether we can increment and whether the new
> length is greater than the old one. Only if both are true we take the
> new length. Shouldn't they be separate, though? Why reject a new
> length that happens to be the maximum? And max_len is not explicitly
> needed for the first check:
>
> /* One more to disambiguate, if possible. */
> if (mad->hex[i])
> i++;
>
> /* New record? */
> if (i > mad->cur_len)
> mad->cur_len = i;
>
> René
Great.
Your observation resolves my puzzlement about the first while() loop
that has been bugging me ever since I started looking at this code.
The mad->hex[] array is NUL terminated, and the loop can terminate
correctly without being told about hexsz at all, and we ought to be
able to use the same information to make sure we stop incrementing
the .cur_len member without running beyond the end of the string.
In other words, wouldn't this be what we want, without any of the
max_len crap?
diff --git c/object-name.c w/object-name.c
index 11aa0e6afc..4cd1d38778 100644
--- c/object-name.c
+++ w/object-name.c
@@ -704,7 +704,7 @@ static int extend_abbrev_len(const struct object_id *oid, void *cb_data)
while (mad->hex[i] && mad->hex[i] == get_hex_char_from_oid(oid, i))
i++;
- if (i < GIT_MAX_RAWSZ && i >= mad->cur_len)
+ if (mad->hex[i] && i >= mad->cur_len)
mad->cur_len = i + 1;
return 0;
next prev parent reply other threads:[~2025-08-12 15:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-11 15:26 [PATCH] abbrev: allow extending beyond 20 chars to disambiguate Junio C Hamano
2025-08-11 18:53 ` Junio C Hamano
2025-08-11 19:06 ` [PATCH v2] " Junio C Hamano
2025-08-11 22:23 ` brian m. carlson
2025-08-12 13:28 ` Derrick Stolee
2025-08-12 14:58 ` René Scharfe
2025-08-12 15:17 ` Junio C Hamano [this message]
2025-08-12 15:59 ` René Scharfe
2025-08-14 15:09 ` [PATCH v3] abbrev: allow extending beyond 32 " Junio C Hamano
2025-08-11 21:17 ` [PATCH] abbrev: allow extending beyond 20 " brian m. carlson
2025-08-11 21:25 ` Junio C Hamano
2025-08-11 21:28 ` Junio C Hamano
2025-08-12 15:26 ` Jon Forrest
2025-08-12 16:21 ` René Scharfe
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=xmqqwm78vaah.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=l.s.r@web.de \
--cc=nobozo@gmail.com \
--cc=stolee@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).