Skip to content

Commit 8655908

Browse files
committed
abbrev: allow extending beyond 32 chars to disambiguate
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 5b20ace (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 <[email protected]> Helped-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2c2ba49 commit 8655908

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

object-name.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ static int extend_abbrev_len(const struct object_id *oid, void *cb_data)
704704
while (mad->hex[i] && mad->hex[i] == get_hex_char_from_oid(oid, i))
705705
i++;
706706

707-
if (i < GIT_MAX_RAWSZ && i >= mad->cur_len)
707+
if (mad->hex[i] && i >= mad->cur_len)
708708
mad->cur_len = i + 1;
709709

710710
return 0;

0 commit comments

Comments
 (0)