@matheusbsbs / matheus-bagliano / commits / 8a5a1884e9
Fork 0

Avoid accessing non-tag refs in git-describe unless --all is requested

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shawn O. Pearce committed Feb 24, 2008 at 03:07 UTC 8a5a1884e93564cb1f46a73184d083a5181d573b
1 file changed +5 -1
builtin-describe.c
+5 -1
@@ -46,11 +46,15 @@ static void add_to_known_names(const char *path,
46
47 static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data)
48 {
49 + int might_be_tag = !prefixcmp(path, "refs/tags/");
50 struct commit *commit;
51 struct object *object;
52 unsigned char peeled[20];
53 int is_tag, prio;
54
55 + if (!all && !might_be_tag)
56 + return 0;
57 +
58 if (!peel_ref(path, peeled) && !is_null_sha1(peeled)) {
59 commit = lookup_commit_reference_gently(peeled, 1);
60 if (!commit)
@@ -68,7 +72,7 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void
72 * If --tags, then any tags are used.
73 * Otherwise only annotated tags are used.
74 */
71 - if (!prefixcmp(path, "refs/tags/")) {
75 + if (might_be_tag) {
76 if (is_tag) {
77 prio = 2;
78 if (pattern && fnmatch(pattern, path + 10, 0))