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

[PATCH v4 5/7] packfile: disentangle return value of `packed_object_info()`

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 7, 2026, 13:08 UTC
Message-ID
<20260107-b4-pks-odb-read-object-info-improvements-v4-5-b5d55c47082a@pks.im>
In-Reply-To
<20260107-b4-pks-odb-read-object-info-improvements-v4-0-b5d55c47082a@pks.im>

The `packed_object_info()` function returns the type of the packed object. While we use an `enum object_type` to store the return value, this type is not to be confused with the actual object type. It _may_ contain the object type, but it may just as well encode that the given packed object is stored as a delta.

We have removed the only caller that relied on this returned object type in the preceding commit, so let's simplify semantics and return either 0 on success or a negative error code otherwise.

This unblocks a small optimization where we can skip reading the object type altogether.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 packfile.c | 21 ++++++++++++---------
 packfile.h |  4 ++++
 2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/packfile.c b/packfile.c
index f7c33a2f77..8c6ef45a67 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1587,6 +1587,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
 	unsigned long size;
 	off_t curpos = obj_offset;
 	enum object_type type;
+	int ret;
 
 	/*
 	 * We always get the representation type, but only convert it to
@@ -1607,12 +1608,12 @@ int packed_object_info(struct repository *r, struct packed_git *p,
 			off_t base_offset = get_delta_base(p, &w_curs, &tmp_pos,
 							   type, obj_offset);
 			if (!base_offset) {
-				type = OBJ_BAD;
+				ret = -1;
 				goto out;
 			}
 			*oi->sizep = get_size_from_delta(p, &w_curs, tmp_pos);
 			if (*oi->sizep == 0) {
-				type = OBJ_BAD;
+				ret = -1;
 				goto out;
 			}
 		} else {
@@ -1625,7 +1626,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
 		if (offset_to_pack_pos(p, obj_offset, &pos) < 0) {
 			error("could not find object at offset %"PRIuMAX" "
 			      "in pack %s", (uintmax_t)obj_offset, p->pack_name);
-			type = OBJ_BAD;
+			ret = -1;
 			goto out;
 		}
 
@@ -1639,7 +1640,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
 		if (oi->typep)
 			*oi->typep = ptot;
 		if (ptot < 0) {
-			type = OBJ_BAD;
+			ret = -1;
 			goto out;
 		}
 	}
@@ -1649,7 +1650,7 @@ int packed_object_info(struct repository *r, struct packed_git *p,
 			if (get_delta_base_oid(p, &w_curs, curpos,
 					       oi->delta_base_oid,
 					       type, obj_offset) < 0) {
-				type = OBJ_BAD;
+				ret = -1;
 				goto out;
 			}
 		} else
@@ -1672,9 +1673,11 @@ int packed_object_info(struct repository *r, struct packed_git *p,
 		break;
 	}
 
+	ret = 0;
+
 out:
 	unuse_pack(&w_curs);
-	return type;
+	return ret;
 }
 
 static void *unpack_compressed_entry(struct packed_git *p,
@@ -2152,7 +2155,7 @@ int packfile_store_read_object_info(struct packfile_store *store,
 				    unsigned flags UNUSED)
 {
 	struct pack_entry e;
-	int rtype;
+	int ret;
 
 	if (!find_pack_entry(store->odb->repo, oid, &e))
 		return 1;
@@ -2164,8 +2167,8 @@ int packfile_store_read_object_info(struct packfile_store *store,
 	if (!oi)
 		return 0;
 
-	rtype = packed_object_info(store->odb->repo, e.p, e.offset, oi);
-	if (rtype < 0) {
+	ret = packed_object_info(store->odb->repo, e.p, e.offset, oi);
+	if (ret < 0) {
 		mark_bad_packed_object(e.p, oid);
 		return -1;
 	}
diff --git a/packfile.h b/packfile.h
index 59d162a3f4..d7cce582af 100644
--- a/packfile.h
+++ b/packfile.h
@@ -378,6 +378,10 @@ void release_pack_memory(size_t);
 /* global flag to enable extra checks when accessing packed objects */
 extern int do_check_packed_object_crc;
 
+/*
+ * Look up the object info for a specific offset in the packfile.
+ * Returns zero on success, a negative error code otherwise.
+ */
 int packed_object_info(struct repository *r,
 		       struct packed_git *pack,
 		       off_t offset, struct object_info *);
-- 
2.52.0.542.g9473a8513b.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 46 of 58 in “Improvements for reading object info”
  1. 0/8 Improvements for reading object infoPatrick Steinhardt, Dec 18, 2025
  2. 1/8 object-file: always set OI_LOOSE when reading object infoPatrick Steinhardt, Dec 18, 2025
  3. 2/8 packfile: always declare object info to be OI_PACKEDPatrick Steinhardt, Dec 18, 2025
  4. Junio C HamanoDec 18, 2025
  5. Patrick SteinhardtDec 18, 2025
  6. 3/8 packfile: extend `is_delta` field to allow for "unknown" statePatrick Steinhardt, Dec 18, 2025
  7. 4/8 packfile: always populate pack-specific info when reading object infoPatrick Steinhardt, Dec 18, 2025
  8. Junio C HamanoDec 18, 2025
  9. 5/8 packfile: disentangle return value of `packed_object_info()`Patrick Steinhardt, Dec 18, 2025
  10. 6/8 packfile: skip unpacking object header for disk size requestsPatrick Steinhardt, Dec 18, 2025
  11. 7/8 packfile: fix short-circuiting of empty requestsPatrick Steinhardt, Dec 18, 2025
  12. 8/8 packfile: drop repository parameter from `packed_object_info()`Patrick Steinhardt, Dec 18, 2025
  13. Junio C HamanoDec 18, 2025
  14. Patrick SteinhardtDec 18, 2025
  15. 0/7 Improvements for reading object infoPatrick Steinhardt, Dec 18, 2025
  16. 1/7 object-file: always set OI_LOOSE when reading object infoPatrick Steinhardt, Dec 18, 2025
  17. 2/7 packfile: always declare object info to be OI_PACKEDPatrick Steinhardt, Dec 18, 2025
  18. Toon ClaesJan 5, 2026
  19. 3/7 packfile: extend `is_delta` field to allow for "unknown" statePatrick Steinhardt, Dec 18, 2025
  20. Toon ClaesJan 5, 2026
  21. Patrick SteinhardtJan 6, 2026
  22. 4/7 packfile: always populate pack-specific info when reading object infoPatrick Steinhardt, Dec 18, 2025
  23. Kristoffer HaugsbakkDec 30, 2025
  24. Patrick SteinhardtJan 5, 2026
  25. 5/7 packfile: disentangle return value of `packed_object_info()`Patrick Steinhardt, Dec 18, 2025
  26. 6/7 packfile: skip unpacking object header for disk size requestsPatrick Steinhardt, Dec 18, 2025
  27. 7/7 packfile: drop repository parameter from `packed_object_info()`Patrick Steinhardt, Dec 18, 2025
  28. 0/7 Improvements for reading object infoPatrick Steinhardt, Jan 6, 2026
  29. 1/7 object-file: always set OI_LOOSE when reading object infoPatrick Steinhardt, Jan 6, 2026
  30. Karthik NayakJan 7, 2026
  31. Patrick SteinhardtJan 7, 2026
  32. 2/7 packfile: always declare object info to be OI_PACKEDPatrick Steinhardt, Jan 6, 2026
  33. 3/7 packfile: extend `is_delta` field to allow for "unknown" statePatrick Steinhardt, Jan 6, 2026
  34. Karthik NayakJan 7, 2026
  35. 4/7 packfile: always populate pack-specific info when reading object infoPatrick Steinhardt, Jan 6, 2026
  36. 5/7 packfile: disentangle return value of `packed_object_info()`Patrick Steinhardt, Jan 6, 2026
  37. 6/7 packfile: skip unpacking object header for disk size requestsPatrick Steinhardt, Jan 6, 2026
  38. 7/7 packfile: drop repository parameter from `packed_object_info()`Patrick Steinhardt, Jan 6, 2026
  39. Karthik NayakJan 7, 2026
  40. 0/7 Improvements for reading object infoPatrick Steinhardt, Jan 7, 2026
  41. 1/7 object-file: always set OI_LOOSE when reading object infoPatrick Steinhardt, Jan 7, 2026
  42. Karthik NayakJan 8, 2026
  43. 2/7 packfile: always declare object info to be OI_PACKEDPatrick Steinhardt, Jan 7, 2026
  44. 3/7 packfile: extend `is_delta` field to allow for "unknown" statePatrick Steinhardt, Jan 7, 2026
  45. 4/7 packfile: always populate pack-specific info when reading object infoPatrick Steinhardt, Jan 7, 2026
  46. 5/7 packfile: disentangle return value of `packed_object_info()`Patrick Steinhardt, Jan 7, 2026
  47. 6/7 packfile: skip unpacking object header for disk size requestsPatrick Steinhardt, Jan 7, 2026
  48. 7/7 packfile: drop repository parameter from `packed_object_info()`Patrick Steinhardt, Jan 7, 2026
  49. Karthik NayakJan 8, 2026
  50. 0/7 Improvements for reading object infoPatrick Steinhardt, Jan 12, 2026
  51. 1/7 object-file: always set OI_LOOSE when reading object infoPatrick Steinhardt, Jan 12, 2026
  52. 2/7 packfile: always declare object info to be OI_PACKEDPatrick Steinhardt, Jan 12, 2026
  53. Junio C HamanoJan 12, 2026
  54. 3/7 packfile: extend `is_delta` field to allow for "unknown" statePatrick Steinhardt, Jan 12, 2026
  55. 4/7 packfile: always populate pack-specific info when reading object infoPatrick Steinhardt, Jan 12, 2026
  56. 5/7 packfile: disentangle return value of `packed_object_info()`Patrick Steinhardt, Jan 12, 2026
  57. 6/7 packfile: skip unpacking object header for disk size requestsPatrick Steinhardt, Jan 12, 2026
  58. 7/7 packfile: drop repository parameter from `packed_object_info()`Patrick Steinhardt, Jan 12, 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.