[PATCH v2 1/3] bisect: read run output from the open descriptor
- From
Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Jul 17, 2026, 18:27 UTC
- Message-ID
- <0de8b12f65530497320b6a4bca395dfd0556c959.1784312854.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2335.v2.git.git.1784312854.gitgitgadget@gmail.com>
From: Harald Nordgren <haraldnordgren@gmail.com>
"git bisect run" redirects each step's output into BISECT_RUN, then prints it back by reopening the file by name. Read it from the already open descriptor instead; this behaves the same and no longer needs the file to be reachable by name.
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com> --- builtin/bisect.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/builtin/bisect.c b/builtin/bisect.c index 798e28f501..69ea14b1b6 100644 --- a/builtin/bisect.c +++ b/builtin/bisect.c @@ -178,17 +178,13 @@ static int append_to_file(const char *path, const char *format, ...) return res; } -static int print_file_to_stdout(const char *path) +static int print_fd_to_stdout(int fd) { - int fd = open(path, O_RDONLY); - int ret = 0; - - if (fd < 0) - return error_errno(_("cannot open file '%s' for reading"), path); + if (lseek(fd, 0, SEEK_SET) < 0) + return error_errno(_("failed to rewind BISECT_RUN output")); if (copy_fd(fd, 1) < 0) - ret = error_errno(_("failed to read '%s'"), path); - close(fd); - return ret; + return error_errno(_("failed to read BISECT_RUN output")); + return 0; } static int check_term_format(const char *term, const char *orig_term) @@ -1291,7 +1287,7 @@ static int bisect_run(struct bisect_terms *terms, int argc, const char **argv) else new_state = terms->term_bad; - temporary_stdout_fd = open(git_path_bisect_run(), O_CREAT | O_WRONLY | O_TRUNC, 0666); + temporary_stdout_fd = open(git_path_bisect_run(), O_CREAT | O_RDWR | O_TRUNC, 0666); if (temporary_stdout_fd < 0) { res = error_errno(_("cannot open file '%s' for writing"), git_path_bisect_run()); @@ -1307,9 +1303,9 @@ static int bisect_run(struct bisect_terms *terms, int argc, const char **argv) fflush(stdout); dup2(saved_stdout, 1); close(saved_stdout); - close(temporary_stdout_fd); - print_file_to_stdout(git_path_bisect_run()); + print_fd_to_stdout(temporary_stdout_fd); + close(temporary_stdout_fd); if (res == BISECT_ONLY_SKIPPED_LEFT) error(_("bisect run cannot continue any more"));
-- gitgitgadget