packfile: add all_packs list
authorDerrick Stolee <dstolee@microsoft.com>
Mon, 20 Aug 2018 16:52:02 +0000 (16:52 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Aug 2018 22:31:40 +0000 (15:31 -0700)
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>
midx.c
midx.h
object-store.h
packfile.c
packfile.h
diff --git a/midx.c b/midx.c
index 0710c4c175c72d17428b5c4e67018185b789a973..f3e8dbc10820303436c07126b85d6024d2fb3e56 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -197,7 +197,7 @@ static void close_midx(struct multi_pack_index *m)
        FREE_AND_NULL(m->pack_names);
 }
 
-static int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id)
+int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id)
 {
        struct strbuf pack_name = STRBUF_INIT;
 
diff --git a/midx.h b/midx.h
index 8aa79f4b628fea9b26654a9c4ba4172ab3327162..a210f1af2af6bd7c7dc2210ac4b5ca398c8c60d1 100644 (file)
--- a/midx.h
+++ b/midx.h
@@ -32,6 +32,7 @@ struct multi_pack_index {
 };
 
 struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);
+int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id);
 int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result);
 struct object_id *nth_midxed_object_oid(struct object_id *oid,
                                        struct multi_pack_index *m,
index 97f1c160e59b96b63011afea03e8c0a9e8f521d1..63b7605a3e0b3000641d8f39f22e1d5c8139f19b 100644 (file)
@@ -129,6 +129,12 @@ struct raw_object_store {
        /* A most-recently-used ordered version of the packed_git list. */
        struct list_head packed_git_mru;
 
+       /*
+        * A linked list containing all packfiles, starting with those
+        * contained in the multi_pack_index.
+        */
+       struct packed_git *all_packs;
+
        /*
         * A fast, rough count of the number of objects in the repository.
         * These two fields are not meant for direct access. Use
index fe713a0242212d925ebab126b0c3584b372c9f53..adcf2e12a0749b0b6ac8529c866e263fc2d8bc54 100644 (file)
@@ -972,6 +972,9 @@ static void prepare_packed_git(struct repository *r)
                prepare_packed_git_one(r, alt->path, 0);
        }
        rearrange_packed_git(r);
+
+       r->objects->all_packs = NULL;
+
        prepare_packed_git_mru(r);
        r->objects->packed_git_initialized = 1;
 }
@@ -995,6 +998,30 @@ struct multi_pack_index *get_multi_pack_index(struct repository *r)
        return r->objects->multi_pack_index;
 }
 
+struct packed_git *get_all_packs(struct repository *r)
+{
+       prepare_packed_git(r);
+
+       if (!r->objects->all_packs) {
+               struct packed_git *p = r->objects->packed_git;
+               struct multi_pack_index *m;
+
+               for (m = r->objects->multi_pack_index; m; m = m->next) {
+                       uint32_t i;
+                       for (i = 0; i < m->num_packs; i++) {
+                               if (!prepare_midx_pack(m, i)) {
+                                       m->packs[i]->next = p;
+                                       p = m->packs[i];
+                               }
+                       }
+               }
+
+               r->objects->all_packs = p;
+       }
+
+       return r->objects->all_packs;
+}
+
 struct list_head *get_packed_git_mru(struct repository *r)
 {
        prepare_packed_git(r);
index 5abfaf2ab5c3471b1494cf41bbcca19ff9d36425..442625723dea4b0c8f22b57d52e760d4b810540e 100644 (file)
@@ -51,6 +51,7 @@ extern void install_packed_git(struct repository *r, struct packed_git *pack);
 struct packed_git *get_packed_git(struct repository *r);
 struct list_head *get_packed_git_mru(struct repository *r);
 struct multi_pack_index *get_multi_pack_index(struct repository *r);
+struct packed_git *get_all_packs(struct repository *r);
 
 /*
  * Give a rough count of objects in the repository. This sacrifices accuracy