pack-objects: fix handling of multiple --filter options

Since 5cb28270a1 (pack-objects: lazily set up "struct rev_info", don't leak, 2022-03-28) --filter options given to git pack-objects overrule earlier ones, letting only the leftmost win and leaking the memory allocated for earlier ones. Fix that by only initializing the rev_info struct once. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Nov 29, 2022 at 13:23 UTC 825babe5d5c720cb196f4f12c8eeb15fe00e95a1
2 files changed +3 -2
builtin/pack-objects.c
+2 -1
@@ -4158,7 +4158,8 @@ static struct list_objects_filter_options *po_filter_revs_init(void *value)
4158 {
4159 struct po_filter_data *data = value;
4160
4161 - repo_init_revisions(the_repository, &data->revs, NULL);
4161 + if (!data->have_revs)
4162 + repo_init_revisions(the_repository, &data->revs, NULL);
4163 data->have_revs = 1;
4164
4165 return &data->revs.filter;
t/t5317-pack-objects-filter-objects.sh
+1 -1
@@ -265,7 +265,7 @@ test_expect_success 'verify normal and blob:limit packfiles have same commits/tr
265 test_cmp expected observed
266 '
267
268 -test_expect_failure 'verify small limit and big limit results in small limit' '
268 +test_expect_success 'verify small limit and big limit results in small limit' '
269 git -C r2 ls-files -s large.1000 >ls_files_result &&
270 test_parse_ls_files_stage_oids <ls_files_result |
271 sort >expected &&