bisect--helper: factor out do_bisect_run()

Deduplicate the code for reporting and starting the bisect run command by moving it to a short helper function. Use a string array instead of a strvec to prepare the arguments, for simplicity. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Taylor Blau <me@ttaylorr.com>

René Scharfe committed Oct 30, 2022 at 12:48 UTC eede29aa359a3049d1d1aea38a2cfc3eb547a23c
1 file changed +11 -11
builtin/bisect--helper.c
+11 -11
@@ -1142,8 +1142,14 @@ static int get_first_good(const char *refname UNUSED,
1142 return 1;
1143 }
1144
1145 -static int verify_good(const struct bisect_terms *terms,
1146 - const char **quoted_argv)
1145 +static int do_bisect_run(const char *command)
1146 +{
1147 + const char *argv[] = { command, NULL };
1148 + printf(_("running %s\n"), command);
1149 + return run_command_v_opt(argv, RUN_USING_SHELL);
1150 +}
1151 +
1152 +static int verify_good(const struct bisect_terms *terms, const char *command)
1153 {
1154 int rc;
1155 enum bisect_error res;
@@ -1163,8 +1169,7 @@ static int verify_good(const struct bisect_terms *terms,
1169 if (res != BISECT_OK)
1170 return -1;
1171
1166 - printf(_("running %s\n"), quoted_argv[0]);
1167 - rc = run_command_v_opt(quoted_argv, RUN_USING_SHELL);
1172 + rc = do_bisect_run(command);
1173
1174 res = bisect_checkout(&current_rev, no_checkout);
1175 if (res != BISECT_OK)
@@ -1177,7 +1182,6 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1182 {
1183 int res = BISECT_OK;
1184 struct strbuf command = STRBUF_INIT;
1180 - struct strvec run_args = STRVEC_INIT;
1185 const char *new_state;
1186 int temporary_stdout_fd, saved_stdout;
1187 int is_first_run = 1;
@@ -1192,11 +1196,8 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1196 return BISECT_FAILED;
1197 }
1198
1195 - strvec_push(&run_args, command.buf);
1196 -
1199 while (1) {
1198 - printf(_("running %s\n"), command.buf);
1199 - res = run_command_v_opt(run_args.v, RUN_USING_SHELL);
1200 + res = do_bisect_run(command.buf);
1201
1202 /*
1203 * Exit code 126 and 127 can either come from the shell
@@ -1206,7 +1207,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1207 * missing or non-executable script.
1208 */
1209 if (is_first_run && (res == 126 || res == 127)) {
1209 - int rc = verify_good(terms, run_args.v);
1210 + int rc = verify_good(terms, command.buf);
1211 is_first_run = 0;
1212 if (rc < 0) {
1213 error(_("unable to verify '%s' on good"
@@ -1273,7 +1274,6 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1274 }
1275
1276 strbuf_release(&command);
1276 - strvec_clear(&run_args);
1277 return res;
1278 }
1279