[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