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

[PATCH 1/7] odb/source: discern missing and corrupt objects

From
Patrick Steinhardt <ps@pks.im>
Date
Aug 18, 2026, 14:19 UTC
Message-ID
<20260818-pks-odb-generic-corrupt-objects-v1-1-ec234567510f@pks.im>
In-Reply-To
<20260818-pks-odb-generic-corrupt-objects-v1-0-ec234567510f@pks.im>

The `read_object_info()` callback of `struct odb_source` is documented to return a negative error code in case reading the object has failed, and zero otherwise. This is overly broad though, as there are two very different kinds of failures:

  - The object may not exist in the source at all.
  - The object exists, but reading it has failed, for example because
    its on-disk state is corrupt.

This distinction matters to callers: when an object is corrupt in one source we may still find a good copy of it in another source, so we may still be able to proceed with a given operation.

The "packed" source already distinguishes these cases by returning a positive value for missing objects and a negative value in case reading the object has failed. But all the other sources conflate them into a single negative return value.

Adapt the documentation to explicitly require the semantics of the "packed" backend, where we return a positive value for missing objects and a negative value for corrupt ones. Subsequent commits will adapt all the other implementations to respect those new semantics.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 odb/source.h | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/odb/source.h b/odb/source.h
index d69f8e2d1c..4ae6cc160e 100644
--- a/odb/source.h
+++ b/odb/source.h
@@ -110,8 +110,17 @@ struct odb_source {
 	 *     second read in case they know that the first read would have
 	 *     already surfaced the object without reloading any on-disk state.
 	 *
-	 * The callback is expected to return a negative error code in case
-	 * reading the object has failed, 0 otherwise.
+	 * The callback is expected to return one of the following values:
+	 *
+	 *   - Zero in case the object has been found and its object info has
+	 *     been read successfully.
+	 *
+	 *   - A positive value in case the object does not exist in this
+	 *     source.
+	 *
+	 *   - A negative value in case the object exists in this source, but
+	 *     reading its object info has failed, for example because its
+	 *     on-disk state is corrupt.
 	 */
 	int (*read_object_info)(struct odb_source *source,
 				const struct object_id *oid,
@@ -340,7 +349,9 @@ static inline void odb_source_prepare(struct odb_source *source,
 
 /*
  * Read an object from the object database source identified by its object ID.
- * Returns 0 on success, a negative error code otherwise.
+ * Returns 0 on success, a positive value in case the object is missing in the
+ * source and a negative value in case the object exists, but reading it has
+ * failed.
  */
 static inline int odb_source_read_object_info(struct odb_source *source,
 					      const struct object_id *oid,
-- 
2.55.0.822.g20453c30eb.dirty
Previous: Patrick SteinhardtNext: Junio C Hamano
Message 2 of 18 in “odb: handle `OBJECT_INFO_DIE_IF_CORRUPT` generically”
  1. 0/7 odb: handle `OBJECT_INFO_DIE_IF_CORRUPT` genericallyPatrick Steinhardt, Aug 18, 2026
  2. 1/7 odb/source: discern missing and corrupt objectsPatrick Steinhardt, Aug 18, 2026
  3. Junio C HamanoAug 18, 2026
  4. Patrick SteinhardtAug 19, 2026
  5. 2/7 odb/source-inmemory: signal missing objects via positive returnPatrick Steinhardt, Aug 18, 2026
  6. Junio C HamanoAug 18, 2026
  7. Patrick SteinhardtAug 19, 2026
  8. 3/7 odb/source-packed: flag known-bad objects as corrupt and not missingPatrick Steinhardt, Aug 18, 2026
  9. Junio C HamanoAug 18, 2026
  10. Patrick SteinhardtAug 19, 2026
  11. Junio C HamanoAug 19, 2026
  12. 4/7 odb/source-loose: distinguish missing and corrupt objectsPatrick Steinhardt, Aug 18, 2026
  13. Junio C HamanoAug 18, 2026
  14. 5/7 odb/source-files: signal mark objects via positive returnPatrick Steinhardt, Aug 18, 2026
  15. Junio C HamanoAug 18, 2026
  16. Patrick SteinhardtAug 19, 2026
  17. 6/7 odb/source: allow `read_object_info()` to bubble up error messagesPatrick Steinhardt, Aug 18, 2026
  18. 7/7 odb: handle `OBJECT_INFO_DIE_IF_CORRUPT` genericallyPatrick Steinhardt, Aug 18, 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.