{"thread":{"id":"20406","subject":"[PATCH] git-describe: Die early if there are no possible descriptions","startedAt":"2009-08-05T14:17:40Z","lastAt":"2009-08-06T12:15:14Z","messageCount":4,"participants":["Björn Steinbrink","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"119619","messageId":"20090805141740.GA16846@atjola.homenet","threadId":"20406","inReplyTo":null,"subject":"[PATCH] git-describe: Die early if there are no possible descriptions","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2009-08-05T14:17:40Z","receivedAt":"2009-08-05T14:17:40Z","isPatch":true,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"If we found no refs that may be used for git-describe with the current\noptions, then die early instead of pointlessly walking the whole history.\n\nSigned-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>\n---\nIn git.git with all the tags dropped, this makes \"git describe\" go down\nfrom 0.244 to 0.003 seconds for me. This is especially noticeable with\n\"git submodule\" which calls describe with increasing levels of allowed\nrefs to be matched. Without tags, this means that it walks the whole\nhistory in the submodule twice (first annotated, then plain tags), just\nto find out that it can't describe the thing anyway.\n\nI'm not particularly sure about found_names actually counting the found\nnames, it was just out of the thought that maybe the walking code could\nmake use of it, but I didn't actually check that and ran out of time, so\nI'm sending this version, hoping that it doesn't suck too much.\n\n builtin-describe.c |    6 ++++++\n 1 files changed, 6 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-describe.c b/builtin-describe.c\nindex 7a66298..cf802d1 100644\n--- a/builtin-describe.c\n+++ b/builtin-describe.c\n@@ -20,6 +20,7 @@ static int tags;\t/* Allow lightweight tags */\n static int longformat;\n static int abbrev = DEFAULT_ABBREV;\n static int max_candidates = 10;\n+static int found_names = 0;\n static const char *pattern;\n static int always;\n \n@@ -39,6 +40,8 @@ static void add_to_known_names(const char *path,\n \t\t\t       const unsigned char *sha1)\n {\n \tstruct commit_name *e = commit->util;\n+\tif (!e)\n+\t\tfound_names++;\n \tif (!e || e->prio < prio) {\n \t\tsize_t len = strlen(path)+1;\n \t\tfree(e);\n@@ -195,6 +198,9 @@ static void describe(const char *arg, int last_one)\n \t\tfor_each_ref(get_name, NULL);\n \t}\n \n+\tif (!found_names)\n+\t\tdie(\"cannot describe '%s'\", sha1_to_hex(sha1));\n+\n \tn = cmit->util;\n \tif (n) {\n \t\t/*\n-- \n1.6.4.19.g42af.dirty\n"},{"id":"119623","messageId":"20090805153411.GG1033@spearce.org","threadId":"20406","inReplyTo":"20090805141740.GA16846@atjola.homenet","subject":"Re: [PATCH] git-describe: Die early if there are no possible descriptions","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-08-05T15:34:12Z","receivedAt":"2009-08-05T15:34:12Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Bj?rn Steinbrink <B.Steinbrink@gmx.de> wrote:\n> If we found no refs that may be used for git-describe with the current\n> options, then die early instead of pointlessly walking the whole history.\n> \n> Signed-off-by: Bj?rn Steinbrink <B.Steinbrink@gmx.de>\n> ---\n> In git.git with all the tags dropped, this makes \"git describe\" go down\n> from 0.244 to 0.003 seconds for me. This is especially noticeable with\n> \"git submodule\" which calls describe with increasing levels of allowed\n> refs to be matched. Without tags, this means that it walks the whole\n> history in the submodule twice (first annotated, then plain tags), just\n> to find out that it can't describe the thing anyway.\n> \n> I'm not particularly sure about found_names actually counting the found\n> names, it was just out of the thought that maybe the walking code could\n> make use of it, but I didn't actually check that and ran out of time, so\n> I'm sending this version, hoping that it doesn't suck too much.\n\nThis seems reasonable to me.  Really you don't need found_names\nto be a counter, but could just always set it to 1 every time the\nadd_to_known_names function is called.  All you care about is that\nadd_to_known_names was invoked at least once.\n\nAlso, I really think that first paragraph after the --- should\nhave been part of the commit message.  The message above doesn't\njustify the change, even if it is fairly trivial, without that\nadditional explanation.\n\n> @@ -39,6 +40,8 @@ static void add_to_known_names(const char *path,\n>  \t\t\t       const unsigned char *sha1)\n>  {\n>  \tstruct commit_name *e = commit->util;\n> +\tif (!e)\n> +\t\tfound_names++;\n>  \tif (!e || e->prio < prio) {\n>  \t\tsize_t len = strlen(path)+1;\n>  \t\tfree(e);\n\n-- \nShawn.\n"},{"id":"119626","messageId":"20090805154205.GA17792@atjola.homenet","threadId":"20406","inReplyTo":"20090805153411.GG1033@spearce.org","subject":"Re: [PATCH] git-describe: Die early if there are no possible descriptions","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2009-08-05T15:42:05Z","receivedAt":"2009-08-05T15:42:05Z","isPatch":true,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"On 2009.08.05 08:34:12 -0700, Shawn O. Pearce wrote:\n> Bj?rn Steinbrink <B.Steinbrink@gmx.de> wrote:\n> > If we found no refs that may be used for git-describe with the current\n> > options, then die early instead of pointlessly walking the whole history.\n> > \n> > Signed-off-by: Bj?rn Steinbrink <B.Steinbrink@gmx.de>\n> > ---\n> > In git.git with all the tags dropped, this makes \"git describe\" go down\n> > from 0.244 to 0.003 seconds for me. This is especially noticeable with\n> > \"git submodule\" which calls describe with increasing levels of allowed\n> > refs to be matched. Without tags, this means that it walks the whole\n> > history in the submodule twice (first annotated, then plain tags), just\n> > to find out that it can't describe the thing anyway.\n> > \n> > I'm not particularly sure about found_names actually counting the found\n> > names, it was just out of the thought that maybe the walking code could\n> > make use of it, but I didn't actually check that and ran out of time, so\n> > I'm sending this version, hoping that it doesn't suck too much.\n> \n> This seems reasonable to me.  Really you don't need found_names\n> to be a counter, but could just always set it to 1 every time the\n> add_to_known_names function is called.  All you care about is that\n> add_to_known_names was invoked at least once.\n\nOK.\n\n> Also, I really think that first paragraph after the --- should\n> have been part of the commit message.  The message above doesn't\n> justify the change, even if it is fairly trivial, without that\n> additional explanation.\n\nOh, d'oh, that's even what I intended to do (the original commit message\nwas written in even more of a hurry than the mail itself), but messed\nup. Will re-send (also with found_names turned boolean)\n\nThanks,\nBjörn\n"},{"id":"119773","messageId":"20090806121514.GA1701@atjola.homenet","threadId":"20406","inReplyTo":"20090805154205.GA17792@atjola.homenet","subject":"[PATCH v2] git-describe: Die early if there are no possible descriptions","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2009-08-06T12:15:14Z","receivedAt":"2009-08-06T12:15:14Z","isPatch":true,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"If we find no refs that may be used for git-describe with the current\noptions, then die early instead of pointlessly walking the whole\nhistory.\n\nIn git.git with all the tags dropped, this makes \"git describe\" go down\nfrom 0.244 to 0.003 seconds for me. This is especially noticeable with\n\"git submodule status\" which calls describe with increasing levels of\nallowed refs to be matched. For a submodule without tags, this means\nthat it walks the whole history in the submodule twice (first annotated,\nthen plain tags), just to find out that it can't describe the commit\nanyway.\n\nSigned-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>\n---\nv2 improved the commit message and turned found_names into a boolean,\ninstead of a counter for the found names.\n\n builtin-describe.c |    5 +++++\n 1 files changed, 5 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-describe.c b/builtin-describe.c\nindex 7a66298..75feb11 100644\n--- a/builtin-describe.c\n+++ b/builtin-describe.c\n@@ -20,6 +20,7 @@ static int tags;\t/* Allow lightweight tags */\n static int longformat;\n static int abbrev = DEFAULT_ABBREV;\n static int max_candidates = 10;\n+static int found_names = 0;\n static const char *pattern;\n static int always;\n \n@@ -49,6 +50,7 @@ static void add_to_known_names(const char *path,\n \t\tmemcpy(e->path, path, len);\n \t\tcommit->util = e;\n \t}\n+\tfound_names = 1;\n }\n \n static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data)\n@@ -195,6 +197,9 @@ static void describe(const char *arg, int last_one)\n \t\tfor_each_ref(get_name, NULL);\n \t}\n \n+\tif (!found_names)\n+\t\tdie(\"cannot describe '%s'\", sha1_to_hex(sha1));\n+\n \tn = cmit->util;\n \tif (n) {\n \t\t/*\n-- \n1.6.4.20.gd25bb.dirty\n"}]}