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
brian m. carlson <sandals@crustytoothpaste.net>
Date
Aug 11, 2025, 22:23 UTC
Message-ID
<aJptcgwQmwIbnrqE@fruit.crustytoothpaste.net>
In-Reply-To
<xmqqzfc51xvk.fsf@gitster.g>
On 2025-08-11 at 19:06:39, Junio C Hamano wrote:
Show 34 quoted lines
> diff --git a/object-name.c b/object-name.c
> index 11aa0e6afc..8f9af57c0a 100644
> --- a/object-name.c
> +++ b/object-name.c
> @@ -680,6 +680,7 @@ static unsigned msb(unsigned long val)
>  struct min_abbrev_data {
>  	unsigned int init_len;
>  	unsigned int cur_len;
> +	unsigned int max_len;
>  	char *hex;
>  	struct repository *repo;
>  	const struct object_id *oid;
> @@ -699,12 +700,12 @@ static inline char get_hex_char_from_oid(const struct object_id *oid,
>  static int extend_abbrev_len(const struct object_id *oid, void *cb_data)
>  {
>  	struct min_abbrev_data *mad = cb_data;
> -
>  	unsigned int i = mad->init_len;
> +
>  	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;
>  
>  	return 0;
> @@ -864,6 +865,7 @@ int repo_find_unique_abbrev_r(struct repository *r, char *hex,
>  	mad.repo = r;
>  	mad.init_len = len;
>  	mad.cur_len = len;
> +	mad.max_len = hexsz;
>  	mad.hex = hex;
>  	mad.oid = oid;

This definitely looks more sensible, since we're using the algorithm specified in the passed in `oid` variable in `repo_find_unique_abbrev_r` to determine the length.

I will admit that despite having touched this code recently in my SHA-1/SHA-256 interoperability work, I'm definitely not an expert in this area, so while I don't see anything that stands out to me as wrong, you probably will want someone else to verify here.

-- 
brian m. carlson (they/them)
Toronto, Ontario, CA
Previous: Junio C HamanoNext: Derrick Stolee
Message 4 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.