git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/6] Teach git-describe to use peeled ref information when scanning tags

From
Shawn O. Pearce <spearce@spearce.org>
Date
Feb 24, 2008, 08:07 UTC
Message-ID
<20080224080725.GC22587@spearce.org>

By using the peeled ref information inside of the packed-refs file we can avoid opening tag objects to obtain the commits they reference. This speeds up git-describe when there are a large number of tags in the repository as we have less objects to parse before we can start commit matching.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 builtin-describe.c |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/builtin-describe.c b/builtin-describe.c
index 3428483..bfd25e2 100644
--- a/builtin-describe.c
+++ b/builtin-describe.c
@@ -46,19 +46,30 @@ static void add_to_known_names(const char *path,
 
 static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data)
 {
-	struct commit *commit = lookup_commit_reference_gently(sha1, 1);
+	struct commit *commit;
 	struct object *object;
-	int prio;
+	unsigned char peeled[20];
+	int is_tag, prio;
+
+	if (!peel_ref(path, peeled) && !is_null_sha1(peeled)) {
+		commit = lookup_commit_reference_gently(peeled, 1);
+		if (!commit)
+			return 0;
+		is_tag = !!hashcmp(sha1, commit->object.sha1);
+	} else {
+		commit = lookup_commit_reference_gently(sha1, 1);
+		object = parse_object(sha1);
+		if (!commit || !object)
+			return 0;
+		is_tag = object->type == OBJ_TAG;
+	}
 
-	if (!commit)
-		return 0;
-	object = parse_object(sha1);
 	/* If --all, then any refs are used.
 	 * If --tags, then any tags are used.
 	 * Otherwise only annotated tags are used.
 	 */
 	if (!prefixcmp(path, "refs/tags/")) {
-		if (object->type == OBJ_TAG) {
+		if (is_tag) {
 			prio = 2;
 			if (pattern && fnmatch(pattern, path + 10, 0))
 				prio = 0;
-- 
1.5.4.3.295.g6b554
Message 1 of 1 in “Teach git-describe to use peeled ref information when scanning tags”
  1. 3/6 Teach git-describe to use peeled ref information when scanning tagsShawn O. Pearce, Feb 24, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.