]> git.ipfire.org Git - thirdparty/git.git/commitdiff
packfile: move `get_multi_pack_index()` into "midx.c"
authorPatrick Steinhardt <ps@pks.im>
Tue, 23 Sep 2025 10:17:11 +0000 (12:17 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 24 Sep 2025 18:53:50 +0000 (11:53 -0700)
The `get_multi_pack_index()` function is declared and implemented in the
packfile subsystem, even though it really belongs into the multi-pack
index subsystem. The reason for this is likely that it needs to call
`packfile_store_prepare()`, which is not exposed by the packfile system.
In a subsequent commit we're about to add another caller outside of the
packfile system though, so we'll have to expose the function anyway.

Do so now already and move `get_multi_pack_index()` into the MIDX
subsystem.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
midx.c
midx.h
packfile.c
packfile.h

diff --git a/midx.c b/midx.c
index 3faeaf2f8faed15caec2d5fd8215c82a1009472d..1d6269f957e7819fb62963cde191360422b29229 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -93,6 +93,12 @@ static int midx_read_object_offsets(const unsigned char *chunk_start,
        return 0;
 }
 
+struct multi_pack_index *get_multi_pack_index(struct odb_source *source)
+{
+       packfile_store_prepare(source->odb->packfiles);
+       return source->midx;
+}
+
 static struct multi_pack_index *load_multi_pack_index_one(struct odb_source *source,
                                                          const char *midx_name)
 {
diff --git a/midx.h b/midx.h
index e241d2d6900bc3a2946e973a3d37df74aa3cbc4f..6e54d73503d56088923ceff1c69e1f8d6013ac12 100644 (file)
--- a/midx.h
+++ b/midx.h
@@ -94,6 +94,7 @@ void get_midx_chain_filename(struct odb_source *source, struct strbuf *out);
 void get_split_midx_filename_ext(struct odb_source *source, struct strbuf *buf,
                                 const unsigned char *hash, const char *ext);
 
+struct multi_pack_index *get_multi_pack_index(struct odb_source *source);
 struct multi_pack_index *load_multi_pack_index(struct odb_source *source);
 int prepare_midx_pack(struct multi_pack_index *m, uint32_t pack_int_id);
 struct packed_git *nth_midxed_pack(struct multi_pack_index *m,
index 9224ca424c187ce6eefea5fcda93d31aa47ce041..7a9193e5ef4664b7dcf4e3497933d944242b5ea9 100644 (file)
@@ -1003,7 +1003,7 @@ static void packfile_store_prepare_mru(struct packfile_store *store)
                list_add_tail(&p->mru, &store->mru);
 }
 
-static void packfile_store_prepare(struct packfile_store *store)
+void packfile_store_prepare(struct packfile_store *store)
 {
        struct odb_source *source;
 
@@ -1033,12 +1033,6 @@ struct packed_git *get_packed_git(struct repository *r)
        return r->objects->packfiles->packs;
 }
 
-struct multi_pack_index *get_multi_pack_index(struct odb_source *source)
-{
-       packfile_store_prepare(source->odb->packfiles);
-       return source->midx;
-}
-
 struct packed_git *get_all_packs(struct repository *r)
 {
        packfile_store_prepare(r->objects->packfiles);
index fcefcbbef65f0bad818820f5323aac88b9664d83..a9e561ac3948634f66fe1fd929aeb50d2f3eb0b5 100644 (file)
@@ -112,6 +112,15 @@ void packfile_store_free(struct packfile_store *store);
  */
 void packfile_store_close(struct packfile_store *store);
 
+/*
+ * Prepare the packfile store by loading packfiles and multi-pack indices for
+ * all alternates. This becomes a no-op if the store is already prepared.
+ *
+ * It shouldn't typically be necessary to call this function directly, as
+ * functions that access the store know to prepare it.
+ */
+void packfile_store_prepare(struct packfile_store *store);
+
 /*
  * Clear the packfile caches and try to look up any new packfiles that have
  * appeared since last preparing the packfiles store.
@@ -213,7 +222,6 @@ extern void (*report_garbage)(unsigned seen_bits, const char *path);
 
 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 odb_source *source);
 struct packed_git *get_all_packs(struct repository *r);
 
 /*