From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796231733; b=FDiRt0yGFi8yV+utCD78sPTFUp+zsnUFXgzDd8kWQKL8P0O/dXLb1tZsWBOLKFniHLli PHuB8OL0DkvyNC2msei3cvKORySpbD+Jx8pHD3Bs3EnJ4QfOLm3e4UyW2A4/YUPRq2zZU uuF/TRJe5L0MGcdy5iXG//HOre1HdQ37uj2KPMhG7f9he4D+CytOC1pfC+cMuFYqSYia3 QpNNMSrdDPNsWwUlmqgsiPZ3Pn5tAdtENvhDZQ0FH22dFq1KIIZJE0xI2xp6RSWv0AiBo P0xbOUfUABdaNWRTn7cUtGhBajmwAl5M+YqKnzH39JrbMVVEHGcSHeIsju2XVAGMHeg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796231733; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=TZWpJfAIM/GyQ3eNF7V5Np3/3JXGQ2vgkZ85Ybg81SY=; b=haoI0H8xZzrBI/4HU1BOxDEuXMdUVkNqKh/239xTvK8c9VEf2vKJ7BQTRtC0t8FFmMDn m/ngiGJo8pEer6QFmazSuCcVByoxRiWtthNJKX4q5sJ37tZjZO6KR1ce8Ea6zYiW3Au/m rrYs6X2kOfokwLcdOhffIOczNA3acpjJPwQO52GdWZRtQH/vOD/wiG9y3aspBCtIwjqBC ZImelNNk/nutSgy9dLFTp5Sho65avOPTk2jdoY7+LSlB0U35MHVYAQ6PpwbhltSo3aaY6 V7uGUnu1XYapDEtXDionfNhkwVS0SbNqzcHTtYsm7xVUB3KLiTthcwCNu1vQAKJb96Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ntPpDosN; arc=none smtp.remote-ip=209.85.216.46 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87E30606A31A for ; Wed, 2 Dec 2026 17:15:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 87E30606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ntPpDosN Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-3b43d30822fso7168997a91.3 for ; Wed, 02 Dec 2026 09:15:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796231733; x=1796836533; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=TZWpJfAIM/GyQ3eNF7V5Np3/3JXGQ2vgkZ85Ybg81SY=; b=ntPpDosNmzfUOetawDprfHD/pTF4+5FAOehYkIAQDukmlN8i9z+fyAMffETGJlx96e ZvThE74lSEofcmydhDfcx55nHsgYTnXeEudFgQMWaGmMbun2fOco3dEFyHpJrF4ZIhnH qbk4BA81Hmod44GdM6CDH28VgUTRBhJ4zPzIOmsPG6FyfxnCH77PkxlIjO1QeXH7ylRm nop1pqmpb2CFY15zsI39sNSRB/b9yG16dnE8jDmcsXg5MURZTm3OthTEGalkLPwHgiaa DWVUX/kFh+0q6PLSBCN/zwFIH+2Z5KdWH02QS2McsSI6DUk4gvVoEhbqKgyKrjXs8BmQ 4bUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796231733; x=1796836533; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=TZWpJfAIM/GyQ3eNF7V5Np3/3JXGQ2vgkZ85Ybg81SY=; b=nZA6NSegQC4m8V9uUC++eLvl9qjSetQj+lV08byGXLqpZkHdkeu0yUxHUe3NI9Ef05 Lrh4d8o2ZbNP5qSUbmPL1mEKUCSw57uuY+EMKo09BzvbQMuBpb5JtdYcoDdAMu/PKGJn nqmgZX5TGcKLUnm8wa1TcjpZ0penbQBkL71O/gjfqqvnQj9D+bnPW/APNISb5JKO4XOa cZ9JJqnENbQHfc/kgEBxXLSD/uN1O5pQYibABlZUDUwxJpP6dEShFINzMKZo+5Q3cxx+ 4ucnMZQqNeYZh39JEoPn4LIYjgjG9jg1qnfIyn8x+RoqmCAbjliyqtG/zKaEGViOxv/v WvUQ== X-Gm-Message-State: APuU4Z+alezUKhflGmrZDiZvdiJ+IT0S3ltJbhxu5NnHZxwFnOk4f3LF 2bjL1v9FoYolOU9gCL9oIpdVmPrxNX/fY7awhDQZJ169aO9sTkogjyuWj9I+jQ== X-Gm-Gg: AZFdTZc2WrC9NwU2SbTE486Su7L3y0+mAV/9twiRv1xsCPeD8NU59GXOqrfnImE1sgH 5jQSoYcvXSRojPg0Eb0XJlDCmwvzwROPEtSnaWSfKAdSDUeo5JLmOmAwhftoOY2nijdd0mmaq7w tolSmzcUYK+OHhzQCFxwCU041xrDVvNDp2tYhfNQTFc09CiCngKe/uB0mfMiBvl6HwZknCu22j4 yyPjadp2NQmlJA/o6ktvSKBFREsTxAUHbXIMVYzo2mFjVW3PO239U28UhE41WRaB60TuteMPO5Z s0atytIrsPamgULiuMLs5PWkhtpuVLrbnPQc3R12Rk3t+qCCtLxs3lVpWemzacLNDTEyuMStxHZ n46KnM3nS9a/MeiwONp3xvq9Gs0+qZfSj9hSTS5QmeoxzW7mNtPYrayrACvkGXT+yTv+Z+vUZ8h hVJVR6aieHlPOVsvtVASRJvV3zySn2ai/uxjwRvG6fYPIOSfIXvn9v4gsKEprcp+dPQvmzfPdCn XdO3N1sygJi87K2IaPLbNLb5g70g96EQG9NB37dEk1aMW0bYKubFN1Ld88K3QKDF0xqhG9Pki/8 tILC+Nx2X8zn6lIbYKXj/disvfX9 X-Received: by 2002:a17:90b:2f8c:b0:39e:4c81:6c5f with SMTP id 98e67ed59e1d1-3b41c92c175mr38757723a91.26.1796231732697; Wed, 02 Dec 2026 09:15:32 -0800 (PST) Received: from aeron-host ([103.177.178.109]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5c7d7a6b5sm9970a91.14.2026.12.02.09.15.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 09:15:32 -0800 (PST) From: Abhishek Agarwal To: git@vger.kernel.org Cc: Junio C Hamano , Patrick Steinhardt , Jacob Keller , Adrian Ratiu Subject: [PATCH 2/2] fetch: reject a negative --jobs Date: Wed, 2 Dec 2026 22:43:28 +0530 Message-ID: <20261202171328.805150-3-agab0323@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261202171328.805150-1-agab0323@gmail.com> References: <20261202171328.805150-1-agab0323@gmail.com> X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit "git fetch" starts max_jobs at -1 to mean that "--jobs" was not given, and both places that use it, fetching from several remotes and fetching submodules, replace any negative value with "fetch.parallel" or "submodule.fetchJobs", or with one job when neither is set. So "--jobs=-1", "--jobs=-5" and the like are accepted without a word, even though both of those configuration variables reject a negative value. "git pull" passes "--jobs" on to "git fetch" and behaves the same way. Parse the option with the same callback the previous commit added to "git clone", so that a negative value is rejected while the command line is parsed. "--no-jobs" still means the same as "--jobs=0". Signed-off-by: Abhishek Agarwal --- builtin/fetch.c | 18 ++++++++++++++++-- t/t5514-fetch-multiple.sh | 8 ++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index 533fdfe7d8..12140f6a87 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -207,6 +207,19 @@ static int parse_refmap_arg(const struct option *opt, const char *arg, int unset return 0; } +static int parse_jobs_cb(const struct option *opt, const char *arg, int unset) +{ + int *jobs = opt->value; + + if (unset) + *jobs = 0; + else if (!git_parse_int(arg, jobs)) + return error(_("invalid value for '%s': '%s'"), "--jobs", arg); + else if (*jobs < 0) + return error(_("'%s' cannot be negative"), "--jobs"); + return 0; +} + static void unlock_pack(unsigned int flags) { if (gtransport) @@ -2555,8 +2568,9 @@ int cmd_fetch(int argc, N_("fetch all tags and associated objects"), TAGS_SET), OPT_SET_INT('n', NULL, &tags, N_("do not fetch all tags (--no-tags)"), TAGS_UNSET), - OPT_INTEGER('j', "jobs", &max_jobs, - N_("number of submodules fetched in parallel")), + OPT_CALLBACK('j', "jobs", &max_jobs, N_("n"), + N_("number of submodules fetched in parallel"), + parse_jobs_cb), OPT_BOOL(0, "prefetch", &prefetch, N_("modify the refspec to place all refs within refs/prefetch/")), OPT_BOOL('p', "prune", &prune, diff --git a/t/t5514-fetch-multiple.sh b/t/t5514-fetch-multiple.sh index 5d79472c39..85c2da185c 100755 --- a/t/t5514-fetch-multiple.sh +++ b/t/t5514-fetch-multiple.sh @@ -227,6 +227,14 @@ test_expect_success 'git fetch --multiple --jobs=0 picks a default' ' git fetch --multiple --jobs=0) ' +test_expect_success 'git fetch rejects a negative --jobs' ' + for jobs in -1 -2 + do + test_must_fail git -C test fetch --multiple --jobs=$jobs 2>err && + test_grep "${SQ}--jobs${SQ} cannot be negative" err || return 1 + done +' + create_fetch_all_expect () { cat >expect <<-\EOF one/HEAD -> one/main -- 2.56.0