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

Re: [PATCH] describe: output tag's ref instead of embedded name

From
Jeff King <peff@peff.net>
Date
Feb 16, 2020, 06:51 UTC
Message-ID
<20200216065101.GA2937208@coredump.intra.peff.net>
In-Reply-To
<fcf19a46b80322c5579142efe4ec681a4dcbdd28.1581802264.git.matheus.bernardino@usp.br>
On Sat, Feb 15, 2020 at 06:34:13PM -0300, Matheus Tavares wrote:
Show 14 quoted lines
> If a tag describes a commit, we currently output not the tag's ref but
> its embedded name. This means that when the tag is locally stored under
> a different name, the output given cannot be used to access the tag in
> any way. A warning is also emitted in this case, but the message is not
> very enlightening:
> 
> $ git tag -am "testing tag body" testing-tag
> $ mv .git/refs/tags/testing-tag .git/refs/tags/testing-tag-with-new-name
> $ git describe --tags --abbrev=0
> warning: tag 'testing-tag' is really 'testing-tag-with-new-name' here
> testing-tag
> 
> Let's make git-describe output the tag's local name instead and
> rephrase the warning to reflect the situation a little better.

Thanks. I had this on my "eh, we should probably do it before we forget" pile, so I was quite happy to see that somebody had already handled it. :)

I think the conversion of the die() to warning() makes sense here. Do we want to cover that with a test?

Show 8 quoted lines
> Since the embedded name will no longer be needed for correct output, we
> can convert the die() call in append_name() when a tag doesn't have the
> embedded name to a warning(). Also, this function will now have two
> disconnected responsibilities: verifying if the tag's embedded name
> matches the ref and actually appending the ref to a given buffer (which
> does not depend on the parsed tag object itself). Thus, to increase
> intelligibility, let's make the function specialize in the former and do
> the latter outside it.

Pulling the buffer append out of the function makes a lot of sense as well. I was puzzled at first that this old code:

Show 9 quoted lines
> -
> -	if (n->tag) {
> -		if (all)
> -			strbuf_addstr(dst, "tags/");
> -		strbuf_addstr(dst, n->tag->tag);
> -	} else {
> -		strbuf_addstr(dst, n->path);
> -	}
>  }
...used "tags/" for "--all", but the new code doesn't:
Show 7 quoted lines
> @@ -313,7 +305,8 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
>  		/*
>  		 * Exact match to an existing ref.
>  		 */
> -		append_name(n, dst);
> +		verify_tag_embedded_name(n);
> +		strbuf_addstr(dst, n->path);

But that makes sense. As the else clause in the old code shows, our n->path is already set up correctly. So not only are we splitting out the "append" concern, but we're able to make it simpler. Good.

Show 15 quoted lines
> diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
> index 09c50f3f04..d34c091e0b 100755
> --- a/t/t6120-describe.sh
> +++ b/t/t6120-describe.sh
> @@ -129,9 +129,9 @@ test_expect_success 'rename tag A to Q locally' '
>  	mv .git/refs/tags/A .git/refs/tags/Q
>  '
>  cat - >err.expect <<EOF
> -warning: tag 'A' is really 'Q' here
> +warning: tag 'Q' is externally known as 'A'
>  EOF
> -check_describe A-* HEAD
> +check_describe Q-* HEAD
>  test_expect_success 'warning was displayed for Q' '
>  	test_i18ncmp err.expect err.actual

And this test change makes sense. I had to look up how check_describe works, but that first argument is the expected output.

So the whole thing looks good to me, with or without the die/warning test I mentioned above.

-Peff
Previous: Matheus TavaresNext: Junio C Hamano
Message 6 of 23 in “git-describe --tags warning: 'X' is really 'Y' here”
  1. Roland HieberFeb 5, 2020
  2. Matheus Tavares BernardinoFeb 5, 2020
  3. Jeff KingFeb 14, 2020
  4. Junio C HamanoFeb 14, 2020
  5. describe: output tag's ref instead of embedded nameMatheus Tavares, Feb 15, 2020
  6. Jeff KingFeb 16, 2020
  7. Junio C HamanoFeb 18, 2020
  8. Jeff KingFeb 18, 2020
  9. Junio C HamanoFeb 18, 2020
  10. Junio C HamanoFeb 18, 2020
  11. Jeff KingFeb 19, 2020
  12. Junio C HamanoFeb 19, 2020
  13. Jeff KingFeb 19, 2020
  14. Junio C HamanoFeb 19, 2020
  15. Jeff KingFeb 20, 2020
  16. Junio C HamanoFeb 20, 2020
  17. Matheus Tavares BernardinoFeb 20, 2020
  18. Junio C HamanoFeb 20, 2020
  19. Matheus TavaresFeb 21, 2020
  20. Junio C HamanoFeb 21, 2020
  21. Jeff KingFeb 21, 2020
  22. Jeff KingFeb 21, 2020
  23. Roland HieberFeb 19, 2020

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.