Skip to content

Commit 6567432

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec4380f commit 6567432

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

midx.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ void close_midx(struct multi_pack_index *m)
401401
if (!m)
402402
return;
403403

404-
close_midx(m->next);
405404
close_midx(m->base_midx);
406405

407406
munmap((unsigned char *)m->data, m->data_len);
@@ -835,11 +834,15 @@ void clear_midx_file(struct repository *r)
835834

836835
get_midx_filename(r->hash_algo, &midx, r->objects->sources->path);
837836

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);
842843
source->midx = NULL;
844+
}
845+
r->objects->multi_pack_index = NULL;
843846
}
844847

845848
if (remove_path(midx.buf))

packfile.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ void close_pack(struct packed_git *p)
361361

362362
void close_object_store(struct object_database *o)
363363
{
364+
struct odb_source *source;
364365
struct packed_git *p;
365366

366367
for (p = o->packed_git; p; p = p->next)
@@ -369,12 +370,12 @@ void close_object_store(struct object_database *o)
369370
else
370371
close_pack(p);
371372

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;
377377
}
378+
o->multi_pack_index = NULL;
378379

379380
close_commit_graph(o);
380381
}

0 commit comments

Comments
 (0)