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

[PATCH v3] abbrev: allow extending beyond 32 chars to disambiguate

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 14, 2025, 15:09 UTC
Message-ID
<xmqqh5ya6iua.fsf_-_@gitster.g>
In-Reply-To
<xmqqzfc51xvk.fsf@gitster.g>

When you have two or more objects with object names that share more than 32 letters in an SHA-1 repository, find_unique_abbrev() fails to show disambiguation.

To see how many leading letters of a given full object name is sufficiently unambiguous, the algorithm starts from a initial length, guessed based on the estimated number of objects in the repository, and see if another object that shares the prefix, and keeps extending the abbreviation. The loop stops at GIT_MAX_RAWSZ, which is counted as the number of bytes, since 5b20ace6 (sha1_name: unroll len loop in find_unique_abbrev_r(), 2017-10-08); before that change, it extended up to GIT_SHA1_HEXSZ, which meant to stop at the end of hexadecimal SHA-1 object name.

Because the hexadecimal object name passed to the function is NUL-terminated, and this fact is used to correctly terminate the loop that scans for the first difference earlier in the function, use it to make sure we do not increment the .cur_len member beyond the end of the string.

Noticed-by: Jon Forrest <nobozo@gmail.com>
Helped-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * To tie the loose ends, here is what is in 'seen'.  We may want to
   merge it down once 2.51 final gets tagged.
 object-name.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/object-name.c b/object-name.c
index 11aa0e6afc..4cd1d38778 100644
--- a/object-name.c
+++ b/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;
-- 
2.51.0-rc2-158-gf97fc618fa
Previous: René ScharfeNext: brian m. carlson
Message 9 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.