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
@@ -1218,6 +1218,7 @@ LIB_OBJS += odb/source.o
1218
LIB_OBJS += odb/source-files.o
1219
LIB_OBJS += odb/source-inmemory.o
1220
LIB_OBJS += odb/source-loose.o
1221
+LIB_OBJS += odb/source-packed.o
1222
LIB_OBJS += odb/streaming.o
1223
LIB_OBJS += odb/transaction.o
1224
LIB_OBJS += oid-array.o
meson.build
+1
@@ -406,6 +406,7 @@ libgit_sources = [
406
'odb/source-files.c',
407
'odb/source-inmemory.c',
408
'odb/source-loose.c',
409
+ 'odb/source-packed.c',
410
'odb/streaming.c',
411
'odb/transaction.c',
412
'oid-array.c',
odb/source-files.c
+1
-1
@@ -269,7 +269,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
269
CALLOC_ARRAY(files, 1);
270
odb_source_init(&files->base, odb, ODB_SOURCE_FILES, path, local);
271
files->loose = odb_source_loose_new(odb, path, local);
272
- files->packed = packfile_store_new(&files->base);
272
+ files->packed = odb_source_packed_new(&files->base);
273
274
files->base.free = odb_source_files_free;
275
files->base.close = odb_source_files_close;
odb/source-packed.c
new
+11
@@ -0,0 +1,11 @@
1
+#include "git-compat-util.h"
2
+#include "odb/source-packed.h"
3
+
4
+struct odb_source_packed *odb_source_packed_new(struct odb_source *source)
5
+{
6
+ struct odb_source_packed *store;
7
+ CALLOC_ARRAY(store, 1);
8
+ store->source = source;
9
+ strmap_init(&store->packs_by_path);
10
+ return store;
11
+}
odb/source-packed.h
new
+72
@@ -0,0 +1,72 @@
1
+#ifndef ODB_SOURCE_PACKED_H
2
+#define ODB_SOURCE_PACKED_H
3
+
4
+#include "odb/source.h"
5
+#include "packfile-list.h"
6
+#include "strmap.h"
7
+
8
+/*
9
+ * A store that manages packfiles for a given object database.
10
+ */
11
+struct odb_source_packed {
12
+ struct odb_source *source;
13
+
14
+ /*
15
+ * The list of packfiles in the order in which they have been most
16
+ * recently used.
17
+ */
18
+ struct packfile_list packs;
19
+
20
+ /*
21
+ * Cache of packfiles which are marked as "kept", either because there
22
+ * is an on-disk ".keep" file or because they are marked as "kept" in
23
+ * memory.
24
+ *
25
+ * Should not be accessed directly, but via
26
+ * `packfile_store_get_kept_pack_cache()`. The list of packs gets
27
+ * invalidated when the stored flags and the flags passed to
28
+ * `packfile_store_get_kept_pack_cache()` mismatch.
29
+ */
30
+ struct {
31
+ struct packed_git **packs;
32
+ unsigned flags;
33
+ } kept_cache;
34
+
35
+ /* The multi-pack index that belongs to this specific packfile store. */
36
+ struct multi_pack_index *midx;
37
+
38
+ /*
39
+ * A map of packfile names to packed_git structs for tracking which
40
+ * packs have been loaded already.
41
+ */
42
+ struct strmap packs_by_path;
43
+
44
+ /*
45
+ * Whether packfiles have already been populated with this store's
46
+ * packs.
47
+ */
48
+ bool initialized;
49
+
50
+ /*
51
+ * Usually, packfiles will be reordered to the front of the `packs`
52
+ * list whenever an object is looked up via them. This has the effect
53
+ * that packs that contain a lot of accessed objects will be located
54
+ * towards the front.
55
+ *
56
+ * This is usually desireable, but there are exceptions. One exception
57
+ * is when the looking up multiple objects in a loop for each packfile.
58
+ * In that case, we may easily end up with an infinite loop as the
59
+ * packfiles get reordered to the front repeatedly.
60
+ *
61
+ * Setting this field to `true` thus disables these reorderings.
62
+ */
63
+ bool skip_mru_updates;
64
+};
65
+
66
+/*
67
+ * Allocate and initialize a new empty packfile store for the given object
68
+ * database source.
69
+ */
70
+struct odb_source_packed *odb_source_packed_new(struct odb_source *source);
71
+
72
+#endif
packfile.c
-9
@@ -2749,15 +2749,6 @@ int parse_pack_header_option(const char *in, unsigned char *out, unsigned int *l
2749
return 0;
2750
}
2751
2752
-struct odb_source_packed *packfile_store_new(struct odb_source *source)
2753
-{
2754
- struct odb_source_packed *store;
2755
- CALLOC_ARRAY(store, 1);
2756
- store->source = source;
2757
- strmap_init(&store->packs_by_path);
2758
- return store;
2759
-}
2760
-
2752
void packfile_store_free(struct odb_source_packed *store)
2753
{
2754
for (struct packfile_list_entry *e = store->packs.head; e; e = e->next)
packfile.h
+1
-65
@@ -5,10 +5,10 @@
5
#include "object.h"
6
#include "odb.h"
7
#include "odb/source-files.h"
8
+#include "odb/source-packed.h"
9
#include "oidset.h"
10
#include "packfile-list.h"
11
#include "repository.h"
11
-#include "strmap.h"
12
13
/* in odb.h */
14
struct object_info;
@@ -55,70 +55,6 @@ struct packed_git {
55
char pack_name[FLEX_ARRAY]; /* more */
56
};
57
58
-/*
59
- * A store that manages packfiles for a given object database.
60
- */
61
-struct odb_source_packed {
62
- struct odb_source *source;
63
-
64
- /*
65
- * The list of packfiles in the order in which they have been most
66
- * recently used.
67
- */
68
- struct packfile_list packs;
69
-
70
- /*
71
- * Cache of packfiles which are marked as "kept", either because there
72
- * is an on-disk ".keep" file or because they are marked as "kept" in
73
- * memory.
74
- *
75
- * Should not be accessed directly, but via
76
- * `packfile_store_get_kept_pack_cache()`. The list of packs gets
77
- * invalidated when the stored flags and the flags passed to
78
- * `packfile_store_get_kept_pack_cache()` mismatch.
79
- */
80
- struct {
81
- struct packed_git **packs;
82
- unsigned flags;
83
- } kept_cache;
84
-
85
- /* The multi-pack index that belongs to this specific packfile store. */
86
- struct multi_pack_index *midx;
87
-
88
- /*
89
- * A map of packfile names to packed_git structs for tracking which
90
- * packs have been loaded already.
91
- */
92
- struct strmap packs_by_path;
93
-
94
- /*
95
- * Whether packfiles have already been populated with this store's
96
- * packs.
97
- */
98
- bool initialized;
99
-
100
- /*
101
- * Usually, packfiles will be reordered to the front of the `packs`
102
- * list whenever an object is looked up via them. This has the effect
103
- * that packs that contain a lot of accessed objects will be located
104
- * towards the front.
105
- *
106
- * This is usually desireable, but there are exceptions. One exception
107
- * is when the looking up multiple objects in a loop for each packfile.
108
- * In that case, we may easily end up with an infinite loop as the
109
- * packfiles get reordered to the front repeatedly.
110
- *
111
- * Setting this field to `true` thus disables these reorderings.
112
- */
113
- bool skip_mru_updates;
114
-};
115
-
116
-/*
117
- * Allocate and initialize a new empty packfile store for the given object
118
- * database source.
119
- */
120
-struct odb_source_packed *packfile_store_new(struct odb_source *source);
121
-
58
/*
59
* Free the packfile store and all its associated state. All packfiles
60
* tracked by the store will be closed.