git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 03/17] packfile: move packed source into "odb/" subsystem

From
Patrick Steinhardt <ps@pks.im>
Date
Jun 17, 2026, 06:39 UTC
Message-ID
<20260617-pks-odb-source-packed-v3-3-b5c7583cd795@pks.im>
In-Reply-To
<20260617-pks-odb-source-packed-v3-0-b5c7583cd795@pks.im>

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>
---
 Makefile            |  1 +
 meson.build         |  1 +
 odb/source-files.c  |  2 +-
 odb/source-packed.c | 11 ++++++++
 odb/source-packed.h | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 packfile.c          |  9 -------
 packfile.h          | 66 +-----------------------------------------------
 7 files changed, 87 insertions(+), 75 deletions(-)
diff --git a/Makefile b/Makefile
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
diff --git a/meson.build b/meson.build
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',
diff --git a/odb/source-files.c b/odb/source-files.c
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;
diff --git a/odb/source-packed.c b/odb/source-packed.c
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;
+}
diff --git a/odb/source-packed.h b/odb/source-packed.h
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
diff --git a/packfile.c b/packfile.c
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)
diff --git a/packfile.h b/packfile.h
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.
-- 
2.55.0.rc0.786.g65d90a0328.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 66 of 85 in “odb: make packed object source a proper `struct odb_source`”
  1. 00/16 odb: make packed object source a proper `struct odb_source`Patrick Steinhardt, Jun 4, 2026
  2. 01/16 packfile: rename `struct packfile_store` to `odb_source_packed`Patrick Steinhardt, Jun 4, 2026
  3. Karthik NayakJun 5, 2026
  4. Patrick SteinhardtJun 8, 2026
  5. 02/16 packfile: move packed source into "odb/" subsystemPatrick Steinhardt, Jun 4, 2026
  6. Karthik NayakJun 8, 2026
  7. Patrick SteinhardtJun 9, 2026
  8. 03/16 odb/source-packed: store pointer to "files" instead of generic sourcePatrick Steinhardt, Jun 4, 2026
  9. 04/16 odb/source-packed: start converting to a proper `struct odb_source`Patrick Steinhardt, Jun 4, 2026
  10. Karthik NayakJun 8, 2026
  11. Patrick SteinhardtJun 9, 2026
  12. Patrick SteinhardtJun 9, 2026
  13. 05/16 odb/source-packed: wire up `close()` callbackPatrick Steinhardt, Jun 4, 2026
  14. Karthik NayakJun 8, 2026
  15. 06/16 odb/source-packed: wire up `reprepare()` callbackPatrick Steinhardt, Jun 4, 2026
  16. 07/16 packfile: use higher-level interface to implement `has_object_pack()`Patrick Steinhardt, Jun 4, 2026
  17. Karthik NayakJun 8, 2026
  18. 08/16 odb/source-packed: wire up `read_object_info()` callbackPatrick Steinhardt, Jun 4, 2026
  19. 09/16 odb/source-packed: wire up `read_object_stream()` callbackPatrick Steinhardt, Jun 4, 2026
  20. 10/16 odb/source-packed: wire up `for_each_object()` callbackPatrick Steinhardt, Jun 4, 2026
  21. 11/16 odb/source-packed: wire up `count_objects()` callbackPatrick Steinhardt, Jun 4, 2026
  22. Karthik NayakJun 8, 2026
  23. Patrick SteinhardtJun 9, 2026
  24. 12/16 odb/source-packed: wire up `find_abbrev_len()` callbackPatrick Steinhardt, Jun 4, 2026
  25. 13/16 odb/source-packed: wire up `freshen_object()` callbackPatrick Steinhardt, Jun 4, 2026
  26. 14/16 odb/source-packed: stub out remaining functionsPatrick Steinhardt, Jun 4, 2026
  27. 15/16 midx: refactor interfaces to work on "packed" sourcePatrick Steinhardt, Jun 4, 2026
  28. 16/16 odb/source-packed: drop pointer to "files" parent sourcePatrick Steinhardt, Jun 4, 2026
  29. Karthik NayakJun 8, 2026
  30. Patrick SteinhardtJun 9, 2026
  31. 00/17 odb: make packed object source a proper `struct odb_source`Patrick Steinhardt, Jun 9, 2026
  32. 01/17 packfile: rename `struct packfile_store` to `odb_source_packed`Patrick Steinhardt, Jun 9, 2026
  33. Justin ToblerJun 16, 2026
  34. 02/17 packfile: split out packfile list logicPatrick Steinhardt, Jun 9, 2026
  35. 03/17 packfile: move packed source into "odb/" subsystemPatrick Steinhardt, Jun 9, 2026
  36. 04/17 odb/source-packed: store pointer to "files" instead of generic sourcePatrick Steinhardt, Jun 9, 2026
  37. Justin ToblerJun 16, 2026
  38. Justin ToblerJun 16, 2026
  39. Patrick SteinhardtJun 17, 2026
  40. 05/17 odb/source-packed: start converting to a proper `struct odb_source`Patrick Steinhardt, Jun 9, 2026
  41. Justin ToblerJun 16, 2026
  42. Patrick SteinhardtJun 17, 2026
  43. 06/17 odb/source-packed: wire up `close()` callbackPatrick Steinhardt, Jun 9, 2026
  44. 07/17 odb/source-packed: wire up `reprepare()` callbackPatrick Steinhardt, Jun 9, 2026
  45. Justin ToblerJun 16, 2026
  46. Patrick SteinhardtJun 17, 2026
  47. 08/17 packfile: use higher-level interface to implement `has_object_pack()`Patrick Steinhardt, Jun 9, 2026
  48. 09/17 odb/source-packed: wire up `read_object_info()` callbackPatrick Steinhardt, Jun 9, 2026
  49. 10/17 odb/source-packed: wire up `read_object_stream()` callbackPatrick Steinhardt, Jun 9, 2026
  50. 11/17 odb/source-packed: wire up `for_each_object()` callbackPatrick Steinhardt, Jun 9, 2026
  51. Justin ToblerJun 16, 2026
  52. Patrick SteinhardtJun 17, 2026
  53. 12/17 odb/source-packed: wire up `count_objects()` callbackPatrick Steinhardt, Jun 9, 2026
  54. 13/17 odb/source-packed: wire up `find_abbrev_len()` callbackPatrick Steinhardt, Jun 9, 2026
  55. 14/17 odb/source-packed: wire up `freshen_object()` callbackPatrick Steinhardt, Jun 9, 2026
  56. 15/17 odb/source-packed: stub out remaining functionsPatrick Steinhardt, Jun 9, 2026
  57. 16/17 midx: refactor interfaces to work on "packed" sourcePatrick Steinhardt, Jun 9, 2026
  58. Justin ToblerJun 16, 2026
  59. Patrick SteinhardtJun 17, 2026
  60. 17/17 odb/source-packed: drop pointer to "files" parent sourcePatrick Steinhardt, Jun 9, 2026
  61. Justin ToblerJun 16, 2026
  62. Patrick SteinhardtJun 17, 2026
  63. 00/17 odb: make packed object source a proper `struct odb_source`Patrick Steinhardt, Jun 17, 2026
  64. 01/17 packfile: rename `struct packfile_store` to `odb_source_packed`Patrick Steinhardt, Jun 17, 2026
  65. 02/17 packfile: split out packfile list logicPatrick Steinhardt, Jun 17, 2026
  66. 03/17 packfile: move packed source into "odb/" subsystemPatrick Steinhardt, Jun 17, 2026
  67. 04/17 odb/source-packed: store pointer to "files" instead of generic sourcePatrick Steinhardt, Jun 17, 2026
  68. 05/17 odb/source-packed: start converting to a proper `struct odb_source`Patrick Steinhardt, Jun 17, 2026
  69. 06/17 odb/source-packed: wire up `close()` callbackPatrick Steinhardt, Jun 17, 2026
  70. 07/17 odb/source-packed: wire up `reprepare()` callbackPatrick Steinhardt, Jun 17, 2026
  71. 08/17 packfile: use higher-level interface to implement `has_object_pack()`Patrick Steinhardt, Jun 17, 2026
  72. 09/17 odb/source-packed: wire up `read_object_info()` callbackPatrick Steinhardt, Jun 17, 2026
  73. 10/17 odb/source-packed: wire up `read_object_stream()` callbackPatrick Steinhardt, Jun 17, 2026
  74. 11/17 odb/source-packed: wire up `for_each_object()` callbackPatrick Steinhardt, Jun 17, 2026
  75. 12/17 odb/source-packed: wire up `count_objects()` callbackPatrick Steinhardt, Jun 17, 2026
  76. 13/17 odb/source-packed: wire up `find_abbrev_len()` callbackPatrick Steinhardt, Jun 17, 2026
  77. 14/17 odb/source-packed: wire up `freshen_object()` callbackPatrick Steinhardt, Jun 17, 2026
  78. 15/17 odb/source-packed: stub out remaining functionsPatrick Steinhardt, Jun 17, 2026
  79. Junio C HamanoJun 18, 2026
  80. Patrick SteinhardtJun 19, 2026
  81. Junio C HamanoJun 19, 2026
  82. 16/17 midx: refactor interfaces to work on "packed" sourcePatrick Steinhardt, Jun 17, 2026
  83. 17/17 odb/source-packed: drop pointer to "files" parent sourcePatrick Steinhardt, Jun 17, 2026
  84. Justin ToblerJun 17, 2026
  85. Junio C HamanoJun 17, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.