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

Re: [PATCH v3 09/12] get_short_oid / peel_onion: ^{tree} should be tree, not treeish

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
May 3, 2018, 07:28 UTC
Message-ID
<87wowlxko8.fsf@evledraar.gmail.com>
In-Reply-To
<xmqqzi1htij7.fsf@gitster-ct.c.googlers.com>
On Thu, May 03 2018, Junio C Hamano wrote:
Show 33 quoted lines
> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>
>> But ^{tree} shows just the trees, but would previously be equivalent
>> to the above:
>>
>>     $ git rev-parse e8f2^{tree}
>>     error: short SHA1 e8f2 is ambiguous
>>     hint: The candidates are:
>>     hint:   e8f2093055 tree
>>     hint:   e8f25a3a50 tree
>>     hint:   e8f28d537c tree
>>     hint:   e8f2cf6ec0 tree
>>     [...]
>
> When a user says "git $cmd e8f2^{tree}", the user is telling Git
> that s/he knows e8f2 *is* a tree-ish, but for whatever reason $cmd
> wants a tree and does not accept an arbitrary tree-ish---that is the
> whole piont of appending ^{tree} as a suffix.  A useful hint in such
> a case would be "oh, you said e8f2 is a tree-ish, but there are more
> than one tree-ish, so let me show them to you to help you decide
> which one among them is the one you meant".  When $cmd is rev-parse,
> I would even say that the user is saying "I know e8f2 is a tree-ish,
> and I know it not a tree--it merely is a tree-ish.  I want the tree
> that e8f2 thing points at".
>
> Limiting that hint to show only real trees does not make any sense
> to me.  I do not think we care _too_ deeply, because most of the
> time, command line location that expects a tree-ish can be given a
> tree-ish, so there is not much reason to use ^{tree} suffix these
> days.  But in a case where it _does_ matter, I think this change
> makes the "hint" almost useless.
>
> Or am I misleading what you wanted to achieve with this patch?

The reason I'm doing this is because I found it confusing that I can't do:

    for t in tag commit tree blob; do ./git --exec-path=$PWD rev-parse 7452^{$t}; done

And get, respectively, only the SHAs that match the respective type, but currently (with released git) you can do:

    for t in tag commit committish treeish tree blob; do git -c core.disambiguate=$t rev-parse 7452; done

And while =tag doesn't work the others do (inluding =blob), so core.disambiguate=tree gives you just trees, but ^{tree} gives you treeish.

Why should ^{tree} be giving me ^{treeish} but =tree be giving me trees, and =treeish be synonymous with ^{tree}?

There's no other cases I know of where the ^{<type>} peel syntax won't give you *only* the <type> you asked for. See peel_onion() -> peel_to_type() and how get_oid_1() will short-circuit if it has an answer, and then finally fall back to this get_short_oid() codepath.

Looking at the code & git log maybe it'll do that internally, but when you peel a tag or commit ^{tree} will only ever find one thing, unlike this disambiguation case where we can match multiple things.

So:
1) Am I missing some subtlety or am I correct that there was no way to
get git to return more than one SHA-1 for ^{commit} or ^{tree} before
this disambiguation feature was added?
2) I think the behavior I've implemented is consistent with how the peel
syntax has been documented in revisions.txt:
    '<rev>{caret}{<type>}', e.g. 'v0.99.8{caret}\{commit\}'::
      A suffix '{caret}' followed by an object type name enclosed in
      brace pair means dereference the object at '<rev>' recursively until
      an object of type '<type>' is found or the object cannot be
      dereferenced anymore (in which case, barf).
      For example, if '<rev>' is a commit-ish, '<rev>{caret}\{commit\}'
      describes the corresponding commit object.
      Similarly, if '<rev>' is a tree-ish, '<rev>{caret}\{tree\}'
      describes the corresponding tree object.
      '<rev>{caret}0'
      is a short-hand for '<rev>{caret}\{commit\}'.

Note "until an object of type '<type>' is found". I.e. my mental model of this has been that yes you can *start* the search at a different object (e.g. tag -> tree), but it'll only ever return the tree. The disambiguation implementation has been inconsistent with this as documented, because it hasn't been drilling don to an object of '<type>' given a request like $short^{<type>}, but rather returning something matching $short because it could be a container for <type>.

Anyway, I'm not saying I'm right. This is the first time I really look at sha1-name.c in any detail. But the above describes the thought process behind this patch.

Previous: Junio C HamanoNext: Junio C Hamano
Message 61 of 99 in “get_short_oid UI improvements”
  1. 0/9 get_short_oid UI improvementsÆvar Arnfjörð Bjarmason, Apr 30, 2018
  2. 1/9 sha1-name.c: remove stray newlineÆvar Arnfjörð Bjarmason, Apr 30, 2018
  3. 2/9 sha1-array.h: align function argumentsÆvar Arnfjörð Bjarmason, Apr 30, 2018
  4. 3/9 sha1-name.c: move around the collect_ambiguous() functionÆvar Arnfjörð Bjarmason, Apr 30, 2018
  5. 4/9 get_short_oid: sort ambiguous objects by type, then SHA-1Ævar Arnfjörð Bjarmason, Apr 30, 2018
  6. Derrick StoleeMay 1, 2018
  7. Ævar Arnfjörð BjarmasonMay 1, 2018
  8. Derrick StoleeMay 1, 2018
  9. Ævar Arnfjörð BjarmasonMay 1, 2018
  10. Derrick StoleeMay 1, 2018
  11. 6/9 get_short_oid: learn to disambiguate by ^{blob}Ævar Arnfjörð Bjarmason, Apr 30, 2018
  12. 7/9 get_short_oid / peel_onion: ^{tree} should mean tree, not treeishÆvar Arnfjörð Bjarmason, Apr 30, 2018
  13. brian m. carlsonMay 1, 2018
  14. 5/9 get_short_oid: learn to disambiguate by ^{tag}Ævar Arnfjörð Bjarmason, Apr 30, 2018
  15. 9/9 config doc: document core.disambiguateÆvar Arnfjörð Bjarmason, Apr 30, 2018
  16. 8/9 get_short_oid / peel_onion: ^{tree} should mean commit, not commitishÆvar Arnfjörð Bjarmason, Apr 30, 2018
  17. Eric SunshineApr 30, 2018
  18. Stefan BellerApr 30, 2018
  19. brian m. carlsonMay 1, 2018
  20. Derrick StoleeMay 1, 2018
  21. 00/12 get_short_oid UI improvementsÆvar Arnfjörð Bjarmason, May 1, 2018
  22. 01/12 sha1-name.c: remove stray newlineÆvar Arnfjörð Bjarmason, May 1, 2018
  23. 02/12 sha1-array.h: align function argumentsÆvar Arnfjörð Bjarmason, May 1, 2018
  24. 03/12 git-p4: change "commitish" typo to "committish"Ævar Arnfjörð Bjarmason, May 1, 2018
  25. 04/12 cache.h: add comment explaining the order in object_typeÆvar Arnfjörð Bjarmason, May 1, 2018
  26. 05/12 sha1-name.c: move around the collect_ambiguous() functionÆvar Arnfjörð Bjarmason, May 1, 2018
  27. 07/12 get_short_oid: learn to disambiguate by ^{tag}Ævar Arnfjörð Bjarmason, May 1, 2018
  28. 06/12 get_short_oid: sort ambiguous objects by type, then SHA-1Ævar Arnfjörð Bjarmason, May 1, 2018
  29. 09/12 get_short_oid / peel_onion: ^{tree} should be tree, not treeishÆvar Arnfjörð Bjarmason, May 1, 2018
  30. 10/12 get_short_oid / peel_onion: ^{commit} should be commit, not committishÆvar Arnfjörð Bjarmason, May 1, 2018
  31. 12/12 get_short_oid: document & warn if we ignore the type selectorÆvar Arnfjörð Bjarmason, May 1, 2018
  32. 11/12 config doc: document core.disambiguateÆvar Arnfjörð Bjarmason, May 1, 2018
  33. 08/12 get_short_oid: learn to disambiguate by ^{blob}Ævar Arnfjörð Bjarmason, May 1, 2018
  34. 06/11 get_short_oid: sort ambiguous objects by type, then SHA-1Derrick Stolee, May 1, 2018
  35. Ævar Arnfjörð BjarmasonMay 1, 2018
  36. Derrick StoleeMay 1, 2018
  37. Ævar Arnfjörð BjarmasonMay 1, 2018
  38. Derrick StoleeMay 1, 2018
  39. 00/12 get_short_oid UI improvementsÆvar Arnfjörð Bjarmason, May 1, 2018
  40. 01/12 sha1-name.c: remove stray newlineÆvar Arnfjörð Bjarmason, May 1, 2018
  41. 02/12 sha1-array.h: align function argumentsÆvar Arnfjörð Bjarmason, May 1, 2018
  42. 04/12 cache.h: add comment explaining the order in object_typeÆvar Arnfjörð Bjarmason, May 1, 2018
  43. Junio C HamanoMay 3, 2018
  44. Duy NguyenMay 8, 2018
  45. pack-format.txt: more details on pack file formatNguyễn Thái Ngọc Duy, May 8, 2018
  46. Stefan BellerMay 8, 2018
  47. Duy NguyenMay 8, 2018
  48. Stefan BellerMay 8, 2018
  49. Ævar Arnfjörð BjarmasonMay 8, 2018
  50. Duy NguyenMay 8, 2018
  51. pack-format.txt: more details on pack file formatNguyễn Thái Ngọc Duy, May 10, 2018
  52. Stefan BellerMay 10, 2018
  53. Duy NguyenMay 11, 2018
  54. Junio C HamanoMay 11, 2018
  55. pack-format.txt: more details on pack file formatNguyễn Thái Ngọc Duy, May 11, 2018
  56. 03/12 git-p4: change "commitish" typo to "committish"Ævar Arnfjörð Bjarmason, May 1, 2018
  57. 05/12 sha1-name.c: move around the collect_ambiguous() functionÆvar Arnfjörð Bjarmason, May 1, 2018
  58. 08/12 get_short_oid: learn to disambiguate by ^{blob}Ævar Arnfjörð Bjarmason, May 1, 2018
  59. 09/12 get_short_oid / peel_onion: ^{tree} should be tree, not treeishÆvar Arnfjörð Bjarmason, May 1, 2018
  60. Junio C HamanoMay 3, 2018
  61. Ævar Arnfjörð BjarmasonMay 3, 2018
  62. Junio C HamanoMay 4, 2018
  63. Ævar Arnfjörð BjarmasonMay 4, 2018
  64. Junio C HamanoMay 7, 2018
  65. Jeff KingMay 8, 2018
  66. Ævar Arnfjörð BjarmasonMay 8, 2018
  67. Jeff KingMay 9, 2018
  68. Ævar Arnfjörð BjarmasonMay 9, 2018
  69. Junio C HamanoMay 10, 2018
  70. Jeff KingMay 10, 2018
  71. 0/6 get_short_oid UI improvementsÆvar Arnfjörð Bjarmason, May 10, 2018
  72. 1/6 sha1-name.c: remove stray newlineÆvar Arnfjörð Bjarmason, May 10, 2018
  73. 2/6 sha1-array.h: align function argumentsÆvar Arnfjörð Bjarmason, May 10, 2018
  74. Jeff KingMay 10, 2018
  75. Junio C HamanoMay 11, 2018
  76. Junio C HamanoMay 11, 2018
  77. 3/6 git-p4: change "commitish" typo to "committish"Ævar Arnfjörð Bjarmason, May 10, 2018
  78. Luke DiamandMay 10, 2018
  79. 4/6 sha1-name.c: move around the collect_ambiguous() functionÆvar Arnfjörð Bjarmason, May 10, 2018
  80. 5/6 get_short_oid: sort ambiguous objects by type, then SHA-1Ævar Arnfjörð Bjarmason, May 10, 2018
  81. Jeff KingMay 10, 2018
  82. Junio C HamanoMay 11, 2018
  83. 6/6 get_short_oid: document & warn if we ignore the type selectorÆvar Arnfjörð Bjarmason, May 10, 2018
  84. Martin ÅgrenMay 10, 2018
  85. Jeff KingMay 10, 2018
  86. Jeff KingMay 10, 2018
  87. Jeff KingMay 10, 2018
  88. Jeff KingMay 10, 2018
  89. 10/12 get_short_oid / peel_onion: ^{commit} should be commit, not committishÆvar Arnfjörð Bjarmason, May 1, 2018
  90. 11/12 config doc: document core.disambiguateÆvar Arnfjörð Bjarmason, May 1, 2018
  91. Jeff KingMay 8, 2018
  92. 12/12 get_short_oid: document & warn if we ignore the type selectorÆvar Arnfjörð Bjarmason, May 1, 2018
  93. 06/12 get_short_oid: sort ambiguous objects by type, then SHA-1Ævar Arnfjörð Bjarmason, May 1, 2018
  94. Junio C HamanoMay 3, 2018
  95. Jeff KingMay 8, 2018
  96. 07/12 get_short_oid: learn to disambiguate by ^{tag}Ævar Arnfjörð Bjarmason, May 1, 2018
  97. Derrick StoleeMay 2, 2018
  98. Derrick StoleeMay 2, 2018
  99. Jacob KellerMay 3, 2018

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.