MCPcopy Create free account
hub / github.com/git/git / pp_start_one

Function pp_start_one

run-command.c:1630–1689  ·  view source on GitHub ↗

returns * 0 if a new task was started. * 1 if no new jobs was started (get_next_task ran out of work, non critical * problem with starting a new command) * <0 no new job was started, user wishes to shutdown early. Use negative code * to signal the children. */

Source from the content-addressed store, hash-verified

1628 * to signal the children.
1629 */
1630static int pp_start_one(struct parallel_processes *pp,
1631 const struct run_process_parallel_opts *opts)
1632{
1633 size_t i;
1634 int code;
1635
1636 for (i = 0; i < opts->processes; i++)
1637 if (pp->children[i].state == GIT_CP_FREE)
1638 break;
1639 if (i == opts->processes)
1640 BUG("bookkeeping is hard");
1641
1642 /*
1643 * By default, do not inherit stdin from the parent process - otherwise,
1644 * all children would share stdin! Users may overwrite this to provide
1645 * something to the child's stdin by having their 'get_next_task'
1646 * callback assign 0 to .no_stdin and an appropriate integer to .in.
1647 */
1648 pp->children[i].process.no_stdin = 1;
1649
1650 code = opts->get_next_task(&pp->children[i].process,
1651 opts->ungroup ? NULL : &pp->children[i].err,
1652 opts->data,
1653 &pp->children[i].data);
1654 if (!code) {
1655 if (!opts->ungroup) {
1656 strbuf_addbuf(&pp->buffered_output, &pp->children[i].err);
1657 strbuf_reset(&pp->children[i].err);
1658 }
1659 return 1;
1660 }
1661 if (!opts->ungroup) {
1662 pp->children[i].process.err = -1;
1663 pp->children[i].process.stdout_to_stderr = 1;
1664 }
1665
1666 if (start_command(&pp->children[i].process)) {
1667 if (opts->start_failure)
1668 code = opts->start_failure(opts->ungroup ? NULL :
1669 &pp->children[i].err,
1670 opts->data,
1671 pp->children[i].data);
1672 else
1673 code = 0;
1674
1675 if (!opts->ungroup) {
1676 strbuf_addbuf(&pp->buffered_output, &pp->children[i].err);
1677 strbuf_reset(&pp->children[i].err);
1678 }
1679 if (code)
1680 pp->shutdown = 1;
1681 return code;
1682 }
1683
1684 pp->nr_processes++;
1685 pp->children[i].state = GIT_CP_WORKING;
1686 if (pp->pfd)
1687 pp->pfd[i].fd = pp->children[i].process.err;

Callers 1

run_processes_parallelFunction · 0.85

Calls 2

strbuf_addbufFunction · 0.85
start_commandFunction · 0.85

Tested by

no test coverage detected