packfile: add all_packs list

If a repo contains a multi-pack-index, then the packed_git list does not contain the packfiles that are covered by the multi-pack-index. This is important for doing object lookups, abbreviations, and approximating object count. However, there are many operations that really want to iterate over all packfiles. Create a new 'all_packs' linked list that contains this list, starting with the packfiles in the multi-pack-index and then continuing along the packed_git linked list. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Aug 20, 2018 at 16:52 UTC 0bff5269d3ed7124259bb3a5b33ddf2c4080b7e7
5 files changed +36 -1
midx.c
+1 -1
@@ -197,7 +197,7 @@ static void close_midx(struct multi_pack_index *m)
197 FREE_AND_NULL(m->pack_names);
198 }
199
200 -static int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id)
200 +int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id)
201 {
202 struct strbuf pack_name = STRBUF_INIT;
203
midx.h
+1
@@ -32,6 +32,7 @@ struct multi_pack_index {
32 };
33
34 struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);
35 +int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id);
36 int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result);
37 struct object_id *nth_midxed_object_oid(struct object_id *oid,
38 struct multi_pack_index *m,
object-store.h
+6
@@ -129,6 +129,12 @@ struct raw_object_store {
129 /* A most-recently-used ordered version of the packed_git list. */
130 struct list_head packed_git_mru;
131
132 + /*
133 + * A linked list containing all packfiles, starting with those
134 + * contained in the multi_pack_index.
135 + */
136 + struct packed_git *all_packs;
137 +
138 /*
139 * A fast, rough count of the number of objects in the repository.
140 * These two fields are not meant for direct access. Use
packfile.c
+27
@@ -972,6 +972,9 @@ static void prepare_packed_git(struct repository *r)
972 prepare_packed_git_one(r, alt->path, 0);
973 }
974 rearrange_packed_git(r);
975 +
976 + r->objects->all_packs = NULL;
977 +
978 prepare_packed_git_mru(r);
979 r->objects->packed_git_initialized = 1;
980 }
@@ -995,6 +998,30 @@ struct multi_pack_index *get_multi_pack_index(struct repository *r)
998 return r->objects->multi_pack_index;
999 }
1000
1001 +struct packed_git *get_all_packs(struct repository *r)
1002 +{
1003 + prepare_packed_git(r);
1004 +
1005 + if (!r->objects->all_packs) {
1006 + struct packed_git *p = r->objects->packed_git;
1007 + struct multi_pack_index *m;
1008 +
1009 + for (m = r->objects->multi_pack_index; m; m = m->next) {
1010 + uint32_t i;
1011 + for (i = 0; i < m->num_packs; i++) {
1012 + if (!prepare_midx_pack(m, i)) {
1013 + m->packs[i]->next = p;
1014 + p = m->packs[i];
1015 + }
1016 + }
1017 + }
1018 +
1019 + r->objects->all_packs = p;
1020 + }
1021 +
1022 + return r->objects->all_packs;
1023 +}
1024 +
1025 struct list_head *get_packed_git_mru(struct repository *r)
1026 {
1027 prepare_packed_git(r);
packfile.h
+1
@@ -51,6 +51,7 @@ extern void install_packed_git(struct repository *r, struct packed_git *pack);
51 struct packed_git *get_packed_git(struct repository *r);
52 struct list_head *get_packed_git_mru(struct repository *r);
53 struct multi_pack_index *get_multi_pack_index(struct repository *r);
54 +struct packed_git *get_all_packs(struct repository *r);
55
56 /*
57 * Give a rough count of objects in the repository. This sacrifices accuracy