{"thread":{"id":"3145","subject":"git describe fails without tags","startedAt":"2006-01-25T07:47:25Z","lastAt":"2006-01-26T09:02:44Z","messageCount":7,"participants":["Uwe Zeisberger","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"15107","messageId":"20060125074725.GA2768@informatik.uni-freiburg.de","threadId":"3145","inReplyTo":null,"subject":"git describe fails without tags","fromName":"Uwe Zeisberger","fromEmail":"zeisberg@informatik.uni-freiburg.de","sentAt":"2006-01-25T07:47:25Z","receivedAt":"2006-01-25T07:47:25Z","isPatch":false,"sender":{"key":"u.kleine-koenig@pengutronix.de","avatar":"https://gravatar.com/avatar/354b5e3ceb2806a2f1e1e382ac29ddbdad18288654da62b61eb13583a857eee7?d=mp&s=160"},"body":"Hello,\n\nusing git describe on Linus' sparse repo results in:\n\n\tuzeisberger@io:~/gsrc/sparse$ git describe\n\tfatal: cannot describe '62ac6c16058aba8693fd5827379debc5f57b60f5'\n\nThe reason is, that there exist no tags at all, so right, there is no\n\"most recent tag that is reachable from HEAD\".\n\nI wonder if it would be sane to assume an implicit tag for the empty\nrepository, s.t. git describe results in \n\n\t<empty>-62ac6c16\n\n(whatever name is choosen for <empty>).\n\nAny opinions?\n\nBest regards\nUwe\n\n-- \nUwe Zeisberger\n\nhttp://www.google.com/search?q=1+degree+celsius+in+kelvin\n"},{"id":"15111","messageId":"7vek2wws61.fsf@assigned-by-dhcp.cox.net","threadId":"3145","inReplyTo":"20060125074725.GA2768@informatik.uni-freiburg.de","subject":"Re: git describe fails without tags","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-01-25T09:52:38Z","receivedAt":"2006-01-25T09:52:38Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Uwe Zeisberger <zeisberg@informatik.uni-freiburg.de> writes:\n\n> I wonder if it would be sane to assume an implicit tag for the empty\n> repository, s.t. git describe results in \n>\n> \t<empty>-62ac6c16\n>\n> (whatever name is choosen for <empty>).\n>\n> Any opinions?\n\nThe value of 'describe' is not in the 62ac6c part, but in the\ntag part, which lets us find out that the rev in question is at\nleast newer than that tag.  If the reason you are doing\n\"describe\" is to find out an usable abbreviated name, you could\nfeed the first few hexdigits to \"git rev-parse --verify\",\nlengthening the prefix longer by one until it says you have a\nunique prefix [*1*].\n\nIn other words, not particularly interested, although it is\ntrivial to implement, like this:\n\ndiff --git a/describe.c b/describe.c\nindex 4866510..aeaf0fb 100644\n--- a/describe.c\n+++ b/describe.c\n@@ -137,7 +137,7 @@ static void describe(char *arg, int last\n \t\t\treturn;\n \t\t}\n \t}\n-\tdie(\"cannot describe '%s'\", sha1_to_hex(cmit->object.sha1));\n+\tprintf(\"%s\\n\", find_unique_abbrev(cmit->object.sha1, abbrev));\n }\n \n int main(int argc, char **argv)\n\n\n[Footnote]\n\n*1* If you do this often, we could introduce\n\n\t$ git rev-parse --abbrev=<n> HEAD\n\n    that quacks like --verify (i.e. makes sure there is a single\n    \"extended SHA1 expression\" that evaluates to a valid object\n    name) but outputs the result abbreviated to at least <n>\n    hexdigits.\n    \n    This has an added advantage that it would work on a\n    non-commit object name.\n\n\n-- >8 --\n[PATCH] rev-parse: --abbrev option.\n\nThe new option behaves just like --verify, but outputs an\nabbreviated object name that is unique within the repository.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n\n rev-parse.c |   14 ++++++++++++++\n 1 files changed, 14 insertions(+), 0 deletions(-)\n\n3c7c31a913c3c4060e85f2919e2136412928dcec\ndiff --git a/rev-parse.c b/rev-parse.c\nindex 0c951af..c1646e4 100644\n--- a/rev-parse.c\n+++ b/rev-parse.c\n@@ -20,6 +20,7 @@ static char *def = NULL;\n #define REVERSED 1\n static int show_type = NORMAL;\n static int symbolic = 0;\n+static int abbrev = 0;\n static int output_sq = 0;\n \n static int revs_count = 0;\n@@ -95,6 +96,8 @@ static void show_rev(int type, const uns\n \t\tputchar('^');\n \tif (symbolic && name)\n \t\tshow(name);\n+\telse if (abbrev)\n+\t\tshow(find_unique_abbrev(sha1, abbrev));\n \telse\n \t\tshow(sha1_to_hex(sha1));\n }\n@@ -195,6 +198,17 @@ int main(int argc, char **argv)\n \t\t\t\tverify = 1;\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(arg, \"--abbrev\") ||\n+\t\t\t    !strncmp(arg, \"--abbrev=\", 9)) {\n+\t\t\t\tfilter &= ~(DO_FLAGS|DO_NOREV);\n+\t\t\t\tverify = 1;\n+\t\t\t\tabbrev = DEFAULT_ABBREV;\n+\t\t\t\tif (arg[8] == '=')\n+\t\t\t\t\tabbrev = strtoul(arg + 9, NULL, 10);\n+\t\t\t\tif (abbrev < 0 || 40 <= abbrev)\n+\t\t\t\t\tabbrev = DEFAULT_ABBREV;\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (!strcmp(arg, \"--sq\")) {\n \t\t\t\toutput_sq = 1;\n \t\t\t\tcontinue;\n-- \n1.1.4.g869a\n"},{"id":"15135","messageId":"20060126074421.GA2941@informatik.uni-freiburg.de","threadId":"3145","inReplyTo":"7vek2wws61.fsf@assigned-by-dhcp.cox.net","subject":"Re: git describe fails without tags","fromName":"Uwe Zeisberger","fromEmail":"zeisberg@informatik.uni-freiburg.de","sentAt":"2006-01-26T07:44:21Z","receivedAt":"2006-01-26T07:44:21Z","isPatch":false,"sender":{"key":"u.kleine-koenig@pengutronix.de","avatar":"https://gravatar.com/avatar/354b5e3ceb2806a2f1e1e382ac29ddbdad18288654da62b61eb13583a857eee7?d=mp&s=160"},"body":"Hello Junio,\n\nJunio C Hamano wrote:\n> Uwe Zeisberger <zeisberg@informatik.uni-freiburg.de> writes:\n> \n> > I wonder if it would be sane to assume an implicit tag for the empty\n> > repository, s.t. git describe results in \n> >\n> > \t<empty>-62ac6c16\n> >\n> > (whatever name is choosen for <empty>).\n> >\n> > Any opinions?\n>\n> [...] If the reason you are doing \"describe\" is to find out an usable\n> abbreviated name, you could feed the first few hexdigits to \"git\n> rev-parse --verify\", lengthening the prefix longer by one until it\n> says you have a unique prefix [*1*].\nYes, I wrote a script that automatically build git and install it to\n${HOME}/usr/stow/git-`git describe HEAD` and then stow(8)s it.  Writing\na similar script for sparse cannot use git describe because there are no\ntags ...\n \n> In other words, not particularly interested, although it is\n> trivial to implement, like this:\n> \n> diff --git a/describe.c b/describe.c\n> index 4866510..aeaf0fb 100644\n> --- a/describe.c\n> +++ b/describe.c\n> @@ -137,7 +137,7 @@ static void describe(char *arg, int last\n>  \t\t\treturn;\n>  \t\t}\n>  \t}\n> -\tdie(\"cannot describe '%s'\", sha1_to_hex(cmit->object.sha1));\n> +\tprintf(\"%s\\n\", find_unique_abbrev(cmit->object.sha1, abbrev));\n>  }\n>  \n>  int main(int argc, char **argv)\n\nIt's a pity your not particularly interested, I like that patch's idea.\ngit describe dies with an error here in a situation where there is the\npossibility to do something sensible.\n\nBTW, for the sake of consistency, I'd suggest\n\n-\tdie(\"cannot describe '%s'\", sha1_to_hex(cmit->object.sha1));\n+\tprintf(\"g%s\\n\", find_unique_abbrev(cmit->object.sha1, abbrev));\n\nBest regards\nUwe\n\n-- \nUwe Zeisberger\n\nhttp://www.google.com/search?q=1+year+divided+by+3+in+seconds\n"},{"id":"15136","messageId":"7vmzhjif8i.fsf@assigned-by-dhcp.cox.net","threadId":"3145","inReplyTo":"20060126074421.GA2941@informatik.uni-freiburg.de","subject":"Re: git describe fails without tags","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-01-26T08:07:57Z","receivedAt":"2006-01-26T08:07:57Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Uwe Zeisberger <zeisberg@informatik.uni-freiburg.de> writes:\n\n> Yes, I wrote a script that automatically build git and install it to\n> ${HOME}/usr/stow/git-`git describe HEAD` and then stow(8)s it.  Writing\n> a similar script for sparse cannot use git describe because there are no\n> tags ...\n> ...\n> It's a pity your not particularly interested, I like that patch's idea.\n> git describe dies with an error here in a situation where there is the\n> possibility to do something sensible.\n\nI think I understand the problem pretty well, and actually I am\nsympathetic to the cause.\n\nHaving said that, I do not agree with the approach of your\npatch.  It makes it inconvenient for scripts to tell describable\nand indescribable revs apart by checking the exit status from\nthe command.\n\nIn other words, I think a sensible thing can be done more sanely\nin your script.  Something like this?\n\n\t#!/bin/sh\n\tproject=git ;# or 'sparse'\n\tversion=`git describe HEAD` ||\n\t\tversion=untagged-g`git rev-parse --abbrev HEAD`\n\t$(MAKE) prefix=$HOME/usr/stow/$project-$version\n\nIf you want to squelch the error message from indescribable rev,\nyou could do:\n\n\tversion=`git describe HEAD 2>/dev/null` ||\n\nof course.\n"},{"id":"15137","messageId":"20060126084151.GB2941@informatik.uni-freiburg.de","threadId":"3145","inReplyTo":"7vek2wws61.fsf@assigned-by-dhcp.cox.net","subject":"Re: git describe fails without tags","fromName":"Uwe Zeisberger","fromEmail":"zeisberg@informatik.uni-freiburg.de","sentAt":"2006-01-26T08:41:52Z","receivedAt":"2006-01-26T08:41:52Z","isPatch":false,"sender":{"key":"u.kleine-koenig@pengutronix.de","avatar":"https://gravatar.com/avatar/354b5e3ceb2806a2f1e1e382ac29ddbdad18288654da62b61eb13583a857eee7?d=mp&s=160"},"body":"Hello Junio,\n\nJunio C Hamano wrote:\n> diff --git a/rev-parse.c b/rev-parse.c\n> index 0c951af..c1646e4 100644\n> --- a/rev-parse.c\n> +++ b/rev-parse.c\n> @@ -20,6 +20,7 @@ static char *def = NULL;\n>  #define REVERSED 1\n>  static int show_type = NORMAL;\n>  static int symbolic = 0;\n> +static int abbrev = 0;\n>  static int output_sq = 0;\n>  \n>  static int revs_count = 0;\n> @@ -95,6 +96,8 @@ static void show_rev(int type, const uns\n>  \t\tputchar('^');\n>  \tif (symbolic && name)\n>  \t\tshow(name);\n> +\telse if (abbrev)\n> +\t\tshow(find_unique_abbrev(sha1, abbrev));\n>  \telse\n>  \t\tshow(sha1_to_hex(sha1));\n>  }\n> @@ -195,6 +198,17 @@ int main(int argc, char **argv)\n>  \t\t\t\tverify = 1;\n>  \t\t\t\tcontinue;\n>  \t\t\t}\n> +\t\t\tif (!strcmp(arg, \"--abbrev\") ||\n> +\t\t\t    !strncmp(arg, \"--abbrev=\", 9)) {\n> +\t\t\t\tfilter &= ~(DO_FLAGS|DO_NOREV);\n> +\t\t\t\tverify = 1;\n> +\t\t\t\tabbrev = DEFAULT_ABBREV;\n> +\t\t\t\tif (arg[8] == '=')\n> +\t\t\t\t\tabbrev = strtoul(arg + 9, NULL, 10);\n> +\t\t\t\tif (abbrev < 0 || 40 <= abbrev)\n> +\t\t\t\t\tabbrev = DEFAULT_ABBREV;\n> +\t\t\t\tcontinue;\n> +\t\t\t}\n>  \t\t\tif (!strcmp(arg, \"--sq\")) {\n>  \t\t\t\toutput_sq = 1;\n>  \t\t\t\tcontinue;\nI see two things to fix in that patch:\n\n 1) define DEFAULT_ABBREV (e.g. by moving it to cache.h, where\n    find_unique_abbrev is defined.)\n\n 2) describe.c allows only abbrev >= 4.  (Allowing values less than 2\n    failes, because find_short_object_filename (and maybe others) assume\n    len to be at least 2.)  I think 4 is sensible.\n\nThis results in the following patch:\n\n--8<--\n[PATCH] rev-parse: --abbrev option.\n\nThe new option behaves just like --verify, but outputs an abbreviated object\nname that is unique within the repository.\n\nThis patch is a modification of a suggestion by Junio C Hamano.\n\nSigned-off-by: Uwe Zeisberger <zeisberg@informatik.uni-freiburg.de>\n\n---\n\n cache.h     |    2 ++\n describe.c  |    1 -\n rev-parse.c |   14 ++++++++++++++\n 3 files changed, 16 insertions(+), 1 deletions(-)\n\n0d43ec7461b38d6a1d1563fd7dc2ebf399eabe9e\ndiff --git a/cache.h b/cache.h\nindex b493b65..139c670 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -177,6 +177,8 @@ extern int check_repository_format(void)\n #define DATA_CHANGED    0x0020\n #define TYPE_CHANGED    0x0040\n \n+#define DEFAULT_ABBREV 8 /* maybe too many */\n+\n /* Return a statically allocated filename matching the sha1 signature */\n extern char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));\n extern char *git_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));\ndiff --git a/describe.c b/describe.c\nindex 4866510..6518f06 100644\n--- a/describe.c\n+++ b/describe.c\n@@ -11,7 +11,6 @@ static const char describe_usage[] =\n static int all = 0;\t/* Default to annotated tags only */\n static int tags = 0;\t/* But allow any tags if --tags is specified */\n \n-#define DEFAULT_ABBREV 8 /* maybe too many */\n static int abbrev = DEFAULT_ABBREV;\n \n static int names = 0, allocs = 0;\ndiff --git a/rev-parse.c b/rev-parse.c\nindex 0c951af..58cff6f 100644\n--- a/rev-parse.c\n+++ b/rev-parse.c\n@@ -20,6 +20,7 @@ static char *def = NULL;\n #define REVERSED 1\n static int show_type = NORMAL;\n static int symbolic = 0;\n+static int abbrev = 0;\n static int output_sq = 0;\n \n static int revs_count = 0;\n@@ -95,6 +96,8 @@ static void show_rev(int type, const uns\n \t\tputchar('^');\n \tif (symbolic && name)\n \t\tshow(name);\n+\telse if (abbrev)\n+\t\tshow(find_unique_abbrev(sha1, abbrev));\n \telse\n \t\tshow(sha1_to_hex(sha1));\n }\n@@ -195,6 +198,17 @@ int main(int argc, char **argv)\n \t\t\t\tverify = 1;\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(arg, \"--abbrev\") ||\n+\t\t\t\t\t!strncmp(arg, \"--abbrev=\", 9)) {\n+\t\t\t\tfilter &= ~(DO_FLAGS|DO_NOREV);\n+\t\t\t\tverify = 1;\n+\t\t\t\tabbrev = DEFAULT_ABBREV;\n+\t\t\t\tif (arg[8] == '=')\n+\t\t\t\t\tabbrev = strtoul(arg + 9, NULL, 10);\n+\t\t\t\tif (abbrev < 4 || 40 <= abbrev)\n+\t\t\t\t\tabbrev = DEFAULT_ABBREV;\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (!strcmp(arg, \"--sq\")) {\n \t\t\t\toutput_sq = 1;\n \t\t\t\tcontinue;\n-- \n1.1.4.g3e6c\n\nBest regards\nUwe\n\n-- \nUwe Zeisberger\n\nhttp://www.google.com/search?q=72+PS+point+in+inch\n"},{"id":"15138","messageId":"20060126084554.GC2941@informatik.uni-freiburg.de","threadId":"3145","inReplyTo":"7vmzhjif8i.fsf@assigned-by-dhcp.cox.net","subject":"Re: git describe fails without tags","fromName":"Uwe Zeisberger","fromEmail":"zeisberg@informatik.uni-freiburg.de","sentAt":"2006-01-26T08:45:54Z","receivedAt":"2006-01-26T08:45:54Z","isPatch":false,"sender":{"key":"u.kleine-koenig@pengutronix.de","avatar":"https://gravatar.com/avatar/354b5e3ceb2806a2f1e1e382ac29ddbdad18288654da62b61eb13583a857eee7?d=mp&s=160"},"body":"Hello Junio,\n\nJunio C Hamano wrote:\n> Uwe Zeisberger <zeisberg@informatik.uni-freiburg.de> writes:\n> \n> > Yes, I wrote a script that automatically build git and install it to\n> > ${HOME}/usr/stow/git-`git describe HEAD` and then stow(8)s it.  Writing\n> > a similar script for sparse cannot use git describe because there are no\n> > tags ...\n> > ...\n> > It's a pity your not particularly interested, I like that patch's idea.\n> > git describe dies with an error here in a situation where there is the\n> > possibility to do something sensible.\n> \n> I think I understand the problem pretty well, and actually I am\n> sympathetic to the cause.\n> \n> Having said that, I do not agree with the approach of your\n> patch.  It makes it inconvenient for scripts to tell describable\n> and indescribable revs apart by checking the exit status from\n> the command.\nOK, that's fine for me.  Then it would be sensible to add a note to the\ndocs describing the exit codes.\n\nThanks for your suggestion for my script.\n\nBest regards\nUwe\n\n-- \nUwe Zeisberger\n\nhttp://www.google.com/search?q=sin%28pi%2F2%29\n"},{"id":"15139","messageId":"7vr76vgy4r.fsf@assigned-by-dhcp.cox.net","threadId":"3145","inReplyTo":"20060126084151.GB2941@informatik.uni-freiburg.de","subject":"Re: git describe fails without tags","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-01-26T09:02:44Z","receivedAt":"2006-01-26T09:02:44Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Uwe Zeisberger <zeisberg@informatik.uni-freiburg.de> writes:\n\n> I see two things to fix in that patch:\n>\n>  1) define DEFAULT_ABBREV (e.g. by moving it to cache.h, where\n>     find_unique_abbrev is defined.)\n\nSorry, the patch alone was not compilable since cleaning up the\ndefinition of symbolic constants *_ABBREV comes before the patch\nyou quoted in the \"pu\" branch.\n\n>  2) describe.c allows only abbrev >= 4.  (Allowing values less than 2\n>     failes, because find_short_object_filename (and maybe others) assume\n>     len to be at least 2.)  I think 4 is sensible.\n\nThanks.  \"rev-parse --abbrev=2\" would have segfaulted without\nyour fix.  I suspect substituting with MINIMUM instead of\nDEFAULT in such a case would be more sensible, so...\n\n-- >8 --\n[PATCH] rev-parse --abbrev: do not try abbrev shorter than minimum.\n\nWe do not allow abbreviation shorter than 4 letters in other\nparts of the system so do not attempt to generate such.\n\nNoticed by Uwe Zeisberger.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n\n rev-parse.c |    6 ++++--\n 1 files changed, 4 insertions(+), 2 deletions(-)\n\n030d25d271adb2671f560b410d77585d8744acbf\ndiff --git a/rev-parse.c b/rev-parse.c\nindex 42969a6..8bf316e 100644\n--- a/rev-parse.c\n+++ b/rev-parse.c\n@@ -206,8 +206,10 @@ int main(int argc, char **argv)\n \t\t\t\tabbrev = DEFAULT_ABBREV;\n \t\t\t\tif (arg[8] == '=')\n \t\t\t\t\tabbrev = strtoul(arg + 9, NULL, 10);\n-\t\t\t\tif (abbrev < 0 || 40 <= abbrev)\n-\t\t\t\t\tabbrev = DEFAULT_ABBREV;\n+\t\t\t\tif (abbrev < MINIMUM_ABBREV)\n+\t\t\t\t\tabbrev = MINIMUM_ABBREV;\n+\t\t\t\telse if (40 <= abbrev)\n+\t\t\t\t\tabbrev = 40;\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--sq\")) {\n-- \n1.1.4.g00a4\n"}]}