Skip to content

Commit 51243f9

Browse files
avargitster
authored andcommitted
run-command API: don't fall back on online_cpus()
When a "jobs = 0" is passed let's BUG() out rather than fall back on online_cpus(). The default behavior was added when this API was implemented in c553c72 (run-command: add an asynchronous parallel child processor, 2015-12-15). Most of our code in-tree that scales up to "online_cpus()" by default calls that function by itself. Keeping this default behavior just for the sake of two callers means that we'd need to maintain this one spot where we're second-guessing the config passed down into pp_init(). The preceding commit has an overview of the API callers that passed "jobs = 0". There were only two of them (actually three, but they resolved to these two config parsing codepaths). The "fetch.parallel" caller already had a test for the "fetch.parallel=0" case added in 0353c68 (fetch: do not run a redundant fetch from submodule, 2022-05-16), but there was no such test for "submodule.fetchJobs". Let's add one here. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6a48b42 commit 51243f9

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

builtin/fetch.c

Lines changed: 2 additions & 0 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

run-command.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,8 +1564,8 @@ static void pp_init(struct parallel_processes *pp,
15641564
task_finished_fn task_finished,
15651565
void *data, int ungroup)
15661566
{
1567-
if (n < 1)
1568-
n = online_cpus();
1567+
if (!n)
1568+
BUG("you must provide a non-zero number of processes!");
15691569

15701570
pp->max_processes = n;
15711571

@@ -1835,8 +1835,7 @@ void run_processes_parallel_tr2(size_t n, get_next_task_fn get_next_task,
18351835
task_finished_fn task_finished, void *pp_cb,
18361836
const char *tr2_category, const char *tr2_label)
18371837
{
1838-
trace2_region_enter_printf(tr2_category, tr2_label, NULL, "max:%d",
1839-
((n < 1) ? online_cpus() : n));
1838+
trace2_region_enter_printf(tr2_category, tr2_label, NULL, "max:%d", n);
18401839

18411840
run_processes_parallel(n, get_next_task, start_failure,
18421841
task_finished, pp_cb);

submodule-config.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ int parse_submodule_fetchjobs(const char *var, const char *value)
303303
int fetchjobs = git_config_int(var, value);
304304
if (fetchjobs < 0)
305305
die(_("negative values not allowed for submodule.fetchJobs"));
306+
if (!fetchjobs)
307+
fetchjobs = online_cpus();
306308
return fetchjobs;
307309
}
308310

t/t5526-fetch-submodules.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,13 @@ test_expect_success 'fetching submodules respects parallel settings' '
714714
GIT_TRACE=$(pwd)/trace.out git fetch &&
715715
grep "8 tasks" trace.out &&
716716
GIT_TRACE=$(pwd)/trace.out git fetch --jobs 9 &&
717-
grep "9 tasks" trace.out
717+
grep "9 tasks" trace.out &&
718+
>trace.out &&
719+
720+
GIT_TRACE=$(pwd)/trace.out git -c submodule.fetchJobs=0 fetch &&
721+
grep "preparing to run up to [0-9]* tasks" trace.out &&
722+
! grep "up to 0 tasks" trace.out &&
723+
>trace.out
718724
)
719725
'
720726

0 commit comments

Comments
 (0)