Skip to content

Commit 7dd5762

Browse files
avargitster
authored andcommitted
run-command API: have "run_processes_parallel{,_tr2}()" return void
Change the "run_processes_parallel{,_tr2}()" functions to return void, instead of int. Ever since c553c72 (run-command: add an asynchronous parallel child processor, 2015-12-15) they have unconditionally returned 0. To get a "real" return value out of this function the caller needs to get it via the "task_finished_fn" callback, see the example in hook.c added in 96e7225 (hook: add 'run' subcommand, 2021-12-22). So the "result = " and "if (!result)" code added to "builtin/fetch.c" d54dea7 (fetch: let --jobs=<n> parallelize --multiple, too, 2019-10-05) has always been redundant, we always took that "if" path. Likewise the "ret =" in "t/helper/test-run-command.c" added in be5d88e (test-tool run-command: learn to run (parts of) the testsuite, 2019-10-04) wasn't used, instead we got the return value from the "if (suite.failed.nr > 0)" block seen in the context. Subsequent commits will alter this API interface, getting rid of this always-zero return value makes it easier to understand those changes. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a083f94 commit 7dd5762

File tree

4 files changed

+35
-41
lines changed

4 files changed

+35
-41
lines changed

builtin/fetch.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,15 +1953,14 @@ static int fetch_multiple(struct string_list *list, int max_children)
19531953
struct parallel_fetch_state state = { argv.v, list, 0, 0 };
19541954

19551955
strvec_push(&argv, "--end-of-options");
1956-
result = run_processes_parallel_tr2(max_children,
1957-
&fetch_next_remote,
1958-
&fetch_failed_to_start,
1959-
&fetch_finished,
1960-
&state,
1961-
"fetch", "parallel/fetch");
1962-
1963-
if (!result)
1964-
result = state.result;
1956+
run_processes_parallel_tr2(max_children,
1957+
&fetch_next_remote,
1958+
&fetch_failed_to_start,
1959+
&fetch_finished,
1960+
&state,
1961+
"fetch", "parallel/fetch");
1962+
1963+
result = state.result;
19651964
} else
19661965
for (i = 0; i < list->nr; i++) {
19671966
const char *name = list->items[i].string;

run-command.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,11 +1783,11 @@ static int pp_collect_finished(struct parallel_processes *pp)
17831783
return result;
17841784
}
17851785

1786-
int run_processes_parallel(int n,
1787-
get_next_task_fn get_next_task,
1788-
start_failure_fn start_failure,
1789-
task_finished_fn task_finished,
1790-
void *pp_cb)
1786+
void run_processes_parallel(int n,
1787+
get_next_task_fn get_next_task,
1788+
start_failure_fn start_failure,
1789+
task_finished_fn task_finished,
1790+
void *pp_cb)
17911791
{
17921792
int i, code;
17931793
int output_timeout = 100;
@@ -1834,25 +1834,20 @@ int run_processes_parallel(int n,
18341834
}
18351835

18361836
pp_cleanup(&pp);
1837-
return 0;
18381837
}
18391838

1840-
int run_processes_parallel_tr2(int n, get_next_task_fn get_next_task,
1841-
start_failure_fn start_failure,
1842-
task_finished_fn task_finished, void *pp_cb,
1843-
const char *tr2_category, const char *tr2_label)
1839+
void run_processes_parallel_tr2(int n, get_next_task_fn get_next_task,
1840+
start_failure_fn start_failure,
1841+
task_finished_fn task_finished, void *pp_cb,
1842+
const char *tr2_category, const char *tr2_label)
18441843
{
1845-
int result;
1846-
18471844
trace2_region_enter_printf(tr2_category, tr2_label, NULL, "max:%d",
18481845
((n < 1) ? online_cpus() : n));
18491846

1850-
result = run_processes_parallel(n, get_next_task, start_failure,
1851-
task_finished, pp_cb);
1847+
run_processes_parallel(n, get_next_task, start_failure,
1848+
task_finished, pp_cb);
18521849

18531850
trace2_region_leave(tr2_category, tr2_label, NULL);
1854-
1855-
return result;
18561851
}
18571852

18581853
int run_auto_maintenance(int quiet)

run-command.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -485,14 +485,14 @@ typedef int (*task_finished_fn)(int result,
485485
* API reads that setting.
486486
*/
487487
extern int run_processes_parallel_ungroup;
488-
int run_processes_parallel(int n,
489-
get_next_task_fn,
490-
start_failure_fn,
491-
task_finished_fn,
492-
void *pp_cb);
493-
int run_processes_parallel_tr2(int n, get_next_task_fn, start_failure_fn,
494-
task_finished_fn, void *pp_cb,
495-
const char *tr2_category, const char *tr2_label);
488+
void run_processes_parallel(int n,
489+
get_next_task_fn,
490+
start_failure_fn,
491+
task_finished_fn,
492+
void *pp_cb);
493+
void run_processes_parallel_tr2(int n, get_next_task_fn, start_failure_fn,
494+
task_finished_fn, void *pp_cb,
495+
const char *tr2_category, const char *tr2_label);
496496

497497
/**
498498
* Convenience function which prepares env for a command to be run in a

t/helper/test-run-command.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ static int testsuite(int argc, const char **argv)
192192
fprintf(stderr, "Running %"PRIuMAX" tests (%d at a time)\n",
193193
(uintmax_t)suite.tests.nr, max_jobs);
194194

195-
ret = run_processes_parallel(max_jobs, next_test, test_failed,
196-
test_finished, &suite);
195+
run_processes_parallel(max_jobs, next_test, test_failed,
196+
test_finished, &suite);
197197

198198
if (suite.failed.nr > 0) {
199199
ret = 1;
@@ -428,16 +428,16 @@ int cmd__run_command(int argc, const char **argv)
428428
strvec_pushv(&proc.args, (const char **)argv + 3);
429429

430430
if (!strcmp(argv[1], "run-command-parallel")) {
431-
exit(run_processes_parallel(jobs, parallel_next,
432-
NULL, NULL, &proc));
431+
run_processes_parallel(jobs, parallel_next, NULL, NULL, &proc);
433432
} else if (!strcmp(argv[1], "run-command-abort")) {
434-
exit(run_processes_parallel(jobs, parallel_next,
435-
NULL, task_finished, &proc));
433+
run_processes_parallel(jobs, parallel_next, NULL,
434+
task_finished, &proc);
436435
} else if (!strcmp(argv[1], "run-command-no-jobs")) {
437-
exit(run_processes_parallel(jobs, no_job,
438-
NULL, task_finished, &proc));
436+
run_processes_parallel(jobs, no_job, NULL, task_finished,
437+
&proc);
439438
} else {
440439
fprintf(stderr, "check usage\n");
441440
return 1;
442441
}
442+
exit(0);
443443
}

0 commit comments

Comments
 (0)