diff mbox series

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

Message ID e26ff58e926dfc6aec15794a68981d6e455cb305.1621451532.git.ps@pks.im (mailing list archive)
State New, archived
Headers show
Series Speed up connectivity checks via quarantine dir | expand

Commit Message

Patrick Steinhardt May 19, 2021, 7:13 p.m. UTC
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 mbox series

Patch

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;