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

[PATCH v2 01/18] odb/source-loose: move loose source into "odb/" subsystem

From
Patrick Steinhardt <ps@pks.im>
Date
Jun 1, 2026, 08:20 UTC
Message-ID
<20260601-b4-pks-odb-source-loose-v2-1-90ff159430af@pks.im>
In-Reply-To
<20260601-b4-pks-odb-source-loose-v2-0-90ff159430af@pks.im>

In subsequent patches we'll be turning `struct odb_source_loose` into a proper `struct odb_source`. As a first step towards this goal, move its struct out of "object-file.c" and into "odb/source-loose.c".

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

No functional changes are intended.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 Makefile           |  1 +
 meson.build        |  1 +
 object-file.c      |  8 --------
 object-file.h      | 21 +--------------------
 odb/source-loose.c | 10 ++++++++++
 odb/source-loose.h | 34 ++++++++++++++++++++++++++++++++++
 6 files changed, 47 insertions(+), 28 deletions(-)
diff --git a/Makefile b/Makefile
index a43b8ee067..01356235c3 100644
--- a/Makefile
+++ b/Makefile
@@ -1217,6 +1217,7 @@ LIB_OBJS += odb.o
 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/streaming.o
 LIB_OBJS += odb/transaction.o
 LIB_OBJS += oid-array.o
diff --git a/meson.build b/meson.build
index 664d831329..c85e598835 100644
--- a/meson.build
+++ b/meson.build
@@ -405,6 +405,7 @@ libgit_sources = [
   'odb/source.c',
   'odb/source-files.c',
   'odb/source-inmemory.c',
+  'odb/source-loose.c',
   'odb/streaming.c',
   'odb/transaction.c',
   'oid-array.c',
diff --git a/object-file.c b/object-file.c
index 90f995d000..641bd9c079 100644
--- a/object-file.c
+++ b/object-file.c
@@ -2205,14 +2205,6 @@ struct odb_transaction *odb_transaction_files_begin(struct odb_source *source)
 	return &transaction->base;
 }
 
-struct odb_source_loose *odb_source_loose_new(struct odb_source *source)
-{
-	struct odb_source_loose *loose;
-	CALLOC_ARRAY(loose, 1);
-	loose->source = source;
-	return loose;
-}
-
 void odb_source_loose_free(struct odb_source_loose *loose)
 {
 	if (!loose)
diff --git a/object-file.h b/object-file.h
index 5241b8dd5c..1d8312cf7f 100644
--- a/object-file.h
+++ b/object-file.h
@@ -4,6 +4,7 @@
 #include "git-zlib.h"
 #include "object.h"
 #include "odb.h"
+#include "odb/source-loose.h"
 
 struct index_state;
 
@@ -20,26 +21,6 @@ struct object_info;
 struct odb_read_stream;
 struct odb_source;
 
-struct odb_source_loose {
-	struct odb_source *source;
-
-	/*
-	 * Used to store the results of readdir(3) calls when we are OK
-	 * sacrificing accuracy due to races for speed. That includes
-	 * object existence with OBJECT_INFO_QUICK, as well as
-	 * our search for unique abbreviated hashes. Don't use it for tasks
-	 * requiring greater accuracy!
-	 *
-	 * Be sure to call odb_load_loose_cache() before using.
-	 */
-	uint32_t subdir_seen[8]; /* 256 bits */
-	struct oidtree *cache;
-
-	/* Map between object IDs for loose objects. */
-	struct loose_object_map *map;
-};
-
-struct odb_source_loose *odb_source_loose_new(struct odb_source *source);
 void odb_source_loose_free(struct odb_source_loose *loose);
 
 /* Reprepare the loose source by emptying the loose object cache. */
diff --git a/odb/source-loose.c b/odb/source-loose.c
new file mode 100644
index 0000000000..b944d21813
--- /dev/null
+++ b/odb/source-loose.c
@@ -0,0 +1,10 @@
+#include "git-compat-util.h"
+#include "odb/source-loose.h"
+
+struct odb_source_loose *odb_source_loose_new(struct odb_source *source)
+{
+	struct odb_source_loose *loose;
+	CALLOC_ARRAY(loose, 1);
+	loose->source = source;
+	return loose;
+}
diff --git a/odb/source-loose.h b/odb/source-loose.h
new file mode 100644
index 0000000000..8b4bac77ea
--- /dev/null
+++ b/odb/source-loose.h
@@ -0,0 +1,34 @@
+#ifndef ODB_SOURCE_LOOSE_H
+#define ODB_SOURCE_LOOSE_H
+
+#include "odb/source.h"
+
+struct object_database;
+struct oidtree;
+
+/*
+ * An object database source that stores its objects in loose format, one
+ * file per object. This source is part of the files source.
+ */
+struct odb_source_loose {
+	struct odb_source *source;
+
+	/*
+	 * Used to store the results of readdir(3) calls when we are OK
+	 * sacrificing accuracy due to races for speed. That includes
+	 * object existence with OBJECT_INFO_QUICK, as well as
+	 * our search for unique abbreviated hashes. Don't use it for tasks
+	 * requiring greater accuracy!
+	 *
+	 * Be sure to call odb_load_loose_cache() before using.
+	 */
+	uint32_t subdir_seen[8]; /* 256 bits */
+	struct oidtree *cache;
+
+	/* Map between object IDs for loose objects. */
+	struct loose_object_map *map;
+};
+
+struct odb_source_loose *odb_source_loose_new(struct odb_source *source);
+
+#endif
-- 
2.54.0.926.g75ba10bac6.dirty
Previous: Patrick SteinhardtNext: Karthik Nayak
Message 24 of 46 in “odb: make loose object source a proper `struct odb_source`”
  1. 00/18 odb: make loose object source a proper `struct odb_source`Patrick Steinhardt, May 21, 2026
  2. 01/18 odb/source-loose: move loose source into "odb/" subsystemPatrick Steinhardt, May 21, 2026
  3. 02/18 odb/source-loose: store pointer to "files" instead of generic sourcePatrick Steinhardt, May 21, 2026
  4. 03/18 odb/source-loose: start converting to a proper `struct odb_source`Patrick Steinhardt, May 21, 2026
  5. Junio C HamanoMay 21, 2026
  6. 04/18 odb/source-loose: wire up `reprepare()` callbackPatrick Steinhardt, May 21, 2026
  7. 05/18 odb/source-loose: wire up `close()` callbackPatrick Steinhardt, May 21, 2026
  8. 06/18 odb/source-loose: wire up `read_object_info()` callbackPatrick Steinhardt, May 21, 2026
  9. 07/18 odb/source-loose: wire up `read_object_stream()` callbackPatrick Steinhardt, May 21, 2026
  10. 08/18 odb/source-loose: wire up `for_each_object()` callbackPatrick Steinhardt, May 21, 2026
  11. 09/18 odb/source-loose: wire up `find_abbrev_len()` callbackPatrick Steinhardt, May 21, 2026
  12. 10/18 odb/source-loose: wire up `count_objects()` callbackPatrick Steinhardt, May 21, 2026
  13. 11/18 odb/source-loose: drop `odb_source_loose_has_object()`Patrick Steinhardt, May 21, 2026
  14. 12/18 odb/source-loose: wire up `freshen_object()` callbackPatrick Steinhardt, May 21, 2026
  15. 13/18 loose: refactor object map to operate on `struct odb_source_loose`Patrick Steinhardt, May 21, 2026
  16. 14/18 odb/source-loose: wire up `write_object()` callbackPatrick Steinhardt, May 21, 2026
  17. 15/18 object-file: refactor writing objects to use loose sourcePatrick Steinhardt, May 21, 2026
  18. 16/18 odb/source-loose: wire up `write_object_stream()` callbackPatrick Steinhardt, May 21, 2026
  19. Junio C HamanoMay 21, 2026
  20. Patrick SteinhardtMay 22, 2026
  21. 17/18 odb/source-loose: stub out remaining callbacksPatrick Steinhardt, May 21, 2026
  22. 18/18 odb/source-loose: drop pointer to the "files" sourcePatrick Steinhardt, May 21, 2026
  23. 00/18 odb: make loose object source a proper `struct odb_source`Patrick Steinhardt, Jun 1, 2026
  24. 01/18 odb/source-loose: move loose source into "odb/" subsystemPatrick Steinhardt, Jun 1, 2026
  25. Karthik NayakJun 3, 2026
  26. Patrick SteinhardtJun 3, 2026
  27. Karthik NayakJun 3, 2026
  28. 02/18 odb/source-loose: store pointer to "files" instead of generic sourcePatrick Steinhardt, Jun 1, 2026
  29. 03/18 odb/source-loose: start converting to a proper `struct odb_source`Patrick Steinhardt, Jun 1, 2026
  30. 04/18 odb/source-loose: wire up `reprepare()` callbackPatrick Steinhardt, Jun 1, 2026
  31. 05/18 odb/source-loose: wire up `close()` callbackPatrick Steinhardt, Jun 1, 2026
  32. 06/18 odb/source-loose: wire up `read_object_info()` callbackPatrick Steinhardt, Jun 1, 2026
  33. 07/18 odb/source-loose: wire up `read_object_stream()` callbackPatrick Steinhardt, Jun 1, 2026
  34. 08/18 odb/source-loose: wire up `for_each_object()` callbackPatrick Steinhardt, Jun 1, 2026
  35. 09/18 odb/source-loose: wire up `find_abbrev_len()` callbackPatrick Steinhardt, Jun 1, 2026
  36. 10/18 odb/source-loose: wire up `count_objects()` callbackPatrick Steinhardt, Jun 1, 2026
  37. 11/18 odb/source-loose: drop `odb_source_loose_has_object()`Patrick Steinhardt, Jun 1, 2026
  38. 12/18 odb/source-loose: wire up `freshen_object()` callbackPatrick Steinhardt, Jun 1, 2026
  39. 13/18 loose: refactor object map to operate on `struct odb_source_loose`Patrick Steinhardt, Jun 1, 2026
  40. 14/18 odb/source-loose: wire up `write_object()` callbackPatrick Steinhardt, Jun 1, 2026
  41. 15/18 object-file: refactor writing objects to use loose sourcePatrick Steinhardt, Jun 1, 2026
  42. 16/18 odb/source-loose: wire up `write_object_stream()` callbackPatrick Steinhardt, Jun 1, 2026
  43. 17/18 odb/source-loose: stub out remaining callbacksPatrick Steinhardt, Jun 1, 2026
  44. 18/18 odb/source-loose: drop pointer to the "files" sourcePatrick Steinhardt, Jun 1, 2026
  45. Junio C HamanoJun 1, 2026
  46. Junio C HamanoJun 1, 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.