Git development
 help / color / mirror / Atom feed
* [PATCH] submodule--helper: check 'update --jobs' like submodule.fetchJobs
@ 2026-11-20 11:32 Abhishek Agarwal
  2026-11-25  7:31 ` Jacob Keller
  2026-11-25 20:37 ` Junio C Hamano
  0 siblings, 2 replies; 3+ messages 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] 3+ messages in thread

* Re: [PATCH] submodule--helper: check 'update --jobs' like submodule.fetchJobs
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Jacob Keller @ 2026-11-25  7:31 UTC (permalink / raw)
  To: Abhishek Agarwal
  Cc: git, Junio C Hamano, Patrick Steinhardt, Matthias Aßhauer

On Fri, Nov 20, 2026 at 3:34 AM Abhishek Agarwal <agab0323@gmail.com> wrote:
>
> "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>
> ---

People might disagree on what "a reasonable number of jobs" means and
not like it being equivalent to the number of CPUs, but its the same
text as git fetch and I think it is an ok enough default (and often
the expected kind of behavior from other software).

Reviewed-by: Jacob Keller <jacob.keller@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	[flat|nested] 3+ messages in thread

* Re: [PATCH] submodule--helper: check 'update --jobs' like submodule.fetchJobs
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2026-11-25 20:37 UTC (permalink / raw)
  To: Abhishek Agarwal
  Cc: git, Patrick Steinhardt, Jacob Keller, Matthias Aßhauer

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-25 20:37 UTC | newest]

Thread overview: 3+ messages (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
2026-11-25  7:31 ` Jacob Keller
2026-11-25 20:37 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox