Skip to content

Commit 6ae1a6e

Browse files
committed
Merge branch 'ab/run-hook-api-cleanup'
Move a global variable added as a hack during regression fixes to its proper place in the API. * ab/run-hook-api-cleanup: run-command.c: remove "max_processes", add "const" to signal() handler run-command.c: pass "opts" further down, and use "opts->processes" run-command.c: use "opts->processes", not "pp->max_processes" run-command.c: don't copy "data" to "struct parallel_processes" run-command.c: don't copy "ungroup" to "struct parallel_processes" run-command.c: don't copy *_fn to "struct parallel_processes" run-command.c: make "struct parallel_processes" const if possible run-command API: move *_tr2() users to "run_processes_parallel()" run-command API: have run_process_parallel() take an "opts" struct run-command.c: use designated init for pp_init(), add "const" run-command API: don't fall back on online_cpus() run-command API: make "n" parameter a "size_t" run-command tests: use "return", not "exit" run-command API: have "run_processes_parallel{,_tr2}()" return void run-command test helper: use "else if" pattern
2 parents f62c546 + 0b0ab95 commit 6ae1a6e

File tree

9 files changed

+268
-208
lines changed

9 files changed

+268
-208
lines changed

builtin/fetch.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
122122
fetch_parallel_config = git_config_int(k, v);
123123
if (fetch_parallel_config < 0)
124124
die(_("fetch.parallel cannot be negative"));
125+
if (!fetch_parallel_config)
126+
fetch_parallel_config = online_cpus();
125127
return 0;
126128
}
127129

@@ -1951,17 +1953,22 @@ static int fetch_multiple(struct string_list *list, int max_children)
19511953

19521954
if (max_children != 1 && list->nr != 1) {
19531955
struct parallel_fetch_state state = { argv.v, list, 0, 0 };
1956+
const struct run_process_parallel_opts opts = {
1957+
.tr2_category = "fetch",
1958+
.tr2_label = "parallel/fetch",
1959+
1960+
.processes = max_children,
1961+
1962+
.get_next_task = &fetch_next_remote,
1963+
.start_failure = &fetch_failed_to_start,
1964+
.task_finished = &fetch_finished,
1965+
.data = &state,
1966+
};
19541967

19551968
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;
1969+
1970+
run_processes_parallel(&opts);
1971+
result = state.result;
19651972
} else
19661973
for (i = 0; i < list->nr; i++) {
19671974
const char *name = list->items[i].string;

builtin/submodule--helper.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,12 +2567,20 @@ static int update_submodules(struct update_data *update_data)
25672567
{
25682568
int i, ret = 0;
25692569
struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT;
2570+
const struct run_process_parallel_opts opts = {
2571+
.tr2_category = "submodule",
2572+
.tr2_label = "parallel/update",
2573+
2574+
.processes = update_data->max_jobs,
2575+
2576+
.get_next_task = update_clone_get_next_task,
2577+
.start_failure = update_clone_start_failure,
2578+
.task_finished = update_clone_task_finished,
2579+
.data = &suc,
2580+
};
25702581

25712582
suc.update_data = update_data;
2572-
run_processes_parallel_tr2(suc.update_data->max_jobs, update_clone_get_next_task,
2573-
update_clone_start_failure,
2574-
update_clone_task_finished, &suc, "submodule",
2575-
"parallel/update");
2583+
run_processes_parallel(&opts);
25762584

25772585
/*
25782586
* We saved the output and put it out all at once now.

hook.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,20 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options)
114114
.options = options,
115115
};
116116
const char *const hook_path = find_hook(hook_name);
117-
int jobs = 1;
118117
int ret = 0;
118+
const struct run_process_parallel_opts opts = {
119+
.tr2_category = "hook",
120+
.tr2_label = hook_name,
121+
122+
.processes = 1,
123+
.ungroup = 1,
124+
125+
.get_next_task = pick_next_hook,
126+
.start_failure = notify_start_failure,
127+
.task_finished = notify_hook_finished,
128+
129+
.data = &cb_data,
130+
};
119131

120132
if (!options)
121133
BUG("a struct run_hooks_opt must be provided to run_hooks");
@@ -137,14 +149,7 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options)
137149
cb_data.hook_path = abs_path.buf;
138150
}
139151

140-
run_processes_parallel_ungroup = 1;
141-
run_processes_parallel_tr2(jobs,
142-
pick_next_hook,
143-
notify_start_failure,
144-
notify_hook_finished,
145-
&cb_data,
146-
"hook",
147-
hook_name);
152+
run_processes_parallel(&opts);
148153
ret = cb_data.rc;
149154
cleanup:
150155
strbuf_release(&abs_path);

0 commit comments

Comments
 (0)