* [PATCH] submodule--helper: check 'update --jobs' like submodule.fetchJobs
@ 2026-11-20 11:32 Abhishek Agarwal
0 siblings, 0 replies; only message in thread
From: Abhishek Agarwal @ 2026-11-20 11:32 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Jacob Keller,
Matthias Aßhauer
"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 space
Before 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".
Signed-off-by: Abhishek Agarwal <agab0323@gmail.com>
---
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(+)
diff --git a/Documentation/git-clone.adoc b/Documentation/git-clone.adoc
index dd3b44817a..a64084488c 100644
--- a/Documentation/git-clone.adoc
+++ b/Documentation/git-clone.adoc
@@ -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
diff --git a/Documentation/git-submodule.adoc b/Documentation/git-submodule.adoc
index 57a21bc8d9..8abeb69cb2 100644
--- a/Documentation/git-submodule.adoc
+++ b/Documentation/git-submodule.adoc
@@ -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`::
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 461b682d0d..e06a724ad9 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -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;
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 10adeabf0f..2b5551044a 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -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 &&
--
2.56.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-20 11:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 11:32 [PATCH] submodule--helper: check 'update --jobs' like submodule.fetchJobs Abhishek Agarwal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox