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

[PATCH v3 05/17] odb/source-packed: start converting to a proper `struct odb_source`

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

Start converting `struct odb_source_packed` into a proper pluggable `struct odb_source` by embedding the base struct and assigning it the new `ODB_SOURCE_PACKED` type. Furthermore, wire up lifecycle management of this source by implementing the `free` callback and taking ownership of the chdir notifications.

Note that the packed source is not yet functional as a standalone `struct odb_source`, as it's missing all of the callback implementations. These will be wired up in subsequent commits.

Further note that we're also registering a `chdir_notify` callback to reparent our path. This wasn't previously necessary (and still isn't at this point in time) because all paths are taken from the owning "files" source, and that source already handles the reparenting for us. But a subsequent commit will change that so that we're using the path of the "packed" source, and once that happens we'll need it to be updated when changing the working directory.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 odb/source-files.c  |  2 +-
 odb/source-packed.c | 49 ++++++++++++++++++++++++++++++++++++++++++++-----
 odb/source-packed.h | 12 ++++++++++++
 odb/source.h        |  3 +++
 packfile.c          | 10 ----------
 packfile.h          |  6 ------
 6 files changed, 60 insertions(+), 22 deletions(-)
diff --git a/odb/source-files.c b/odb/source-files.c
index e04525fb08..3608808e7c 100644
--- a/odb/source-files.c
+++ b/odb/source-files.c
@@ -29,7 +29,7 @@ static void odb_source_files_free(struct odb_source *source)
 	struct odb_source_files *files = odb_source_files_downcast(source);
 	chdir_notify_unregister(NULL, odb_source_files_reparent, files);
 	odb_source_free(&files->loose->base);
-	packfile_store_free(files->packed);
+	odb_source_free(&files->packed->base);
 	odb_source_release(&files->base);
 	free(files);
 }
diff --git a/odb/source-packed.c b/odb/source-packed.c
index 12e785be48..f81a990cbd 100644
--- a/odb/source-packed.c
+++ b/odb/source-packed.c
@@ -1,11 +1,50 @@
 #include "git-compat-util.h"
+#include "abspath.h"
+#include "chdir-notify.h"
 #include "odb/source-packed.h"
+#include "packfile.h"
+
+static void odb_source_packed_reparent(const char *name UNUSED,
+				       const char *old_cwd,
+				       const char *new_cwd,
+				       void *cb_data)
+{
+	struct odb_source_packed *packed = cb_data;
+	char *path = reparent_relative_path(old_cwd, new_cwd,
+					    packed->base.path);
+	free(packed->base.path);
+	packed->base.path = path;
+}
+
+static void odb_source_packed_free(struct odb_source *source)
+{
+	struct odb_source_packed *packed = odb_source_packed_downcast(source);
+
+	chdir_notify_unregister(NULL, odb_source_packed_reparent, packed);
+
+	for (struct packfile_list_entry *e = packed->packs.head; e; e = e->next)
+		free(e->pack);
+	packfile_list_clear(&packed->packs);
+
+	strmap_clear(&packed->packs_by_path, 0);
+	odb_source_release(&packed->base);
+	free(packed);
+}
 
 struct odb_source_packed *odb_source_packed_new(struct odb_source_files *parent)
 {
-	struct odb_source_packed *store;
-	CALLOC_ARRAY(store, 1);
-	store->files = parent;
-	strmap_init(&store->packs_by_path);
-	return store;
+	struct odb_source_packed *packed;
+
+	CALLOC_ARRAY(packed, 1);
+	odb_source_init(&packed->base, parent->base.odb, ODB_SOURCE_PACKED,
+			parent->base.path, parent->base.local);
+	packed->files = parent;
+	strmap_init(&packed->packs_by_path);
+
+	packed->base.free = odb_source_packed_free;
+
+	if (!is_absolute_path(parent->base.path))
+		chdir_notify_register(NULL, odb_source_packed_reparent, packed);
+
+	return packed;
 }
diff --git a/odb/source-packed.h b/odb/source-packed.h
index 3c2d229a17..68e64cabab 100644
--- a/odb/source-packed.h
+++ b/odb/source-packed.h
@@ -9,6 +9,7 @@
  * A store that manages packfiles for a given object database.
  */
 struct odb_source_packed {
+	struct odb_source base;
 	struct odb_source_files *files;
 
 	/*
@@ -69,4 +70,15 @@ struct odb_source_packed {
  */
 struct odb_source_packed *odb_source_packed_new(struct odb_source_files *parent);
 
+/*
+ * Cast the given object database source to the packed backend. This will cause
+ * a BUG in case the source doesn't use this backend.
+ */
+static inline struct odb_source_packed *odb_source_packed_downcast(struct odb_source *source)
+{
+	if (source->type != ODB_SOURCE_PACKED)
+		BUG("trying to downcast source of type '%d' to packed", source->type);
+	return container_of(source, struct odb_source_packed, base);
+}
+
 #endif
diff --git a/odb/source.h b/odb/source.h
index 8bcb67787e..6865e1f71a 100644
--- a/odb/source.h
+++ b/odb/source.h
@@ -17,6 +17,9 @@ enum odb_source_type {
 	/* The "loose" backend that uses loose objects, only. */
 	ODB_SOURCE_LOOSE,
 
+	/* The "packed" backend that uses packfiles. */
+	ODB_SOURCE_PACKED,
+
 	/* The "in-memory" backend that stores objects in memory. */
 	ODB_SOURCE_INMEMORY,
 };
diff --git a/packfile.c b/packfile.c
index 862a24ad49..6d492216de 100644
--- a/packfile.c
+++ b/packfile.c
@@ -2749,16 +2749,6 @@ int parse_pack_header_option(const char *in, unsigned char *out, unsigned int *l
 	return 0;
 }
 
-void packfile_store_free(struct odb_source_packed *store)
-{
-	for (struct packfile_list_entry *e = store->packs.head; e; e = e->next)
-		free(e->pack);
-	packfile_list_clear(&store->packs);
-
-	strmap_clear(&store->packs_by_path, 0);
-	free(store);
-}
-
 void packfile_store_close(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 2d0bb7adbe..e8bc9349f8 100644
--- a/packfile.h
+++ b/packfile.h
@@ -55,12 +55,6 @@ struct packed_git {
 	char pack_name[FLEX_ARRAY]; /* more */
 };
 
-/*
- * Free the packfile store and all its associated state. All packfiles
- * tracked by the store will be closed.
- */
-void packfile_store_free(struct odb_source_packed *store);
-
 /*
  * Close all packfiles associated with this store. The packfiles won't be
  * free'd, so they can be re-opened at a later point in time.
-- 
2.55.0.rc0.786.g65d90a0328.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 68 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.