submodule--helper: check 'update --jobs' like submodule.fetchJobs
PATCH 1/1 submodule--helper: check 'update --jobs' like submodule.fetchJobs
"git submodule update --jobs=0" aborts:
$ git submodule update --jobs=0
BUG: run-command.c:1574: you must provide a non-zero number of processes!"git clone --recurse-submodules --jobs=0" passes the value on to it and aborts the same way. A negative value fails with a confusing message:
$ git submodule update --jobs=-1
fatal: data too large to fit into virtual memory spaceBefore 51243f9f0f (run-command API: don't fall back on online_cpus(), 2022-10-12), run_processes_parallel() turned any value below 1 into online_cpus(). That commit made 0 a BUG() and moved the fallback into the parsers of fetch.parallel and submodule.fetchJobs, which already die on a negative value. The list of callers in the commit before it, 6a48b428b4 (run-command API: make "n" parameter a "size_t", 2022-10-12), describes "submodule update" only as a reader of submodule.fetchJobs. But its "--jobs" option is read with OPT_INTEGER() after the configuration and is used as is.
c39952b925 (fetch: choose a sensible default with --jobs=0 again, 2023-02-20) fixed the same problem for "git fetch --jobs=0". Do the same here and use online_cpus() for 0. Also die on a negative value, as parse_submodule_fetchjobs() does for the variable. Negative values meant online_cpus() too before v2.39, but they have failed since then, and rejecting them keeps the option and the variable in agreement.
The documentation of --jobs in git-submodule(1) and git-clone(1) only says that it defaults to submodule.fetchJobs. Say what 0 means, with the wording used for "git fetch --jobs".
--- Documentation/git-clone.adoc | 1 + Documentation/git-submodule.adoc | 1 + builtin/submodule--helper.c | 6 ++++++ t/t7406-submodule-update.sh | 20 ++++++++++++++++++++ 4 files changed, 28 insertions(+)
Documentation/git-clone.adoc +1 -0
@@ -375,6 +375,7 @@ repository uses a non-default object storage. `--jobs=<n>`:: The number of submodules fetched at the same time. Defaults to the `submodule.fetchJobs` option. + A value of 0 will use some reasonable default. _<repository>_:: The (possibly remote) _<repository>_ to clone from. See the
Documentation/git-submodule.adoc +1 -0
@@ -465,6 +465,7 @@ NOTE: See the NOTE above for the `--reference` option. Clone new submodules in parallel with _<n>_ jobs. This option is only valid for the `update` command. Defaults to the `submodule.fetchJobs` option. + A value of 0 will use some reasonable default. `--single-branch`:: `--no-single-branch`::
builtin/submodule--helper.c +6 -0
@@ -37,6 +37,7 @@#include "wildmatch.h" #include "strbuf.h" #include "url.h" +#include "thread-utils.h" #define OPT_QUIET (1 << 0)#define OPT_CACHED (1 << 1)
@@ -3079,6 +3080,11 @@ static int module_update(int argc, const char **argv, const char *prefix, argc =parse_options (argc, argv, prefix, module_update_options, git_submodule_helper_usage,0 ); +if (opt.max_jobs <0 ) +die (_ ("'%s' cannot be negative" ),"--jobs" ); +if (!opt.max_jobs) + opt.max_jobs =online_cpus (); +if (opt.require_init) opt.init =1 ;
t/t7406-submodule-update.sh +20 -0
@@ -1096,6 +1096,26 @@ test_expect_success 'git clone passes the parallel jobs config on to submodules' rm -rf super4 ' +test_expect_success 'submodule update --jobs 0 uses the number of CPUs' ' + test_when_finished "rm -rf super5 trace-jobs.out" && + git clone cloned super5 && + GIT_TRACE="$(pwd)/trace-jobs.out" \ + git -C super5 -c submodule.fetchJobs=1 submodule update --init --jobs 0 && + test_grep "up to $(test-tool online-cpus) tasks" trace-jobs.out +' + +test_expect_success 'submodule update rejects a negative --jobs' ' + test_must_fail git -C super2 submodule update --jobs -1 2>err && + test_grep "${SQ}--jobs${SQ} cannot be negative" err +' + +test_expect_success 'git clone --recurse-submodules --jobs 0 uses the number of CPUs' ' + test_when_finished "rm -rf super5 trace-jobs.out" && + GIT_TRACE="$(pwd)/trace-jobs.out" \ + git -c submodule.fetchJobs=1 clone --recurse-submodules --jobs 0 . super5 && + test_grep "up to $(test-tool online-cpus) tasks" trace-jobs.out +' + test_expect_success 'submodule update --quiet passes quietness to merge/rebase' ' (cd super && test_commit -C rebasing message &&
Signature · 1 line
2.56.0