]> git.ipfire.org Git - thirdparty/git.git/commitdiff
packfile: move packed source into "odb/" subsystem
authorPatrick Steinhardt <ps@pks.im>
Wed, 17 Jun 2026 06:39:46 +0000 (08:39 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 17 Jun 2026 12:00:00 +0000 (05:00 -0700)
In subsequent patches we'll be turning `struct odb_source_packed` into a
proper `struct odb_source`. As a first step towards this goal, move its
struct out of "packfile.{c,h}" and into "odb/source-packed.{c,h}".

This detaches the implementation of the packfile object source from the
generic packfile code, following the same convention already used by the
"files" and "in-memory" sources.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Makefile
meson.build
odb/source-files.c
odb/source-packed.c [new file with mode: 0644]
odb/source-packed.h [new file with mode: 0644]
packfile.c
packfile.h

index ed1731548e903f02ac16c6a2455413247452458f..113fa459939cae965b12bd903a1c504e8ac6968c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1218,6 +1218,7 @@ LIB_OBJS += odb/source.o
 LIB_OBJS += odb/source-files.o
 LIB_OBJS += odb/source-inmemory.o
 LIB_OBJS += odb/source-loose.o
+LIB_OBJS += odb/source-packed.o
 LIB_OBJS += odb/streaming.o
 LIB_OBJS += odb/transaction.o
 LIB_OBJS += oid-array.o
index 12913fc9489ec31a83065aa234c1add42bb49efa..ca235801cf48482e92f25f4d4e1370e00300f91a 100644 (file)
@@ -406,6 +406,7 @@ libgit_sources = [
   'odb/source-files.c',
   'odb/source-inmemory.c',
   'odb/source-loose.c',
+  'odb/source-packed.c',
   'odb/streaming.c',
   'odb/transaction.c',
   'oid-array.c',
index 5bdd04292253971fdfc3cb60fb9f1201a6075f2e..191562f316743efbaa6631c3e67980b26b6a4d5e 100644 (file)
@@ -269,7 +269,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
        CALLOC_ARRAY(files, 1);
        odb_source_init(&files->base, odb, ODB_SOURCE_FILES, path, local);
        files->loose = odb_source_loose_new(odb, path, local);
-       files->packed = packfile_store_new(&files->base);
+       files->packed = odb_source_packed_new(&files->base);
 
        files->base.free = odb_source_files_free;
        files->base.close = odb_source_files_close;
diff --git a/odb/source-packed.c b/odb/source-packed.c
new file mode 100644 (file)
index 0000000..1e94b47
--- /dev/null
@@ -0,0 +1,11 @@
+#include "git-compat-util.h"
+#include "odb/source-packed.h"
+
+struct odb_source_packed *odb_source_packed_new(struct odb_source *source)
+{
+       struct odb_source_packed *store;
+       CALLOC_ARRAY(store, 1);
+       store->source = source;
+       strmap_init(&store->packs_by_path);
+       return store;
+}
diff --git a/odb/source-packed.h b/odb/source-packed.h
new file mode 100644 (file)
index 0000000..327be4a
--- /dev/null
@@ -0,0 +1,72 @@
+#ifndef ODB_SOURCE_PACKED_H
+#define ODB_SOURCE_PACKED_H
+
+#include "odb/source.h"
+#include "packfile-list.h"
+#include "strmap.h"
+
+/*
+ * A store that manages packfiles for a given object database.
+ */
+struct odb_source_packed {
+       struct odb_source *source;
+
+       /*
+        * The list of packfiles in the order in which they have been most
+        * recently used.
+        */
+       struct packfile_list packs;
+
+       /*
+        * Cache of packfiles which are marked as "kept", either because there
+        * is an on-disk ".keep" file or because they are marked as "kept" in
+        * memory.
+        *
+        * Should not be accessed directly, but via
+        * `packfile_store_get_kept_pack_cache()`. The list of packs gets
+        * invalidated when the stored flags and the flags passed to
+        * `packfile_store_get_kept_pack_cache()` mismatch.
+        */
+       struct {
+               struct packed_git **packs;
+               unsigned flags;
+       } kept_cache;
+
+       /* The multi-pack index that belongs to this specific packfile store. */
+       struct multi_pack_index *midx;
+
+       /*
+        * A map of packfile names to packed_git structs for tracking which
+        * packs have been loaded already.
+        */
+       struct strmap packs_by_path;
+
+       /*
+        * Whether packfiles have already been populated with this store's
+        * packs.
+        */
+       bool initialized;
+
+       /*
+        * Usually, packfiles will be reordered to the front of the `packs`
+        * list whenever an object is looked up via them. This has the effect
+        * that packs that contain a lot of accessed objects will be located
+        * towards the front.
+        *
+        * This is usually desireable, but there are exceptions. One exception
+        * is when the looking up multiple objects in a loop for each packfile.
+        * In that case, we may easily end up with an infinite loop as the
+        * packfiles get reordered to the front repeatedly.
+        *
+        * Setting this field to `true` thus disables these reorderings.
+        */
+       bool skip_mru_updates;
+};
+
+/*
+ * Allocate and initialize a new empty packfile store for the given object
+ * database source.
+ */
+struct odb_source_packed *odb_source_packed_new(struct odb_source *source);
+
+#endif
index 27ea4a8436a53591998efa06330cf43d773d730d..99be5789efbad4ce5433abb78f6fcfc954c6b872 100644 (file)
@@ -2749,15 +2749,6 @@ int parse_pack_header_option(const char *in, unsigned char *out, unsigned int *l
        return 0;
 }
 
-struct odb_source_packed *packfile_store_new(struct odb_source *source)
-{
-       struct odb_source_packed *store;
-       CALLOC_ARRAY(store, 1);
-       store->source = source;
-       strmap_init(&store->packs_by_path);
-       return store;
-}
-
 void packfile_store_free(struct odb_source_packed *store)
 {
        for (struct packfile_list_entry *e = store->packs.head; e; e = e->next)
index 4e3d701a3a25042b77b13e4ba35d459a4c13b8ca..2d0bb7adbe83c61c9be8c34948c58560d9f4b66e 100644 (file)
@@ -5,10 +5,10 @@
 #include "object.h"
 #include "odb.h"
 #include "odb/source-files.h"
+#include "odb/source-packed.h"
 #include "oidset.h"
 #include "packfile-list.h"
 #include "repository.h"
-#include "strmap.h"
 
 /* in odb.h */
 struct object_info;
@@ -55,70 +55,6 @@ struct packed_git {
        char pack_name[FLEX_ARRAY]; /* more */
 };
 
-/*
- * A store that manages packfiles for a given object database.
- */
-struct odb_source_packed {
-       struct odb_source *source;
-
-       /*
-        * The list of packfiles in the order in which they have been most
-        * recently used.
-        */
-       struct packfile_list packs;
-
-       /*
-        * Cache of packfiles which are marked as "kept", either because there
-        * is an on-disk ".keep" file or because they are marked as "kept" in
-        * memory.
-        *
-        * Should not be accessed directly, but via
-        * `packfile_store_get_kept_pack_cache()`. The list of packs gets
-        * invalidated when the stored flags and the flags passed to
-        * `packfile_store_get_kept_pack_cache()` mismatch.
-        */
-       struct {
-               struct packed_git **packs;
-               unsigned flags;
-       } kept_cache;
-
-       /* The multi-pack index that belongs to this specific packfile store. */
-       struct multi_pack_index *midx;
-
-       /*
-        * A map of packfile names to packed_git structs for tracking which
-        * packs have been loaded already.
-        */
-       struct strmap packs_by_path;
-
-       /*
-        * Whether packfiles have already been populated with this store's
-        * packs.
-        */
-       bool initialized;
-
-       /*
-        * Usually, packfiles will be reordered to the front of the `packs`
-        * list whenever an object is looked up via them. This has the effect
-        * that packs that contain a lot of accessed objects will be located
-        * towards the front.
-        *
-        * This is usually desireable, but there are exceptions. One exception
-        * is when the looking up multiple objects in a loop for each packfile.
-        * In that case, we may easily end up with an infinite loop as the
-        * packfiles get reordered to the front repeatedly.
-        *
-        * Setting this field to `true` thus disables these reorderings.
-        */
-       bool skip_mru_updates;
-};
-
-/*
- * Allocate and initialize a new empty packfile store for the given object
- * database source.
- */
-struct odb_source_packed *packfile_store_new(struct odb_source *source);
-
 /*
  * Free the packfile store and all its associated state. All packfiles
  * tracked by the store will be closed.