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

[PATCH 4/6] odb/source-loose: deduplicate logic to mmap objects

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 2, 2026, 11:20 UTC
Message-ID
<20261102-pks-odb-loose-cleanups-v1-4-fbbc86c29693@pks.im>
In-Reply-To
<20261102-pks-odb-loose-cleanups-v1-0-fbbc86c29693@pks.im>

The logic to mmap objects is duplicated across `map_fd()` and `odb_source_loose_map_object()`. The only difference is that the former takes an arbitrary path, whereas the latter derives the path from an object ID.

Deduplicate the logic.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 odb/source-loose.c | 23 +++--------------------
 1 file changed, 3 insertions(+), 20 deletions(-)
diff --git a/odb/source-loose.c b/odb/source-loose.c
index a90268e200a..5cd679e802c 100644
--- a/odb/source-loose.c
+++ b/odb/source-loose.c
@@ -544,28 +544,11 @@ static void *odb_source_loose_map_object(struct odb_source_loose *loose,
 					 const struct object_id *oid,
 					 unsigned long *size)
 {
-	const char *p;
-	int fd = open_loose_object(loose, oid, &p);
-	void *map = NULL;
-	struct stat st;
-
+	const char *path;
+	int fd = open_loose_object(loose, oid, &path);
 	if (fd < 0)
 		return NULL;
-
-	if (!fstat(fd, &st)) {
-		*size = xsize_t(st.st_size);
-		if (!*size) {
-			/* mmap() is forbidden on empty files */
-			error(_("object file %s is empty"), p);
-			goto out;
-		}
-
-		map = xmmap(NULL, *size, PROT_READ, MAP_PRIVATE, fd, 0);
-	}
-
-out:
-	close(fd);
-	return map;
+	return map_fd(fd, path, size);
 }
 
 struct odb_loose_read_stream {
-- 
2.56.0.500.g5d06dc02cd.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 5 of 7 in “object-file: move logic related to the loose backend”
  1. 0/6 object-file: move logic related to the loose backendPatrick Steinhardt, Nov 2, 2026
  2. 1/6 object-file: move logic to read loose objects into backendPatrick Steinhardt, Nov 2, 2026
  3. 2/6 object-file: move logic to derive loose object paths into backendPatrick Steinhardt, Nov 2, 2026
  4. 3/6 object-file: move iteration over loose files into backendPatrick Steinhardt, Nov 2, 2026
  5. 4/6 odb/source-loose: deduplicate logic to mmap objectsPatrick Steinhardt, Nov 2, 2026
  6. 5/6 object-file: stop including "odb/source-loose.h"Patrick Steinhardt, Nov 2, 2026
  7. 6/6 object-file: stop including "git-zlib.h"Patrick Steinhardt, Nov 2, 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.