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

[PATCH 5/5] packfile: inline custom read_object()

From
Jeff King <peff@peff.net>
Date
Jan 7, 2023, 13:50 UTC
Message-ID
<Y7l4vQwRZzGtxlBB@coredump.intra.peff.net>
In-Reply-To
<Y7l4LsEQcDT9HZ21@coredump.intra.peff.net>

When the pack code was split into its own file[1], it got a copy of the static read_object() function. But there's only one caller here, so we could just inline it. And it's worth doing so, as the name read_object() invites comparisons to the public read_object_file(), but the two don't behave quite the same.

[1] The move happened over several commits, but the relevant one here is
    f1d8130be0 (pack: move clear_delta_base_cache(), packed_object_info(),
    unpack_entry(), 2017-08-18).
Signed-off-by: Jeff King <peff@peff.net>
---
 packfile.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)
diff --git a/packfile.c b/packfile.c
index c0d7dd93f4..79e21ab18e 100644
--- a/packfile.c
+++ b/packfile.c
@@ -1650,22 +1650,6 @@ struct unpack_entry_stack_ent {
 	unsigned long size;
 };
 
-static void *read_object(struct repository *r,
-			 const struct object_id *oid,
-			 enum object_type *type,
-			 unsigned long *size)
-{
-	struct object_info oi = OBJECT_INFO_INIT;
-	void *content;
-	oi.typep = type;
-	oi.sizep = size;
-	oi.contentp = &content;
-
-	if (oid_object_info_extended(r, oid, &oi, 0) < 0)
-		return NULL;
-	return content;
-}
-
 void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
 		   enum object_type *final_type, unsigned long *final_size)
 {
@@ -1798,14 +1782,22 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
 			uint32_t pos;
 			struct object_id base_oid;
 			if (!(offset_to_pack_pos(p, obj_offset, &pos))) {
+				struct object_info oi = OBJECT_INFO_INIT;
+
 				nth_packed_object_id(&base_oid, p,
 						     pack_pos_to_index(p, pos));
 				error("failed to read delta base object %s"
 				      " at offset %"PRIuMAX" from %s",
 				      oid_to_hex(&base_oid), (uintmax_t)obj_offset,
 				      p->pack_name);
 				mark_bad_packed_object(p, &base_oid);
-				base = read_object(r, &base_oid, &type, &base_size);
+
+				oi.typep = &type;
+				oi.sizep = &base_size;
+				oi.contentp = &base;
+				if (oid_object_info_extended(r, &base_oid, &oi, 0) < 0)
+					base = NULL;
+
 				external_base = base;
 			}
 		}
-- 
2.39.0.469.g9000b9c396
Previous: Jeff KingNext: Ævar Arnfjörð Bjarmason
Message 10 of 20 in “cleaning up read_object() family of functions”
  1. 0/5 cleaning up read_object() family of functionsJeff King, Jan 7, 2023
  2. 1/5 object-file: inline calls to read_object()Jeff King, Jan 7, 2023
  3. Ævar Arnfjörð BjarmasonJan 12, 2023
  4. object-file: fix indent-with-spaceJeff King, Jan 12, 2023
  5. Ævar Arnfjörð BjarmasonJan 12, 2023
  6. Junio C HamanoJan 13, 2023
  7. 2/5 streaming: inline call to read_object_file_extended()Jeff King, Jan 7, 2023
  8. 3/5 read_object_file_extended(): drop lookup_replace optionJeff King, Jan 7, 2023
  9. 4/5 repo_read_object_file(): stop wrapping read_object_file_extended()Jeff King, Jan 7, 2023
  10. 5/5 packfile: inline custom read_object()Jeff King, Jan 7, 2023
  11. Ævar Arnfjörð BjarmasonJan 12, 2023
  12. Jeff KingJan 12, 2023
  13. Derrick StoleeJan 9, 2023
  14. Jeff KingJan 11, 2023
  15. Derrick StoleeJan 11, 2023
  16. Jeff KingJan 11, 2023
  17. Ævar Arnfjörð BjarmasonJan 12, 2023
  18. Jeff KingJan 12, 2023
  19. Ævar Arnfjörð BjarmasonJan 12, 2023
  20. Jeff KingJan 12, 2023

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.