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>
Ævar Arnfjörð Bjarmason committed
Oct 12, 2022 at 23:02 UTC
357f8e6e184e8e01c502ee5d7a81cca71d59f322
1 file changed
+8
-10
run-command.c
+8
-10
@@ -1515,7 +1515,6 @@ struct parallel_processes {
1515
struct pollfd *pfd;
1516
1517
unsigned shutdown : 1;
1518
- const unsigned ungroup : 1;
1518
1519
size_t output_owner;
1520
struct strbuf buffered_output; /* of finished children */
@@ -1552,7 +1551,7 @@ static void pp_init(struct parallel_processes *pp,
1551
BUG("you need to specify a get_next_task function");
1552
1553
CALLOC_ARRAY(pp->children, n);
1555
- if (!pp->ungroup)
1554
+ if (!opts->ungroup)
1555
CALLOC_ARRAY(pp->pfd, n);
1556
1557
for (size_t i = 0; i < n; i++) {
@@ -1609,17 +1608,17 @@ static int pp_start_one(struct parallel_processes *pp,
1608
BUG("bookkeeping is hard");
1609
1610
code = opts->get_next_task(&pp->children[i].process,
1612
- pp->ungroup ? NULL : &pp->children[i].err,
1611
+ opts->ungroup ? NULL : &pp->children[i].err,
1612
pp->data,
1613
&pp->children[i].data);
1614
if (!code) {
1616
- if (!pp->ungroup) {
1615
+ if (!opts->ungroup) {
1616
strbuf_addbuf(&pp->buffered_output, &pp->children[i].err);
1617
strbuf_reset(&pp->children[i].err);
1618
}
1619
return 1;
1620
}
1622
- if (!pp->ungroup) {
1621
+ if (!opts->ungroup) {
1622
pp->children[i].process.err = -1;
1623
pp->children[i].process.stdout_to_stderr = 1;
1624
}
@@ -1627,14 +1626,14 @@ static int pp_start_one(struct parallel_processes *pp,
1626
1627
if (start_command(&pp->children[i].process)) {
1628
if (opts->start_failure)
1630
- code = opts->start_failure(pp->ungroup ? NULL :
1629
+ code = opts->start_failure(opts->ungroup ? NULL :
1630
&pp->children[i].err,
1631
pp->data,
1632
pp->children[i].data);
1633
else
1634
code = 0;
1635
1637
- if (!pp->ungroup) {
1636
+ if (!opts->ungroup) {
1637
strbuf_addbuf(&pp->buffered_output, &pp->children[i].err);
1638
strbuf_reset(&pp->children[i].err);
1639
}
@@ -1705,7 +1704,7 @@ static int pp_collect_finished(struct parallel_processes *pp,
1704
code = finish_command(&pp->children[i].process);
1705
1706
if (opts->task_finished)
1708
- code = opts->task_finished(code, pp->ungroup ? NULL :
1707
+ code = opts->task_finished(code, opts->ungroup ? NULL :
1708
&pp->children[i].err, pp->data,
1709
pp->children[i].data);
1710
else
@@ -1722,7 +1721,7 @@ static int pp_collect_finished(struct parallel_processes *pp,
1721
pp->pfd[i].fd = -1;
1722
child_process_init(&pp->children[i].process);
1723
1725
- if (pp->ungroup) {
1724
+ if (opts->ungroup) {
1725
; /* no strbuf_*() work to do here */
1726
} else if (i != pp->output_owner) {
1727
strbuf_addbuf(&pp->buffered_output, &pp->children[i].err);
@@ -1761,7 +1760,6 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts)
1760
.max_processes = opts->processes,
1761
.data = opts->data,
1762
.buffered_output = STRBUF_INIT,
1764
- .ungroup = opts->ungroup,
1763
};
1764
/* options */
1765
const char *tr2_category = opts->tr2_category;