Thanks everyone for your comments. Here's a reroll. Jonathan Tan (4): object-file: remove OBJECT_INFO_IGNORE_LOOSE object-file: refactor map_loose_object_1() object-file: emit corruption errors when detected commit: don't lazy-fetch commits commit.c | 15 ++++++- object-file.c | 108 ++++++++++++++++++++++++------------------------- object-store.h | 7 ++-- 3 files changed, 69 insertions(+), 61 deletions(-) Range-diff against v3: 1: be0b08cac2 = 1: be0b08cac2 object-file: remove OBJECT_INFO_IGNORE_LOOSE 2: 7419e4ac70 ! 2: 4b2fb68743 object-file: refactor map_loose_object_1() @@ Commit message 2. Simultaneously gets a path and fd given an OID 3. Memory maps an fd - Split this function up. Only one caller needs 1, so inline that. As for - 2, a future patch will also need this functionality and, in addition, - the calculated path, so extract this into a separate function with an - out parameter for the path. + Keep 3 (renaming the function accordingly) and inline 1 and 2 into their + respective callers. Signed-off-by: Jonathan Tan <jonathantanmy@xxxxxxxxxx> @@ object-file.c: static int quick_has_loose(struct repository *r, return map; } -+static void *map_loose_object_1(struct repository *r, -+ const struct object_id *oid, -+ unsigned long *size, -+ const char **path) -+{ +@@ object-file.c: void *map_loose_object(struct repository *r, + const struct object_id *oid, + unsigned long *size) + { +- return map_loose_object_1(r, NULL, oid, size); + const char *p; + int fd = open_loose_object(r, oid, &p); + + if (fd < 0) + return NULL; -+ if (path) -+ *path = p; + return map_fd(fd, p, size); -+} -+ - void *map_loose_object(struct repository *r, - const struct object_id *oid, - unsigned long *size) - { -- return map_loose_object_1(r, NULL, oid, size); -+ return map_loose_object_1(r, oid, size, NULL); } enum unpack_loose_header_result unpack_loose_header(git_zstream *stream, 3: 7c9ed861e7 ! 3: 07d28db92c object-file: emit corruption errors when detected @@ Commit message which an indirect caller of do_oid_object_info_extended() will need such functionality. + Helped-by: Jeff King <peff@xxxxxxxx> Signed-off-by: Jonathan Tan <jonathantanmy@xxxxxxxxxx> ## object-file.c ## @@ object-file.c: static int loose_object_info(struct repository *r, + struct object_info *oi, int flags) { int status = 0; ++ int fd; unsigned long mapsize; -+ const char *path = NULL; ++ const char *path; void *map; git_zstream stream; char hdr[MAX_HEADER_LEN]; +@@ object-file.c: static int loose_object_info(struct repository *r, + * object even exists. + */ + if (!oi->typep && !oi->type_name && !oi->sizep && !oi->contentp) { +- const char *path; + struct stat st; + if (!oi->disk_sizep && (flags & OBJECT_INFO_QUICK)) + return quick_has_loose(r, oid) ? 0 : -1; @@ object-file.c: static int loose_object_info(struct repository *r, return 0; } - map = map_loose_object(r, oid, &mapsize); -+ map = map_loose_object_1(r, oid, &mapsize, &path); ++ fd = open_loose_object(r, oid, &path); ++ if (fd < 0) { ++ if (errno != ENOENT) ++ error_errno(_("unable to open loose object %s"), path); ++ return -1; ++ } ++ map = map_fd(fd, path, &mapsize); if (!map) return -1; @@ object-file.c: static void *read_object(struct repository *r, oi.contentp = &content; - if (oid_object_info_extended(r, oid, &oi, 0) < 0) -+ if (oid_object_info_extended(r, oid, &oi, -+ die_if_corrupt ? OBJECT_INFO_DIE_IF_CORRUPT : 0) -+ < 0) ++ if (oid_object_info_extended(r, oid, &oi, die_if_corrupt ++ ? OBJECT_INFO_DIE_IF_CORRUPT : 0) < 0) return NULL; return content; } 4: 5924a5120b = 4: 1a0cd5b244 commit: don't lazy-fetch commits -- 2.39.0.rc1.256.g54fd8350bd-goog