git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] abbrev: allow extending beyond 20 chars to disambiguate

From
René Scharfe <l.s.r@web.de>
Date
Aug 12, 2025, 15:59 UTC
Message-ID
<6d0631ed-9a28-4107-8c07-298a9424769b@web.de>
In-Reply-To
<xmqqwm78vaah.fsf@gitster.g>
On 8/12/25 5:17 PM, Junio C Hamano wrote:
Show 50 quoted lines
> 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;

This combines the two checks and I don't see why. Why not update cur_len when oid and mad->oid are the same (mad->hex[i] == '\0')? Ah, to _ignore_ duplicates on purpose, when we have the same object loose and packed or in multiple packs, right? We wouldn't want to let that affect abbreviations, makes sense.

René
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 14 in “abbrev: allow extending beyond 20 chars to disambiguate”
  1. abbrev: allow extending beyond 20 chars to disambiguateJunio C Hamano, Aug 11, 2025
  2. Junio C HamanoAug 11, 2025
  3. abbrev: allow extending beyond 20 chars to disambiguateJunio C Hamano, Aug 11, 2025
  4. brian m. carlsonAug 11, 2025
  5. Derrick StoleeAug 12, 2025
  6. René ScharfeAug 12, 2025
  7. Junio C HamanoAug 12, 2025
  8. René ScharfeAug 12, 2025
  9. abbrev: allow extending beyond 32 chars to disambiguateJunio C Hamano, Aug 14, 2025
  10. brian m. carlsonAug 11, 2025
  11. Junio C HamanoAug 11, 2025
  12. Junio C HamanoAug 11, 2025
  13. Jon ForrestAug 12, 2025
  14. René ScharfeAug 12, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.