Skip to content

Commit eede29a

Browse files
rscharfettaylorr
authored andcommitted
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 <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 48750b2 commit eede29a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

builtin/bisect--helper.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,8 +1142,14 @@ static int get_first_good(const char *refname UNUSED,
11421142
return 1;
11431143
}
11441144

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)
11471153
{
11481154
int rc;
11491155
enum bisect_error res;
@@ -1163,8 +1169,7 @@ static int verify_good(const struct bisect_terms *terms,
11631169
if (res != BISECT_OK)
11641170
return -1;
11651171

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);
11681173

11691174
res = bisect_checkout(&current_rev, no_checkout);
11701175
if (res != BISECT_OK)
@@ -1177,7 +1182,6 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
11771182
{
11781183
int res = BISECT_OK;
11791184
struct strbuf command = STRBUF_INIT;
1180-
struct strvec run_args = STRVEC_INIT;
11811185
const char *new_state;
11821186
int temporary_stdout_fd, saved_stdout;
11831187
int is_first_run = 1;
@@ -1192,11 +1196,8 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
11921196
return BISECT_FAILED;
11931197
}
11941198

1195-
strvec_push(&run_args, command.buf);
1196-
11971199
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);
12001201

12011202
/*
12021203
* 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)
12061207
* missing or non-executable script.
12071208
*/
12081209
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);
12101211
is_first_run = 0;
12111212
if (rc < 0) {
12121213
error(_("unable to verify '%s' on good"
@@ -1273,7 +1274,6 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
12731274
}
12741275

12751276
strbuf_release(&command);
1276-
strvec_clear(&run_args);
12771277
return res;
12781278
}
12791279

0 commit comments

Comments
 (0)