{"thread":{"id":"66895","subject":"[PATCH] submodule--helper: check 'update --jobs' like submodule.fetchJobs","startedAt":"2026-11-20T11:32:33Z","lastAt":"2026-11-20T11:32:33Z","messageCount":1,"participants":["Abhishek Agarwal"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"558920","messageId":"20261120113233.783523-1-agab0323@gmail.com","threadId":"66895","inReplyTo":null,"subject":"[PATCH] submodule--helper: check 'update --jobs' like submodule.fetchJobs","fromName":"Abhishek Agarwal","fromEmail":"agab0323@gmail.com","sentAt":"2026-11-20T11:32:33Z","receivedAt":"2026-11-20T11:32:33Z","isPatch":true,"sender":{"key":"agab0323@gmail.com","avatar":null},"body":"\"git submodule update --jobs=0\" aborts:\n\n    $ git submodule update --jobs=0\n    BUG: run-command.c:1574: you must provide a non-zero number of processes!\n\n\"git clone --recurse-submodules --jobs=0\" passes the value on to it\nand aborts the same way. A negative value fails with a confusing\nmessage:\n\n    $ git submodule update --jobs=-1\n    fatal: data too large to fit into virtual memory space\n\nBefore 51243f9f0f (run-command API: don't fall back on online_cpus(),\n2022-10-12), run_processes_parallel() turned any value below 1 into\nonline_cpus(). That commit made 0 a BUG() and moved the fallback into\nthe parsers of fetch.parallel and submodule.fetchJobs, which already\ndie on a negative value. The list of callers in the commit before it,\n6a48b428b4 (run-command API: make \"n\" parameter a \"size_t\",\n2022-10-12), describes \"submodule update\" only as a reader of\nsubmodule.fetchJobs. But its \"--jobs\" option is read with\nOPT_INTEGER() after the configuration and is used as is.\n\nc39952b925 (fetch: choose a sensible default with --jobs=0 again,\n2023-02-20) fixed the same problem for \"git fetch --jobs=0\". Do the\nsame here and use online_cpus() for 0. Also die on a negative value,\nas parse_submodule_fetchjobs() does for the variable. Negative values\nmeant online_cpus() too before v2.39, but they have failed since\nthen, and rejecting them keeps the option and the variable in\nagreement.\n\nThe documentation of --jobs in git-submodule(1) and git-clone(1)\nonly says that it defaults to submodule.fetchJobs. Say what 0 means,\nwith the wording used for \"git fetch --jobs\".\n\nSigned-off-by: Abhishek Agarwal <agab0323@gmail.com>\n---\n Documentation/git-clone.adoc     |  1 +\n Documentation/git-submodule.adoc |  1 +\n builtin/submodule--helper.c      |  6 ++++++\n t/t7406-submodule-update.sh      | 20 ++++++++++++++++++++\n 4 files changed, 28 insertions(+)\n\ndiff --git a/Documentation/git-clone.adoc b/Documentation/git-clone.adoc\nindex dd3b44817a..a64084488c 100644\n--- a/Documentation/git-clone.adoc\n+++ b/Documentation/git-clone.adoc\n@@ -375,6 +375,7 @@ repository uses a non-default object storage.\n `--jobs=<n>`::\n \tThe number of submodules fetched at the same time.\n \tDefaults to the `submodule.fetchJobs` option.\n+\tA value of 0 will use some reasonable default.\n \n _<repository>_::\n \tThe (possibly remote) _<repository>_ to clone from.  See the\ndiff --git a/Documentation/git-submodule.adoc b/Documentation/git-submodule.adoc\nindex 57a21bc8d9..8abeb69cb2 100644\n--- a/Documentation/git-submodule.adoc\n+++ b/Documentation/git-submodule.adoc\n@@ -465,6 +465,7 @@ NOTE: See the NOTE above for the `--reference` option.\n \tClone new submodules in parallel with _<n>_ jobs.\n \tThis option is only valid for the `update` command.\n \tDefaults to the `submodule.fetchJobs` option.\n+\tA value of 0 will use some reasonable default.\n \n `--single-branch`::\n `--no-single-branch`::\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 461b682d0d..e06a724ad9 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -37,6 +37,7 @@\n #include \"wildmatch.h\"\n #include \"strbuf.h\"\n #include \"url.h\"\n+#include \"thread-utils.h\"\n \n #define OPT_QUIET (1 << 0)\n #define OPT_CACHED (1 << 1)\n@@ -3079,6 +3080,11 @@ static int module_update(int argc, const char **argv, const char *prefix,\n \targc = parse_options(argc, argv, prefix, module_update_options,\n \t\t\t     git_submodule_helper_usage, 0);\n \n+\tif (opt.max_jobs < 0)\n+\t\tdie(_(\"'%s' cannot be negative\"), \"--jobs\");\n+\tif (!opt.max_jobs)\n+\t\topt.max_jobs = online_cpus();\n+\n \tif (opt.require_init)\n \t\topt.init = 1;\n \ndiff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh\nindex 10adeabf0f..2b5551044a 100755\n--- a/t/t7406-submodule-update.sh\n+++ b/t/t7406-submodule-update.sh\n@@ -1096,6 +1096,26 @@ test_expect_success 'git clone passes the parallel jobs config on to submodules'\n \trm -rf super4\n '\n \n+test_expect_success 'submodule update --jobs 0 uses the number of CPUs' '\n+\ttest_when_finished \"rm -rf super5 trace-jobs.out\" &&\n+\tgit clone cloned super5 &&\n+\tGIT_TRACE=\"$(pwd)/trace-jobs.out\" \\\n+\t\tgit -C super5 -c submodule.fetchJobs=1 submodule update --init --jobs 0 &&\n+\ttest_grep \"up to $(test-tool online-cpus) tasks\" trace-jobs.out\n+'\n+\n+test_expect_success 'submodule update rejects a negative --jobs' '\n+\ttest_must_fail git -C super2 submodule update --jobs -1 2>err &&\n+\ttest_grep \"${SQ}--jobs${SQ} cannot be negative\" err\n+'\n+\n+test_expect_success 'git clone --recurse-submodules --jobs 0 uses the number of CPUs' '\n+\ttest_when_finished \"rm -rf super5 trace-jobs.out\" &&\n+\tGIT_TRACE=\"$(pwd)/trace-jobs.out\" \\\n+\t\tgit -c submodule.fetchJobs=1 clone --recurse-submodules --jobs 0 . super5 &&\n+\ttest_grep \"up to $(test-tool online-cpus) tasks\" trace-jobs.out\n+'\n+\n test_expect_success 'submodule update --quiet passes quietness to merge/rebase' '\n \t(cd super &&\n \t test_commit -C rebasing message &&\n-- \n2.56.0\n\n\n"}]}