Skip to content

Commit 9c30b70

Browse files
committed
midx: prevent duplicate packfile loads
The multi-pack-index, when present, tracks the existence of objects and their offsets within a list of packfiles. This allows us to use the multi-pack-index for object lookups, abbreviations, and object counts. When the multi-pack-index tracks a packfile, then we do not need to add that packfile to the packed_git linked list or the MRU list. We still need to load the packfiles that are not tracked by the multi-pack-index. Signed-off-by: Derrick Stolee <[email protected]>
1 parent cb97ae4 commit 9c30b70

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packfile.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ struct prepare_pack_data {
795795
struct repository *r;
796796
struct string_list *garbage;
797797
int local;
798+
struct multi_pack_index *m;
798799
};
799800

800801
static void prepare_pack(const char *full_name, size_t full_name_len,
@@ -805,6 +806,8 @@ static void prepare_pack(const char *full_name, size_t full_name_len,
805806
size_t base_len = full_name_len;
806807

807808
if (strip_suffix_mem(full_name, &base_len, ".idx")) {
809+
if (data->m && midx_contains_pack(data->m, file_name))
810+
return;
808811
/* Don't reopen a pack we already have. */
809812
for (p = data->r->objects->packed_git; p; p = p->next) {
810813
size_t len;
@@ -839,6 +842,12 @@ static void prepare_packed_git_one(struct repository *r, char *objdir, int local
839842
struct prepare_pack_data data;
840843
struct string_list garbage = STRING_LIST_INIT_DUP;
841844

845+
data.m = r->objects->multi_pack_index;
846+
847+
/* look for the multi-pack-index for this object directory */
848+
while (data.m && strcmp(data.m->object_dir, objdir))
849+
data.m = data.m->next;
850+
842851
data.r = r;
843852
data.garbage = &garbage;
844853
data.local = local;

0 commit comments

Comments
 (0)