When adding a packfile to it store we add it both to the list and map of packfiles, but we don't append it to the most-recently-used list of packs. We do know to add the packfile to the MRU list as soon as we access any of its objects, but in between we're being inconistent. It doesn't help that there are some subsystems that _do_ add the packfile to the MRU after having added it, which only adds to the confusion. Refactor the code so that we unconditionally add packfiles to the MRU when adding them to a packfile store. Signed-off-by: Patrick Steinhardt <ps@xxxxxx> --- midx.c | 4 +--- packfile.c | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/midx.c b/midx.c index 95e74c79c1..3cfe7884ad 100644 --- a/midx.c +++ b/midx.c @@ -476,10 +476,8 @@ int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, struct packed_git, packmap_ent); if (!p) { p = add_packed_git(r, pack_name.buf, pack_name.len, m->local); - if (p) { + if (p) packfile_store_add_pack(r->objects->packfiles, p); - list_add_tail(&p->mru, &r->objects->packfiles->mru); - } } strbuf_release(&pack_name); diff --git a/packfile.c b/packfile.c index c885046d9f..a79d0fc1fa 100644 --- a/packfile.c +++ b/packfile.c @@ -790,6 +790,7 @@ void packfile_store_add_pack(struct packfile_store *store, hashmap_entry_init(&pack->packmap_ent, strhash(pack->pack_name)); hashmap_add(&store->map, &pack->packmap_ent); + list_add_tail(&pack->mru, &store->mru); } void (*report_garbage)(unsigned seen_bits, const char *path); -- 2.51.0.261.g7ce5a0a67e.dirty