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

Re: [PATCH] sha1_name: accept output of git-describe

From
Junio C Hamano <junkio@cox.net>
Date
Sep 20, 2006, 21:25 UTC
Message-ID
<7v64figrhu.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.63.0609202255290.19042@wbgn013.biozentrum.uni-wuerzburg.de>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 31 quoted lines
> Now, 'git log $(git describe)' does the same as 'git log'.
>
> NOTE: it might be possible that the unique abbreviation generated by
> git-describe is no longer unique at a later stage. Evidently, in this
> case the sha1 resolution fails.
>
> Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
> ---
>  sha1_name.c |   12 ++++++++++++
>  1 files changed, 12 insertions(+), 0 deletions(-)
>
> diff --git a/sha1_name.c b/sha1_name.c
> index b497528..c1f6cca 100644
> --- a/sha1_name.c
> +++ b/sha1_name.c
> @@ -159,6 +159,18 @@ static int get_short_sha1(const char *na
>  
>  	if (len < MINIMUM_ABBREV)
>  		return -1;
> +
> +	/* check for output of git-describe */
> +	if (len > MINIMUM_ABBREV + 2) {
> +		int i;
> +		for (i = len - MINIMUM_ABBREV - 2; i > 0 && name[i] != '-'; i--)
> +			; /* do nothing */
> +		if (i > 0 && name[i + 1] == 'g') {
> +			name += i + 2;
> +			len -= i + 2;
> +		}
> +	}
> +

Shouldn't you also verify the leading ref (most likely a tag) exists (and optionally check that it precedes the commit you decoded into, but that is probably more expensive than it's worth)?

Previous: Johannes SchindelinNext: Johannes Schindelin
Message 2 of 4 in “sha1_name: accept output of git-describe”
  1. sha1_name: accept output of git-describeJohannes Schindelin, Sep 20, 2006
  2. Junio C HamanoSep 20, 2006
  3. Johannes SchindelinSep 20, 2006
  4. Shawn PearceSep 20, 2006

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.