1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-14 03:06:51 +02:00

run-command.c: don't copy "ungroup" to "struct parallel_processes"

As with the *_fn members removed in the preceding commit, let's not
copy the "ungroup" member of the "struct run_process_parallel_opts"
over to the "struct parallel_processes". Now that we're passing the
"opts" down there's no reason to do so.

This makes the code easier to follow, as we have a "const" attribute
on the "struct run_process_parallel_opts", but not "struct
parallel_processes". We do not alter the "ungroup" argument, so
storing it in the non-const structure would make this control flow
less obvious.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason 2022-10-12 23:02:30 +02:00 committed by Junio C Hamano
parent fa93951d79
commit 357f8e6e18

View File

@ -1515,7 +1515,6 @@ struct parallel_processes {
struct pollfd *pfd; struct pollfd *pfd;
unsigned shutdown : 1; unsigned shutdown : 1;
const unsigned ungroup : 1;
size_t output_owner; size_t output_owner;
struct strbuf buffered_output; /* of finished children */ struct strbuf buffered_output; /* of finished children */
@ -1552,7 +1551,7 @@ static void pp_init(struct parallel_processes *pp,
BUG("you need to specify a get_next_task function"); BUG("you need to specify a get_next_task function");
CALLOC_ARRAY(pp->children, n); CALLOC_ARRAY(pp->children, n);
if (!pp->ungroup) if (!opts->ungroup)
CALLOC_ARRAY(pp->pfd, n); CALLOC_ARRAY(pp->pfd, n);
for (size_t i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {
@ -1609,17 +1608,17 @@ static int pp_start_one(struct parallel_processes *pp,
BUG("bookkeeping is hard"); BUG("bookkeeping is hard");
code = opts->get_next_task(&pp->children[i].process, code = opts->get_next_task(&pp->children[i].process,
pp->ungroup ? NULL : &pp->children[i].err, opts->ungroup ? NULL : &pp->children[i].err,
pp->data, pp->data,
&pp->children[i].data); &pp->children[i].data);
if (!code) { if (!code) {
if (!pp->ungroup) { if (!opts->ungroup) {
strbuf_addbuf(&pp->buffered_output, &pp->children[i].err); strbuf_addbuf(&pp->buffered_output, &pp->children[i].err);
strbuf_reset(&pp->children[i].err); strbuf_reset(&pp->children[i].err);
} }
return 1; return 1;
} }
if (!pp->ungroup) { if (!opts->ungroup) {
pp->children[i].process.err = -1; pp->children[i].process.err = -1;
pp->children[i].process.stdout_to_stderr = 1; pp->children[i].process.stdout_to_stderr = 1;
} }
@ -1627,14 +1626,14 @@ static int pp_start_one(struct parallel_processes *pp,
if (start_command(&pp->children[i].process)) { if (start_command(&pp->children[i].process)) {
if (opts->start_failure) if (opts->start_failure)
code = opts->start_failure(pp->ungroup ? NULL : code = opts->start_failure(opts->ungroup ? NULL :
&pp->children[i].err, &pp->children[i].err,
pp->data, pp->data,
pp->children[i].data); pp->children[i].data);
else else
code = 0; code = 0;
if (!pp->ungroup) { if (!opts->ungroup) {
strbuf_addbuf(&pp->buffered_output, &pp->children[i].err); strbuf_addbuf(&pp->buffered_output, &pp->children[i].err);
strbuf_reset(&pp->children[i].err); strbuf_reset(&pp->children[i].err);
} }
@ -1705,7 +1704,7 @@ static int pp_collect_finished(struct parallel_processes *pp,
code = finish_command(&pp->children[i].process); code = finish_command(&pp->children[i].process);
if (opts->task_finished) if (opts->task_finished)
code = opts->task_finished(code, pp->ungroup ? NULL : code = opts->task_finished(code, opts->ungroup ? NULL :
&pp->children[i].err, pp->data, &pp->children[i].err, pp->data,
pp->children[i].data); pp->children[i].data);
else else
@ -1722,7 +1721,7 @@ static int pp_collect_finished(struct parallel_processes *pp,
pp->pfd[i].fd = -1; pp->pfd[i].fd = -1;
child_process_init(&pp->children[i].process); child_process_init(&pp->children[i].process);
if (pp->ungroup) { if (opts->ungroup) {
; /* no strbuf_*() work to do here */ ; /* no strbuf_*() work to do here */
} else if (i != pp->output_owner) { } else if (i != pp->output_owner) {
strbuf_addbuf(&pp->buffered_output, &pp->children[i].err); strbuf_addbuf(&pp->buffered_output, &pp->children[i].err);
@ -1761,7 +1760,6 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts)
.max_processes = opts->processes, .max_processes = opts->processes,
.data = opts->data, .data = opts->data,
.buffered_output = STRBUF_INIT, .buffered_output = STRBUF_INIT,
.ungroup = opts->ungroup,
}; };
/* options */ /* options */
const char *tr2_category = opts->tr2_category; const char *tr2_category = opts->tr2_category;