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

Re: [PATCH] find_unique_abbrev(): honor caller-supplied "len" better

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 11, 2011, 03:03 UTC
Message-ID
<7vipvq1hpw.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7vmxl21lwr.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 5 quoted lines
> Hmph, why?
>
> That 979f79 one already have enough other objects with similar names, so
> compared to 83c3c that doesn't, it is natural that you would need more
> digits to protect its uniqueness, no?

Yuck, this is showing my total non-understanding of statistics and secure hashing. The example does not mean the next object we will create in git.git project somehow magically is more likely to have 979 prefix than 83c prefix. In other words, 979f7929 is much less likely to collide with new objects than 83c3c, simply because it has 4 more digits in it (making the likelyhood of collision with the next one by four orders of magnitude in base-16), the likelyhood does not depend on what other objects happen to share the same prefix right now, and adding one digits to each would make it 1/16 less likely to have collision relative to the likelyhood with their current length.

In any case, if we want to protect abbreviations we generate today from future collisions, the only sane thing to do is to give sufficiently long "len" that is computed globally by taking the total number of objects into account. We should consider the loop in find_unique_abbrev that makes sure that prefix truncated to len is unique, and increments until the result becomes unique, merely a last-ditch thing, not contributing to futureproofing. Even though adding 1 to make it minimally unique as we have always did before the abbrevguard patch has the same "that 1 extra has different effectiveness for protecting against future collisions, depending on how long the base string is" issue, we cannot get away by adding less than 1 character, and adding more doesn't make it better.

So let's scrap the abbrevguard thing. I somehow thought that I already took your "make DEFAULT_ABBREV tweakable" patch, but apparently I didn't. That one is the real fix to the issue of futureproofing.

Previous: Junio C HamanoNext: Jeff King
Message 12 of 18 in “Minimum git commit abbrev length (Was Re: -tip: origin tree build failure (was: [GIT PULL] ext4 update) for 2.6.37)”
  1. Ted Ts'oOct 28, 2010
  2. Linus TorvaldsOct 28, 2010
  3. Linus TorvaldsOct 28, 2010
  4. Brandon CaseyOct 29, 2010
  5. find_unique_abbrev(): honor caller-supplied "len" betterJunio C Hamano, Mar 10, 2011
  6. Linus TorvaldsMar 10, 2011
  7. Junio C HamanoMar 11, 2011
  8. Linus TorvaldsMar 11, 2011
  9. Junio C HamanoMar 11, 2011
  10. Linus TorvaldsMar 11, 2011
  11. Junio C HamanoMar 11, 2011
  12. Junio C HamanoMar 11, 2011
  13. Jeff KingMar 11, 2011
  14. Jeff KingMar 11, 2011
  15. Junio C HamanoMar 11, 2011
  16. Namhyung KimMar 13, 2011
  17. Jay SoffianMar 19, 2011
  18. Namhyung KimMar 19, 2011

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.