{"thread":{"id":"5624","subject":"[PATCH] sha1_name: accept output of git-describe","startedAt":"2006-09-20T20:56:18Z","lastAt":"2006-09-20T21:34:10Z","messageCount":4,"participants":["Johannes Schindelin","Junio C Hamano","Shawn Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"27283","messageId":"Pine.LNX.4.63.0609202255290.19042@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"5624","inReplyTo":null,"subject":"[PATCH] sha1_name: accept output of git-describe","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-09-20T20:56:18Z","receivedAt":"2006-09-20T20:56:18Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nNow, 'git log $(git describe)' does the same as 'git log'.\n\nNOTE: it might be possible that the unique abbreviation generated by\ngit-describe is no longer unique at a later stage. Evidently, in this\ncase the sha1 resolution fails.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n---\n sha1_name.c |   12 ++++++++++++\n 1 files changed, 12 insertions(+), 0 deletions(-)\n\ndiff --git a/sha1_name.c b/sha1_name.c\nindex b497528..c1f6cca 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -159,6 +159,18 @@ static int get_short_sha1(const char *na\n \n \tif (len < MINIMUM_ABBREV)\n \t\treturn -1;\n+\n+\t/* check for output of git-describe */\n+\tif (len > MINIMUM_ABBREV + 2) {\n+\t\tint i;\n+\t\tfor (i = len - MINIMUM_ABBREV - 2; i > 0 && name[i] != '-'; i--)\n+\t\t\t; /* do nothing */\n+\t\tif (i > 0 && name[i + 1] == 'g') {\n+\t\t\tname += i + 2;\n+\t\t\tlen -= i + 2;\n+\t\t}\n+\t}\n+\n \thashclr(res);\n \tmemset(canonical, 'x', 40);\n \tfor (i = 0; i < len ;i++) {\n-- \n1.4.2.1.ga0df5-dirty\n"},{"id":"27289","messageId":"7v64figrhu.fsf@assigned-by-dhcp.cox.net","threadId":"5624","inReplyTo":"Pine.LNX.4.63.0609202255290.19042@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] sha1_name: accept output of git-describe","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-09-20T21:25:33Z","receivedAt":"2006-09-20T21:25:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> Now, 'git log $(git describe)' does the same as 'git log'.\n>\n> NOTE: it might be possible that the unique abbreviation generated by\n> git-describe is no longer unique at a later stage. Evidently, in this\n> case the sha1 resolution fails.\n>\n> Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n> ---\n>  sha1_name.c |   12 ++++++++++++\n>  1 files changed, 12 insertions(+), 0 deletions(-)\n>\n> diff --git a/sha1_name.c b/sha1_name.c\n> index b497528..c1f6cca 100644\n> --- a/sha1_name.c\n> +++ b/sha1_name.c\n> @@ -159,6 +159,18 @@ static int get_short_sha1(const char *na\n>  \n>  \tif (len < MINIMUM_ABBREV)\n>  \t\treturn -1;\n> +\n> +\t/* check for output of git-describe */\n> +\tif (len > MINIMUM_ABBREV + 2) {\n> +\t\tint i;\n> +\t\tfor (i = len - MINIMUM_ABBREV - 2; i > 0 && name[i] != '-'; i--)\n> +\t\t\t; /* do nothing */\n> +\t\tif (i > 0 && name[i + 1] == 'g') {\n> +\t\t\tname += i + 2;\n> +\t\t\tlen -= i + 2;\n> +\t\t}\n> +\t}\n> +\n\nShouldn't you also verify the leading ref (most likely a tag)\nexists (and optionally check that it precedes the commit you\ndecoded into, but that is probably more expensive than it's\nworth)?\n"},{"id":"27292","messageId":"Pine.LNX.4.63.0609202330190.19042@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"5624","inReplyTo":"7v64figrhu.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] sha1_name: accept output of git-describe","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-09-20T21:31:36Z","receivedAt":"2006-09-20T21:31:36Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 20 Sep 2006, Junio C Hamano wrote:\n\n> Shouldn't you also verify the leading ref (most likely a tag)\n> exists (and optionally check that it precedes the commit you\n> decoded into, but that is probably more expensive than it's\n> worth)?\n\nI debated this with myself. But there is the cost, and more importantly \nthe possibility that your victim^H^H^H^H^H^Hother side does not have the \ntag at all (for whatever reasons).\n\nCiao,\nDscho\n"},{"id":"27293","messageId":"20060920213410.GC24415@spearce.org","threadId":"5624","inReplyTo":"7v64figrhu.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] sha1_name: accept output of git-describe","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-09-20T21:34:10Z","receivedAt":"2006-09-20T21:34:10Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > Now, 'git log $(git describe)' does the same as 'git log'.\n> >\n> > NOTE: it might be possible that the unique abbreviation generated by\n> > git-describe is no longer unique at a later stage. Evidently, in this\n> > case the sha1 resolution fails.\n[snip]\n> Shouldn't you also verify the leading ref (most likely a tag)\n> exists (and optionally check that it precedes the commit you\n> decoded into, but that is probably more expensive than it's\n> worth)?\n\nI thought the same thing when I first posted that it was probably\nan easy change to this code (and then didn't do it myself) and\nagain when I read Johannes' implementation.  Both times I agreed\nwith you Junio that it was probably too expensive and not worth\ndoing.\n\nMost of the time we assume not only that the SHA1 itself is unique\nbut also that it some hex character prefix is unique (such as 6 or\n8 digits).  One might be able to argue that if we have duplicate\ncommits (when abbreviated) that you might be able to break the tie by\nlooking at the tag but even then you may not always be able to do so.\n\nSo no, probably not worth it...\n\n-- \nShawn.\n"}]}