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

Re: [PATCH 04/10] get_short_sha1: peel tags when looking for treeish

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 26, 2016, 16:55 UTC
Message-ID
<xmqq7f9yvbwn.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160926115947.hksmtkqp3i4tfftx@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 11 quoted lines
> The treeish disambiguation function tries to peel tags, but
> it does so by calling:
>
>   deref_tag(lookup_object(sha1), ...);
>
> This will only work if we have previously looked at the tag
> and created a "struct tag" for it. Since parsing revision
> arguments typically happens before anything else, this is
> usually not the case, and we would fail to peel the tag (we
> are lucky that deref_tag() gracefully handles the NULL and
> does not segfault).
Makes perfect sense.
Show 5 quoted lines
> Instead, we can use parse_object(). Note that this is the
> same fix done by 94d75d1 (get_short_sha1(): correctly
> disambiguate type-limited abbreviation, 2013-07-01), but
> that commit fixed only the committish disambiguator, and
> left the bug in the treeish one.

Can you share your secret tool you use to find this kind of thing? Yes, the patch from that commit does look very similar to what we see in this patch, but I'd love to see "I am fixing an incorrect call to lookup-object by replacing it with parse-object; has there been a similar fix?" automated ;-)

Show 37 quoted lines
> Signed-off-by: Jeff King <peff@peff.net>
> ---
>  sha1_name.c                         | 2 +-
>  t/t1512-rev-parse-disambiguation.sh | 7 +++++++
>  2 files changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/sha1_name.c b/sha1_name.c
> index 38e51d9..432a308 100644
> --- a/sha1_name.c
> +++ b/sha1_name.c
> @@ -269,7 +269,7 @@ static int disambiguate_treeish_only(const unsigned char *sha1, void *cb_data_un
>  		return 0;
>  
>  	/* We need to do this the hard way... */
> -	obj = deref_tag(lookup_object(sha1), NULL, 0);
> +	obj = deref_tag(parse_object(sha1), NULL, 0);
>  	if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))
>  		return 1;
>  	return 0;
> diff --git a/t/t1512-rev-parse-disambiguation.sh b/t/t1512-rev-parse-disambiguation.sh
> index 30e0b80..dfd3567 100755
> --- a/t/t1512-rev-parse-disambiguation.sh
> +++ b/t/t1512-rev-parse-disambiguation.sh
> @@ -264,6 +264,13 @@ test_expect_success 'ambiguous commit-ish' '
>  	test_must_fail git log 000000000...
>  '
>  
> +# There are three objects with this prefix: a blob, a tree, and a tag. We know
> +# the blob will not pass as a treeish, but the tree and tag should (and thus
> +# cause an error).
> +test_expect_success 'ambiguous tags peel to treeish' '
> +	test_must_fail git rev-parse 0000000000f^{tree}
> +'
> +
>  test_expect_success 'rev-parse --disambiguate' '
>  	# The test creates 16 objects that share the prefix and two
>  	# commits created by commit-tree in earlier tests share a
Previous: Jeff KingNext: Jeff King
Message 14 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.