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

[PATCH v2 09/17] odb/source-packed: wire up `read_object_info()` callback

From
Patrick Steinhardt <ps@pks.im>
Date
Jun 9, 2026, 08:51 UTC
Message-ID
<20260609-pks-odb-source-packed-v2-9-839089132c8b@pks.im>
In-Reply-To
<20260609-pks-odb-source-packed-v2-0-839089132c8b@pks.im>

Move the logic to read object info from a "packed" source into "odb/source-packed.c" and wire it up as the `read_object_info()` callback.

Note that we also move around the supporting `find_pack_entry()`, but we still have to expose it to other callers that exist in "packfile.c". This will be fixed in subsequent commits though, where all callers in "packfile.c" will have been moved into "odb/source-packed.c", and at that point we'll be able to make `find_pack_entry()` file-local again.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 odb/source-files.c  |  2 +-
 odb/source-packed.c | 60 +++++++++++++++++++++++++++++++++++++++++++
 odb/source-packed.h |  6 +++++
 packfile.c          | 74 ++++++-----------------------------------------------
 packfile.h          | 15 +++--------
 5 files changed, 79 insertions(+), 78 deletions(-)
diff --git a/odb/source-files.c b/odb/source-files.c
index 7b1e0ac565..8cae35d25e 100644
--- a/odb/source-files.c
+++ b/odb/source-files.c
@@ -55,7 +55,7 @@ static int odb_source_files_read_object_info(struct odb_source *source,
 {
 	struct odb_source_files *files = odb_source_files_downcast(source);
 
-	if (!packfile_store_read_object_info(files->packed, oid, oi, flags) ||
+	if (!odb_source_read_object_info(&files->packed->base, oid, oi, flags) ||
 	    !odb_source_read_object_info(&files->loose->base, oid, oi, flags))
 		return 0;
 
diff --git a/odb/source-packed.c b/odb/source-packed.c
index e8e2e5bb48..f71a194739 100644
--- a/odb/source-packed.c
+++ b/odb/source-packed.c
@@ -7,6 +7,65 @@
 #include "odb/source-packed.h"
 #include "packfile.h"
 
+int find_pack_entry(struct odb_source_packed *store,
+		    const struct object_id *oid,
+		    struct pack_entry *e)
+{
+	struct packfile_list_entry *l;
+
+	odb_source_packed_prepare(store);
+	if (store->midx && fill_midx_entry(store->midx, oid, e))
+		return 1;
+
+	for (l = store->packs.head; l; l = l->next) {
+		struct packed_git *p = l->pack;
+
+		if (!p->multi_pack_index && packfile_fill_entry(p, oid, e)) {
+			if (!store->skip_mru_updates)
+				packfile_list_prepend(&store->packs, p);
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
+static int odb_source_packed_read_object_info(struct odb_source *source,
+					      const struct object_id *oid,
+					      struct object_info *oi,
+					      enum object_info_flags flags)
+{
+	struct odb_source_packed *packed = odb_source_packed_downcast(source);
+	struct pack_entry e;
+	int ret;
+
+	/*
+	 * In case the first read didn't surface the object, we have to reload
+	 * packfiles. This may cause us to discover new packfiles that have
+	 * been added since the last time we have prepared the packfile store.
+	 */
+	if (flags & OBJECT_INFO_SECOND_READ)
+		odb_source_reprepare(source);
+
+	if (!find_pack_entry(packed, oid, &e))
+		return 1;
+
+	/*
+	 * We know that the caller doesn't actually need the
+	 * information below, so return early.
+	 */
+	if (!oi)
+		return 0;
+
+	ret = packed_object_info(e.p, e.offset, oi);
+	if (ret < 0) {
+		mark_bad_packed_object(e.p, oid);
+		return -1;
+	}
+
+	return 0;
+}
+
 void (*report_garbage)(unsigned seen_bits, const char *path);
 
 static void report_helper(const struct string_list *list,
@@ -215,6 +274,7 @@ struct odb_source_packed *odb_source_packed_new(struct odb_source_files *parent)
 	packed->base.free = odb_source_packed_free;
 	packed->base.close = odb_source_packed_close;
 	packed->base.reprepare = odb_source_packed_reprepare;
+	packed->base.read_object_info = odb_source_packed_read_object_info;
 
 	if (!is_absolute_path(parent->base.path))
 		chdir_notify_register(NULL, odb_source_packed_reparent, packed);
diff --git a/odb/source-packed.h b/odb/source-packed.h
index 9d4796261a..f430ee0b94 100644
--- a/odb/source-packed.h
+++ b/odb/source-packed.h
@@ -90,4 +90,10 @@ static inline struct odb_source_packed *odb_source_packed_downcast(struct odb_so
  */
 void odb_source_packed_prepare(struct odb_source_packed *source);
 
+struct pack_entry;
+
+int find_pack_entry(struct odb_source_packed *store,
+		    const struct object_id *oid,
+		    struct pack_entry *e);
+
 #endif
diff --git a/packfile.c b/packfile.c
index b35afd7797..29530532ba 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1895,9 +1895,9 @@ int is_pack_valid(struct packed_git *p)
 	return !open_packed_git(p);
 }
 
-static int fill_pack_entry(const struct object_id *oid,
-			   struct pack_entry *e,
-			   struct packed_git *p)
+int packfile_fill_entry(struct packed_git *p,
+			const struct object_id *oid,
+			struct pack_entry *e)
 {
 	off_t offset;
 
@@ -1923,29 +1923,6 @@ static int fill_pack_entry(const struct object_id *oid,
 	return 1;
 }
 
-static int find_pack_entry(struct odb_source_packed *store,
-			   const struct object_id *oid,
-			   struct pack_entry *e)
-{
-	struct packfile_list_entry *l;
-
-	odb_source_packed_prepare(store);
-	if (store->midx && fill_midx_entry(store->midx, oid, e))
-		return 1;
-
-	for (l = store->packs.head; l; l = l->next) {
-		struct packed_git *p = l->pack;
-
-		if (!p->multi_pack_index && fill_pack_entry(oid, e, p)) {
-			if (!store->skip_mru_updates)
-				packfile_list_prepend(&store->packs, p);
-			return 1;
-		}
-	}
-
-	return 0;
-}
-
 int packfile_store_freshen_object(struct odb_source_packed *store,
 				  const struct object_id *oid)
 {
@@ -1962,41 +1939,6 @@ int packfile_store_freshen_object(struct odb_source_packed *store,
 	return 1;
 }
 
-int packfile_store_read_object_info(struct odb_source_packed *store,
-				    const struct object_id *oid,
-				    struct object_info *oi,
-				    enum object_info_flags flags)
-{
-	struct pack_entry e;
-	int ret;
-
-	/*
-	 * In case the first read didn't surface the object, we have to reload
-	 * packfiles. This may cause us to discover new packfiles that have
-	 * been added since the last time we have prepared the packfile store.
-	 */
-	if (flags & OBJECT_INFO_SECOND_READ)
-		odb_source_reprepare(&store->base);
-
-	if (!find_pack_entry(store, oid, &e))
-		return 1;
-
-	/*
-	 * We know that the caller doesn't actually need the
-	 * information below, so return early.
-	 */
-	if (!oi)
-		return 0;
-
-	ret = packed_object_info(e.p, e.offset, oi);
-	if (ret < 0) {
-		mark_bad_packed_object(e.p, oid);
-		return -1;
-	}
-
-	return 0;
-}
-
 static void maybe_invalidate_kept_pack_cache(struct odb_source_packed *store,
 					     unsigned flags)
 {
@@ -2053,7 +1995,7 @@ int has_object_pack(struct repository *r, const struct object_id *oid)
 	odb_prepare_alternates(r->objects);
 	for (source = r->objects->sources; source; source = source->next) {
 		struct odb_source_files *files = odb_source_files_downcast(source);
-		if (!packfile_store_read_object_info(files->packed, oid, NULL, 0))
+		if (!odb_source_read_object_info(&files->packed->base, oid, NULL, 0))
 			return 1;
 	}
 
@@ -2074,7 +2016,7 @@ int has_object_kept_pack(struct repository *r, const struct object_id *oid,
 
 		for (; *cache; cache++) {
 			struct packed_git *p = *cache;
-			if (fill_pack_entry(oid, &e, p))
+			if (packfile_fill_entry(p, oid, &e))
 				return 1;
 		}
 	}
@@ -2208,8 +2150,8 @@ static int for_each_prefixed_object_in_midx(
 			if (data->request) {
 				struct object_info oi = *data->request;
 
-				ret = packfile_store_read_object_info(store, current,
-								      &oi, 0);
+				ret = odb_source_read_object_info(&store->base, current,
+								  &oi, 0);
 				if (ret)
 					goto out;
 
@@ -2259,7 +2201,7 @@ static int for_each_prefixed_object_in_pack(
 		if (data->request) {
 			struct object_info oi = *data->request;
 
-			ret = packfile_store_read_object_info(store, &oid, &oi, 0);
+			ret = odb_source_read_object_info(&store->base, &oid, &oi, 0);
 			if (ret)
 				goto out;
 
diff --git a/packfile.h b/packfile.h
index 9674e573ae..25d458beb0 100644
--- a/packfile.h
+++ b/packfile.h
@@ -128,17 +128,6 @@ int packfile_store_read_object_stream(struct odb_read_stream **out,
 				      struct odb_source_packed *store,
 				      const struct object_id *oid);
 
-/*
- * Try to read the object identified by its ID from the object store and
- * populate the object info with its data. Returns 1 in case the object was
- * not found, 0 if it was and read successfully, and a negative error code in
- * case the object was corrupted.
- */
-int packfile_store_read_object_info(struct odb_source_packed *store,
-				    const struct object_id *oid,
-				    struct object_info *oi,
-				    enum object_info_flags flags);
-
 /*
  * Open the packfile and add it to the store if it isn't yet known. Returns
  * either the newly opened packfile or the preexisting packfile. Returns a
@@ -340,6 +329,10 @@ off_t nth_packed_object_offset(const struct packed_git *, uint32_t n);
  */
 off_t find_pack_entry_one(const struct object_id *oid, struct packed_git *);
 
+int packfile_fill_entry(struct packed_git *p,
+			const struct object_id *oid,
+			struct pack_entry *e);
+
 int is_pack_valid(struct packed_git *);
 void *unpack_entry(struct repository *r, struct packed_git *, off_t, enum object_type *, unsigned long *);
 unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, size_t *sizep);
-- 
2.54.0.1136.gdb2ca164c4.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 48 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.