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

[PATCH v3] describe: limit default ref iteration to tags

From
Tamir Duberstein <tamird@gmail.com>
Date
Jun 10, 2026, 18:50 UTC
Message-ID
<20260610-describe-tag-ref-scope-v3-1-5aa63ab279f7@gmail.com>
In-Reply-To
<20260608-describe-tag-ref-scope-v2-1-256fd36dca32@gmail.com>

Without --all, git describe ignores refs outside refs/tags/. Commit 8a5a1884e9 (Avoid accessing non-tag refs in git-describe unless --all is requested, 2008-02-24) moved this check ahead of object lookup. That avoided loading objects for irrelevant refs, but the backend still has to yield every ref before get_name() can reject it.

Pass refs/tags/ to the iterator so the backend can avoid visiting those refs in the first place.

The new perf test creates 10,000 unrelated packed refs. It measures:
    git describe --exact-match HEAD

The runtime drops from 0.03(0.01+0.01) to 0.02(0.00+0.00). In a repository with 120,532 refs but only 330 tags, the same command went from 171.7 ms to 9.9 ms.

Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
Changes in v3:
- Pack the synthetic refs to better match repositories with many refs.
- Generate update-ref input with test_seq -f.
- Shorten the commit message and report the p6100.6 result.
- Link to v2: https://patch.msgid.link/20260608-describe-tag-ref-scope-v2-1-256fd36dca32@gmail.com
Changes in v2:
- Exercise the performance test with both ref backends.
- Keep the ref count local to its setup test.
- Report native hyperfine output for an exact-tag lookup.
- Link to v1: https://patch.msgid.link/20260607-describe-tag-ref-scope-v1-1-653d232b86b5@gmail.com
---
 builtin/describe.c       |  3 +++
 t/perf/p6100-describe.sh | 12 ++++++++++++
 2 files changed, 15 insertions(+)
diff --git a/builtin/describe.c b/builtin/describe.c
index 1c47d7c0b7..3532c8ff22 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -740,6 +740,9 @@ int cmd_describe(int argc,
 		return ret;
 	}
 
+	if (!all)
+		for_each_ref_opts.prefix = "refs/tags/";
+
 	hashmap_init(&names, commit_name_neq, NULL, 0);
 	refs_for_each_ref_ext(get_main_ref_store(the_repository),
 			      get_name, NULL, &for_each_ref_opts);
diff --git a/t/perf/p6100-describe.sh b/t/perf/p6100-describe.sh
index 069f91ce49..b1c61529bb 100755
--- a/t/perf/p6100-describe.sh
+++ b/t/perf/p6100-describe.sh
@@ -27,4 +27,16 @@ test_perf 'describe HEAD with one tag' '
 	git describe --match=new HEAD
 '
 
+test_expect_success 'set up many unrelated refs' '
+	ref_count=10000 &&
+	git tag -m tip tip HEAD &&
+	test_seq -f "create refs/heads/describe-perf/%05d HEAD" $ref_count |
+	git update-ref --stdin &&
+	git pack-refs --all
+'
+
+test_perf 'describe exact tag with many unrelated refs' '
+	git describe --exact-match HEAD
+'
+
 test_done

---
base-commit: 9ac3f193c05c2237e2b14ebaa1149e9fc8a1abe0
change-id: 20260607-describe-tag-ref-scope-7d00ae140a58

Best regards,
--  
Tamir Duberstein <tamird@gmail.com>
Previous: Jeff KingNext: Jeff King
Message 11 of 12 in “describe: limit default ref iteration to tags”
  1. describe: limit default ref iteration to tagsTamir Duberstein, Jun 9, 2026
  2. Jeff KingJun 9, 2026
  3. Junio C HamanoJun 9, 2026
  4. D. Ben KnobleJun 9, 2026
  5. Jeff KingJun 11, 2026
  6. Tamir DubersteinJun 9, 2026
  7. Junio C HamanoJun 10, 2026
  8. Patrick SteinhardtJun 10, 2026
  9. Junio C HamanoJun 10, 2026
  10. Jeff KingJun 11, 2026
  11. describe: limit default ref iteration to tagsTamir Duberstein, Jun 10, 2026
  12. Jeff KingJun 11, 2026

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.