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

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

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Mar 11, 2011, 01:16 UTC
Message-ID
<AANLkTikPxSspRFQWke4=u55cmmHw8NsyizeH2gL1kD0y@mail.gmail.com>
In-Reply-To
<7vzkp21ocm.fsf@alter.siamese.dyndns.org>
On Thu, Mar 10, 2011 at 4:40 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 8 quoted lines
>
> How many characters do we need to name master uniquely today?
>
>    $ ./git -c core.abbrevguard=0 rev-parse --short=1 master
>    83c3c
>
> Ok, so there are more than one object with 83c3 and 83c3c is the absolute
> minimum.
Actually, that's just lucky.
Do this:
  git rev-list --abbrev=4 --abbrev-commit --all --objects | grep '^.........*$'

and you'll see several commits in the git tree that need eight characters to be unique. The fact that your current 'master' isn't one of them, and in fact happens to be one that only needs five, is just pure luck.

So even in the (much smaller) git repo, 7 is not a sufficient unique minimum even today. Never mind any future guarding.

And your argument fails for exactly that reason: yes, for an _individual_ SHA1, you may think that "five characters is sufficient", and when you then use that random number (5) as a basis for forming your "max 8 character" logic, it fails miserably for other cases.

Now, if the "abbrevguard" was based not one one random data-point, but on the _whole_ current state of the repository, things would be different. Then it would actually become a "let's pick a good default abbreviation length for this repo". But that's now that it does. The abbrevguard depends on the one particular SHA1 you're looking at, so you can actually be asking for a longer abbreviation, but still get a _shorter_ end result than when you asked for a shorter abbreviation.

IOW, try your example thing not just with "master", but with two extreme commits. For example, try

  git -c core.abbrevguard=2 rev-parse --short=5 83c3c622
  git -c core.abbrevguard=2 rev-parse --short=4 979f7929

and tell me what you get. I _think_ you should get 7 digits for the first case, and 8 digits for the second one. Even though you "asked" for a longer name in the first case, and you had the same abbrevguard.

See what I'm saying? I think that's just insane. And it comes exactly from the fact that abbreviation ends up being a "local" thing.

                          Linus
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 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.