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

[PATCH 5/8] object-file: allow reading loose objects without reading their contents

From
Patrick Steinhardt <ps@pks.im>
Date
May 19, 2021, 19:13 UTC
Message-ID
<e26ff58e926dfc6aec15794a68981d6e455cb305.1621451532.git.ps@pks.im>
In-Reply-To
<cover.1621451532.git.ps@pks.im>

We're about to add a new implementation of the connectivity check via the object quarantine directory, which will directly iterate over any loose object via their paths. For optimization purposes, we'll want to skip over any loose blobs, but right now there's no easy way to read a loose object without also slurping in all its contents.

Fix this shortcoming by modifying `read_loose_object()` such that it can handle the case where no pointer for `contents` was passed in. If so, then we'll simply skip reading the loose object.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 object-file.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/object-file.c b/object-file.c
index 884855b9df..ab695823fd 100644
--- a/object-file.c
+++ b/object-file.c
@@ -2552,7 +2552,8 @@ int read_loose_object(const char *path,
 	git_zstream stream;
 	char hdr[MAX_HEADER_LEN];
 
-	*contents = NULL;
+	if (contents)
+		*contents = NULL;
 
 	map = map_loose_object_1(the_repository, path, NULL, &mapsize);
 	if (!map) {
@@ -2572,6 +2573,12 @@ int read_loose_object(const char *path,
 		goto out;
 	}
 
+	if (!contents) {
+		git_inflate_end(&stream);
+		ret = 0;
+		goto out;
+	}
+
 	if (*type == OBJ_BLOB && *size > big_file_threshold) {
 		if (check_stream_oid(&stream, hdr, *size, path, expected_oid) < 0)
 			goto out;
-- 
2.31.1
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 11 of 22 in “Speed up connectivity checks via quarantine dir”
  1. 0/8 Speed up connectivity checks via quarantine dirPatrick Steinhardt, May 19, 2021
  2. 1/8 perf: fix when running with TEST_OUTPUT_DIRECTORYPatrick Steinhardt, May 19, 2021
  3. Chris TorekMay 20, 2021
  4. 2/8 p5400: add perf tests for git-receive-pack(1)Patrick Steinhardt, May 19, 2021
  5. Chris TorekMay 20, 2021
  6. Jeff KingMay 20, 2021
  7. SZEDER GáborMay 21, 2021
  8. 3/8 tmp-objdir: expose function to retrieve pathPatrick Steinhardt, May 19, 2021
  9. Elijah NewrenMay 20, 2021
  10. 4/8 packfile: have `for_each_file_in_pack_dir()` return error codesPatrick Steinhardt, May 19, 2021
  11. 5/8 object-file: allow reading loose objects without reading their contentsPatrick Steinhardt, May 19, 2021
  12. 6/8 connected: implement connectivity check via temporary object dirsPatrick Steinhardt, May 19, 2021
  13. 7/8 receive-pack: skip connectivity checks on delete-only commandsPatrick Steinhardt, May 19, 2021
  14. Felipe ContrerasMay 21, 2021
  15. Jeff KingMay 27, 2021
  16. 8/8 receive-pack: check connectivity via quarantined objectsPatrick Steinhardt, May 19, 2021
  17. Chris TorekMay 20, 2021
  18. Jeff KingMay 20, 2021
  19. Junio C HamanoMay 20, 2021
  20. Jeff KingMay 21, 2021
  21. Patrick SteinhardtMay 21, 2021
  22. Ævar Arnfjörð BjarmasonMay 21, 2021

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.