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

[PATCH 2/5] streaming: inline call to read_object_file_extended()

From
Jeff King <peff@peff.net>
Date
Jan 7, 2023, 13:49 UTC
Message-ID
<Y7l4W/3kgT8/Ti2H@coredump.intra.peff.net>
In-Reply-To
<Y7l4LsEQcDT9HZ21@coredump.intra.peff.net>

The open_istream_incore() function is the only direct user of read_object_file_extended(), and the only caller which unsets the lookup_replace flag. Since read_object_file_extended() is now just a thin wrapper around oid_object_info_extended(), let's inline the call. That will let us simplify read_object_file_extended() in the next patch.

The inlined version here is a few more lines because of the query setup, but it's much more flexible, since we can pass (or omit) any flags we want.

Note the updated comment in the istream struct definition. It was already slightly wrong (we never called read_object(); it has been read_object_file_extended() since day one), but should now be accurate.

Signed-off-by: Jeff King <peff@peff.net>
---
 streaming.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/streaming.c b/streaming.c
index 7b2f8b2b93..27841dc1d9 100644
--- a/streaming.c
+++ b/streaming.c
@@ -38,7 +38,7 @@ struct git_istream {
 
 	union {
 		struct {
-			char *buf; /* from read_object() */
+			char *buf; /* from oid_object_info_extended() */
 			unsigned long read_ptr;
 		} incore;
 
@@ -388,12 +388,17 @@ static ssize_t read_istream_incore(struct git_istream *st, char *buf, size_t sz)
 static int open_istream_incore(struct git_istream *st, struct repository *r,
 			       const struct object_id *oid, enum object_type *type)
 {
-	st->u.incore.buf = read_object_file_extended(r, oid, type, &st->size, 0);
+	struct object_info oi = OBJECT_INFO_INIT;
+
 	st->u.incore.read_ptr = 0;
 	st->close = close_istream_incore;
 	st->read = read_istream_incore;
 
-	return st->u.incore.buf ? 0 : -1;
+	oi.typep = type;
+	oi.sizep = &st->size;
+	oi.contentp = (void **)&st->u.incore.buf;
+	return oid_object_info_extended(r, oid, &oi,
+					OBJECT_INFO_DIE_IF_CORRUPT);
 }
 
 /*****************************************************************************
-- 
2.39.0.469.g9000b9c396
Previous: Junio C HamanoNext: Jeff King
Message 7 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.