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 <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Jul 12, 2018 at 15:39 UTC
f3a002bd84790e89399c3a18f1e7101b850ed6f8
1 file changed
+9
packfile.c
+9
@@ -795,6 +795,7 @@ struct prepare_pack_data {
795
struct repository *r;
796
struct string_list *garbage;
797
int local;
798
+ struct multi_pack_index *m;
799
};
800
801
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,
806
size_t base_len = full_name_len;
807
808
if (strip_suffix_mem(full_name, &base_len, ".idx")) {
809
+ if (data->m && midx_contains_pack(data->m, file_name))
810
+ return;
811
/* Don't reopen a pack we already have. */
812
for (p = data->r->objects->packed_git; p; p = p->next) {
813
size_t len;
@@ -839,6 +842,12 @@ static void prepare_packed_git_one(struct repository *r, char *objdir, int local
842
struct prepare_pack_data data;
843
struct string_list garbage = STRING_LIST_INIT_DUP;
844
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
+
851
data.r = r;
852
data.garbage = &garbage;
853
data.local = local;