{"thread":{"id":"66973","subject":"[PATCH 0/2] clone, fetch: reject a negative --jobs","startedAt":"2026-12-02T17:13:26Z","lastAt":"2026-12-03T09:56:08Z","messageCount":5,"participants":["Abhishek Agarwal","Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"559902","messageId":"20261202171328.805150-1-agab0323@gmail.com","threadId":"66973","inReplyTo":null,"subject":"[PATCH 0/2] clone, fetch: reject a negative --jobs","fromName":"Abhishek Agarwal","fromEmail":"agab0323@gmail.com","sentAt":"2026-12-02T17:13:26Z","receivedAt":"2026-12-02T17:13:26Z","isPatch":true,"sender":{"key":"agab0323@gmail.com","avatar":null},"body":"In the review of aa/submodule-update-jobs [1], Junio pointed out that\n\"git clone --recurse-submodules --jobs=-1\" is ignored without a word,\nbecause clone uses -1 to mean \"not given\" and does not pass it on,\nwhile \"--jobs=-2\" is passed on and only rejected by \"submodule update\"\nafter the clone is done. He wondered if \"fetch\" has a similar issue.\nIt does: \"git fetch\" and \"git pull\" treat any negative \"--jobs\" as if\nthe option was not given.\n\nThese two patches make both commands reject a negative value while\nthe command line is parsed, with the same message \"submodule update\"\nnow gives. The series is built on top of aa/submodule-update-jobs,\nbecause the first patch adds its test next to the tests from that\ntopic.\n\nTwo things I was not sure about:\n\n - Both patches add the same small callback. I kept a copy in each\n   command so that the two stay independent, but I can move it to\n   parse-options-cb.c if that is preferred.\n\n - \"git hook run -j-1\" uses -1 to mean \"all CPUs\" (495b7d54dc). I did\n   not do that here, because the configuration variables clone and\n   fetch fall back to (submodule.fetchJobs and fetch.parallel) reject\n   negative values and use 0 for \"all CPUs\", and so does \"submodule\n   update --jobs\" after the topic above.\n\n[1] https://lore.kernel.org/git/xmqqtsl4zlyl.fsf@gitster.g/\n\nAbhishek Agarwal (2):\n  clone: reject a negative --jobs before cloning\n  fetch: reject a negative --jobs\n\n builtin/clone.c             | 18 ++++++++++++++++--\n builtin/fetch.c             | 18 ++++++++++++++++--\n t/t5514-fetch-multiple.sh   |  8 ++++++++\n t/t7406-submodule-update.sh | 10 ++++++++++\n 4 files changed, 50 insertions(+), 4 deletions(-)\n\n\nbase-commit: 5d6ad3960bf5d6e577b706d8c642429b504b065d\n-- \n2.56.0\n\n\n"},{"id":"559903","messageId":"20261202171328.805150-2-agab0323@gmail.com","threadId":"66973","inReplyTo":"20261202171328.805150-1-agab0323@gmail.com","subject":"[PATCH 1/2] clone: reject a negative --jobs before cloning","fromName":"Abhishek Agarwal","fromEmail":"agab0323@gmail.com","sentAt":"2026-12-02T17:13:27Z","receivedAt":"2026-12-02T17:13:27Z","isPatch":true,"sender":{"key":"agab0323@gmail.com","avatar":null},"body":"\"git clone --recurse-submodules --jobs=<n>\" passes \"--jobs=<n>\" on to\n\"git submodule update\", but only when <n> is not -1, because max_jobs\nstarts at -1 to mean that the option was not given. So \"--jobs=-1\" is\ndropped without a word and the submodules are fetched with the default\nnumber of jobs, while \"--jobs=-2\" is passed on and rejected by\n\"submodule update\". That happens only after the superproject has been\ncloned, so the user waits for the whole clone and is left with one\nwhose submodules are not checked out.\n\nParse the option with a callback that rejects a negative value, like\n\"git submodule update --jobs\" and \"submodule.fetchJobs\" already do.\nThe error now comes before anything is cloned, and -1 can again only\nmean that the option was not given. \"--no-jobs\" still means the same\nas \"--jobs=0\". A value that is not a number is still rejected, now\nwith the \"invalid value for\" message that other options already use.\n\nReported-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Abhishek Agarwal <agab0323@gmail.com>\n---\n builtin/clone.c             | 18 ++++++++++++++++--\n t/t7406-submodule-update.sh | 10 ++++++++++\n 2 files changed, 26 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex ac40250d25..f9ecbede1b 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -94,6 +94,19 @@ static int recurse_submodules_cb(const struct option *opt,\n \treturn 0;\n }\n \n+static int parse_jobs_cb(const struct option *opt, const char *arg, int unset)\n+{\n+\tint *jobs = opt->value;\n+\n+\tif (unset)\n+\t\t*jobs = 0;\n+\telse if (!git_parse_int(arg, jobs))\n+\t\treturn error(_(\"invalid value for '%s': '%s'\"), \"--jobs\", arg);\n+\telse if (*jobs < 0)\n+\t\treturn error(_(\"'%s' cannot be negative\"), \"--jobs\");\n+\treturn 0;\n+}\n+\n static const char *get_repo_path_1(struct strbuf *path, int *is_bundle)\n {\n \tstatic const char *suffix[] = { \"/.git\", \"\", \".git/.git\", \".git\" };\n@@ -949,8 +962,9 @@ int cmd_clone(int argc,\n \t\t\t.defval = (intptr_t)\".\",\n \t\t},\n \t\tOPT_ALIAS(0, \"recursive\", \"recurse-submodules\"),\n-\t\tOPT_INTEGER('j', \"jobs\", &max_jobs,\n-\t\t\t    N_(\"number of submodules cloned in parallel\")),\n+\t\tOPT_CALLBACK('j', \"jobs\", &max_jobs, N_(\"n\"),\n+\t\t\t     N_(\"number of submodules cloned in parallel\"),\n+\t\t\t     parse_jobs_cb),\n \t\tOPT_STRING(0, \"template\", &option_template, N_(\"template-directory\"),\n \t\t\t   N_(\"directory from which templates will be used\")),\n \t\tOPT_STRING_LIST(0, \"reference\", &option_required_reference, N_(\"repo\"),\ndiff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh\nindex 2b5551044a..7a440709aa 100755\n--- a/t/t7406-submodule-update.sh\n+++ b/t/t7406-submodule-update.sh\n@@ -1116,6 +1116,16 @@ test_expect_success 'git clone --recurse-submodules --jobs 0 uses the number of\n \ttest_grep \"up to $(test-tool online-cpus) tasks\" trace-jobs.out\n '\n \n+test_expect_success 'git clone --recurse-submodules rejects a negative --jobs' '\n+\ttest_when_finished \"rm -rf super6\" &&\n+\tfor jobs in -1 -2\n+\tdo\n+\t\ttest_must_fail git clone --recurse-submodules --jobs $jobs . super6 2>err &&\n+\t\ttest_grep \"${SQ}--jobs${SQ} cannot be negative\" err &&\n+\t\ttest_path_is_missing super6 || return 1\n+\tdone\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"},{"id":"559904","messageId":"20261202171328.805150-3-agab0323@gmail.com","threadId":"66973","inReplyTo":"20261202171328.805150-1-agab0323@gmail.com","subject":"[PATCH 2/2] fetch: reject a negative --jobs","fromName":"Abhishek Agarwal","fromEmail":"agab0323@gmail.com","sentAt":"2026-12-02T17:13:28Z","receivedAt":"2026-12-02T17:13:28Z","isPatch":true,"sender":{"key":"agab0323@gmail.com","avatar":null},"body":"\"git fetch\" starts max_jobs at -1 to mean that \"--jobs\" was not given,\nand both places that use it, fetching from several remotes and\nfetching submodules, replace any negative value with \"fetch.parallel\"\nor \"submodule.fetchJobs\", or with one job when neither is set. So\n\"--jobs=-1\", \"--jobs=-5\" and the like are accepted without a word,\neven though both of those configuration variables reject a negative\nvalue. \"git pull\" passes \"--jobs\" on to \"git fetch\" and behaves the\nsame way.\n\nParse the option with the same callback the previous commit added to\n\"git clone\", so that a negative value is rejected while the command\nline is parsed. \"--no-jobs\" still means the same as \"--jobs=0\".\n\nSigned-off-by: Abhishek Agarwal <agab0323@gmail.com>\n---\n builtin/fetch.c           | 18 ++++++++++++++++--\n t/t5514-fetch-multiple.sh |  8 ++++++++\n 2 files changed, 24 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 533fdfe7d8..12140f6a87 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -207,6 +207,19 @@ static int parse_refmap_arg(const struct option *opt, const char *arg, int unset\n \treturn 0;\n }\n \n+static int parse_jobs_cb(const struct option *opt, const char *arg, int unset)\n+{\n+\tint *jobs = opt->value;\n+\n+\tif (unset)\n+\t\t*jobs = 0;\n+\telse if (!git_parse_int(arg, jobs))\n+\t\treturn error(_(\"invalid value for '%s': '%s'\"), \"--jobs\", arg);\n+\telse if (*jobs < 0)\n+\t\treturn error(_(\"'%s' cannot be negative\"), \"--jobs\");\n+\treturn 0;\n+}\n+\n static void unlock_pack(unsigned int flags)\n {\n \tif (gtransport)\n@@ -2555,8 +2568,9 @@ int cmd_fetch(int argc,\n \t\t\t    N_(\"fetch all tags and associated objects\"), TAGS_SET),\n \t\tOPT_SET_INT('n', NULL, &tags,\n \t\t\t    N_(\"do not fetch all tags (--no-tags)\"), TAGS_UNSET),\n-\t\tOPT_INTEGER('j', \"jobs\", &max_jobs,\n-\t\t\t    N_(\"number of submodules fetched in parallel\")),\n+\t\tOPT_CALLBACK('j', \"jobs\", &max_jobs, N_(\"n\"),\n+\t\t\t     N_(\"number of submodules fetched in parallel\"),\n+\t\t\t     parse_jobs_cb),\n \t\tOPT_BOOL(0, \"prefetch\", &prefetch,\n \t\t\t N_(\"modify the refspec to place all refs within refs/prefetch/\")),\n \t\tOPT_BOOL('p', \"prune\", &prune,\ndiff --git a/t/t5514-fetch-multiple.sh b/t/t5514-fetch-multiple.sh\nindex 5d79472c39..85c2da185c 100755\n--- a/t/t5514-fetch-multiple.sh\n+++ b/t/t5514-fetch-multiple.sh\n@@ -227,6 +227,14 @@ test_expect_success 'git fetch --multiple --jobs=0 picks a default' '\n \t git fetch --multiple --jobs=0)\n '\n \n+test_expect_success 'git fetch rejects a negative --jobs' '\n+\tfor jobs in -1 -2\n+\tdo\n+\t\ttest_must_fail git -C test fetch --multiple --jobs=$jobs 2>err &&\n+\t\ttest_grep \"${SQ}--jobs${SQ} cannot be negative\" err || return 1\n+\tdone\n+'\n+\n create_fetch_all_expect () {\n \tcat >expect <<-\\EOF\n \t  one/HEAD -> one/main\n-- \n2.56.0\n\n\n"},{"id":"559956","messageId":"axE8s0A8snwyvyX9@pks.im","threadId":"66973","inReplyTo":"20261202171328.805150-2-agab0323@gmail.com","subject":"Re: [PATCH 1/2] clone: reject a negative --jobs before cloning","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-12-03T09:56:03Z","receivedAt":"2026-12-03T09:56:03Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Wed, Dec 02, 2026 at 10:43:27PM +0530, Abhishek Agarwal wrote:\n> diff --git a/builtin/clone.c b/builtin/clone.c\n> index ac40250d25..f9ecbede1b 100644\n> --- a/builtin/clone.c\n> +++ b/builtin/clone.c\n> @@ -94,6 +94,19 @@ static int recurse_submodules_cb(const struct option *opt,\n>  \treturn 0;\n>  }\n>  \n> +static int parse_jobs_cb(const struct option *opt, const char *arg, int unset)\n> +{\n> +\tint *jobs = opt->value;\n> +\n> +\tif (unset)\n> +\t\t*jobs = 0;\n> +\telse if (!git_parse_int(arg, jobs))\n> +\t\treturn error(_(\"invalid value for '%s': '%s'\"), \"--jobs\", arg);\n> +\telse if (*jobs < 0)\n> +\t\treturn error(_(\"'%s' cannot be negative\"), \"--jobs\");\n> +\treturn 0;\n> +}\n> +\n>  static const char *get_repo_path_1(struct strbuf *path, int *is_bundle)\n>  {\n>  \tstatic const char *suffix[] = { \"/.git\", \"\", \".git/.git\", \".git\" };\n> @@ -949,8 +962,9 @@ int cmd_clone(int argc,\n>  \t\t\t.defval = (intptr_t)\".\",\n>  \t\t},\n>  \t\tOPT_ALIAS(0, \"recursive\", \"recurse-submodules\"),\n> -\t\tOPT_INTEGER('j', \"jobs\", &max_jobs,\n> -\t\t\t    N_(\"number of submodules cloned in parallel\")),\n> +\t\tOPT_CALLBACK('j', \"jobs\", &max_jobs, N_(\"n\"),\n> +\t\t\t     N_(\"number of submodules cloned in parallel\"),\n> +\t\t\t     parse_jobs_cb),\n\nDoes this really warrant `OPT_CALLBACK()`? Can't we use `OPT_UNSIGNED()`\ninstead?\n\nWell, the answer is \"not trivially\" because of the sentinel value, which\nis \"-1\". But we could convert `max_jobs` to an unsigned value and use a\nsentinel value of `UINT_MAX`. I don't think anyone would ever configure\na maximum job count of multiple billions of jobs, so that might be an\nalternative that requires less plumbing overall.\n\nThe status quo isn't all that bad either, though, so I'll leave it up to\nyou to decide whether you want to take this suggestion.\n\n> diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh\n> index 2b5551044a..7a440709aa 100755\n> --- a/t/t7406-submodule-update.sh\n> +++ b/t/t7406-submodule-update.sh\n> @@ -1116,6 +1116,16 @@ test_expect_success 'git clone --recurse-submodules --jobs 0 uses the number of\n>  \ttest_grep \"up to $(test-tool online-cpus) tasks\" trace-jobs.out\n>  '\n>  \n> +test_expect_success 'git clone --recurse-submodules rejects a negative --jobs' '\n> +\ttest_when_finished \"rm -rf super6\" &&\n> +\tfor jobs in -1 -2\n> +\tdo\n> +\t\ttest_must_fail git clone --recurse-submodules --jobs $jobs . super6 2>err &&\n> +\t\ttest_grep \"${SQ}--jobs${SQ} cannot be negative\" err &&\n> +\t\ttest_path_is_missing super6 || return 1\n> +\tdone\n> +'\n\nOkay, and here you cover both of the different failure scenarios that\nyou mention in the commit message. Makes sense.\n\nPatrick\n\n"},{"id":"559957","messageId":"axE8uP_wHC4p70YC@pks.im","threadId":"66973","inReplyTo":"20261202171328.805150-3-agab0323@gmail.com","subject":"Re: [PATCH 2/2] fetch: reject a negative --jobs","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-12-03T09:56:08Z","receivedAt":"2026-12-03T09:56:08Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Wed, Dec 02, 2026 at 10:43:28PM +0530, Abhishek Agarwal wrote:\n> diff --git a/builtin/fetch.c b/builtin/fetch.c\n> index 533fdfe7d8..12140f6a87 100644\n> --- a/builtin/fetch.c\n> +++ b/builtin/fetch.c\n> @@ -207,6 +207,19 @@ static int parse_refmap_arg(const struct option *opt, const char *arg, int unset\n>  \treturn 0;\n>  }\n>  \n> +static int parse_jobs_cb(const struct option *opt, const char *arg, int unset)\n> +{\n> +\tint *jobs = opt->value;\n> +\n> +\tif (unset)\n> +\t\t*jobs = 0;\n> +\telse if (!git_parse_int(arg, jobs))\n> +\t\treturn error(_(\"invalid value for '%s': '%s'\"), \"--jobs\", arg);\n> +\telse if (*jobs < 0)\n> +\t\treturn error(_(\"'%s' cannot be negative\"), \"--jobs\");\n> +\treturn 0;\n> +}\n> +\n>  static void unlock_pack(unsigned int flags)\n>  {\n>  \tif (gtransport)\n> @@ -2555,8 +2568,9 @@ int cmd_fetch(int argc,\n>  \t\t\t    N_(\"fetch all tags and associated objects\"), TAGS_SET),\n>  \t\tOPT_SET_INT('n', NULL, &tags,\n>  \t\t\t    N_(\"do not fetch all tags (--no-tags)\"), TAGS_UNSET),\n> -\t\tOPT_INTEGER('j', \"jobs\", &max_jobs,\n> -\t\t\t    N_(\"number of submodules fetched in parallel\")),\n> +\t\tOPT_CALLBACK('j', \"jobs\", &max_jobs, N_(\"n\"),\n> +\t\t\t     N_(\"number of submodules fetched in parallel\"),\n> +\t\t\t     parse_jobs_cb),\n>  \t\tOPT_BOOL(0, \"prefetch\", &prefetch,\n>  \t\t\t N_(\"modify the refspec to place all refs within refs/prefetch/\")),\n>  \t\tOPT_BOOL('p', \"prune\", &prune,\n\nAnd this is essentially the equivalent change, just for git-fetch(1).\nThe same suggestion as for git-clone(1) applies here of course.\n\nOverall, these changes look good to me though, thanks!\n\nPatrick\n\n"}]}