packfile: move packed source into "odb/" subsystem
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>
Patrick Steinhardt committed
Jun 17, 2026 at 08:39 UTC
c71a1214156374b7b8c3c9158aa27e94e70df6c9
7 files changed
+87
-75
Makefile
+1
index ed1731548e..113fa45993 100644
--- 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
meson.build
+1
index 12913fc948..ca235801cf 100644
--- a/meson.build
+++ b/meson.build
@@ -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',
odb/source-files.c
+1
-1
index 5bdd042922..191562f316 100644
--- a/odb/source-files.c
+++ b/odb/source-files.c
@@ -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;
odb/source-packed.c
+11
new file mode 100644
index 0000000000..1e94b47ea0
--- /dev/null
+++ b/odb/source-packed.c
@@ -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;
+}
odb/source-packed.h
+72
new file mode 100644
index 0000000000..327be4ad65
--- /dev/null
+++ b/odb/source-packed.h
@@ -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
packfile.c
-9
index 27ea4a8436..99be5789ef 100644
--- a/packfile.c
+++ b/packfile.c
@@ -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)
packfile.h
+1
-65
index 4e3d701a3a..2d0bb7adbe 100644
--- a/packfile.h
+++ b/packfile.h
@@ -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.