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

Re: [PATCH 10/10] get_short_sha1: list ambiguous objects on error

From
Kyle J. McKay <mackyle@gmail.com>
Date
Sep 29, 2016, 13:01 UTC
Message-ID
<841D4FC2-9673-486A-8D94-8967188CCC60@gmail.com>
In-Reply-To
<CA+55aFyfvvqq1c=hZcuL-yPavp2tjzx8r3bFJnMY7DAE7YcB=Q@mail.gmail.com>
On Sep 26, 2016, at 09:36, Linus Torvalds wrote:
Show 16 quoted lines
> On Mon, Sep 26, 2016 at 5:00 AM, Jeff King <peff@peff.net> wrote:
>>
>> This patch teaches get_short_sha1() to list the sha1s of the
>> objects it found, along with a few bits of information that
>> may help the user decide which one they meant.
>
> This looks very good to me, but I wonder if it couldn't be even more  
> aggressive.
>
> In particular, the only hashes that most people ever use in short form
> are commit hashes. Those are the ones you'd use in normal human
> interactions to point to something happening.
>
> So when the disambiguation notices that there is ambiguity, but there
> is only _one_ commit, maybe it should just have an aggressive mode
> that says "use that as if it wasn't ambiguous".
If you have this:

faa23ec9b437812ce2fc9a5b3d59418d672debc1 refs/heads/ambig 7f40afe646fa3f8a0f361b6f567d8f7d7a184c10 refs/tags/ambig

and you do this:

$ git rev-parse ambig warning: refname 'ambig' is ambiguous. 7f40afe646fa3f8a0f361b6f567d8f7d7a184c10

Git automatically prefers the tag over the branch, but it does spit out a warning.

> And then have an explicit command (or flag) to do disambiguation for
> when you explicitly want it.

I think you don't even need that. Git already does disambiguation for ref names, picks one and spits out a warning.

Why not do the same for short hash names when it makes sense?
Show 12 quoted lines
> Rationale: you'd never care about short forms for tags. You'd just use
> the tag name. And while blob ID's certainly show up in short form in
> diff output (in the "index" line), very few people will use them. And
> tree hashes are basically never seen outside of any plumbing commands
> and then seldom in shortened form.
>
> So I think it would make sense to default to a mode that just picks
> the commit hash if there is only one such hash. Sure, some command
> might want a "treeish", but a commit is still more likely than a tree
> or a tag.
>
> But regardless, this series looks like a good thing.
I like it too.

But perhaps it makes sense to actually pick one if there's only one disambiguation of the type you're looking for.

For example given:

235234a blob 2352347 tag 235234f tree 2352340 commit

If you are doing "git cat-file blob 235234" it should pick the blob and spit out a warning (and similarly for other cat-file types). But "git cat-file -p 235234" would give the fatal error with the disambiguation hints because it wants type "any".

If you are doing "git show 235234" it should pick the tag (if it peels to a committish) because Git has already set a precedent of preferring tags over commits when it disambiguates ref names and otherwise pick the commit.

Lets consider this approach using the stats for the Linux kernel:
Show 27 quoted lines
> Ambiguous prefix length 7 counts:
>   prefixes:   44733
>    objects:   89766
>
> Ambiguous length 11 (but not at length 12) info:
>   prefixes:       2
>                   0 (with 1 or more commit disambiguations)
>
> Ambiguous length 10 (but not at length 11) info:
>   prefixes:      12
>                   3 (with 1 or more commit disambiguations)
>                   0 (with 2 or more commit disambiguations)
>
> Ambiguous length 9 (but not at length 10) info:
>   prefixes:     186
>                  43 (with 1 or more commit disambiguations)
>                   1 (with 2 or more commit disambiguations)
>
> Ambiguous length 8 (but not at length 9) info:
>   prefixes:    2723
>                 651 (with 1 or more commit disambiguations)
>                  40 (with 2 or more commit disambiguations)
>
> Ambiguous length 7 (but not at length 8) info:
>   prefixes:   41864
>                9842 (with 1 or more commit disambiguations)
>                 680 (with 2 or more commit disambiguations)

Of the 44733 ambiguous length 7 prefixes, only about 10539 of them disambiguate into one or more commit objects.

But if we apply the "spit a warning and prefer a commit object if there's only one and you're looking for a committish" rule, that drops the number from 10539 to about 721. In other words, only about 7% of the previously ambiguous short commit SHA1 prefixes would continue to be ambiguous at length 7. In fact it almost makes a prefix length of 9 good enough, there's just the one at length 9 that disambiguates into more than one commit (45f014c52).

--Kyle
Previous: Jeff KingNext: Jeff King
Message 28 of 111 in “Changing the default for "core.abbrev"?”
  1. Linus TorvaldsSep 26, 2016
  2. Junio C HamanoSep 26, 2016
  3. Jeff KingSep 26, 2016
  4. Junio C HamanoSep 26, 2016
  5. 0/10 helping people resolve ambiguous sha1sJeff King, Sep 26, 2016
  6. 01/10 get_sha1: detect buggy calls with multiple disambiguatorsJeff King, Sep 26, 2016
  7. Junio C HamanoSep 26, 2016
  8. Jeff KingSep 26, 2016
  9. Junio C HamanoSep 26, 2016
  10. 02/10 get_sha1: avoid repeating ourselves via ONLY_TO_DIEJeff King, Sep 26, 2016
  11. 03/10 get_sha1: propagate flags to child functionsJeff King, Sep 26, 2016
  12. 04/10 get_short_sha1: peel tags when looking for treeishJeff King, Sep 26, 2016
  13. Jeff KingSep 26, 2016
  14. Junio C HamanoSep 26, 2016
  15. Jeff KingSep 26, 2016
  16. 05/10 get_short_sha1: refactor init of disambiguation codeJeff King, Sep 26, 2016
  17. 06/10 get_short_sha1: NUL-terminate hex prefixJeff King, Sep 26, 2016
  18. Junio C HamanoSep 26, 2016
  19. Jeff KingSep 26, 2016
  20. Junio C HamanoSep 26, 2016
  21. 07/10 get_short_sha1: mark ambiguity error for translationJeff King, Sep 26, 2016
  22. 08/10 sha1_array: let callbacks interrupt iterationJeff King, Sep 26, 2016
  23. 09/10 for_each_abbrev: drop duplicate objectsJeff King, Sep 26, 2016
  24. 10/10 get_short_sha1: list ambiguous objects on errorJeff King, Sep 26, 2016
  25. Linus TorvaldsSep 26, 2016
  26. Jacob KellerSep 27, 2016
  27. Jeff KingSep 27, 2016
  28. Kyle J. McKaySep 29, 2016
  29. Jeff KingSep 29, 2016
  30. Kyle J. McKaySep 29, 2016
  31. Jeff KingSep 29, 2016
  32. Junio C HamanoSep 26, 2016
  33. Jeff KingSep 26, 2016
  34. Junio C HamanoSep 26, 2016
  35. Kyle J. McKaySep 29, 2016
  36. Jeff KingSep 29, 2016
  37. Junio C HamanoSep 29, 2016
  38. Jacob KellerSep 30, 2016
  39. core.abbrev doc: document and test the abbreviation lengthÆvar Arnfjörð Bjarmason, Feb 4, 2019
  40. Junio C HamanoFeb 4, 2019
  41. Junio C HamanoFeb 4, 2019
  42. Ævar Arnfjörð BjarmasonFeb 4, 2019
  43. Jeff KingFeb 4, 2019
  44. Ævar Arnfjörð BjarmasonFeb 4, 2019
  45. Jeff KingFeb 6, 2019
  46. Ævar Arnfjörð BjarmasonFeb 6, 2019
  47. Matthieu MoySep 26, 2016
  48. Jeff KingSep 26, 2016
  49. Kyle J. McKaySep 29, 2016
  50. Christian CouderSep 26, 2016
  51. 0/4 raising core.abbrev default to 12 hexdigitsJunio C Hamano, Sep 28, 2016
  52. 3/4 worktree: honor configuration variablesJunio C Hamano, Sep 28, 2016
  53. 4/4 core.abbrev: raise the default abbreviation to 12 hexdigitsJunio C Hamano, Sep 28, 2016
  54. SZEDER GáborSep 29, 2016
  55. Lukas FleischerSep 29, 2016
  56. Jeff KingSep 29, 2016
  57. Jeff KingSep 29, 2016
  58. Matthieu MoySep 29, 2016
  59. SZEDER GáborSep 29, 2016
  60. Johannes SixtSep 29, 2016
  61. Junio C HamanoSep 29, 2016
  62. Linus TorvaldsSep 29, 2016
  63. Linus TorvaldsSep 29, 2016
  64. Linus TorvaldsSep 29, 2016
  65. Junio C HamanoSep 29, 2016
  66. Mike HommeySep 30, 2016
  67. Linus TorvaldsSep 30, 2016
  68. Ævar Arnfjörð BjarmasonSep 30, 2016
  69. Jeff KingSep 29, 2016
  70. Linus TorvaldsSep 29, 2016
  71. Junio C HamanoSep 29, 2016
  72. Linus TorvaldsSep 29, 2016
  73. Junio C HamanoSep 29, 2016
  74. Junio C HamanoSep 29, 2016
  75. Linus TorvaldsSep 30, 2016
  76. Linus TorvaldsSep 30, 2016
  77. Linus TorvaldsSep 30, 2016
  78. Linus TorvaldsSep 30, 2016
  79. Junio C HamanoSep 30, 2016
  80. Junio C HamanoSep 30, 2016
  81. Linus TorvaldsSep 30, 2016
  82. Linus TorvaldsSep 30, 2016
  83. Junio C HamanoSep 30, 2016
  84. Junio C HamanoSep 30, 2016
  85. Junio C HamanoSep 30, 2016
  86. Linus TorvaldsSep 30, 2016
  87. Junio C HamanoSep 30, 2016
  88. Linus TorvaldsSep 30, 2016
  89. Jeff KingSep 30, 2016
  90. Linus TorvaldsSep 30, 2016
  91. Jeff KingSep 30, 2016
  92. Linus TorvaldsSep 30, 2016
  93. Junio C HamanoSep 30, 2016
  94. Junio C HamanoSep 30, 2016
  95. Jeff KingSep 30, 2016
  96. Jeff KingSep 29, 2016
  97. 2/4 t13xx: do not assume system config is emptyJunio C Hamano, Sep 28, 2016
  98. Jeff KingSep 29, 2016
  99. Junio C HamanoSep 29, 2016
  100. Jeff KingSep 29, 2016
  101. Junio C HamanoSep 29, 2016
  102. Jeff KingSep 29, 2016
  103. Junio C HamanoSep 29, 2016
  104. Junio C HamanoSep 29, 2016
  105. Jeff KingSep 29, 2016
  106. Junio C HamanoSep 29, 2016
  107. Jeff KingSep 29, 2016
  108. 1/4 config: allow customizing /etc/gitconfig locationJunio C Hamano, Sep 28, 2016
  109. Jakub NarębskiSep 29, 2016
  110. Junio C HamanoSep 29, 2016
  111. Matthieu MoySep 29, 2016

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.