Refactor the code in cmd__run_command() to make a subsequent changes smaller by reducing duplication. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx> --- t/helper/test-run-command.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c index f3b90aa834a..bd98dd9624b 100644 --- a/t/helper/test-run-command.c +++ b/t/helper/test-run-command.c @@ -371,6 +371,8 @@ int cmd__run_command(int argc, const char **argv) { struct child_process proc = CHILD_PROCESS_INIT; int jobs; + get_next_task_fn next_fn = NULL; + task_finished_fn finished_fn = NULL; if (argc > 1 && !strcmp(argv[1], "testsuite")) exit(testsuite(argc - 1, argv + 1)); @@ -411,18 +413,18 @@ int cmd__run_command(int argc, const char **argv) strvec_clear(&proc.args); strvec_pushv(&proc.args, (const char **)argv + 3); - if (!strcmp(argv[1], "run-command-parallel")) - exit(run_processes_parallel(jobs, parallel_next, - NULL, NULL, &proc)); - - if (!strcmp(argv[1], "run-command-abort")) - exit(run_processes_parallel(jobs, parallel_next, - NULL, task_finished, &proc)); - - if (!strcmp(argv[1], "run-command-no-jobs")) - exit(run_processes_parallel(jobs, no_job, - NULL, task_finished, &proc)); + if (!strcmp(argv[1], "run-command-parallel")) { + next_fn = parallel_next; + } else if (!strcmp(argv[1], "run-command-abort")) { + next_fn = parallel_next; + finished_fn = task_finished; + } else if (!strcmp(argv[1], "run-command-no-jobs")) { + next_fn = no_job; + finished_fn = task_finished; + } else { + fprintf(stderr, "check usage\n"); + return 1; + } - fprintf(stderr, "check usage\n"); - return 1; + exit(run_processes_parallel(jobs, next_fn, NULL, finished_fn, &proc)); } -- 2.36.1.952.g0ae626f6cd7