git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] abbrev: allow extending beyond 20 chars to disambiguate
@ 2025-08-11 15:26 Junio C Hamano
  2025-08-11 18:53 ` Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Junio C Hamano @ 2025-08-11 15:26 UTC (permalink / raw)
  To: git; +Cc: Jon Forrest, Derrick Stolee

When you have two or more objects with object names that share more
than half the length of the hash algorithm in use (e.g. 10 bytes for
SHA-1 that produces 20-byte/160-bit hash), 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_MAX_HEXSZ, which is the correct limit
because the loop is adding one output letter per iteration.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 * No tests added, since I do not think I want to find two valid
   objects with their object names sharing the same prefix that is
   more than 20 letters long.  The current abbreviation code happens
   to ignore validity of the object and takes invalid objects into
   account when disambiguating, but I do not want to see a test rely
   on that.

   Git 2.15 (that predates 5b20ace6 which is in Git 2.16) does the
   right thing, even though it is a bit too old codebase to build
   these days (I had to omit curl and pcre, as I didn't need to get
   them working again only to see how its disambiguation code works)
   with the up-to-date libraries.

 object-name.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git c/object-name.c w/object-name.c
index 11aa0e6afc..13e8a4e47d 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 (i < GIT_MAX_HEXSZ && i >= mad->cur_len)
 		mad->cur_len = i + 1;
 
 	return 0;


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-08-14 15:09 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).