From: Junio C Hamano <gitster@pobox.com>
To: Abhishek Agarwal <agab0323@gmail.com>
Cc: git@vger.kernel.org, "Patrick Steinhardt" <ps@pks.im>,
"Jacob Keller" <jacob.keller@gmail.com>,
"Matthias Aßhauer" <mha1993@live.de>
Subject: Re: [PATCH] submodule--helper: check 'update --jobs' like submodule.fetchJobs
Date: Wed, 25 Nov 2026 12:37:38 -0800 [thread overview]
Message-ID: <xmqqtsl4zlyl.fsf@gitster.g> (raw)
In-Reply-To: <20261120113233.783523-1-agab0323@gmail.com> (Abhishek Agarwal's message of "Fri, 20 Nov 2026 17:02:33 +0530")
Abhishek Agarwal <agab0323@gmail.com> writes:
> "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
Ouch.
> 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.
Good archeology. builtin/submodule--helper.c:module_update() does:
update_clone_config_from_gitmodules(the_repository, &opt.max_jobs);
repo_config(the_repository, git_update_clone_config, &opt.max_jobs);
argc = parse_options(argc, argv, prefix, module_update_options,
git_submodule_helper_usage, 0);
Both update_clone_config_from_gitmodules() and git_update_clone_config()
calls down to parse_submodule_fetchjobs() to parse these values and barf
on negative settings, way before parse_options() has a chance to kick in.
Also "--jobs" parsed by parse_options() is not validated for zero or
negative values.
> 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.
As the proposed commit log message said, this is deliberately left
vague, but matches how "git fetch --jobs" is described, which is good.
> 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.
Likewise.
> 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"
Hmph, we need this for online_cpus(), OK.
> @@ -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();
> +
So this makes sure that negative and zero inputs are reacted to
appropriately.
One related thing I noticed is that builtin/clone.c:cmd_clone() forwards
the --jobs=<n> to recursive submodule update only when max_jobs != -1
because -1 is used as a sign that nobody set an explicit value to it.
So --jobs=-1 in 'git clone --recurse-submodules --jobs=-1' is ignored
silently (because it is not passed down) but --jobs=-2 would be passed
to 'submodule update' and will be caught by the above check. 'fetch'
might have a similar issue around this (I didn't check).
If anybody cares, it may want to be addressed after the dust settles
(#leftoverbits).
Looking good. Thanks.
prev parent reply other threads:[~2026-11-25 20:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 11:32 [PATCH] submodule--helper: check 'update --jobs' like submodule.fetchJobs Abhishek Agarwal
2026-11-25 7:31 ` Jacob Keller
2026-11-25 20:37 ` Junio C Hamano [this message]
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=xmqqtsl4zlyl.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=agab0323@gmail.com \
--cc=git@vger.kernel.org \
--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