{"thread":{"id":"12284","subject":"[PATCH 3/6] Teach git-describe to use peeled ref information when scanning tags","startedAt":"2008-02-24T08:07:25Z","lastAt":"2008-02-24T08:07:25Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"69764","messageId":"20080224080725.GC22587@spearce.org","threadId":"12284","inReplyTo":null,"subject":"[PATCH 3/6] Teach git-describe to use peeled ref information when scanning tags","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-02-24T08:07:25Z","receivedAt":"2008-02-24T08:07:25Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"By using the peeled ref information inside of the packed-refs file we\ncan avoid opening tag objects to obtain the commits they reference.\nThis speeds up git-describe when there are a large number of tags\nin the repository as we have less objects to parse before we can\nstart commit matching.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n builtin-describe.c |   23 +++++++++++++++++------\n 1 files changed, 17 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin-describe.c b/builtin-describe.c\nindex 3428483..bfd25e2 100644\n--- a/builtin-describe.c\n+++ b/builtin-describe.c\n@@ -46,19 +46,30 @@ 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-\tstruct commit *commit = lookup_commit_reference_gently(sha1, 1);\n+\tstruct commit *commit;\n \tstruct object *object;\n-\tint prio;\n+\tunsigned char peeled[20];\n+\tint is_tag, prio;\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+\t\t\treturn 0;\n+\t\tis_tag = !!hashcmp(sha1, commit->object.sha1);\n+\t} else {\n+\t\tcommit = lookup_commit_reference_gently(sha1, 1);\n+\t\tobject = parse_object(sha1);\n+\t\tif (!commit || !object)\n+\t\t\treturn 0;\n+\t\tis_tag = object->type == OBJ_TAG;\n+\t}\n \n-\tif (!commit)\n-\t\treturn 0;\n-\tobject = parse_object(sha1);\n \t/* If --all, then any refs are used.\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-\t\tif (object->type == OBJ_TAG) {\n+\t\tif (is_tag) {\n \t\t\tprio = 2;\n \t\t\tif (pattern && fnmatch(pattern, path + 10, 0))\n \t\t\t\tprio = 0;\n-- \n1.5.4.3.295.g6b554\n"}]}