From: Abhishek Agarwal <agab0323@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Patrick Steinhardt" <ps@pks.im>,
"Jacob Keller" <jacob.keller@gmail.com>,
"Matthias Aßhauer" <mha1993@live.de>
Subject: [PATCH] submodule--helper: check 'update --jobs' like submodule.fetchJobs
Date: Fri, 20 Nov 2026 17:02:33 +0530 [thread overview]
Message-ID: <20261120113233.783523-1-agab0323@gmail.com> (raw)
"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
reply other threads:[~2026-11-20 11:34 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120113233.783523-1-agab0323@gmail.com \
--to=agab0323@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jacob.keller@gmail.com \
--cc=mha1993@live.de \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox