[PATCH 4/5] merge-ll: use read_mmfile() to read external merge results
- From
Jeff King <peff@peff.net>
- Date
- Sep 29, 2026, 06:54 UTC
- Message-ID
- <20260929065442.GD1697497@coredump.intra.peff.net>
- In-Reply-To
- <20260929064935.GA1276867@coredump.intra.peff.net>
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().
As a bonus, note that read_mmfile() correctly uses xsize_t() to detect the case when we'd truncate the result.
Signed-off-by: Jeff King <peff@peff.net> --- 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.325.g545d7e68bc