{"thread":{"id":"12286","subject":"[PATCH 4/6] Avoid accessing non-tag refs in git-describe unless --all is requested","startedAt":"2008-02-24T08:07:28Z","lastAt":"2008-02-24T08:07:28Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"69766","messageId":"20080224080728.GD22587@spearce.org","threadId":"12286","inReplyTo":null,"subject":"[PATCH 4/6] Avoid accessing non-tag refs in git-describe unless --all is requested","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-02-24T08:07:28Z","receivedAt":"2008-02-24T08:07:28Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"If we aren't going to use a ref there is no reason for us to open\nits object from the object database.  This avoids opening any of\nthe head commits reachable from refs/heads/ unless they are also\nreachable through the commit we have been asked to describe and\nwe need to walk through it to find a tag.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n builtin-describe.c |    6 +++++-\n 1 files changed, 5 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-describe.c b/builtin-describe.c\nindex bfd25e2..9c958bd 100644\n--- a/builtin-describe.c\n+++ b/builtin-describe.c\n@@ -46,11 +46,15 @@ static void add_to_known_names(const char *path,\n \n static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data)\n {\n+\tint might_be_tag = !prefixcmp(path, \"refs/tags/\");\n \tstruct commit *commit;\n \tstruct object *object;\n \tunsigned char peeled[20];\n \tint is_tag, prio;\n \n+\tif (!all && !might_be_tag)\n+\t\treturn 0;\n+\n \tif (!peel_ref(path, peeled) && !is_null_sha1(peeled)) {\n \t\tcommit = lookup_commit_reference_gently(peeled, 1);\n \t\tif (!commit)\n@@ -68,7 +72,7 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void\n \t * If --tags, then any tags are used.\n \t * Otherwise only annotated tags are used.\n \t */\n-\tif (!prefixcmp(path, \"refs/tags/\")) {\n+\tif (might_be_tag) {\n \t\tif (is_tag) {\n \t\t\tprio = 2;\n \t\t\tif (pattern && fnmatch(pattern, path + 10, 0))\n-- \n1.5.4.3.295.g6b554\n"}]}