[PATCH v2 5/7] merge-ll: use read_mmfile() to read external merge results
COOLING4d
From: Jeff King <hidden>
Date: 2026-09-30 23:44:17
Subsystem:
the rest · Maintainer:
Linus Torvalds
After running an external merge driver, ll_ext_merge() reads the result back from a temporary file. We can do the same thing with much less code by using read_mmfile(). There are also two behavior improvements. One, read_mmfile() correctly uses xsize_t() to detect the case when we'd truncate the result. And two, read_mmfile() will report errors to stderr if it can't read the file (whereas the existing code silently returned NULL). I think most callers would have said _something_ in this case like "failed to execute merge" (from merge-ort), but more specifics are probably helpful (e.g., to distinguish a random system error from a badly configured merge driver). Signed-off-by: Jeff King <redacted> --- merge-ll.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-)
diff --git a/merge-ll.c b/merge-ll.c
index dfed6411a8..7fab7c5438 100644
--- a/merge-ll.c
+++ b/merge-ll.c@@ -201,8 +201,7 @@ static enum ll_merge_result ll_ext_merge(const struct ll_merge_driver *fn, struct strbuf cmd = STRBUF_INIT; const char *format = fn->cmdline; struct child_process child = CHILD_PROCESS_INIT; - int status, fd, i; - struct stat st; + int status, i; enum ll_merge_result ret; assert(opts);
@@ -241,20 +240,10 @@ static enum ll_merge_result ll_ext_merge(const struct ll_merge_driver *fn, child.use_shell = 1; strvec_push(&child.args, cmd.buf); status = run_command(&child); - fd = open(temp[1], O_RDONLY); - if (fd < 0) - goto bad; - if (fstat(fd, &st)) - goto close_bad; - result->size = st.st_size; - result->ptr = xmallocz(result->size); - if (read_in_full(fd, result->ptr, result->size) != result->size) { - FREE_AND_NULL(result->ptr); - result->size = 0; - } - close_bad: - close(fd); - bad: + + /* We can ignore errors; result is left NULL/0 in that case. */ + read_mmfile(result, temp[1]); + for (i = 0; i < 3; i++) unlink_or_warn(temp[i]); strbuf_release(&cmd);
--
2.56.0.354.gb6b32d5be5