Subject: [PATCH 1/1] builtin/pack-objects.c: avoid iterating all refs

From: Jacob Vosmaer <[email-masked]>
Date: Tue, 19 Jan 2021 15:33:48 +0100

In git-pack-objects, we iterate over all the tags if the --include-tag
option is passed on the command line. For some reason this uses
for_each_ref which is expensive if the repo has many refs. We should
use a prefix iterator instead.

Signed-off-by: Jacob Vosmaer <[email-masked]>
---
 builtin/pack-objects.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 2a00358f34..2b32bc93bd 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -3740,7 +3740,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 	}
 	cleanup_preferred_base();
 	if (include_tag && nr_result)
-		for_each_ref(add_ref_tag, NULL);
+		for_each_fullref_in("refs/tags/", add_ref_tag, NULL, 0);
 	stop_progress(&progress_state);
 	trace2_region_leave("pack-objects", "enumerate-objects",
 			    the_repository);
-- 
2.30.0