summaryrefslogtreecommitdiff
path: root/t/helper
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2022-10-12 21:02:26 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-10-12 21:12:41 (GMT)
commit6e5ba0bae447dba2adabea588b248b5fc6f59cd6 (patch)
treef2ba0540002a8ed4cbbec0bf8d23298dc352ca88 /t/helper
parentc333e6f3a86140c39797f8dedf6d078aec453dc3 (diff)
downloadgit-6e5ba0bae447dba2adabea588b248b5fc6f59cd6.zip
git-6e5ba0bae447dba2adabea588b248b5fc6f59cd6.tar.gz
git-6e5ba0bae447dba2adabea588b248b5fc6f59cd6.tar.bz2
run-command API: have run_process_parallel() take an "opts" struct
As noted in fd3aaf53f71 (run-command: add an "ungroup" option to run_process_parallel(), 2022-06-07) which added the "ungroup" passing it to "run_process_parallel()" via the global "run_processes_parallel_ungroup" variable was a compromise to get the smallest possible regression fix for "maint" at the time. This follow-up to that is a start at passing that parameter and others via a new "struct run_process_parallel_opts", as the earlier version[1] of what became fd3aaf53f71 did. Since we need to change all of the occurrences of "n" to "opt->SOMETHING" let's take the opportunity and rename the terse "n" to "processes". We could also have picked "max_processes", "jobs", "threads" etc., but as the API is named "run_processes_parallel()" let's go with "processes". Since the new "run_processes_parallel()" function is able to take an optional "tr2_category" and "tr2_label" via the struct we can at this point migrate all of the users of "run_processes_parallel_tr2()" over to it. But let's not migrate all the API users yet, only the two users that passed the "ungroup" parameter via the "run_processes_parallel_ungroup" global 1. https://lore.kernel.org/git/cover-v2-0.8-00000000000-20220518T195858Z-avarab@gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/helper')
-rw-r--r--t/helper/test-run-command.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c
index ee509ae..3ecb830 100644
--- a/t/helper/test-run-command.c
+++ b/t/helper/test-run-command.c
@@ -136,7 +136,7 @@ static const char * const testsuite_usage[] = {
static int testsuite(int argc, const char **argv)
{
struct testsuite suite = TESTSUITE_INIT;
- int max_jobs = 1, i, ret;
+ int max_jobs = 1, i, ret = 0;
DIR *dir;
struct dirent *d;
struct option options[] = {
@@ -152,6 +152,12 @@ static int testsuite(int argc, const char **argv)
"write JUnit-style XML files"),
OPT_END()
};
+ struct run_process_parallel_opts opts = {
+ .get_next_task = next_test,
+ .start_failure = test_failed,
+ .task_finished = test_finished,
+ .data = &suite,
+ };
argc = parse_options(argc, argv, NULL, options,
testsuite_usage, PARSE_OPT_STOP_AT_NON_OPTION);
@@ -192,8 +198,8 @@ static int testsuite(int argc, const char **argv)
fprintf(stderr, "Running %"PRIuMAX" tests (%d at a time)\n",
(uintmax_t)suite.tests.nr, max_jobs);
- run_processes_parallel(max_jobs, next_test, test_failed,
- test_finished, &suite);
+ opts.processes = max_jobs;
+ run_processes_parallel(&opts);
if (suite.failed.nr > 0) {
ret = 1;
@@ -206,7 +212,7 @@ static int testsuite(int argc, const char **argv)
string_list_clear(&suite.tests, 0);
string_list_clear(&suite.failed, 0);
- return !!ret;
+ return ret;
}
static uint64_t my_random_next = 1234;
@@ -382,6 +388,9 @@ int cmd__run_command(int argc, const char **argv)
struct child_process proc = CHILD_PROCESS_INIT;
int jobs;
int ret;
+ struct run_process_parallel_opts opts = {
+ .data = &proc,
+ };
if (argc > 1 && !strcmp(argv[1], "testsuite"))
return testsuite(argc - 1, argv + 1);
@@ -427,7 +436,7 @@ int cmd__run_command(int argc, const char **argv)
if (!strcmp(argv[1], "--ungroup")) {
argv += 1;
argc -= 1;
- run_processes_parallel_ungroup = 1;
+ opts.ungroup = 1;
}
jobs = atoi(argv[2]);
@@ -435,18 +444,20 @@ int cmd__run_command(int argc, const char **argv)
strvec_pushv(&proc.args, (const char **)argv + 3);
if (!strcmp(argv[1], "run-command-parallel")) {
- run_processes_parallel(jobs, parallel_next, NULL, NULL, &proc);
+ opts.get_next_task = parallel_next;
} else if (!strcmp(argv[1], "run-command-abort")) {
- run_processes_parallel(jobs, parallel_next, NULL,
- task_finished, &proc);
+ opts.get_next_task = parallel_next;
+ opts.task_finished = task_finished;
} else if (!strcmp(argv[1], "run-command-no-jobs")) {
- run_processes_parallel(jobs, no_job, NULL, task_finished,
- &proc);
+ opts.get_next_task = no_job;
+ opts.task_finished = task_finished;
} else {
ret = 1;
fprintf(stderr, "check usage\n");
goto cleanup;
}
+ opts.processes = jobs;
+ run_processes_parallel(&opts);
ret = 0;
cleanup:
child_process_clear(&proc);