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

[PATCH 4/6] Avoid accessing non-tag refs in git-describe unless --all is requested

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

If we aren't going to use a ref there is no reason for us to open its object from the object database. This avoids opening any of the head commits reachable from refs/heads/ unless they are also reachable through the commit we have been asked to describe and we need to walk through it to find a tag.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 builtin-describe.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/builtin-describe.c b/builtin-describe.c
index bfd25e2..9c958bd 100644
--- a/builtin-describe.c
+++ b/builtin-describe.c
@@ -46,11 +46,15 @@ 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)
 {
+	int might_be_tag = !prefixcmp(path, "refs/tags/");
 	struct commit *commit;
 	struct object *object;
 	unsigned char peeled[20];
 	int is_tag, prio;
 
+	if (!all && !might_be_tag)
+		return 0;
+
 	if (!peel_ref(path, peeled) && !is_null_sha1(peeled)) {
 		commit = lookup_commit_reference_gently(peeled, 1);
 		if (!commit)
@@ -68,7 +72,7 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void
 	 * If --tags, then any tags are used.
 	 * Otherwise only annotated tags are used.
 	 */
-	if (!prefixcmp(path, "refs/tags/")) {
+	if (might_be_tag) {
 		if (is_tag) {
 			prio = 2;
 			if (pattern && fnmatch(pattern, path + 10, 0))
-- 
1.5.4.3.295.g6b554
Message 1 of 1 in “Avoid accessing non-tag refs in git-describe unless --all is requested”
  1. 4/6 Avoid accessing non-tag refs in git-describe unless --all is requestedShawn 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.