midx: stop using linked list when closing MIDX
When calling `close_midx()` we not only close the multi-pack index for one object source, but instead we iterate through the whole linked list of MIDXs to close all of them. This linked list is about to go away in favor of using the new per-source pointer to its respective MIDX. Refactor the function to iterate through sources instead. Note that after this patch, there's a couple of callsites left that continue to use `close_midx()` without iterating through all sources. These are all cases where we don't care about the MIDX from other sources though, so it's fine to keep them as-is. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Jul 15, 2025 at 13:29 UTC
6567432ab4f93f63cd2111197c91651a9b04c517
2 files changed
+14
-10
midx.c
+8
-5
@@ -401,7 +401,6 @@ void close_midx(struct multi_pack_index *m)
401
if (!m)
402
return;
403
404
- close_midx(m->next);
404
close_midx(m->base_midx);
405
406
munmap((unsigned char *)m->data, m->data_len);
@@ -835,11 +834,15 @@ void clear_midx_file(struct repository *r)
834
835
get_midx_filename(r->hash_algo, &midx, r->objects->sources->path);
836
838
- if (r->objects && r->objects->multi_pack_index) {
839
- close_midx(r->objects->multi_pack_index);
840
- r->objects->multi_pack_index = NULL;
841
- for (struct odb_source *source = r->objects->sources; source; source = source->next)
837
+ if (r->objects) {
838
+ struct odb_source *source;
839
+
840
+ for (source = r->objects->sources; source; source = source->next) {
841
+ if (source->midx)
842
+ close_midx(source->midx);
843
source->midx = NULL;
844
+ }
845
+ r->objects->multi_pack_index = NULL;
846
}
847
848
if (remove_path(midx.buf))
packfile.c
+6
-5
@@ -361,6 +361,7 @@ void close_pack(struct packed_git *p)
361
362
void close_object_store(struct object_database *o)
363
{
364
+ struct odb_source *source;
365
struct packed_git *p;
366
367
for (p = o->packed_git; p; p = p->next)
@@ -369,12 +370,12 @@ void close_object_store(struct object_database *o)
370
else
371
close_pack(p);
372
372
- if (o->multi_pack_index) {
373
- close_midx(o->multi_pack_index);
374
- o->multi_pack_index = NULL;
375
- for (struct odb_source *source = o->sources; source; source = source->next)
376
- source->midx = NULL;
373
+ for (source = o->sources; source; source = source->next) {
374
+ if (source->midx)
375
+ close_midx(source->midx);
376
+ source->midx = NULL;
377
}
378
+ o->multi_pack_index = NULL;
379
380
close_commit_graph(o);
381
}