From patchwork Sun Aug 21 13:57:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949903 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02E27C00140 for ; Sun, 21 Aug 2022 13:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230261AbiHUN6d (ORCPT ); Sun, 21 Aug 2022 09:58:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229519AbiHUN6a (ORCPT ); Sun, 21 Aug 2022 09:58:30 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F687DFEB for ; Sun, 21 Aug 2022 06:58:27 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id d5so4362188wms.5 for ; Sun, 21 Aug 2022 06:58:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=vpUWgAite+njSsV0pix4nXdyE4UDKY1kaTgKm5eVWGE=; b=ZL1LiyjWmQi+htJ2b9U9+jleTDdF5WVSB1asNVxL4614ocSiH4bIjVsFHFg3ynvd2y f7whH9lOna0uQdjQyRNiYfjqIGsknTK8ly/KTnUYv1Hzn6CQMiGPtEbfZ7KJpSGsmcCb /M2DC6wnxCe80xJXaeqNZrJtaW0vnN0ry5ZEFUs1+IM4xyOQkSRNtzEe7WTWVTz++81p TTYTrO9sz+JerHPHDEH/1GI9ay/8v3vXiZL8b+d1pJaQmulKSlhquHld3rAvQyTkR/4x LNQQ0pqVJc4e8uGJU5ATcJGSzZGIoZHAZnyMftOAXnWdHx8WtlBL86RWIrfYqh0U9owY xnkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=vpUWgAite+njSsV0pix4nXdyE4UDKY1kaTgKm5eVWGE=; b=eq+AhrR03jNRLixkKcBwrlG8DsFMW7dv4NKqozGgnCwSeSsusBTkJ6RCy6nWEoHvKI htjNblwBIt+kxTDzb9MCsNcjXxkXENdb3Qjs0wbaVP27Mn7+9kLvNYptp4aBhj8bvFqx CssAw57YYquTN/uAKnHGABPXCxgih5jf4X7X9xYdxTpPCnDDiNunaox2ELj6zctv0i1j iFvjkA2NkkgYY/PAqkglcUrF/XC+EF6tOeLNkD9UvQ/F7Sm03e5P8YnVPAdVabWMXh8A MVRgjrAD53+TRwfHSBGhp98jSDsF6FZ+hG78ubL1jQw8ZtfROkc641Z9Dpm4sUsyiHCu 95/w== X-Gm-Message-State: ACgBeo1gJlZqEx/KgmTBU/xMmfUBBenKyoLsAdLxcKw/WMlL3Km7GTqn /jIemRkW9evFQkOp2NOydkl08shfLRHkaA== X-Google-Smtp-Source: AA6agR4Fh9ZFAjDshL0GxU6ikzLiHDn6pLpNxcaFMz9HnHF6dTAa9l7smMzAH+RVHwhqgFroPWaYDg== X-Received: by 2002:a05:600c:19d0:b0:3a6:2eb1:cfa5 with SMTP id u16-20020a05600c19d000b003a62eb1cfa5mr8009699wmq.37.1661090305880; Sun, 21 Aug 2022 06:58:25 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:25 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 01/32] submodule tests: test usage behavior Date: Sun, 21 Aug 2022 15:57:10 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Test what exit code and output we emit on "git submodule -h", how we handle "--" when no subcommand is specified, and how the top-level "--recursive" option is handled. For "-h" this doesn't make sense, but let's test for it so that any subsequent eventual behavior change will become clear. For "--" this follows up on 68cabbfda36 (submodule: document default behavior, 2019-02-15) and tests that "status" doesn't support the "--" delimiter. There's no intrinsically good reason not to support that. We behave this way due to edge cases in git-submodule.sh's implementation, but as with "-h" let's assert our current long-standing behavior for now. For "--recursive" the exclusion of it from the top-level appears to have been an omission in 15fc56a8536 (git submodule foreach: Add --recursive to recurse into nested submodules, 2009-08-19), there doesn't seem to be a reason not to support it alongside "--quiet" and "--cached", but let's likewise assert our existing behavior for now. I.e. as long as "status" is optional it would make sense to support all of its options when it's omitted, but we only do that with "--quiet" and "--cached", and curiously omit "--recursive". Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t7400-submodule-basic.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index e7cec2e457a..b858871a953 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -14,6 +14,32 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh +test_expect_success 'submodule usage: -h' ' + git submodule -h >out 2>err && + grep "^usage: git submodule" out && + test_must_be_empty err +' + +test_expect_success 'submodule usage: --recursive' ' + test_expect_code 1 git submodule --recursive >out 2>err && + grep "^usage: git submodule" err && + test_must_be_empty out +' + +test_expect_success 'submodule usage: status --' ' + test_expect_code 1 git submodule -- && + test_expect_code 1 git submodule --end-of-options +' + +for opt in '--quiet' '--cached' +do + test_expect_success "submodule usage: status $opt" ' + git submodule $opt && + git submodule status $opt && + git submodule $opt status + ' +done + test_expect_success 'submodule deinit works on empty repository' ' git submodule deinit --all ' From patchwork Sun Aug 21 13:57:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949905 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 123D6C32772 for ; Sun, 21 Aug 2022 13:58:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230390AbiHUN6i (ORCPT ); Sun, 21 Aug 2022 09:58:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229599AbiHUN6a (ORCPT ); Sun, 21 Aug 2022 09:58:30 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3B27331 for ; Sun, 21 Aug 2022 06:58:28 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id n7so10297065wrv.4 for ; Sun, 21 Aug 2022 06:58:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=QzSFAnmN90nqAoOi8T1Xe9XNleKMDBcGXw3m6NCagAQ=; b=bytV50PnSTBd1dYdfAUKLSqh0iwslf+oq/totkc1LutF2cNDEn+ZopyE7ogcX4Tm+P RIi+PxJHCxQKIBMQAANqYfAgaNv0wy1HB5KnDX+Hmm0Re1tgNwBbC0tHKVd4qcf039cy hR/pLxnIarOh77mxJlWj6/Kt0wU2xCueYlOEzaXkI9JfpkCRnGeVuwQoe7TF3rbtpamp yl7GIj4GLxwZ7WbymYl3zqRPA6BLcjAXzpSIJp3P732km9dYdifE7x1W5Jm6wDYDfWgv tl+/rv8eb3zFx3lZShfrYtzEqhuFV8GDFtHLSSSzcTQFroy8yZh1OGRrQbPHbWHQyC3e 8Enw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=QzSFAnmN90nqAoOi8T1Xe9XNleKMDBcGXw3m6NCagAQ=; b=X2iMXPDrq/FZdtioXSu8HlFwIHi3hSXON0zVyNuzovFwupRw1lJT3n6ku2UNbHQdJg D3M0HB8FySVtA6bvL8yslhU0j44J6a8PUAPxHOaSYfpNzbP/OIlskwNsGJOVlsdnMq5T V+7j33DLhCPUubOivUKBhJ9JUv3uaat1Z/zVR0ijNURi73snGrIK+bx7vmrZ7tzhgOUT rKlND6WfgV2mQCrZd7dFGT1u/7iMWuIOobDEhNUf6rJhFwgVFczHLsTMR4E+R0wbJkXN XMROeiYt8RIdx1AttHqolsBqjCMZ5k23EpPdddM9lBZuPo9kLr07t+Pby/mBHiDkxSmn EJFQ== X-Gm-Message-State: ACgBeo1MjlQu1bBfJOStuRvHhVh5sHKX4uPXtVmqz7YMri7eSbH+Wva7 0HEOepo0mfuKGFKiWLpdRWZtiNqSZDYhupFz X-Google-Smtp-Source: AA6agR5JvMC9Nan8P78yoiZcbvHif9L936sjnTZ8NYTQFeaJMFc6ixzNOyLDO69zs1ZdtLtscllmtA== X-Received: by 2002:adf:c803:0:b0:225:3d30:27db with SMTP id d3-20020adfc803000000b002253d3027dbmr5700513wrh.454.1661090306908; Sun, 21 Aug 2022 06:58:26 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:26 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 02/32] submodule tests: test for "add " Date: Sun, 21 Aug 2022 15:57:11 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a missing test for ""add " where "" is an absolute path. This tests code added in [1] and later turned into an "else" branch in clone_submodule() in [2] that's never been tested. This needs to be skipped on WINDOWS because all of $PWD, $(pwd) and the "$(pwd -P)" we get via "$submodurl" would fail in CI with e.g.: fatal: could not create directory 'D:/a/git/git/t/trash directory.t7400-submodule-basic/.git/modules/D:/a/git/git/t/trash directory.t7400-submodule-basic/add-abs' I.e. we can't handle these sorts of paths in this context on that platform. I'm not sure where we run into the edges of "$PWD" behavior on Windows (see [1] for a previous loose end on the topic), but for the purposes of this test it's sufficient that we test this on other platforms. 1. ee8838d1577 (submodule: rewrite `module_clone` shell function in C, 2015-09-08) 2. f8eaa0ba98b (submodule--helper, module_clone: always operate on absolute paths, 2016-03-31) 1. https://lore.kernel.org/git/220630.86edz6c75c.gmgdl@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t7400-submodule-basic.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index b858871a953..6a77d817a82 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -178,6 +178,11 @@ test_expect_success 'submodule add' ' test_must_be_empty untracked ' +test_expect_success !WINDOWS 'submodule add (absolute path)' ' + test_when_finished "git reset --hard" && + git submodule add "$submodurl" "$submodurl/add-abs" +' + test_expect_success 'setup parent and one repository' ' test_create_repo parent && test_commit -C parent one From patchwork Sun Aug 21 13:57:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949906 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76611C00140 for ; Sun, 21 Aug 2022 13:58:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230368AbiHUN6j (ORCPT ); Sun, 21 Aug 2022 09:58:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229775AbiHUN6a (ORCPT ); Sun, 21 Aug 2022 09:58:30 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5A19DFCC for ; Sun, 21 Aug 2022 06:58:29 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id d5so4362220wms.5 for ; Sun, 21 Aug 2022 06:58:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=QzytqYsDc5k+qrEFl5M7MTJCwbRB7Ji7zsl2SqIbLUE=; b=Mcp6EBCzOM/6VpLgg4nu9PSxDHzEglXaCFeJdmYo1+B88lBNSzdPM0t6IVpZIBO7jy 3yGW3yIOOdEPS+I1wJW14bpBnqb0cekeDeZyvvbTvkhoWKFRGGmfbTaQKtXMeLhBBhri oxkVHaPBFQo1M8fHl6XwhRnZJEn/x+/QhoD7a2uYNG1x9nrhc4lHHt1IopZbEPKJnXAN l9LvNyM0tzklv+O0KNrdUsAkhjeYnsexz/BPDukPdP3LPU7qUElmxzQt3qFa/eh1vdCr HF0nVSd9Ha4Bmqm5cPs+2kR1EzC4NtVws4MbWgOJ1gDZGtU4/dXnmqyooUdVylFAc6Ms levw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=QzytqYsDc5k+qrEFl5M7MTJCwbRB7Ji7zsl2SqIbLUE=; b=FlI4X8G0y8wXMuADB7MRzJzT9VxpehyJVArD2o66IIOQwOrpS4hzLpHE/6NsE3jvYg OvYViqDgeQoQYvQe8eGa1xTpVgisWuvQX8xrmzQ+h0eTdo0LY5h1rC149SWlNp8cNPsm ZoNNRNNGs6myMbu2otzXTwEMvcQE0br3zetpABrvqtovL/XgPheUXFdZ4P/c7zz0bE6c jc5WU13XEYumh6wxua53u2VXVfJPMxfinulrkSuZ4PkaaRN99NrSP6sBlb4A5b5sc54w pOJf501EyHph6tz5qc3TcF1g16ozbXpqPH9a0g0CJIyrBTuSbTJSOZAt5t4ys/4r9iUD 1dsg== X-Gm-Message-State: ACgBeo13dSrC8Ae/Gx/zNDT2dOwDvBHwPfIu7weogCsx26X5DHnEiua9 vLFvinPgb+F+UYlFBOFVyZqb/r0Xtv918Fbo X-Google-Smtp-Source: AA6agR7wCLkuU/CuzeLqHhK7dlp7GywMKCASkeXx3LP1NNosCMJK0nEhIg6kb+A7SKGKQdf6L1yB0w== X-Received: by 2002:a7b:ce89:0:b0:3a5:cefe:80f6 with SMTP id q9-20020a7bce89000000b003a5cefe80f6mr13583300wmj.113.1661090308085; Sun, 21 Aug 2022 06:58:28 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:27 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 03/32] submodule--helper: remove unused "name" helper Date: Sun, 21 Aug 2022 15:57:12 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The "name" helper has not been used since e83e3333b57 (submodule: port submodule subcommand 'summary' from shell to C, 2020-08-13). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index b63f420ecef..fc4d2779da6 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -771,24 +771,6 @@ static int module_status(int argc, const char **argv, const char *prefix) return 0; } -static int module_name(int argc, const char **argv, const char *prefix) -{ - const struct submodule *sub; - - if (argc != 2) - usage(_("git submodule--helper name ")); - - sub = submodule_from_path(the_repository, null_oid(), argv[1]); - - if (!sub) - die(_("no submodule mapping found in .gitmodules for path '%s'"), - argv[1]); - - printf("%s\n", sub->name); - - return 0; -} - struct module_cb { unsigned int mod_src; unsigned int mod_dst; @@ -3362,7 +3344,6 @@ struct cmd_struct { static struct cmd_struct commands[] = { {"list", module_list, 0}, - {"name", module_name, 0}, {"clone", module_clone, SUPPORT_SUPER_PREFIX}, {"add", module_add, 0}, {"update", module_update, SUPPORT_SUPER_PREFIX}, From patchwork Sun Aug 21 13:57:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949907 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 742A2C32772 for ; Sun, 21 Aug 2022 13:58:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230411AbiHUN6m (ORCPT ); Sun, 21 Aug 2022 09:58:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229982AbiHUN6c (ORCPT ); Sun, 21 Aug 2022 09:58:32 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCC76E007 for ; Sun, 21 Aug 2022 06:58:30 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id m17-20020a7bce11000000b003a5bedec07bso6447316wmc.0 for ; Sun, 21 Aug 2022 06:58:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=FxP8Bdc/zCpIH1B22L2MFbnrA4tgAap1tkuH6wpfSRc=; b=ghAnxG7KlCPgR1kydQJDPxe5uD0yqHNVkaURLpsW9TYfbt6cRh+IRMMYVYM5Usayxb Dqw4agmdJB2uLff1R66/okYdM+f4thh0wwix2froHmWD6r4hDtI/YaCNsn13m+YUqea+ IBqvpBk72DEXeDstu3/WtUzojELM2xWJmrgzgUbWWmxZQ+0EFjMFyEX07lQjX8WeJhcF TiyXJoAriqEFX5wzrkrpSSAMRTz0UwHxKzO+dXRhvRRng3XH9VpUcZ0PuxOy0VMHM3/Y cowMLsKsIKMS4HxEu6saRPF/5HDNht6Z5AI622LxC/TXAKvaftbRq9COddX29tS0G48d lmbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=FxP8Bdc/zCpIH1B22L2MFbnrA4tgAap1tkuH6wpfSRc=; b=VE6oVQeia/I3u846WJH2H0zDar4e87dnevpd9DRShghrT4A3hfA8AtpHlRiTTnw2Fc WamzAxjezcLXkuCE3Fvw+seGtm5+YBMhsXYgRFTsjRQvZg/p+JugYzmbzEtzCL1kJ862 RTQFdAwzvvWpsdWKvpUSf++iasYUKLRoXp9iJ4QxjECBZiBIctDifi+XrlFdo1aSj/MS Mi6Oz7Q3tj3XCxTXDyAmTla+tln24yicTyLOOiy9WoJJzkeDOlYi3jUNWW22aQQnQ3Tc ploFXMHz6yodMKo7QzmjG1hlmCvoeQg28D0iN0nT3nfO+GvJkbMnBanO1ZJ6z0ZTe+Jw uBfA== X-Gm-Message-State: ACgBeo2NMAe88lL2wW4jd16B4FTBup4OfCbLYrufT/jOMrB1x4/t4lU1 b/Ovfwuet7jOidiQ3FoY0W3RQK53v8+AyklF X-Google-Smtp-Source: AA6agR5MHyjY9SqOkZdmh8iKw7TEoOQ+Qm8KRAHrGEm6tCe585/SVXV3an7hMOFSoRq4Bhw9w2fHZQ== X-Received: by 2002:a05:600c:1e8b:b0:3a6:acc:ebfb with SMTP id be11-20020a05600c1e8b00b003a60accebfbmr9836116wmb.66.1661090309009; Sun, 21 Aug 2022 06:58:29 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:28 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 04/32] submodule--helper: remove unused "list" helper Date: Sun, 21 Aug 2022 15:57:13 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove the "submodule--helper list" sub-command, which hasn't been used by git-submodule.sh since 2964d6e5e1e (submodule: port subcommand 'set-branch' from shell to C, 2020-06-02). There was a test added in 2b56bb7a87a (submodule helper list: respect correct path prefix, 2016-02-24) which relied on it, but the right thing to do here is to delete that test as well. That test was regression testing the "list" subcommand itself. We're not getting anything useful from the "list | cut -f2" invocation that we couldn't get from "foreach 'echo $sm_path'". Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 40 ------------------------------------- t/t7400-submodule-basic.sh | 25 ----------------------- 2 files changed, 65 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index fc4d2779da6..24a305151d1 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -266,45 +266,6 @@ static char *get_up_path(const char *path) return strbuf_detach(&sb, NULL); } -static int module_list(int argc, const char **argv, const char *prefix) -{ - int i; - struct pathspec pathspec; - struct module_list list = MODULE_LIST_INIT; - - struct option module_list_options[] = { - OPT_STRING(0, "prefix", &prefix, - N_("path"), - N_("alternative anchor for relative paths")), - OPT_END() - }; - - const char *const git_submodule_helper_usage[] = { - N_("git submodule--helper list [--prefix=] [...]"), - NULL - }; - - argc = parse_options(argc, argv, prefix, module_list_options, - git_submodule_helper_usage, 0); - - if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) - return 1; - - for (i = 0; i < list.nr; i++) { - const struct cache_entry *ce = list.entries[i]; - - if (ce_stage(ce)) - printf("%06o %s U\t", ce->ce_mode, - oid_to_hex(null_oid())); - else - printf("%06o %s %d\t", ce->ce_mode, - oid_to_hex(&ce->oid), ce_stage(ce)); - - fprintf(stdout, "%s\n", ce->name); - } - return 0; -} - static void for_each_listed_submodule(const struct module_list *list, each_submodule_fn fn, void *cb_data) { @@ -3343,7 +3304,6 @@ struct cmd_struct { }; static struct cmd_struct commands[] = { - {"list", module_list, 0}, {"clone", module_clone, SUPPORT_SUPER_PREFIX}, {"add", module_add, 0}, {"update", module_update, SUPPORT_SUPER_PREFIX}, diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 6a77d817a82..b50db3f1031 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -1255,31 +1255,6 @@ test_expect_success 'submodule add clone shallow submodule' ' ) ' -test_expect_success 'submodule helper list is not confused by common prefixes' ' - mkdir -p dir1/b && - ( - cd dir1/b && - git init && - echo hi >testfile2 && - git add . && - git commit -m "test1" - ) && - mkdir -p dir2/b && - ( - cd dir2/b && - git init && - echo hello >testfile1 && - git add . && - git commit -m "test2" - ) && - git submodule add /dir1/b dir1/b && - git submodule add /dir2/b dir2/b && - git commit -m "first submodule commit" && - git submodule--helper list dir1/b | cut -f 2 >actual && - echo "dir1/b" >expect && - test_cmp expect actual -' - test_expect_success 'setup superproject with submodules' ' git init sub1 && test_commit -C sub1 test && From patchwork Sun Aug 21 13:57:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949908 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2E7CC00140 for ; Sun, 21 Aug 2022 13:58:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230419AbiHUN6n (ORCPT ); Sun, 21 Aug 2022 09:58:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230129AbiHUN6c (ORCPT ); Sun, 21 Aug 2022 09:58:32 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC5EBDFAD for ; Sun, 21 Aug 2022 06:58:31 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id v7-20020a1cac07000000b003a6062a4f81so6426079wme.1 for ; Sun, 21 Aug 2022 06:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=kG6xvmLw8G8Iez44RPZVg3tFpKOK4qrGd4LnfhdaHY4=; b=ACOIJl0qMX5hHiAbr42V45BxS0e+Sc5DH5WuveA6VXnW/BJR4XoO8cU4dxoYSPQe69 XhCBWT+nZ5mvTnT74Td6zqAOpSwAOAeZ63TRUqkTpdfqGRLAIBQcMzQyUQZckgsxAXfD PGAT7sYjwTdbfbl9QZF1ENOjzlwkp0+SAGYEBILA9JZD53awaP7lnv5Mc/m3lVDQ2vT9 NfTl7hLeloa7ygNAX68gb9fxBIXcyd4IOvrMgAkqJJwE2NTdp7gJvxA9MmnSct85fn1X NqTrAdMySEVIuGJRIxRSTZZNakOMtVa23BKgU0xvGlzJxQS1c3o21+yjxBlUdpiS24YV 249A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=kG6xvmLw8G8Iez44RPZVg3tFpKOK4qrGd4LnfhdaHY4=; b=jUJyF7hus8y85DCWqCE6B2mg2P/fuuYhEtzKjYpCvo7Yd8neeRCI46pGyJyg6Cv1Xl xMFZiMGsWtjx8WAskYS+mD6D+YzhzjvrcoAklbE2Tfd3cQQi5bxJDSq4piDr2nbO6uiZ 8CVxv1iA1v9FIVAnlHdC3OCr7rself0RnYgdbdiVVwBt/M0gXdrwArRtW503F9w1FY/Z Vp6QSQXArK8A/qUcxHHbgnuy2aI/EKhbquoNKfWBTsQvKtenWh0WXrUShHp5p2vMIDYs v+QpF7QEpMujoP+GeZLcigKdeKDghtenKJqVMfgW9CMhuOXOP89w2lcr4XT8u+szC5Wc e1og== X-Gm-Message-State: ACgBeo183PCaYAEYYyF09ygm0WhrzFNUP24PNOjKAQe9M6we7rD1nb1x XqpX9Q4mhK3B19l6zqlP3VYh7XLgZ0F5raQC X-Google-Smtp-Source: AA6agR7Vl1nAXvoabc9RosfINXzx788iV1CcjIovW/whbfyELLXpe6SyIjwAD2EXUj6YabuVH/s1Vw== X-Received: by 2002:a1c:3b04:0:b0:3a5:487c:6240 with SMTP id i4-20020a1c3b04000000b003a5487c6240mr12863819wma.152.1661090310105; Sun, 21 Aug 2022 06:58:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:29 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 05/32] test-tool submodule-config: remove unused "--url" handling Date: Sun, 21 Aug 2022 15:57:14 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org No test has used this "--url" parameter since the test code that made use of it was removed in 32bc548329d (submodule-config: remove support for overlaying repository config, 2017-08-03). Signed-off-by: Ævar Arnfjörð Bjarmason --- t/helper/test-submodule-config.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c index e2692746dfd..22a41c40926 100644 --- a/t/helper/test-submodule-config.c +++ b/t/helper/test-submodule-config.c @@ -15,14 +15,11 @@ int cmd__submodule_config(int argc, const char **argv) { const char **arg = argv; int my_argc = argc; - int output_url = 0; int lookup_name = 0; arg++; my_argc--; while (arg[0] && starts_with(arg[0], "--")) { - if (!strcmp(arg[0], "--url")) - output_url = 1; if (!strcmp(arg[0], "--name")) lookup_name = 1; arg++; @@ -57,12 +54,8 @@ int cmd__submodule_config(int argc, const char **argv) if (!submodule) die_usage(argc, argv, "Submodule not found."); - if (output_url) - printf("Submodule url: '%s' for path '%s'\n", - submodule->url, submodule->path); - else - printf("Submodule name: '%s' for path '%s'\n", - submodule->name, submodule->path); + printf("Submodule name: '%s' for path '%s'\n", submodule->name, + submodule->path); arg += 2; } From patchwork Sun Aug 21 13:57:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A59FC28D13 for ; Sun, 21 Aug 2022 13:58:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230426AbiHUN6p (ORCPT ); Sun, 21 Aug 2022 09:58:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230365AbiHUN6e (ORCPT ); Sun, 21 Aug 2022 09:58:34 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C5BD11C39 for ; Sun, 21 Aug 2022 06:58:33 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id u5so2473038wrt.11 for ; Sun, 21 Aug 2022 06:58:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=ErSh/Y6/2IZ/pTwc3r3i2qexQwGSKLkGR89ovseodwQ=; b=Jm0bMsudh8B052ZYZROHvB4hN6FbnFd/tka6Hm17Dj2DpLJAjJC9d9xz+/Tu/9uQza pKu+4IfjR+C2fgXWvsdXThb8ZHUMrWFHZ9PIpKkiaNhRj8ZaESaJRc0DaRDIS43vu+0P 1Kuk+eIjGqi2GSxw7taBz4ynI6PEk7Dl5rgeh+DKE+JWO/xJY7mFrhlw7xy4FH90P0CU DLyiBqqP2m58yXLLIRZ7ddeoaCE/YNu57+jvCtmN0W5OJEsZ+qOf70PzwkvAe6b9epm3 TWSljm5xQ3Ia6yhboJlw7dZRy4xSpTee5I0XOYLvVAN1yZHIcLKnsYrpTQRXBXo/Z3uL dVZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=ErSh/Y6/2IZ/pTwc3r3i2qexQwGSKLkGR89ovseodwQ=; b=HTl90fn2ifhxENP6Y/upzjBR5HmOKR540V0bz8gS//JMe7u7UcfF2bfstL03u6jBik XGi8yXxv1T4m5RIvR+F4n4DGZix/K9StF4CE6AX7JrHynjVpEghPzeL2O4+wL+pKtcOz 3haDDK8dSkPWvb9J9xz63nifhCGJty+zaxvMC8QccgvkYVD2uW8X+CblcFS79KTviL33 yRw0D2ZrrNWwK8KuMzEPDiAN96xVTNyJt4IOWgaNSEtfU0JiQB0srkRgVcg0ABmUMqv4 OxIxfeIeIifXqLfqVIyIxHnR8SZl+0N9MHlGi04eJprbmwb8c3NPiSM1tY1+VNZAYtAP 2l3Q== X-Gm-Message-State: ACgBeo0wLPvPOxRPMZ16Je6xo+h4coTmDWnjdWpkOp5PgtonSj2swpkG PQOs8H1WFLZbU6bxs6MtKdaaxLHhojY2g164 X-Google-Smtp-Source: AA6agR7l4CAO396O1urPtyHYmEGisPnit86y6u9kWKz/Ynos3m4vL6mpDzUOUIAk2zfWzp6YUOD9uw== X-Received: by 2002:a5d:6da9:0:b0:225:59e4:1497 with SMTP id u9-20020a5d6da9000000b0022559e41497mr642288wrs.262.1661090311071; Sun, 21 Aug 2022 06:58:31 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:30 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 06/32] submodule--helper: move "is-active" to a test-tool Date: Sun, 21 Aug 2022 15:57:15 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Create a new "test-tool submodule" and move the "is-active" subcommand over to it. It was added in 5c2bd8b77ae (submodule--helper: add is-active subcommand, 2017-03-16), since a452128a36c (submodule--helper: introduce add-config subcommand, 2021-08-06) it hasn't been used by git-submodule.sh. Since we're creating a command dispatch similar to test-tool.c itself let's split out the "struct test_cmd" into a new test-tool-utils.h, which both this new code and test-tool.c itself can use. Signed-off-by: Ævar Arnfjörð Bjarmason --- Makefile | 1 + builtin/submodule--helper.c | 9 ------ t/helper/test-submodule.c | 58 ++++++++++++++++++++++++++++++++++ t/helper/test-tool-utils.h | 9 ++++++ t/helper/test-tool.c | 7 ++-- t/helper/test-tool.h | 1 + t/t7413-submodule-is-active.sh | 35 ++++++++++---------- 7 files changed, 90 insertions(+), 30 deletions(-) create mode 100644 t/helper/test-submodule.c create mode 100644 t/helper/test-tool-utils.h diff --git a/Makefile b/Makefile index e8adeb09f1c..b6acd560e75 100644 --- a/Makefile +++ b/Makefile @@ -785,6 +785,7 @@ TEST_BUILTINS_OBJS += test-strcmp-offset.o TEST_BUILTINS_OBJS += test-string-list.o TEST_BUILTINS_OBJS += test-submodule-config.o TEST_BUILTINS_OBJS += test-submodule-nested-repo-config.o +TEST_BUILTINS_OBJS += test-submodule.o TEST_BUILTINS_OBJS += test-subprocess.o TEST_BUILTINS_OBJS += test-trace2.o TEST_BUILTINS_OBJS += test-urlmatch-normalization.o diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 24a305151d1..e10c3ac7550 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2731,14 +2731,6 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) return 0; } -static int is_active(int argc, const char **argv, const char *prefix) -{ - if (argc != 2) - die("submodule--helper is-active takes exactly 1 argument"); - - return !is_submodule_active(the_repository, argv[1]); -} - /* * Exit non-zero if any of the submodule names given on the command line is * invalid. If no names are given, filter stdin to print only valid names @@ -3316,7 +3308,6 @@ static struct cmd_struct commands[] = { {"summary", module_summary, 0}, {"push-check", push_check, 0}, {"absorbgitdirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX}, - {"is-active", is_active, 0}, {"check-name", check_name, 0}, {"config", module_config, 0}, {"set-url", module_set_url, 0}, diff --git a/t/helper/test-submodule.c b/t/helper/test-submodule.c new file mode 100644 index 00000000000..494c6558d9f --- /dev/null +++ b/t/helper/test-submodule.c @@ -0,0 +1,58 @@ +#include "test-tool.h" +#include "test-tool-utils.h" +#include "cache.h" +#include "parse-options.h" +#include "submodule.h" + +#define TEST_TOOL_IS_ACTIVE_USAGE \ + "test-tool submodule is-active " +static const char *submodule_is_active_usage[] = { + TEST_TOOL_IS_ACTIVE_USAGE, + NULL +}; + +static const char *submodule_usage[] = { + TEST_TOOL_IS_ACTIVE_USAGE, + NULL +}; + +static int cmd__submodule_is_active(int argc, const char **argv) +{ + struct option options[] = { + OPT_END() + }; + argc = parse_options(argc, argv, "test-tools", options, + submodule_is_active_usage, 0); + if (argc != 1) + usage_with_options(submodule_is_active_usage, options); + + setup_git_directory(); + + return !is_submodule_active(the_repository, argv[0]); +} + +static struct test_cmd cmds[] = { + { "is-active", cmd__submodule_is_active }, +}; + +int cmd__submodule(int argc, const char **argv) +{ + struct option options[] = { + OPT_END() + }; + size_t i; + + argc = parse_options(argc, argv, "test-tools", options, submodule_usage, + PARSE_OPT_STOP_AT_NON_OPTION); + if (argc < 1) + usage_with_options(submodule_usage, options); + + for (i = 0; i < ARRAY_SIZE(cmds); i++) + if (!strcmp(cmds[i].name, argv[0])) + return cmds[i].fn(argc, argv); + + usage_msg_optf("unknown subcommand '%s'", submodule_usage, options, + argv[0]); + + return 0; +} diff --git a/t/helper/test-tool-utils.h b/t/helper/test-tool-utils.h new file mode 100644 index 00000000000..6a0e5e0074f --- /dev/null +++ b/t/helper/test-tool-utils.h @@ -0,0 +1,9 @@ +#ifndef TEST_TOOL_UTILS_H +#define TEST_TOOL_UTILS_H + +struct test_cmd { + const char *name; + int (*fn)(int argc, const char **argv); +}; + +#endif diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index 318fdbab0c3..7a6a8b88a91 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "test-tool.h" +#include "test-tool-utils.h" #include "trace2.h" #include "parse-options.h" @@ -8,11 +9,6 @@ static const char * const test_tool_usage[] = { NULL }; -struct test_cmd { - const char *name; - int (*fn)(int argc, const char **argv); -}; - static struct test_cmd cmds[] = { { "advise", cmd__advise_if_enabled }, { "bitmap", cmd__bitmap }, @@ -78,6 +74,7 @@ static struct test_cmd cmds[] = { { "simple-ipc", cmd__simple_ipc }, { "strcmp-offset", cmd__strcmp_offset }, { "string-list", cmd__string_list }, + { "submodule", cmd__submodule }, { "submodule-config", cmd__submodule_config }, { "submodule-nested-repo-config", cmd__submodule_nested_repo_config }, { "subprocess", cmd__subprocess }, diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index bb799271631..5f4f69dee81 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -68,6 +68,7 @@ int cmd__sigchain(int argc, const char **argv); int cmd__simple_ipc(int argc, const char **argv); int cmd__strcmp_offset(int argc, const char **argv); int cmd__string_list(int argc, const char **argv); +int cmd__submodule(int argc, const char **argv); int cmd__submodule_config(int argc, const char **argv); int cmd__submodule_nested_repo_config(int argc, const char **argv); int cmd__subprocess(int argc, const char **argv); diff --git a/t/t7413-submodule-is-active.sh b/t/t7413-submodule-is-active.sh index c8e7e983317..ede6f02dbd5 100755 --- a/t/t7413-submodule-is-active.sh +++ b/t/t7413-submodule-is-active.sh @@ -1,9 +1,12 @@ #!/bin/sh -test_description='Test submodule--helper is-active +test_description='Test with test-tool submodule is-active -This test verifies that `git submodue--helper is-active` correctly identifies +This test verifies that `test-tool submodule is-active` correctly identifies submodules which are "active" and interesting to the user. + +This is a unit test of the submodule.c is_submodule_active() function, +which is also indirectly tested elsewhere. ' . ./test-lib.sh @@ -25,13 +28,13 @@ test_expect_success 'setup' ' ' test_expect_success 'is-active works with urls' ' - git -C super submodule--helper is-active sub1 && - git -C super submodule--helper is-active sub2 && + test-tool -C super submodule is-active sub1 && + test-tool -C super submodule is-active sub2 && git -C super config --unset submodule.sub1.URL && - test_must_fail git -C super submodule--helper is-active sub1 && + test_must_fail test-tool -C super submodule is-active sub1 && git -C super config submodule.sub1.URL ../sub && - git -C super submodule--helper is-active sub1 + test-tool -C super submodule is-active sub1 ' test_expect_success 'is-active works with submodule..active config' ' @@ -39,11 +42,11 @@ test_expect_success 'is-active works with submodule..active config' ' test_when_finished "git -C super config submodule.sub1.URL ../sub" && git -C super config --bool submodule.sub1.active "false" && - test_must_fail git -C super submodule--helper is-active sub1 && + test_must_fail test-tool -C super submodule is-active sub1 && git -C super config --bool submodule.sub1.active "true" && git -C super config --unset submodule.sub1.URL && - git -C super submodule--helper is-active sub1 + test-tool -C super submodule is-active sub1 ' test_expect_success 'is-active works with basic submodule.active config' ' @@ -53,17 +56,17 @@ test_expect_success 'is-active works with basic submodule.active config' ' git -C super config --add submodule.active "." && git -C super config --unset submodule.sub1.URL && - git -C super submodule--helper is-active sub1 && - git -C super submodule--helper is-active sub2 + test-tool -C super submodule is-active sub1 && + test-tool -C super submodule is-active sub2 ' test_expect_success 'is-active correctly works with paths that are not submodules' ' test_when_finished "git -C super config --unset-all submodule.active" && - test_must_fail git -C super submodule--helper is-active not-a-submodule && + test_must_fail test-tool -C super submodule is-active not-a-submodule && git -C super config --add submodule.active "." && - test_must_fail git -C super submodule--helper is-active not-a-submodule + test_must_fail test-tool -C super submodule is-active not-a-submodule ' test_expect_success 'is-active works with exclusions in submodule.active config' ' @@ -72,8 +75,8 @@ test_expect_success 'is-active works with exclusions in submodule.active config' git -C super config --add submodule.active "." && git -C super config --add submodule.active ":(exclude)sub1" && - test_must_fail git -C super submodule--helper is-active sub1 && - git -C super submodule--helper is-active sub2 + test_must_fail test-tool -C super submodule is-active sub1 && + test-tool -C super submodule is-active sub2 ' test_expect_success 'is-active with submodule.active and submodule..active' ' @@ -85,8 +88,8 @@ test_expect_success 'is-active with submodule.active and submodule..active git -C super config --bool submodule.sub1.active "false" && git -C super config --bool submodule.sub2.active "true" && - test_must_fail git -C super submodule--helper is-active sub1 && - git -C super submodule--helper is-active sub2 + test_must_fail test-tool -C super submodule is-active sub1 && + test-tool -C super submodule is-active sub2 ' test_expect_success 'is-active, submodule.active and submodule add' ' From patchwork Sun Aug 21 13:57:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949910 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95F2EC00140 for ; Sun, 21 Aug 2022 13:58:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230449AbiHUN6t (ORCPT ); Sun, 21 Aug 2022 09:58:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230266AbiHUN6f (ORCPT ); Sun, 21 Aug 2022 09:58:35 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EE4E11145 for ; Sun, 21 Aug 2022 06:58:34 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id k17so4375249wmr.2 for ; Sun, 21 Aug 2022 06:58:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=hjdESJGog2T5WAlUFII3ek6mzY9CaXBVt2zJijzNBa0=; b=eY1ztPZ0ex+MT74+G98zIouMQT5NztdW5hS2/n9nSdPO9V1a3/Gutw5GIWECSMCgaM bmq93h3YE9GaCFMo+HggprVpSH2UQsCWBx+hF4327nkriyhc1GF8qUJuvAF/SSu/bFEU jWPHIzVS0k+5xR9SWVuwXpsKHoj47IFmi9Wy4a5b+r4LFBuwoc9AdbqY/7RYy1bBui48 jd+mMKW6s2BjMcQ5PetA81UCit/iLS7W3iPmtAHX8HJMhgcfog4x+ku6Pq6yLQfSc8wu 8Xplui1TA4Q+IfeDHMq8BeNhDwWzENcoklODce/gTMz2pf3xF+knP3HX+i0bX1DaHNGP NnEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=hjdESJGog2T5WAlUFII3ek6mzY9CaXBVt2zJijzNBa0=; b=mDJIrLVCSYQxcA5cxTU2w3+XRRUWousmgZOfOBlEQMbFnHWWZ2VC0QLMh1Mz00IecH IlE0ZdPH6oX6ncWwTmLTzNgXxahrac8WBfAtHYGVzzGQpa45v4BcWk73GWmIMtTcvOtT 6JUWQuQaalhPA6fNPFvwjh3G1BmtkiqsFfCfAmKFGIzP0+U8+lFu214ZAfqA0WuQLSrf g7wnn+Ietr8Hc9ooNczf6G9gy3XV48cRQhoyCM2A/LEKR3jVfQkJjmCu+WW5qskUEj8z Y8ICTVewbuBEwXKDZNI/NSc4w8xwwtUnmkfXdaBj+Lkw1QpDMBUyhDQGRR1Ya3XTzZM6 RU8w== X-Gm-Message-State: ACgBeo3kOcggG8HHbmC3nBnlmFJlz3LCXo8cx61p0Wg7ldUR22RAKbsJ J6rNtzOMvnCbiuvm1SslyLdg/RByy1JR8Or9 X-Google-Smtp-Source: AA6agR5XY+Hk20YhAvPmTmTQD/1WQiB5kmKqA20cicX2xFOE2KwPkvru7PqcnLTTxw4UjRu2yWmZgQ== X-Received: by 2002:a05:600c:1988:b0:3a5:f47c:abce with SMTP id t8-20020a05600c198800b003a5f47cabcemr9827451wmq.121.1661090312473; Sun, 21 Aug 2022 06:58:32 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:31 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 07/32] submodule--helper: move "check-name" to a test-tool Date: Sun, 21 Aug 2022 15:57:16 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the "check-name" helper to a test-tool, since a6226fd772b (submodule--helper: convert the bulk of cmd_add() to C, 2021-08-10) it has only been used by this test, not git-submodule.sh. As noted with its introduction in 0383bbb9015 (submodule-config: verify submodule names as paths, 2018-04-30) the intent of t7450-bad-git-dotfiles.sh has always been to unit test the check_submodule_name() function. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 24 ------------------- t/helper/test-submodule.c | 46 +++++++++++++++++++++++++++++++++++++ t/t7450-bad-git-dotfiles.sh | 2 +- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index e10c3ac7550..e8458567976 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2731,29 +2731,6 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) return 0; } -/* - * Exit non-zero if any of the submodule names given on the command line is - * invalid. If no names are given, filter stdin to print only valid names - * (which is primarily intended for testing). - */ -static int check_name(int argc, const char **argv, const char *prefix) -{ - if (argc > 1) { - while (*++argv) { - if (check_submodule_name(*argv) < 0) - return 1; - } - } else { - struct strbuf buf = STRBUF_INIT; - while (strbuf_getline(&buf, stdin) != EOF) { - if (!check_submodule_name(buf.buf)) - printf("%s\n", buf.buf); - } - strbuf_release(&buf); - } - return 0; -} - static int module_config(int argc, const char **argv, const char *prefix) { enum { @@ -3308,7 +3285,6 @@ static struct cmd_struct commands[] = { {"summary", module_summary, 0}, {"push-check", push_check, 0}, {"absorbgitdirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX}, - {"check-name", check_name, 0}, {"config", module_config, 0}, {"set-url", module_set_url, 0}, {"set-branch", module_set_branch, 0}, diff --git a/t/helper/test-submodule.c b/t/helper/test-submodule.c index 494c6558d9f..9f0eb440192 100644 --- a/t/helper/test-submodule.c +++ b/t/helper/test-submodule.c @@ -2,8 +2,16 @@ #include "test-tool-utils.h" #include "cache.h" #include "parse-options.h" +#include "submodule-config.h" #include "submodule.h" +#define TEST_TOOL_CHECK_NAME_USAGE \ + "test-tool submodule check-name " +static const char *submodule_check_name_usage[] = { + TEST_TOOL_CHECK_NAME_USAGE, + NULL +}; + #define TEST_TOOL_IS_ACTIVE_USAGE \ "test-tool submodule is-active " static const char *submodule_is_active_usage[] = { @@ -12,10 +20,47 @@ static const char *submodule_is_active_usage[] = { }; static const char *submodule_usage[] = { + TEST_TOOL_CHECK_NAME_USAGE, TEST_TOOL_IS_ACTIVE_USAGE, NULL }; +/* + * Exit non-zero if any of the submodule names given on the command line is + * invalid. If no names are given, filter stdin to print only valid names + * (which is primarily intended for testing). + */ +static int check_name(int argc, const char **argv) +{ + if (argc > 1) { + while (*++argv) { + if (check_submodule_name(*argv) < 0) + return 1; + } + } else { + struct strbuf buf = STRBUF_INIT; + while (strbuf_getline(&buf, stdin) != EOF) { + if (!check_submodule_name(buf.buf)) + printf("%s\n", buf.buf); + } + strbuf_release(&buf); + } + return 0; +} + +static int cmd__submodule_check_name(int argc, const char **argv) +{ + struct option options[] = { + OPT_END() + }; + argc = parse_options(argc, argv, "test-tools", options, + submodule_check_name_usage, 0); + if (argc) + usage_with_options(submodule_check_name_usage, options); + + return check_name(argc, argv); +} + static int cmd__submodule_is_active(int argc, const char **argv) { struct option options[] = { @@ -32,6 +77,7 @@ static int cmd__submodule_is_active(int argc, const char **argv) } static struct test_cmd cmds[] = { + { "check-name", cmd__submodule_check_name }, { "is-active", cmd__submodule_is_active }, }; diff --git a/t/t7450-bad-git-dotfiles.sh b/t/t7450-bad-git-dotfiles.sh index 41706c1c9ff..2c24f120da3 100755 --- a/t/t7450-bad-git-dotfiles.sh +++ b/t/t7450-bad-git-dotfiles.sh @@ -21,7 +21,7 @@ test_expect_success 'check names' ' valid/with/paths EOF - git submodule--helper check-name >actual <<-\EOF && + test-tool submodule check-name >actual <<-\EOF && valid valid/with/paths From patchwork Sun Aug 21 13:57:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53B8EC32772 for ; Sun, 21 Aug 2022 13:58:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230389AbiHUN6u (ORCPT ); Sun, 21 Aug 2022 09:58:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230387AbiHUN6h (ORCPT ); Sun, 21 Aug 2022 09:58:37 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 805FF13D69 for ; Sun, 21 Aug 2022 06:58:34 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id m17-20020a7bce11000000b003a5bedec07bso6447399wmc.0 for ; Sun, 21 Aug 2022 06:58:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=8Rz1uVDQWz4U0y4cf4XURYAetYXhFpBSzZfUy6MXW2E=; b=BwOG2boKdfyQC+iDIslCmtk4KvoNlxVwayqRW7Ktk9/EjeIbsb0+8mZ3e8gRKHgVea vwH6KaJgLh528dCxeTEmpTeEJLkXdfUyvOJOrF5ogtxycpjqAbRp/Ps8Ih54ZPQ9C6rO bsrrramblCyHKh10Dn/5psTRe6y52vpX9d1G9fbnHYOms30UjYTBciG0EIozn4gVXiZi wiA3cNcKBnDyMdT7pkza+IfPWhEWDJq+GK3bEsD6+UFJrhzHbTGKmQPxTIoHWWIKPRQT 6VbbtaYTPI/WreyXrIPOdTeUAeiJlj+VDsuQSRvzRhunzdasWQiBv/PoYLF0jnSx5Fm4 F4vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=8Rz1uVDQWz4U0y4cf4XURYAetYXhFpBSzZfUy6MXW2E=; b=dofhTWNgIAhYlShYazMFY6doXE+khRW86BYdm9smYQprxxnasgtSSkAC+gQvY1GzkW W7KiqUVR1Yh8mq23ZSrppwi7enJIrFmNxLJhyRgcLcUzVF2+lOhts/BojMa33AihTJqK 95lENMfE+Yu8RZK3/9YhpF+F4vdKRxiFUjT+nqQyktw15LcnWvMVm/eq+mzSD9OvEJVK l1dRtqsDSRc3L6CAsxLw7z+AmlJe3Levpn4ah/Npqk3tuF5w31fCQm1fUYP5BgcS9DLX 1QAQOWegHDKWKDLSPwVeaEw8LhvD1bAWslT5YIu1tiD75lfSH9TdkjLPoUDqZChe1k74 +JpA== X-Gm-Message-State: ACgBeo2NzvgiISxm+iCrfrGx6PT3OT8mlcxWiAvROL0F8JZcGK7/JDHa mg96Gg1J1prShr0kLJfdQTmSdpHCb696QSYi X-Google-Smtp-Source: AA6agR5oDAlhX4ybw4WGKKdxTm6VIbnN8NwSxoOJ1jzrZfq89RYj/+2n/KE/1/etkdOS1qSDOCNiaA== X-Received: by 2002:a05:600c:2315:b0:3a5:c2cc:1bee with SMTP id 21-20020a05600c231500b003a5c2cc1beemr9330758wmo.55.1661090313763; Sun, 21 Aug 2022 06:58:33 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:32 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 08/32] submodule--helper: move "resolve-relative-url-test" to a test-tool Date: Sun, 21 Aug 2022 15:57:17 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As its name suggests the "resolve-relative-url-test" has never been used outside of the test suite, see 63e95beb085 (submodule: port resolve_relative_url from shell to C, 2016-04-15) for its original addition. Perhaps it would make sense to drop this code entirely, as we feel that we've got enough indirect test coverage, but let's leave that question to a possible follow-up change. For now let's keep the test coverage this gives us. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 23 -------------------- t/helper/test-submodule.c | 42 +++++++++++++++++++++++++++++++++++++ t/t0060-path-utils.sh | 2 +- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index e8458567976..7e2986902dd 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -96,28 +96,6 @@ static char *resolve_relative_url(const char *rel_url, const char *up_path, int return resolved_url; } -static int resolve_relative_url_test(int argc, const char **argv, const char *prefix) -{ - char *remoteurl, *res; - const char *up_path, *url; - - if (argc != 4) - die("resolve-relative-url-test only accepts three arguments: "); - - up_path = argv[1]; - remoteurl = xstrdup(argv[2]); - url = argv[3]; - - if (!strcmp(up_path, "(null)")) - up_path = NULL; - - res = relative_url(remoteurl, url, up_path); - puts(res); - free(res); - free(remoteurl); - return 0; -} - /* the result should be freed by the caller. */ static char *get_submodule_displaypath(const char *path, const char *prefix) { @@ -3276,7 +3254,6 @@ static struct cmd_struct commands[] = { {"clone", module_clone, SUPPORT_SUPER_PREFIX}, {"add", module_add, 0}, {"update", module_update, SUPPORT_SUPER_PREFIX}, - {"resolve-relative-url-test", resolve_relative_url_test, 0}, {"foreach", module_foreach, SUPPORT_SUPER_PREFIX}, {"init", module_init, 0}, {"status", module_status, SUPPORT_SUPER_PREFIX}, diff --git a/t/helper/test-submodule.c b/t/helper/test-submodule.c index 9f0eb440192..e0e0c53d386 100644 --- a/t/helper/test-submodule.c +++ b/t/helper/test-submodule.c @@ -2,6 +2,7 @@ #include "test-tool-utils.h" #include "cache.h" #include "parse-options.h" +#include "remote.h" #include "submodule-config.h" #include "submodule.h" @@ -19,9 +20,17 @@ static const char *submodule_is_active_usage[] = { NULL }; +#define TEST_TOOL_RESOLVE_RELATIVE_URL_USAGE \ + "test-tool submodule resolve-relative-url " +static const char *submodule_resolve_relative_url_usage[] = { + TEST_TOOL_RESOLVE_RELATIVE_URL_USAGE, + NULL, +}; + static const char *submodule_usage[] = { TEST_TOOL_CHECK_NAME_USAGE, TEST_TOOL_IS_ACTIVE_USAGE, + TEST_TOOL_RESOLVE_RELATIVE_URL_USAGE, NULL }; @@ -76,9 +85,42 @@ static int cmd__submodule_is_active(int argc, const char **argv) return !is_submodule_active(the_repository, argv[0]); } +static int resolve_relative_url(int argc, const char **argv) +{ + char *remoteurl, *res; + const char *up_path, *url; + + up_path = argv[0]; + remoteurl = xstrdup(argv[1]); + url = argv[2]; + + if (!strcmp(up_path, "(null)")) + up_path = NULL; + + res = relative_url(remoteurl, url, up_path); + puts(res); + free(res); + free(remoteurl); + return 0; +} + +static int cmd__submodule_resolve_relative_url(int argc, const char **argv) +{ + struct option options[] = { + OPT_END() + }; + argc = parse_options(argc, argv, "test-tools", options, + submodule_resolve_relative_url_usage, 0); + if (argc != 3) + usage_with_options(submodule_resolve_relative_url_usage, options); + + return resolve_relative_url(argc, argv); +} + static struct test_cmd cmds[] = { { "check-name", cmd__submodule_check_name }, { "is-active", cmd__submodule_is_active }, + { "resolve-relative-url", cmd__submodule_resolve_relative_url}, }; int cmd__submodule(int argc, const char **argv) diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index 1f2007e62b7..68e29c904a6 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -22,7 +22,7 @@ relative_path() { test_submodule_relative_url() { test_expect_success "test_submodule_relative_url: $1 $2 $3 => $4" " - actual=\$(git submodule--helper resolve-relative-url-test '$1' '$2' '$3') && + actual=\$(test-tool submodule resolve-relative-url '$1' '$2' '$3') && test \"\$actual\" = '$4' " } From patchwork Sun Aug 21 13:57:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949912 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B63EBC00140 for ; Sun, 21 Aug 2022 13:58:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230459AbiHUN64 (ORCPT ); Sun, 21 Aug 2022 09:58:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230396AbiHUN6i (ORCPT ); Sun, 21 Aug 2022 09:58:38 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAEC713FB4 for ; Sun, 21 Aug 2022 06:58:36 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id m17-20020a7bce11000000b003a5bedec07bso6447414wmc.0 for ; Sun, 21 Aug 2022 06:58:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=5uUC0k+hOpJ9QDYTWREhJiAkTxyAIb7Z7qrtsQjBO8A=; b=f5ovtG4wl3kTHgmS4fdvR/XTmywEauVzvMvyxXPWvhgLvoFClj8Iyun7KOWYP81kzP 5K57h0xzA0dilri5wkBgoNrB7zzBIz8olV9PABBQrZMGObKjCsroK6Lyg5ak4pqfxP3Y A+A8sWtaTwzEktlkU2+dy5mNo8CmiNHYCwoeDxBN9l3NsQ7KFKu7fRwqKlhKeMOyF1Ol lB+uHJY3jkFE0d7nkUCKb1pmL93dbVjzdS/EcpNzPMN5IcEU5NRZ3FYEhxnPtcg6KTiJ PhzZjW1uxOyJrZNAXMrhMl5qhJoB9l13sV8trxwZnzSV0dwR1hkd4vqqO8egq7n2R7iY K7Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=5uUC0k+hOpJ9QDYTWREhJiAkTxyAIb7Z7qrtsQjBO8A=; b=ZdaYd+xYwI8hGOeGwUVXyDRSuWB5fcrtgFLjJbrB23/kIN2e3O9YTfoXkyML5UoW+k zdDldTfdHum0ouCJDXSDn+94HNiQ6CQMi5kVpr/Y6R4SQiyqH3rrRrRRd7e0VcSg09gF Qd2+LmC1kFUEJMa531cipuQUCasvNcjkCfVz1ilia1bkV2vamJ4uu0tpN8BqI9sSHZiM HZa7hwselh6tuqfBh/u7GgqQ81++hJUDFzCZZwrTszF5+enlW1nHOaptTzI9usR/5aF5 rixNU/KhdVUn0bOLr08T/ykMRnllA4EiB5bllHOJbcYcuffMIzEaUuG6qtpRhKO3cPG0 bbJg== X-Gm-Message-State: ACgBeo39nNkGbP71Jis+5stv4GaSOYXobtyGegW9lTAe8C9EjErjRun0 X3AKDqG/L3dA7tX9V8tJRC70UZUgytg+Y7gR X-Google-Smtp-Source: AA6agR7bZAVoCwVBg+Lv1stlp21y5XfDgn9qXBG5/4ix4q3iLofG+6bVIRnL1KqrnTxH7yFV8ufQyg== X-Received: by 2002:a05:600c:4fd4:b0:3a6:2694:e3bc with SMTP id o20-20020a05600c4fd400b003a62694e3bcmr9086623wmq.60.1661090314719; Sun, 21 Aug 2022 06:58:34 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:34 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 09/32] submodule--helper style: don't separate declared variables with \n\n Date: Sun, 21 Aug 2022 15:57:18 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The usual style in the codebase is to separate declared variables with a single newline, not two, let's adjust this code to conform to that. This makes the eventual addition of various "int ret" variables more consistent. In doing this the comment added in 2964d6e5e1e (submodule: port subcommand 'set-branch' from shell to C, 2020-06-02) might become ambiguous to some, although it should be clear what it's referring to, let's move it above the 'OPT_NOOP_NOARG('q', "quiet")' to make that clearer. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 7e2986902dd..02552410679 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -368,14 +368,12 @@ static int module_foreach(int argc, const char **argv, const char *prefix) struct foreach_cb info = FOREACH_CB_INIT; struct pathspec pathspec; struct module_list list = MODULE_LIST_INIT; - struct option module_foreach_options[] = { OPT__QUIET(&info.quiet, N_("suppress output of entering each submodule command")), OPT_BOOL(0, "recursive", &info.recursive, N_("recurse into nested submodules")), OPT_END() }; - const char *const git_submodule_helper_usage[] = { N_("git submodule foreach [--quiet] [--recursive] [--] "), NULL @@ -504,12 +502,10 @@ static int module_init(int argc, const char **argv, const char *prefix) struct pathspec pathspec; struct module_list list = MODULE_LIST_INIT; int quiet = 0; - struct option module_init_options[] = { OPT__QUIET(&quiet, N_("suppress output for initializing a submodule")), OPT_END() }; - const char *const git_submodule_helper_usage[] = { N_("git submodule init [] []"), NULL @@ -682,14 +678,12 @@ static int module_status(int argc, const char **argv, const char *prefix) struct pathspec pathspec; struct module_list list = MODULE_LIST_INIT; int quiet = 0; - struct option module_status_options[] = { OPT__QUIET(&quiet, N_("suppress submodule status output")), OPT_BIT(0, "cached", &info.flags, N_("use commit stored in the index instead of the one stored in the submodule HEAD"), OPT_CACHED), OPT_BIT(0, "recursive", &info.flags, N_("recurse into nested submodules"), OPT_RECURSIVE), OPT_END() }; - const char *const git_submodule_helper_usage[] = { N_("git submodule status [--quiet] [--cached] [--recursive] [...]"), NULL @@ -1085,7 +1079,6 @@ static int module_summary(int argc, const char **argv, const char *prefix) enum diff_cmd diff_cmd = DIFF_INDEX; struct object_id head_oid; int ret; - struct option module_summary_options[] = { OPT_BOOL(0, "cached", &cached, N_("use the commit stored in the index instead of the submodule HEAD")), @@ -1097,7 +1090,6 @@ static int module_summary(int argc, const char **argv, const char *prefix) N_("limit the summary size")), OPT_END() }; - const char *const git_submodule_helper_usage[] = { N_("git submodule summary [] [] [--] []"), NULL @@ -1254,14 +1246,12 @@ static int module_sync(int argc, const char **argv, const char *prefix) struct module_list list = MODULE_LIST_INIT; int quiet = 0; int recursive = 0; - struct option module_sync_options[] = { OPT__QUIET(&quiet, N_("suppress output of synchronizing submodule url")), OPT_BOOL(0, "recursive", &recursive, N_("recurse into nested submodules")), OPT_END() }; - const char *const git_submodule_helper_usage[] = { N_("git submodule sync [--quiet] [--recursive] []"), NULL @@ -1393,14 +1383,12 @@ static int module_deinit(int argc, const char **argv, const char *prefix) int quiet = 0; int force = 0; int all = 0; - struct option module_deinit_options[] = { OPT__QUIET(&quiet, N_("suppress submodule status output")), OPT__FORCE(&force, N_("remove submodule working trees even if they contain local changes"), 0), OPT_BOOL(0, "all", &all, N_("unregister all submodules")), OPT_END() }; - const char *const git_submodule_helper_usage[] = { N_("git submodule deinit [--quiet] [-f | --force] [--all | [--] [...]]"), NULL @@ -1669,7 +1657,6 @@ static int module_clone(int argc, const char **argv, const char *prefix) int dissociate = 0, quiet = 0, progress = 0, require_init = 0; struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT; struct list_objects_filter_options filter_options; - struct option module_clone_options[] = { OPT_STRING(0, "prefix", &clone_data.prefix, N_("path"), @@ -1701,7 +1688,6 @@ static int module_clone(int argc, const char **argv, const char *prefix) OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options), OPT_END() }; - const char *const git_submodule_helper_usage[] = { N_("git submodule--helper clone [--prefix=] [--quiet] " "[--reference ] [--name ] [--depth ] " @@ -2489,7 +2475,6 @@ static int module_update(int argc, const char **argv, const char *prefix) struct update_data opt = UPDATE_DATA_INIT; struct list_objects_filter_options filter_options; int ret; - struct option module_update_options[] = { OPT__FORCE(&opt.force, N_("force checkout updates"), 0), OPT_BOOL(0, "init", &opt.init, @@ -2533,7 +2518,6 @@ static int module_update(int argc, const char **argv, const char *prefix) OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options), OPT_END() }; - const char *const git_submodule_helper_usage[] = { N_("git submodule [--quiet] update" " [--init [--filter=]] [--remote]" @@ -2682,7 +2666,6 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) struct pathspec pathspec; struct module_list list = MODULE_LIST_INIT; unsigned flags = ABSORB_GITDIR_RECURSE_SUBMODULES; - struct option embed_gitdir_options[] = { OPT_STRING(0, "prefix", &prefix, N_("path"), @@ -2691,7 +2674,6 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) ABSORB_GITDIR_RECURSE_SUBMODULES), OPT_END() }; - const char *const git_submodule_helper_usage[] = { N_("git submodule absorbgitdirs [] [...]"), NULL @@ -2715,7 +2697,6 @@ static int module_config(int argc, const char **argv, const char *prefix) CHECK_WRITEABLE = 1, DO_UNSET = 2 } command = 0; - struct option module_config_options[] = { OPT_CMDMODE(0, "check-writeable", &command, N_("check if it is safe to write to the .gitmodules file"), @@ -2761,7 +2742,6 @@ static int module_set_url(int argc, const char **argv, const char *prefix) const char *newurl; const char *path; char *config_name; - struct option options[] = { OPT__QUIET(&quiet, N_("suppress output for setting url of a submodule")), OPT_END() @@ -2792,13 +2772,13 @@ static int module_set_branch(int argc, const char **argv, const char *prefix) const char *opt_branch = NULL; const char *path; char *config_name; - - /* - * We accept the `quiet` option for uniformity across subcommands, - * though there is nothing to make less verbose in this subcommand. - */ struct option options[] = { + /* + * We accept the `quiet` option for uniformity across subcommands, + * though there is nothing to make less verbose in this subcommand. + */ OPT_NOOP_NOARG('q', "quiet"), + OPT_BOOL('d', "default", &opt_default, N_("set the default tracking branch to master")), OPT_STRING('b', "branch", &opt_branch, N_("branch"), @@ -2833,7 +2813,6 @@ static int module_create_branch(int argc, const char **argv, const char *prefix) { enum branch_track track; int quiet = 0, force = 0, reflog = 0, dry_run = 0; - struct option options[] = { OPT__QUIET(&quiet, N_("print only error messages")), OPT__FORCE(&force, N_("force creation"), 0), @@ -3132,7 +3111,6 @@ static int module_add(int argc, const char **argv, const char *prefix) int force = 0, quiet = 0, progress = 0, dissociate = 0; struct add_data add_data = ADD_DATA_INIT; char *to_free = NULL; - struct option options[] = { OPT_STRING('b', "branch", &add_data.branch, N_("branch"), N_("branch of repository to add as submodule")), @@ -3149,7 +3127,6 @@ static int module_add(int argc, const char **argv, const char *prefix) OPT_INTEGER(0, "depth", &add_data.depth, N_("depth for shallow clones")), OPT_END() }; - const char *const usage[] = { N_("git submodule add [] [--] []"), NULL From patchwork Sun Aug 21 13:57:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949913 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D5F9C32772 for ; Sun, 21 Aug 2022 13:59:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230461AbiHUN67 (ORCPT ); Sun, 21 Aug 2022 09:58:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230409AbiHUN6k (ORCPT ); Sun, 21 Aug 2022 09:58:40 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D578E14D05 for ; Sun, 21 Aug 2022 06:58:37 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id l33-20020a05600c1d2100b003a645240a95so2365886wms.1 for ; Sun, 21 Aug 2022 06:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=OMMN1wDfVJjIDccNQXy2fAFFOYAehx0B9gZf8DS42o0=; b=Py0SyTuMCQnofGyAWbLlaZ38F6Fiff98feS0JzCYbeTKGN17hG3Njkmiv+ChadWsy4 7STMqoz1gucgee72ObpLR+jodx+5F75oXE1HPE6X9JxZ83K7toJuJt6fyYrUTWfxCLI5 q+c2jeta6upEvnd/6xI4RJ/ocslF99fi2cbxSrwrHvWmV42C1HiSlvnx/W1eJB+LUEcK s+kO9Rzr61dCSREGl1dRmt0LxabeA7oU6mNCMl1j8i2I5raY/R1VVVKUod9+VAbsn81z MkUcK75xzEz59Y/7KqRoIb/dlhpq9TNn7dxUVTCiXUoBk+vp0iPsFNCl4iPY5p8P9m2I mSug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=OMMN1wDfVJjIDccNQXy2fAFFOYAehx0B9gZf8DS42o0=; b=r48JZ+lolaFOTV1PMHi4HyfIcQeBujSOl0+GeveDaNFlQxCAPnq1HrxUoYIxdSQo/h ZwSwI84BAOlVF71Ej9Duaw1iA57ryywWfj+8HI2SAZ/VOSuepoL0BsSv4ABshRmWLtSX 9pv1+OEY9AaWWhQYQKiUwPPbBKlljZbGIyL1KMEtaiCrjM/AnIDD4kBD8hwLTlfq2Izt H6eIjGjVdX2qgj7CXxJ4dSuZYOgttLhMqz6JWiBa3KVGAuZOwW/DpP2CjIqdP2HvmxmF VzqDvm2jqXnIJbFRALClHfYR34wLas23gkp5kw0nUTbPHkgnPFOph3ibSH2V17/Xs4MO 8c2Q== X-Gm-Message-State: ACgBeo2wL6yl4/uuE57Oz5kOxPULr1SyjKnFCb7RccXZ3x/8+6eqSth3 ditlrxTnmXNT3RCfTkwanaTaYqdry6Ct8pGE X-Google-Smtp-Source: AA6agR6p34CRIo+2RnSj5LSrOPUhZzBmpDjYsgDxVhj+6rQJoxLsJHFC+51RRWc9p++4mV4OFUyHuQ== X-Received: by 2002:a1c:7916:0:b0:3a6:3540:5b3c with SMTP id l22-20020a1c7916000000b003a635405b3cmr6837528wme.178.1661090315972; Sun, 21 Aug 2022 06:58:35 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:35 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 10/32] submodule--helper style: add \n\n after variable declarations Date: Sun, 21 Aug 2022 15:57:19 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Since the preceding commit fixed style issues with \n\n among the declared variables let's fix the minor stylistic issues with those variables not being consistently followed by a \n\n. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 02552410679..a492ea3cfed 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -167,6 +167,7 @@ static int module_list_compute(int argc, const char **argv, { int i, result = 0; char *ps_matched = NULL; + parse_pathspec(pathspec, 0, PATHSPEC_PREFER_FULL, prefix, argv); @@ -248,6 +249,7 @@ static void for_each_listed_submodule(const struct module_list *list, each_submodule_fn fn, void *cb_data) { int i; + for (i = 0; i < list->nr; i++) fn(list->entries[i], cb_data); } @@ -267,7 +269,6 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item, struct foreach_cb *info = cb_data; const char *path = list_item->name; const struct object_id *ce_oid = &list_item->oid; - const struct submodule *sub; struct child_process cp = CHILD_PROCESS_INIT; char *displaypath; @@ -456,6 +457,7 @@ static void init_submodule(const char *path, const char *prefix, if (starts_with_dot_dot_slash(url) || starts_with_dot_slash(url)) { char *oldurl = url; + url = resolve_relative_url(oldurl, NULL, 0); free(oldurl); } @@ -493,6 +495,7 @@ static void init_submodule(const char *path, const char *prefix, static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data) { struct init_cb *info = cb_data; + init_submodule(list_item->name, info->prefix, info->flags); } @@ -562,6 +565,7 @@ static int handle_submodule_head_ref(const char *refname, void *cb_data) { struct object_id *output = cb_data; + if (oid) oidcpy(output, oid); @@ -668,6 +672,7 @@ static void status_submodule_cb(const struct cache_entry *list_item, void *cb_data) { struct status_cb *info = cb_data; + status_submodule(list_item->name, &list_item->oid, list_item->ce_flags, info->prefix, info->flags); } @@ -820,6 +825,7 @@ static void generate_submodule_summary(struct summary_cb *info, if (!info->cached && oideq(&p->oid_dst, null_oid())) { if (S_ISGITLINK(p->mod_dst)) { struct ref_store *refs = get_submodule_ref_store(p->sm_path); + if (refs) refs_head_ref(refs, handle_submodule_head_ref, &p->oid_dst); } else if (S_ISLNK(p->mod_dst) || S_ISREG(p->mod_dst)) { @@ -1161,6 +1167,7 @@ static void sync_submodule(const char *path, const char *prefix, if (starts_with_dot_dot_slash(sub->url) || starts_with_dot_slash(sub->url)) { char *up_path = get_up_path(path); + sub_origin_url = resolve_relative_url(sub->url, up_path, 1); super_config_url = resolve_relative_url(sub->url, NULL, 1); free(up_path); @@ -1236,6 +1243,7 @@ static void sync_submodule(const char *path, const char *prefix, static void sync_submodule_cb(const struct cache_entry *list_item, void *cb_data) { struct sync_cb *info = cb_data; + sync_submodule(list_item->name, info->prefix, info->flags); } @@ -1315,6 +1323,7 @@ static void deinit_submodule(const char *path, const char *prefix, if (!(flags & OPT_FORCE)) { struct child_process cp_rm = CHILD_PROCESS_INIT; + cp_rm.git_cmd = 1; strvec_pushl(&cp_rm.args, "rm", "-qn", path, NULL); @@ -1351,6 +1360,7 @@ static void deinit_submodule(const char *path, const char *prefix, /* remove the .git/config entries (unless the user already did it) */ if (!capture_command(&cp_config, &sb_config, 0) && sb_config.len) { char *sub_key = xstrfmt("submodule.%s", sub->name); + /* * remove the whole section so we have a clean state when * the user later decides to init this submodule again @@ -1588,6 +1598,7 @@ static int clone_submodule(struct module_clone_data *clone_data) strvec_pushl(&cp.args, "--depth", clone_data->depth, NULL); if (clone_data->reference.nr) { struct string_list_item *item; + for_each_string_list_item(item, &clone_data->reference) strvec_pushl(&cp.args, "--reference", item->string, NULL); @@ -1938,6 +1949,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, strvec_pushl(&child->args, "--url", url, NULL); if (suc->update_data->references.nr) { struct string_list_item *item; + for_each_string_list_item(item, &suc->update_data->references) strvec_pushl(&child->args, "--reference", item->string, NULL); } @@ -1970,6 +1982,7 @@ static int update_clone_get_next_task(struct child_process *child, ce = suc->update_data->list.entries[suc->current]; if (prepare_to_clone_next_submodule(ce, child, suc, err)) { int *p = xmalloc(sizeof(*p)); + *p = suc->current; *idx_task_cb = p; suc->current++; @@ -1985,6 +1998,7 @@ static int update_clone_get_next_task(struct child_process *child, index = suc->current - suc->update_data->list.nr; if (index < suc->failed_clones_nr) { int *p; + ce = suc->failed_clones[index]; if (!prepare_to_clone_next_submodule(ce, child, suc, err)) { suc->current ++; @@ -2008,6 +2022,7 @@ static int update_clone_start_failure(struct strbuf *err, void *idx_task_cb) { struct submodule_update_clone *suc = suc_cb; + suc->quickstop = 1; return 1; } @@ -2019,9 +2034,9 @@ static int update_clone_task_finished(int result, { const struct cache_entry *ce; struct submodule_update_clone *suc = suc_cb; - int *idxP = idx_task_cb; int idx = *idxP; + free(idxP); if (!result) @@ -2054,6 +2069,7 @@ static int git_update_clone_config(const char *var, const char *value, void *cb) { int *max_jobs = cb; + if (!strcmp(var, "submodule.fetchjobs")) *max_jobs = parse_submodule_fetchjobs(var, value); return 0; @@ -2094,6 +2110,7 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, str if (oid) { char *hex = oid_to_hex(oid); char *remote = get_default_remote(); + strvec_pushl(&cp.args, remote, hex, NULL); free(remote); } @@ -2343,6 +2360,7 @@ static void update_data_to_args(struct update_data *update_data, struct strvec * if (update_data->references.nr) { struct string_list_item *item; + for_each_string_list_item(item, &update_data->references) strvec_pushl(args, "--reference", item->string, NULL); } @@ -2875,8 +2893,10 @@ static void append_fetch_remotes(struct strbuf *msg, const char *git_dir_path) if (!capture_command(&cp_remote, &sb_remote_out, 0)) { char *next_line; char *line = sb_remote_out.buf; + while ((next_line = strchr(line, '\n')) != NULL) { size_t len = next_line - line; + if (strip_suffix_mem(line, &len, " (fetch)")) strbuf_addf(msg, " %.*s\n", (int)len, line); line = next_line + 1; @@ -3183,6 +3203,7 @@ static int module_add(int argc, const char **argv, const char *prefix) int exit_code = -1; struct strbuf sb = STRBUF_INIT; struct child_process cp = CHILD_PROCESS_INIT; + cp.git_cmd = 1; cp.no_stdout = 1; strvec_pushl(&cp.args, "add", "--dry-run", "--ignore-missing", From patchwork Sun Aug 21 13:57:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949914 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 722DEC00140 for ; Sun, 21 Aug 2022 13:59:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230429AbiHUN7L (ORCPT ); Sun, 21 Aug 2022 09:59:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230422AbiHUN6o (ORCPT ); Sun, 21 Aug 2022 09:58:44 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABB8811C39 for ; Sun, 21 Aug 2022 06:58:38 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id ay12so4373296wmb.1 for ; Sun, 21 Aug 2022 06:58:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=gy3cziut9rZ/LQaoyK7gX74eQB971/zs39WOQEPEnJ4=; b=hvG+8ZAOe1aBNBDz7sLOo5eBImxvmncB7YjbDlvvWTy8ys4PCLUT2pKNE/oKpmRWsC YYDOHbmn1OYhzsNtMja7Eh/U12w/fRZd+OSEFjWBLLud/KgIFoDGdY8oZVDOZWIsF+TM TBa8Y/8gGZpd7NtsuteD14D5XLbeglA/WMEUS9qEOxG5VtJcAb3BSMsSYTLdjA/laKuJ QZb7LaY2TezCxqh72YzAso2mlOYKYVZ8o/t/1EvoZZ6v33kH2jdQSYE59BAa5qjXq3t7 2FjX0uguHANrJc7jKzp5p3p32ncdugbkRh0Rcl88nq/11TiWdh3zGkXZk6dMjKvO+myn 1POw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=gy3cziut9rZ/LQaoyK7gX74eQB971/zs39WOQEPEnJ4=; b=NT1IhPPV6wzi6bYPatObHm0XxozFjTUJF5IpbJ12wCV56ZnQFK7wyy6IEarNFx935v SJs9xf1BsOzilpAxvZbQUqeC/m73S+atKxZK9cXrUqHZMz+1tKS76vE3nwtdR3Wkk43+ PxDDz3IV0MTRiz5N46RWdB2YA3GBt4WbD8iTVHw+2gb/QgXlZCa068mV58sJk97M5IeP nt2W34eXR+7HfQ8PNvFjlZX4aIBFjxAT/EXrVYRCVtAmpBFe5fAm9uUBUJUTE0cMxyfV pTIQx0qfF323wIPcw3yF3K4+R4EGBLf+MWdKvUFbICQXK5EGgyniTeQMfOQE9WB8iyp+ 33QQ== X-Gm-Message-State: ACgBeo2koKVvFdivC7F98bINQBOTh69h7a5yQbzk48ZI4Mcbcu9Wefxw V+UE/on1O79DtI/rU6cDpdtlnA2W7Ekage0/ X-Google-Smtp-Source: AA6agR516ETeH/yDmq+nat0pz8Do+wRJ0lSFzg7+Gmw9RVyvmk1ozsz4LPkZNl0l8Et8AbXq6StToQ== X-Received: by 2002:a05:600c:2909:b0:3a6:2ef5:772e with SMTP id i9-20020a05600c290900b003a62ef5772emr7771072wmd.16.1661090316886; Sun, 21 Aug 2022 06:58:36 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:36 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 11/32] submodule--helper: replace memset() with { 0 }-initialization Date: Sun, 21 Aug 2022 15:57:20 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Use the less verbose { 0 }-initialization syntax rather than memset() in builtin/submodule--helper.c, this doesn't make a difference in terms of behavior, but as we're about to modify adjacent code makes this more consistent, and lets us avoid worrying about when the memset() happens v.s. a "goto cleanup". Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index a492ea3cfed..7eb9fb2f00f 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1667,7 +1667,7 @@ static int module_clone(int argc, const char **argv, const char *prefix) { int dissociate = 0, quiet = 0, progress = 0, require_init = 0; struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT; - struct list_objects_filter_options filter_options; + struct list_objects_filter_options filter_options = { 0 }; struct option module_clone_options[] = { OPT_STRING(0, "prefix", &clone_data.prefix, N_("path"), @@ -1707,7 +1707,6 @@ static int module_clone(int argc, const char **argv, const char *prefix) NULL }; - memset(&filter_options, 0, sizeof(filter_options)); argc = parse_options(argc, argv, prefix, module_clone_options, git_submodule_helper_usage, 0); @@ -2491,7 +2490,7 @@ static int module_update(int argc, const char **argv, const char *prefix) { struct pathspec pathspec; struct update_data opt = UPDATE_DATA_INIT; - struct list_objects_filter_options filter_options; + struct list_objects_filter_options filter_options = { 0 }; int ret; struct option module_update_options[] = { OPT__FORCE(&opt.force, N_("force checkout updates"), 0), @@ -2549,7 +2548,6 @@ static int module_update(int argc, const char **argv, const char *prefix) update_clone_config_from_gitmodules(&opt.max_jobs); git_config(git_update_clone_config, &opt.max_jobs); - memset(&filter_options, 0, sizeof(filter_options)); argc = parse_options(argc, argv, prefix, module_update_options, git_submodule_helper_usage, 0); From patchwork Sun Aug 21 13:57:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949916 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89627C00140 for ; Sun, 21 Aug 2022 13:59:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230388AbiHUN7P (ORCPT ); Sun, 21 Aug 2022 09:59:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230439AbiHUN6p (ORCPT ); Sun, 21 Aug 2022 09:58:45 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F40714D3C for ; Sun, 21 Aug 2022 06:58:39 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id l33-20020a05600c1d2100b003a645240a95so2365910wms.1 for ; Sun, 21 Aug 2022 06:58:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=G999UANO/P//+oBJzGxMvACgs143Fxywo0p0bcC5tJQ=; b=UguXMIUhQ48qAL1zP070EubicfnfTwV7Aq4xv1Se3aALX8XGJz2vU9qlxDT4A2geMM TsTNAv5tvoCKrmBjA6w+hw6viJHwqB6gpcZiUnBJCsIXC4fdXCaHu3IcOfAmpnAfLGij Mn8L++FfNOyaNIkaZAvxufMTNviZp9Uuva3O/IfDF5dWVI3t2qx9PZNDseVpC1l29Lfe 1YUgzMw32JWdpKTQmC+pm1FEXMY5oVE20qvphZ/fvbANQS08Y+Z2l82rMw8nDPfPO9nE ktihiPVd4q8OZJ6E7mJ6XhoTpz/6mgVoPQ1S+vciutAvWhkJ8YoF558WySUTggjvG3sT V1YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=G999UANO/P//+oBJzGxMvACgs143Fxywo0p0bcC5tJQ=; b=j1EVIUnXxMz+usGKCz1bVf/m/WjQCCo4q8YnuhdB+d2KMWIBnYOFfgrIwLoI0yCqY4 uVqqo/krHmas5HhekK0q/+9TX+I/oX9cjIqWVjCzYsQ0YbQXsHWeWvNrumVMshuFM+z2 bgAFu3QtG5hFVvs7cxbTP/MRpWV1CQMP+F5JiReLrIuAlsandUFjOJGKkhzd38Rb4rXM mEiV48Uz3mKSJdESryRYbn8383xW63m3f8njF4OJAnMxBS5PoCv62jQFFxixV0DBIr70 1flWdXUdqUic+tvYGf75bazQ0ZfwrjREGBfsM427TPSeCTiwO/exYgrrikHd6Ci27/cE s9fw== X-Gm-Message-State: ACgBeo2wKXCtXyxLKB2luF9BzXlBZFNWLXYmhby60X3FDclfWRc7N7a/ zHfeXqtzZLMqq6wNsyCNWkyQtaHEJ/SBxZ5Y X-Google-Smtp-Source: AA6agR6V9Ih9LP4WPID0MaFBAY+hfmkiRU369Rgw/qRPJG96GpSLLxJWNcec8qVTXATZkI0l0xmpuw== X-Received: by 2002:a05:600c:198e:b0:3a5:d4a2:8896 with SMTP id t14-20020a05600c198e00b003a5d4a28896mr12383326wmq.140.1661090318038; Sun, 21 Aug 2022 06:58:38 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:37 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 12/32] submodule--helper: use xstrfmt() in clone_submodule() Date: Sun, 21 Aug 2022 15:57:21 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Use xstrfmt() in clone_submodule() instead of a "struct strbuf" in two cases where we weren't getting anything out of using the "struct strbuf". This changes code that was was added along with other uses of "struct strbuf" in this function in ee8838d1577 (submodule: rewrite `module_clone` shell function in C, 2015-09-08). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 7eb9fb2f00f..c7833bae81e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1571,12 +1571,11 @@ static int clone_submodule(struct module_clone_data *clone_data) sm_gitdir = absolute_pathdup(sb.buf); strbuf_reset(&sb); - if (!is_absolute_path(clone_data->path)) { - strbuf_addf(&sb, "%s/%s", get_git_work_tree(), clone_data->path); - clone_data->path = strbuf_detach(&sb, NULL); - } else { + if (!is_absolute_path(clone_data->path)) + clone_data->path = xstrfmt("%s/%s", get_git_work_tree(), + clone_data->path); + else clone_data->path = xstrdup(clone_data->path); - } if (validate_submodule_git_dir(sm_gitdir, clone_data->name) < 0) die(_("refusing to create/use '%s' in another submodule's " @@ -1628,14 +1627,16 @@ static int clone_submodule(struct module_clone_data *clone_data) die(_("clone of '%s' into submodule path '%s' failed"), clone_data->url, clone_data->path); } else { + char *path; + if (clone_data->require_init && !access(clone_data->path, X_OK) && !is_empty_dir(clone_data->path)) die(_("directory not empty: '%s'"), clone_data->path); if (safe_create_leading_directories_const(clone_data->path) < 0) die(_("could not create directory '%s'"), clone_data->path); - strbuf_addf(&sb, "%s/index", sm_gitdir); - unlink_or_warn(sb.buf); - strbuf_reset(&sb); + path = xstrfmt("%s/index", sm_gitdir); + unlink_or_warn(path); + free(path); } connect_work_tree_and_git_dir(clone_data->path, sm_gitdir, 0); From patchwork Sun Aug 21 13:57:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 757FAC32772 for ; Sun, 21 Aug 2022 13:59:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230488AbiHUN7N (ORCPT ); Sun, 21 Aug 2022 09:59:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230440AbiHUN6p (ORCPT ); Sun, 21 Aug 2022 09:58:45 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D85517058 for ; Sun, 21 Aug 2022 06:58:41 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id bs25so10300156wrb.2 for ; Sun, 21 Aug 2022 06:58:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=QcF0k+7hSaB899OyvlOfZqH+MgbAnK8B6coZoKwPuuc=; b=WqprT+uBiLP78O/yzjs+169RkofjBHGj7xZlLRs1qLw/eBqMaw33PobGPoawTWEf72 4LyekNh3NpUciSvQdbQSBNzRlEJNfySNPxg0gx71IET4YJtzKYO945EtY0xZP2w9sciJ 8fiDb8Btld8Um7IbNYuXKFN1oBMYZUsUXyVccauX0mqhmrMkFYqtyRcj9bXpYzYZ0JS1 hB5TPOW64Qoy9fDCO6MPMUeKjNMKT7wRgv26TIAjqYdgXLUr6lcLUcGLZGXUvdstBCJX CwE1JTJXgOYZXd7Nj8YaPnXM2mJmDrNSyywcLVGv8ocVqEPxrMkVKHWVdpIvO+53T79y 57mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=QcF0k+7hSaB899OyvlOfZqH+MgbAnK8B6coZoKwPuuc=; b=Anqg3X+ICXUDrIdvMOCgROnBqVg4PZbrD7izpryPZblf4G/vJsC+PiTtR2894uRm83 ul3TDGVGipT3iuhnGul7rID/RQowyQnOiJm6AeGT8qAXABfSHxcAPLrgoJXtDTd5zvjx f6c0YOOEbCwDH8Wcf6xQ2QZ7zN84awDcY+fw9OH+CeT3rE1xuwQHta/ZjflQ0dT//DvZ DSku/cgfbmMiBkoBRw86AetoqqiK8BS4XzgNcZrPfHAeMKTda0HnkMGsjJVesmi/UfCW q/leI/PKrNPizzEfthuaYWQD9ZDhBKaaAvhQMiRabt4i6ZVKYF5yZ+5ZB8IDi+GUFzVX QuKw== X-Gm-Message-State: ACgBeo1hOuBcneu6CIAZD/6zg3zOajKpiBa25JxAEOkYt+hl3N/GNb+t LrnSFCx2hjlJc1vZsoH4BV+l1UjztBxj0n4U X-Google-Smtp-Source: AA6agR70j+idxjLhO09mx+7nkaGE2g9djxhKJGlBXJlYq6YY3c0cGrhvn3HCMrl8dZ2flKGX8DmXEA== X-Received: by 2002:adf:f88c:0:b0:225:4c23:6788 with SMTP id u12-20020adff88c000000b002254c236788mr2792972wrp.140.1661090319079; Sun, 21 Aug 2022 06:58:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:38 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 13/32] submodule--helper: move "sb" in clone_submodule() to its own scope Date: Sun, 21 Aug 2022 15:57:22 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor the only remaining use of a "struct strbuf sb" in clone_submodule() to live in its own scope. This makes the code clearer by limiting its lifetime. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index c7833bae81e..2f1f0e1bf34 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1560,16 +1560,24 @@ static void prepare_possible_alternates(const char *sm_name, free(error_strategy); } -static int clone_submodule(struct module_clone_data *clone_data) +static char *clone_submodule_sm_gitdir(const char *name) { - char *p, *sm_gitdir; - char *sm_alternate = NULL, *error_strategy = NULL; struct strbuf sb = STRBUF_INIT; - struct child_process cp = CHILD_PROCESS_INIT; + char *sm_gitdir; - submodule_name_to_gitdir(&sb, the_repository, clone_data->name); + submodule_name_to_gitdir(&sb, the_repository, name); sm_gitdir = absolute_pathdup(sb.buf); - strbuf_reset(&sb); + strbuf_release(&sb); + + return sm_gitdir; +} + +static int clone_submodule(struct module_clone_data *clone_data) +{ + char *p; + char *sm_gitdir = clone_submodule_sm_gitdir(clone_data->name); + char *sm_alternate = NULL, *error_strategy = NULL; + struct child_process cp = CHILD_PROCESS_INIT; if (!is_absolute_path(clone_data->path)) clone_data->path = xstrfmt("%s/%s", get_git_work_tree(), @@ -1658,7 +1666,6 @@ static int clone_submodule(struct module_clone_data *clone_data) free(sm_alternate); free(error_strategy); - strbuf_release(&sb); free(sm_gitdir); free(p); return 0; From patchwork Sun Aug 21 13:57:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9FC9FC00140 for ; Sun, 21 Aug 2022 13:59:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230502AbiHUN7S (ORCPT ); Sun, 21 Aug 2022 09:59:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230365AbiHUN6q (ORCPT ); Sun, 21 Aug 2022 09:58:46 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2602817AAB for ; Sun, 21 Aug 2022 06:58:41 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id ay12so4373334wmb.1 for ; Sun, 21 Aug 2022 06:58:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=DOQgtSb1e64SllI1i6oH4T0Tq9wMW4+1Ny4nIHi5g+0=; b=M97x+EQTJJ4/s/dm9yefYlfQPDFAmF2/j0Za7nw+92o+nPrdK+8hNAb7SPSx/R6xIg e48B20C5KR+Tg0JV5OJWKIZKv8/RHoWVNZceyW1W3R0nk+VliEzcnv5CZGHfAXEyPRcn Pdx+HYBFcR/ZpoH6m8um7QaTOeA4xhG/kmF3jER6vfsIWQaLz9lmDZZ2/OjF8RBdRdWM /0pZ05tF4xqiy1M6wFQrZ7Ryy3r7HrGKjRdX33d+TuwXujvogqC4O+xRkZiHX8tMqYdJ paRQ/Q3APR2ke31v+RC6YHlHI1llDugivw66x3C0ctfyowSNZphutzUg/lufmT1NPq4a cayA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=DOQgtSb1e64SllI1i6oH4T0Tq9wMW4+1Ny4nIHi5g+0=; b=rjESlptvkUOAefNRc3diSbI6lnUE70mch40RZf4DaZuxvmRj54dAE/LtZQ0tbPNixa OgnwFGuMZt73ZyaWW4oqpNbcF1g/1/LLklF16/nqQUgHtCr+V0FFo6d1shT/i4xRe7KP WxD8a33xUtH6/CGZ978b3VufCI3fTFZk7o/o7xmGFZDuuIrrD5tgEM0MyPhxEdmQgkWP V3DIXhiSmLCxiwLPxgnKx/E04Ff8hFNJEz3zMjdYSPfzNmauLyBbT0EsyNlxxTt1UiT4 eqpforW9eagcKSkCKuzrC+1wd648AgrGRbZCikyDC6QG0Hf8cShEfNhIPZU/TuyRQrA6 34bA== X-Gm-Message-State: ACgBeo3YbptWDAZpJR6MnFapYSDjS4dmCqaF9lUjeG+UN+9e7DxluP5G qNc1uHR27cBks+JNgOq0rULzHBeWvXdt1Y0n X-Google-Smtp-Source: AA6agR7JdJRcsQYrftXOJoG2g83FHhU3x99rVaFkwjBVtKb3gM6XDQi7R7BdYYBk+TIv6Sw9EH0irw== X-Received: by 2002:a7b:cd0f:0:b0:3a5:ec59:daf0 with SMTP id f15-20020a7bcd0f000000b003a5ec59daf0mr12695908wmj.13.1661090319897; Sun, 21 Aug 2022 06:58:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:39 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 14/32] submodule--helper: add "const" to passed "module_clone_data" Date: Sun, 21 Aug 2022 15:57:23 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add "const" to the "struct module_clone_data" that we pass to clone_submodule(), which makes the ownership clear, and stops us from clobbering the "clone_data->path". We still need to add to the "reference" member, which is a "struct string_list". Let's do this by having clone_submodule() create its own, and copy the contents over, allowing us to pass it as a separate parameter. This new "struct string_list" still leaks memory, just as the "struct module_clone_data" did before. let's not fix that for now, to fix that we'll need to add some "goto cleanup" to the relevant code. That will eventually be done in follow-up commits, this change makes it easier to fix the memory leak. The scope of the new "reference" variable in add_submodule() could be narrowed to the "else" block, but as we'll eventually free it with a "goto cleanup" let's declare it at the start of the function. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 49 ++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 2f1f0e1bf34..d243c3ddfd3 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1437,7 +1437,6 @@ struct module_clone_data { const char *url; const char *depth; struct list_objects_filter_options *filter_options; - struct string_list reference; unsigned int quiet: 1; unsigned int progress: 1; unsigned int dissociate: 1; @@ -1445,7 +1444,6 @@ struct module_clone_data { int single_branch; }; #define MODULE_CLONE_DATA_INIT { \ - .reference = STRING_LIST_INIT_NODUP, \ .single_branch = -1, \ } @@ -1572,18 +1570,20 @@ static char *clone_submodule_sm_gitdir(const char *name) return sm_gitdir; } -static int clone_submodule(struct module_clone_data *clone_data) +static int clone_submodule(const struct module_clone_data *clone_data, + struct string_list *reference) { char *p; char *sm_gitdir = clone_submodule_sm_gitdir(clone_data->name); char *sm_alternate = NULL, *error_strategy = NULL; struct child_process cp = CHILD_PROCESS_INIT; + const char *clone_data_path; if (!is_absolute_path(clone_data->path)) - clone_data->path = xstrfmt("%s/%s", get_git_work_tree(), - clone_data->path); + clone_data_path = xstrfmt("%s/%s", get_git_work_tree(), + clone_data->path); else - clone_data->path = xstrdup(clone_data->path); + clone_data_path = xstrdup(clone_data->path); if (validate_submodule_git_dir(sm_gitdir, clone_data->name) < 0) die(_("refusing to create/use '%s' in another submodule's " @@ -1593,7 +1593,7 @@ static int clone_submodule(struct module_clone_data *clone_data) if (safe_create_leading_directories_const(sm_gitdir) < 0) die(_("could not create directory '%s'"), sm_gitdir); - prepare_possible_alternates(clone_data->name, &clone_data->reference); + prepare_possible_alternates(clone_data->name, reference); strvec_push(&cp.args, "clone"); strvec_push(&cp.args, "--no-checkout"); @@ -1603,10 +1603,10 @@ static int clone_submodule(struct module_clone_data *clone_data) strvec_push(&cp.args, "--progress"); if (clone_data->depth && *(clone_data->depth)) strvec_pushl(&cp.args, "--depth", clone_data->depth, NULL); - if (clone_data->reference.nr) { + if (reference->nr) { struct string_list_item *item; - for_each_string_list_item(item, &clone_data->reference) + for_each_string_list_item(item, reference) strvec_pushl(&cp.args, "--reference", item->string, NULL); } @@ -1625,7 +1625,7 @@ static int clone_submodule(struct module_clone_data *clone_data) strvec_push(&cp.args, "--"); strvec_push(&cp.args, clone_data->url); - strvec_push(&cp.args, clone_data->path); + strvec_push(&cp.args, clone_data_path); cp.git_cmd = 1; prepare_submodule_repo_env(&cp.env); @@ -1633,25 +1633,25 @@ static int clone_submodule(struct module_clone_data *clone_data) if(run_command(&cp)) die(_("clone of '%s' into submodule path '%s' failed"), - clone_data->url, clone_data->path); + clone_data->url, clone_data_path); } else { char *path; - if (clone_data->require_init && !access(clone_data->path, X_OK) && - !is_empty_dir(clone_data->path)) - die(_("directory not empty: '%s'"), clone_data->path); - if (safe_create_leading_directories_const(clone_data->path) < 0) - die(_("could not create directory '%s'"), clone_data->path); + if (clone_data->require_init && !access(clone_data_path, X_OK) && + !is_empty_dir(clone_data_path)) + die(_("directory not empty: '%s'"), clone_data_path); + if (safe_create_leading_directories_const(clone_data_path) < 0) + die(_("could not create directory '%s'"), clone_data_path); path = xstrfmt("%s/index", sm_gitdir); unlink_or_warn(path); free(path); } - connect_work_tree_and_git_dir(clone_data->path, sm_gitdir, 0); + connect_work_tree_and_git_dir(clone_data_path, sm_gitdir, 0); - p = git_pathdup_submodule(clone_data->path, "config"); + p = git_pathdup_submodule(clone_data_path, "config"); if (!p) - die(_("could not get submodule directory for '%s'"), clone_data->path); + die(_("could not get submodule directory for '%s'"), clone_data_path); /* setup alternateLocation and alternateErrorStrategy in the cloned submodule if needed */ git_config_get_string("submodule.alternateLocation", &sm_alternate); @@ -1676,6 +1676,7 @@ static int module_clone(int argc, const char **argv, const char *prefix) int dissociate = 0, quiet = 0, progress = 0, require_init = 0; struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT; struct list_objects_filter_options filter_options = { 0 }; + struct string_list reference = STRING_LIST_INIT_NODUP; struct option module_clone_options[] = { OPT_STRING(0, "prefix", &clone_data.prefix, N_("path"), @@ -1689,7 +1690,7 @@ static int module_clone(int argc, const char **argv, const char *prefix) OPT_STRING(0, "url", &clone_data.url, N_("string"), N_("url where to clone the submodule from")), - OPT_STRING_LIST(0, "reference", &clone_data.reference, + OPT_STRING_LIST(0, "reference", &reference, N_("repo"), N_("reference repository")), OPT_BOOL(0, "dissociate", &dissociate, @@ -1728,7 +1729,7 @@ static int module_clone(int argc, const char **argv, const char *prefix) usage_with_options(git_submodule_helper_usage, module_clone_options); - clone_submodule(&clone_data); + clone_submodule(&clone_data, &reference); list_objects_filter_release(&filter_options); return 0; } @@ -2916,6 +2917,7 @@ static int add_submodule(const struct add_data *add_data) { char *submod_gitdir_path; struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT; + struct string_list reference = STRING_LIST_INIT_NODUP; /* perhaps the path already exists and is already a git repo, else clone it */ if (is_directory(add_data->sm_path)) { @@ -2932,6 +2934,7 @@ static int add_submodule(const struct add_data *add_data) free(submod_gitdir_path); } else { struct child_process cp = CHILD_PROCESS_INIT; + submod_gitdir_path = xstrfmt(".git/modules/%s", add_data->sm_name); if (is_directory(submod_gitdir_path)) { @@ -2971,13 +2974,13 @@ static int add_submodule(const struct add_data *add_data) clone_data.quiet = add_data->quiet; clone_data.progress = add_data->progress; if (add_data->reference_path) - string_list_append(&clone_data.reference, + string_list_append(&reference, xstrdup(add_data->reference_path)); clone_data.dissociate = add_data->dissociate; if (add_data->depth >= 0) clone_data.depth = xstrfmt("%d", add_data->depth); - if (clone_submodule(&clone_data)) + if (clone_submodule(&clone_data, &reference)) return -1; prepare_submodule_repo_env(&cp.env); From patchwork Sun Aug 21 13:57:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949918 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51968C28D13 for ; Sun, 21 Aug 2022 13:59:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230510AbiHUN7U (ORCPT ); Sun, 21 Aug 2022 09:59:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230394AbiHUN6z (ORCPT ); Sun, 21 Aug 2022 09:58:55 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA69121818 for ; Sun, 21 Aug 2022 06:58:42 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id e20so9798847wri.13 for ; Sun, 21 Aug 2022 06:58:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=aIBTj9MYFsAY2N/IG3ERGESFbx4oxG5dO/qioT6/u/I=; b=PBg09TaOk4tyv3OO2tmKLPB5183VClOoX8T2LpUHAILshC+zso9kb//cqGxmUDzdqZ 0N1Pq11rxuBtf2mFQyiJ/MSWulSX3236NFe7IMHqn9bBJEl9ke0H9jPbCfuUTtOe3GuG YeGxaUyozD4fI1BJixiAoLsnfI+hHLMU1trNgreuluO0Gl2qrGAEvauSmM2s3Yi2GxB2 vM78aCVLFZjeiZQFG0qJChmZOgkPL4OnLstRLNchWyPNf7M+kBaWN01+pUO+P939t6/k C3jcNnmi9jQKGQo/EIigBOB0yKvfn0ZixcfEHlcFEvpBtKmLWswRCX0Z/VZh4/OaI6r+ EBIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=aIBTj9MYFsAY2N/IG3ERGESFbx4oxG5dO/qioT6/u/I=; b=G/8euXBgUI44wxqMzo8XyP19YmykyZusEha7co96tmwmjBFbjd2BnJKzJk+iQlEAev y8/pyOIE8PQ+NGo1Emf2u2CJrFxKBn31KwH2RP5KEeuNiCHiMUhYArOhB9tONDo33oYx JVx6B2cI9WbjGAeOY5kpytBfoBqCVwff4L2T74bBXttySojziv086ZtyeMVgIzxoQPUz +Y3EESisaQAmAkVXtkn4ZpLgXdUQch1g4S6mJgL1nzHqC0HB2En0k2+iP1KQVw7Q4/6f QnIX6SomKNQ4IWtbIYIdH68E06EVCe6jc4rgClscOW4XTXj4jZ4YrdkYFg7CV9gfpbIN mXhw== X-Gm-Message-State: ACgBeo0CB7Wv9ptAcevGuG0i+XI6j6Lz4Gb2vLbL76z7ZCjrUGCrNnw4 Z/OsL/JCJLZpucSGSXOnB16Ort92Pood54wu X-Google-Smtp-Source: AA6agR7VpBLcNt8jJTluAxCh72/vugdJuX+SFvd7xDYnuphR8gT9VwinhlR59eoiPQzggMP5lQE0KQ== X-Received: by 2002:a05:6000:178c:b0:223:141:8a14 with SMTP id e12-20020a056000178c00b0022301418a14mr8724124wrg.629.1661090320938; Sun, 21 Aug 2022 06:58:40 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:40 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 15/32] submodule--helper: add "const" to copy of "update_data" Date: Sun, 21 Aug 2022 15:57:24 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Glen Choo Add a "const" to the copy of "struct update_data" that's tracked by the "struct submodule_update_clone", as it neither owns nor modifies it. Signed-off-by: Glen Choo Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index d243c3ddfd3..829a57ce8a9 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1780,7 +1780,7 @@ struct submodule_update_clone { int current; /* configuration parameters which are passed on to the children */ - struct update_data *update_data; + const struct update_data *update_data; /* to be consumed by update_submodule() */ struct update_clone_data *update_clone; @@ -1865,7 +1865,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, const char *update_string; enum submodule_update_type update_type; char *key; - struct update_data *ud = suc->update_data; + const struct update_data *ud = suc->update_data; char *displaypath = get_submodule_displaypath(ce->name, ud->prefix); struct strbuf sb = STRBUF_INIT; int needs_cloning = 0; From patchwork Sun Aug 21 13:57:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949919 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC3F7C00140 for ; Sun, 21 Aug 2022 13:59:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230525AbiHUN7Z (ORCPT ); Sun, 21 Aug 2022 09:59:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230455AbiHUN6z (ORCPT ); Sun, 21 Aug 2022 09:58:55 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 347E72315C for ; Sun, 21 Aug 2022 06:58:43 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id e20so9798867wri.13 for ; Sun, 21 Aug 2022 06:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=Fm9382WO8O47G+FM+UhOtgrneE9PPBtHqtMqreYeSPs=; b=aiq0i3gaOeqX/JDPD0MSTeBUN1/YyM9wF+Ea3L/bzQx7HvO2YRbXwCj7zxNKYU7zgv hvj2IB/26bCjmax1xniI7JuM3KrvVSTntZyeKe6S+cK2nsUaDVH6tkEajHBI0rKyg4MM bTMsTsdSqn9OHVhUTiwy1j7pULOIVMxgKInLrEwhVtVHzbtP5C9QcT8P9h/a1/zxZpq6 BZfmuftO+KVzUQdQM/dy5cLhvaSDyPHpxtRjj6ViNSj/5sphn+ZNWRAdpa9svijAjJS8 DE7j3RcHlL+jk5apGd2QPL/KE7ZBKDNuLEBTcPubdCFP/+sUA5Ba/cWND97q/tK4qpqL pGqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=Fm9382WO8O47G+FM+UhOtgrneE9PPBtHqtMqreYeSPs=; b=nOBw9B2UhJWFpUG8DS8I/fcZezXhPS/fzJhx7wV48OLJTemcZSPbwV1FDh6Hm4CUsg JnAB8yMtbP69qDa1vu3nzJyY9i7lfeGV9mX/0Vo5HRetBaBG/SMl9avg/Y0yNYzYbIZr 4FdPKbRuTHBJsQz8IAOk82SGvieE8k8X6o9+8+nVYwNAz6W/AsIGlsbyvNdFA2PrcOYv iSruVbJInWRnEKiSUCmPxsXTYLYAaNxr6EGI4sCWu5+PhCuunTKOrsSqi4mTM4Wv0MKK Eu0T33jneR38337HFQATxopLl+mBLjWAPZn2ficEZ4J7RkHupUcY+kNx4Ph7mhOtnbqD dKig== X-Gm-Message-State: ACgBeo1ANol5Um+lyHjVpG6U6vmvbNgRQStfCJSlQ9eJAaQdfhShEp4+ fNOKxtGki0pSKpx1CddygFWF+fI+C/b2AyBC X-Google-Smtp-Source: AA6agR5LiiipKcMhJGIRyIBaxbdhhE2Q6TuUCZDkmcJ+GmaxtSL9K3jDG5eUX5ljb5yPCQmOawjBaw== X-Received: by 2002:a5d:6da5:0:b0:222:4634:6a4e with SMTP id u5-20020a5d6da5000000b0022246346a4emr8787348wrs.172.1661090321868; Sun, 21 Aug 2022 06:58:41 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:41 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 16/32] submodule--helper: refactor "errmsg_str" to be a "struct strbuf" Date: Sun, 21 Aug 2022 15:57:25 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Glen Choo Refactor code added in e83e3333b57 (submodule: port submodule subcommand 'summary' from shell to C, 2020-08-13) so that "errmsg" and "errmsg_str" are folded into one. The distinction between the empty string and NULL is something that's tested for by e.g. "t/t7401-submodule-summary.sh". This is in preparation for fixing a memory leak the "struct strbuf" in the pre-image. Let's also pass a "const char *" to print_submodule_summary(), as it should not be modifying the "errmsg". Signed-off-by: Glen Choo Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 829a57ce8a9..a694b18b55e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -761,7 +761,7 @@ static char *verify_submodule_committish(const char *sm_path, return strbuf_detach(&result, NULL); } -static void print_submodule_summary(struct summary_cb *info, char *errmsg, +static void print_submodule_summary(struct summary_cb *info, const char *errmsg, int total_commits, const char *displaypath, const char *src_abbrev, const char *dst_abbrev, struct module_cb *p) @@ -819,7 +819,7 @@ static void generate_submodule_summary(struct summary_cb *info, { char *displaypath, *src_abbrev = NULL, *dst_abbrev; int missing_src = 0, missing_dst = 0; - char *errmsg = NULL; + struct strbuf errmsg = STRBUF_INIT; int total_commits = -1; if (!info->cached && oideq(&p->oid_dst, null_oid())) { @@ -920,23 +920,21 @@ static void generate_submodule_summary(struct summary_cb *info, * submodule, i.e., deleted or changed to blob */ if (S_ISGITLINK(p->mod_dst)) { - struct strbuf errmsg_str = STRBUF_INIT; if (missing_src && missing_dst) { - strbuf_addf(&errmsg_str, " Warn: %s doesn't contain commits %s and %s\n", + strbuf_addf(&errmsg, " Warn: %s doesn't contain commits %s and %s\n", displaypath, oid_to_hex(&p->oid_src), oid_to_hex(&p->oid_dst)); } else { - strbuf_addf(&errmsg_str, " Warn: %s doesn't contain commit %s\n", + strbuf_addf(&errmsg, " Warn: %s doesn't contain commit %s\n", displaypath, missing_src ? oid_to_hex(&p->oid_src) : oid_to_hex(&p->oid_dst)); } - errmsg = strbuf_detach(&errmsg_str, NULL); } } - print_submodule_summary(info, errmsg, total_commits, - displaypath, src_abbrev, + print_submodule_summary(info, errmsg.len ? errmsg.buf : NULL, + total_commits, displaypath, src_abbrev, dst_abbrev, p); free(displaypath); From patchwork Sun Aug 21 13:57:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949920 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A13E9C28D13 for ; Sun, 21 Aug 2022 13:59:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231126AbiHUN70 (ORCPT ); Sun, 21 Aug 2022 09:59:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230458AbiHUN64 (ORCPT ); Sun, 21 Aug 2022 09:58:56 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01F2A11145 for ; Sun, 21 Aug 2022 06:58:44 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id bd26-20020a05600c1f1a00b003a5e82a6474so4720893wmb.4 for ; Sun, 21 Aug 2022 06:58:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=UETBDGHxON93iX2/uc2BL9CuytcjVdLo+av/+YvxHlc=; b=X8wdkdY7TnQD5911sbtArZVuae3YnRPwQlgmnkxRFYatQThI1WtRKqZ1EYgdT5LACB 9MkN7empF4TW0uvEPj4kZw9Nh0EKvCaDNXOykAKYUaYjJJxvRNmuewX+XLyb3Ldadnul VHlsD0QeZ1aX7kQC/TksRUSDKx21TCd1xuCpDo+xwmQAxmRX/mZ+9+2UxR0TbJnX+cBM YuYUa1MWFiMeKOrt+FREJlcjPB+wFQL9kMhsha7JmZPgILvILHtX+zHYjNDW527VTOwV LoeYR7upWU8OLKOjGzwP3EQkTwssY37SI5BJofG2J5XFulLwwoa2RWjfYl0IhUNHf4/j VBDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=UETBDGHxON93iX2/uc2BL9CuytcjVdLo+av/+YvxHlc=; b=nsXoM4V7qR7zq9fDwoJTyrgcgIePz7AC1bpzW3fyNXFQZQL5fjDWtkQiQ+VxIdxgs+ 3/T1KcdMiR/9wkZ+YH035QChrtnRrNrVeHfkDsS6RN5zHt9m8Quz3LJeT9/hP7J3gYFh sOGdJdRxr9zf5iXd0/IpCrr3zzkgmY/4jk9BODb/P3AtBr6ttZNA99VE8cCf8Gd084+y SmCPPhFBOFav+JOGVPlRM+zbgTAlKkh7qkCITarJAfjcOlJCdfbARSZL7f8S6lc+T6z0 WxjUoVabfM8e8yjryYaAY/24rRiPAAJHf9G8zFFMNu2ZrYHY0eC9hwdWOqQaQ37efTWF 8XSg== X-Gm-Message-State: ACgBeo20MDkya6UukVhRF+TPgGqFIOq08OGU3+C3Ytu2C/WgyffvQKoz KYH9dsCII6pLbQvICV88ynMIfxbWxW3CPHy2 X-Google-Smtp-Source: AA6agR6nkvSknK5EcDTXb6Pw+gm2xWUS4/INL4Ggq8qmoQN4l1lbQpa4BQjHT/lUR1mdJfbUmjfK2g== X-Received: by 2002:a05:600c:3d12:b0:3a5:f600:4fe9 with SMTP id bh18-20020a05600c3d1200b003a5f6004fe9mr12962136wmb.98.1661090322889; Sun, 21 Aug 2022 06:58:42 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:42 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 17/32] submodule--helper: don't redundantly check "else if (res)" Date: Sun, 21 Aug 2022 15:57:26 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The "res" variable must be true at this point in update_submodule(), as just a few lines above this we've unconditionally: if (!res) return 0; So we don't need to guard the "return 1" with an "else if (res)", we an return unconditionally at this point. See b3c5f5cb048 (submodule: move core cmd_update() logic to C, 2022-03-15) for the initial introduction of this code, this check of "res" has always been redundant. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index a694b18b55e..a9808224f01 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2446,8 +2446,7 @@ static int update_submodule(struct update_data *update_data) update_data->displaypath); if (res == 128) exit(res); - else if (res) - return 1; + return 1; } return 0; From patchwork Sun Aug 21 13:57:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949922 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87D22C00140 for ; Sun, 21 Aug 2022 13:59:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230478AbiHUN7n (ORCPT ); Sun, 21 Aug 2022 09:59:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230470AbiHUN7K (ORCPT ); Sun, 21 Aug 2022 09:59:10 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1066213F0B for ; Sun, 21 Aug 2022 06:58:46 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id b5so6015178wrr.5 for ; Sun, 21 Aug 2022 06:58:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=aU6G11qCC/BaUbqtt2q06Eo7PqmIwWLoUAtX9oWpvWM=; b=iKEkmldWzAjcsn+r986jFjdCOP5mCX8jLSlqaf7zPTGmvVJNEnAUBcAEKI+m5nmD5a qKmKiQQRG2RveBxUvvQuRgNVjSxvUE55HT4RW6HzFktc3mpaaMozht4k9Xru0xxM1SLS uwRQndH8ff+obIoW7uMbzPIAU3Qi+yJlCPoZm0lYLAn1tj9/oiqb8ulIy6NihJk4/lgm sUiWiO5bbgla69rs1T44SraVWHyIOhTX5TWVfTe0Gkw6ABn/TTnhLOSuZBiLX6hgNqZ0 x+But4x6qyuCmKp6IO9Sk7oWE7auzzeaWKbUlZkA24Pdkx87Z6eV/JdgiT3VI5uCqt3T 2zfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=aU6G11qCC/BaUbqtt2q06Eo7PqmIwWLoUAtX9oWpvWM=; b=6Hu+/MACsgOmaP6d1/wkwTtukN79xUTlgvlro/Dn5fWcTC6SQWYVQKdh1kHvel3Q+W GEAa1W6nEQNmASloymR3/IS6qqXbz5Q5aZaioMo/2TzaRireU1NjvfNQP5o2PJ+zeAyS qj2ZmCLiedeTjg9+gHByJWMk9yY4Om6LHNTmu8zpVwvCdMKyHq3PoKQn6i6v62+8Ohai nAR3ftQB3STnqdDOabj4WLX+5rNexdW+Pvfe1EeG2jGQXPbDgNDoReIsYzj1marGfjlR Kh7l3/35BxCUa7O+ok4sew+jIlI9+QTFv9tpS1SE6K3ocLI2cTyzxEB6ya8Vqq2yX+xh OMiA== X-Gm-Message-State: ACgBeo2YBw/Tjvv0qE6V1hnl7URzjYQaYwZUIMSHggsojEtkiqxGQ6XY 4BORYTAlLuj7/0Mi70K+mRbi4nTULSOUpSG2 X-Google-Smtp-Source: AA6agR5FXIAp7999JgekqYFShEOmyLA8yDTwW5CCoK8uUYM/88ZE67u1LAJR/xrdmyaAW/JrjE7/Rw== X-Received: by 2002:a5d:628b:0:b0:225:4638:a7df with SMTP id k11-20020a5d628b000000b002254638a7dfmr3603460wru.98.1661090323951; Sun, 21 Aug 2022 06:58:43 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:43 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 18/32] submodule--helper: rename "int res" to "int ret" Date: Sun, 21 Aug 2022 15:57:27 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Rename the "res" variable added in b3c5f5cb048 (submodule: move core cmd_update() logic to C, 2022-03-15) to "ret", which is the convention in the rest of this file. Eventual follow-up commits will change the code in update_submodule() to a "goto cleanup" pattern, let's have the post image look consistent with the rest. For update_submodules() let's also use a "ret" for consistency, that use was also added in b3c5f5cb048. We'll be modifying that codepath in subsequent commits. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index a9808224f01..fed92585a02 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2427,7 +2427,7 @@ static int update_submodule(struct update_data *update_data) if (update_data->recursive) { struct child_process cp = CHILD_PROCESS_INIT; struct update_data next = *update_data; - int res; + int ret; next.prefix = NULL; oidcpy(&next.oid, null_oid()); @@ -2439,13 +2439,13 @@ static int update_submodule(struct update_data *update_data) update_data_to_args(&next, &cp.args); /* die() if child process die()'d */ - res = run_command(&cp); - if (!res) + ret = run_command(&cp); + if (!ret) return 0; die_message(_("Failed to recurse into submodule path '%s'"), update_data->displaypath); - if (res == 128) - exit(res); + if (ret == 128) + exit(ret); return 1; } @@ -2454,7 +2454,7 @@ static int update_submodule(struct update_data *update_data) static int update_submodules(struct update_data *update_data) { - int i, res = 0; + int i, ret = 0; struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT; suc.update_data = update_data; @@ -2472,7 +2472,7 @@ static int update_submodules(struct update_data *update_data) * - the listener can avoid doing any work if fetching failed. */ if (suc.quickstop) { - res = 1; + ret = 1; goto cleanup; } @@ -2484,12 +2484,12 @@ static int update_submodules(struct update_data *update_data) update_data->sm_path = ucd.sub->path; if (update_submodule(update_data)) - res = 1; + ret = 1; } cleanup: string_list_clear(&update_data->references, 0); - return res; + return ret; } static int module_update(int argc, const char **argv, const char *prefix) From patchwork Sun Aug 21 13:57:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949921 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A77FC00140 for ; Sun, 21 Aug 2022 13:59:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231134AbiHUN7l (ORCPT ); Sun, 21 Aug 2022 09:59:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230464AbiHUN7J (ORCPT ); Sun, 21 Aug 2022 09:59:09 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E00314D24 for ; Sun, 21 Aug 2022 06:58:45 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id v7-20020a1cac07000000b003a6062a4f81so6426288wme.1 for ; Sun, 21 Aug 2022 06:58:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=CZ+1rJlcEOd3WDzfyKDS3w+DRVvtuvCcmVvyklN4ljs=; b=K+Wh8R3BOK/dQ/Ks1SgrxZlS2Wv+DulNTLaT9JDugdWUcBfn8DUBYongQHD5vxBCfC NNgB05Gf6P4/pFG2uyKhhH3g8vgZzQYntNJeW6gvb7kXZM8uffFy8Mb4SGmbogmJiukA DUyFP692/pCuGINaNN+MHi4sREsSOs1FAR/77rMkyezYzxu71wu8ah9mFq1tXbGDgBMh 9t4X6UCXqBv8lda0WVmcr2+IAJzqtCRPPH3HuvhXNA8fRYtpPM9EXbWoXDUXsCY4WqmQ SXHxxr/gY6uPLQ5D6JND7KLfUlNt7Al/0FffJ5QPpj9PM89wKPTtbZlQUfTGJ53RxfQw R1iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=CZ+1rJlcEOd3WDzfyKDS3w+DRVvtuvCcmVvyklN4ljs=; b=swlLhzsaVQYr1oRlm9O6jBo/1V0p1PSl3pViXV6wVYjg3yNNapS6AaF83zzLYQWt2b vVUnF4OYIudmj7Im8FdbN5rZQPM50CMmiye3UX8ZZ7eu1HGCQc3K+USCJt73YllPeQ+n jRUrmRq4e0IKiwbVcDOp3iA4Fz+n/d77BJuEkuyU++TPYwbREYN3Yq+OVir3bupWbYqR m7kZxwyqjJFDPxu7HVgLPSa4GbNl5ZhoRNNCcS6p6OGga983wVEH97+6WSF7lgu8PIvH LmiPMqJbJXtn3LAyk5iblbUNe0kgHXe52yamWNf1FURiZ/A7OiksL5BNUX0bveDAJJ/C eFFA== X-Gm-Message-State: ACgBeo2n4Znvt6JVqfeoIrIhtTDs+TBLuOqEZvyCnJ9tXJ0bMViJ7hPL hXb74FZJJaCIbJgCsVYZslFywfYuwImHaKEe X-Google-Smtp-Source: AA6agR7UNj68AiDZHIKBc0F7B2367OMazhzRUJeXW9sLTYDM3WGBMmaWWDua/C35T2Ygmm+td9Cmtw== X-Received: by 2002:a05:600c:35d0:b0:3a5:f7ee:82be with SMTP id r16-20020a05600c35d000b003a5f7ee82bemr9664325wmq.206.1661090324900; Sun, 21 Aug 2022 06:58:44 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:44 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 19/32] submodule--helper: return "ret", not "1" from update_submodule() Date: Sun, 21 Aug 2022 15:57:28 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Amend the update_submodule() function to return the failing "ret" on error, instead of overriding it with "1". This code was added in b3c5f5cb048 (submodule: move core cmd_update() logic to C, 2022-03-15), and this change ends up not making a difference as this function is only called in update_submodules(). If we return non-zero here we'll always in turn return "1" in module_update(). But if we didn't do that and returned any other non-zero exit code in update_submodules() we'd fail the test that's being amended here. We're still testing the status quo here. This change makes subsequent refactoring of update_submodule() easier, as we'll no longer need to worry about clobbering the "ret" we get from the run_command(). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 2 +- t/t7406-submodule-update.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index fed92585a02..61468237af2 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2446,7 +2446,7 @@ static int update_submodule(struct update_data *update_data) update_data->displaypath); if (ret == 128) exit(ret); - return 1; + return ret; } return 0; diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index 6cc07460dd2..c5f5dbe55e0 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -769,7 +769,7 @@ test_expect_success 'submodule update continues after recursive checkout error' echo "" > file ) ) && - test_must_fail git submodule update --recursive && + test_expect_code 1 git submodule update --recursive && (cd submodule2 && git rev-parse --verify HEAD >../actual ) && From patchwork Sun Aug 21 13:57:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE302C00140 for ; Sun, 21 Aug 2022 13:59:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230444AbiHUN7q (ORCPT ); Sun, 21 Aug 2022 09:59:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230472AbiHUN7K (ORCPT ); Sun, 21 Aug 2022 09:59:10 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA36323177 for ; Sun, 21 Aug 2022 06:58:46 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id e20so9799001wri.13 for ; Sun, 21 Aug 2022 06:58:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=O1E0SVvoKCx8EjxdtzxxzB896hN9DbOouwuakVukSxo=; b=nv0bEY9O4+1a0d5b7FcDXDEU30LFU6Jb6VNpUcJVBMvKaK6wX8J5MMWX4JW0MeP0Bo KJeOjh8WTYpT0MAfU7T/UAnaNukBkXHufDw7xDm4CbHeWL3+1l/KRlRwfCZN5HhLOGXM /1LV4A6alNUgasE/4129p1ghhFZJPH8nZByCm1ksVgslpI4ZnuJlT/p4vNrjxFiFh3Zb 0dvcuZS1sc8fzAZeIXX8p6vuwf9tOSgzPlbxWVi30X99Us2a4sDebw7l7yYvxLlqdb2x URzAr9FjQ4Vhr4T8qrfmJQ7cStdi/9Mx1WtRu6d85yc2u9sIbXyDy7Dkf5VJYwsienFn ju8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=O1E0SVvoKCx8EjxdtzxxzB896hN9DbOouwuakVukSxo=; b=kz9yI7EzzEC6rCxbehHxcEbK5wi2DpB3fIn0yZhVC+kz6U0N/oAmksmZzbSNGHSYVR 8JlKPv/w8ijzD95Yj7IcRqdjtWqa20vijqUdC7orTaQ+L+xa+JOvEQBBLd1xQCOvaFg/ kbIOZTQgnvBTEsE/grF2BWo3l4iO5VHRk9p/VBXMEvUAUN+QiBrd9Pagu4/v/OyrRO79 Nlg25+fxqpAYXaNzaC1e4jpHrrn/mQyOR3UdsVHuXEMIf5eZA7FH5qhCpnIP8fjIJeov Qy3wLciJ8VJZbIPGU3oPAt3IuTC33FeWZI1atV+ePsq8kEd++AqQI+e4mDyakRYngjeX SdOg== X-Gm-Message-State: ACgBeo1DqwCNuuJIhcD+ifruu9IxAzEL3XLpVg4CYwhzxDNJXjPwKLOi /HNbAoP9Sqyv0DwhfE1l5lmOLwxUkvqhiJv8 X-Google-Smtp-Source: AA6agR4kI7E+Dvxx+uDpD4C5s1QbGeI5OP626wK/Lg4ZzQKDJIVaQWTG5q8L8rbS9Unr/arzdGmsdw== X-Received: by 2002:a5d:5581:0:b0:20f:fc51:7754 with SMTP id i1-20020a5d5581000000b0020ffc517754mr9008799wrv.413.1661090326070; Sun, 21 Aug 2022 06:58:46 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:45 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 20/32] submodule--helper: add missing braces to "else" arm Date: Sun, 21 Aug 2022 15:57:29 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add missing braces to an "else" arm in init_submodule(), this stylistic change makes this code conform to the CodingGuidelines, and makes a subsequent commit smaller. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 61468237af2..ebd3e118eb7 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -480,8 +480,9 @@ static void init_submodule(const char *path, const char *prefix, fprintf(stderr, _("warning: command update mode suggested for submodule '%s'\n"), sub->name); upd = xstrdup("none"); - } else + } else { upd = xstrdup(submodule_strategy_to_string(&sub->update_strategy)); + } if (git_config_set_gently(sb.buf, upd)) die(_("Failed to register update mode for submodule path '%s'"), displaypath); From patchwork Sun Aug 21 13:57:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949924 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0C3FC28D13 for ; Sun, 21 Aug 2022 13:59:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230490AbiHUN7t (ORCPT ); Sun, 21 Aug 2022 09:59:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230487AbiHUN7N (ORCPT ); Sun, 21 Aug 2022 09:59:13 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5712237D1 for ; Sun, 21 Aug 2022 06:58:48 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id h24so10285525wrb.8 for ; Sun, 21 Aug 2022 06:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=zDcpI1HylAdjISL08lO4mdt4UujXGz4v4rtsca2e6z4=; b=SLtDSztGt9rciULPWL8j46qQGZCkw2wShjXxOAQSPcSC2V6bPDkyy3I/twaJBJRWeA sJyClyv8H3T7JdpuiYgk1rz2rqm1zAfN4bxALtop4oSF59n2HtCY0/lb6wzX7W8ARmuf a9rtL40ObYDrxaG5fstzm+ZzAF7nuPi5uQQqbzVAEU7t8i454kS1M7r6ItrnnhZ7IbZs L/vqgOTsFDVMTQtrq2V3k0wqrKwgRm/MGE9KuxGJ+4nlnwWwN1b0FnHmg+FmZa0D8fhb 6kQTGw5ITOpIStxR+KqB1Tz4SPK09QlyFtNz9g5yAr2tCoFynOnTXLcU4t2sxS9WrjOd o2ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=zDcpI1HylAdjISL08lO4mdt4UujXGz4v4rtsca2e6z4=; b=uVwgZoIZDZXcwtLYV/hXc5j3eKOsfLA7Cuw/KG7Ovouf56LpnsuT0uANbna38pgCGa 6wxM+1Q/LxX1niMlUs8Myh18lzhYOcZcSU6C6eHUZdW2KSK5JjzWSSsOsNLoK5EJXgl7 ivk9OT/WifwoXv4HfS0BN97VQUeeYgp3Il4kgeGv3k6S6ROlX2jwAz1vDQr76FXo2Ruy 2lmGIvov7b3/6E6MsOBEVCO6SQzzApF5oBF63vdvwkmLDk5KyiZzTcezO9MsHyKB6NS2 aVnVNFLfej7ZmoJluiqO8BI/pUbvSXz9YvZpeTk8j+v7mwUaondR/eoVDPNxZLrcTKX0 e50g== X-Gm-Message-State: ACgBeo1rptCF28NDvREztZGA81rdpYWIRsO0r7zNt6lbvr2wEJdvnvLU hSaWFp0lmF4HY4PioUxSAYbsHxRXNLAqkiNF X-Google-Smtp-Source: AA6agR6k1mMZ7DAHkbXHFhYYEga7CiDA5B+OwcYMRup3R2BjTjaWQGNPR/eoV7MImmfK7yfpOuIQQw== X-Received: by 2002:a5d:5311:0:b0:224:f76e:ad6f with SMTP id e17-20020a5d5311000000b00224f76ead6fmr9013625wrv.54.1661090326964; Sun, 21 Aug 2022 06:58:46 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:46 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 21/32] submodule--helper: don't call submodule_strategy_to_string() in BUG() Date: Sun, 21 Aug 2022 15:57:30 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Don't call submodule_strategy_to_string() in a BUG() message. These calls added in c51f8f94e5b (submodule--helper: run update procedures from C, 2021-08-24) don't need the extra information submodule_strategy_to_string() gives us, as we'll never reach the SM_UPDATE_COMMAND case here. That case is the only one where we'd get any information beyond the straightforward number-to-string mapping. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index ebd3e118eb7..75bba8621b2 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2158,8 +2158,8 @@ static int run_update_command(struct update_data *ud, int subforce) must_die_on_failure = 1; break; default: - BUG("unexpected update strategy type: %s", - submodule_strategy_to_string(&ud->update_strategy)); + BUG("unexpected update strategy type: %d", + ud->update_strategy.type); } strvec_push(&cp.args, oid); @@ -2184,8 +2184,8 @@ static int run_update_command(struct update_data *ud, int subforce) ud->update_strategy.command, oid, ud->displaypath); break; default: - BUG("unexpected update strategy type: %s", - submodule_strategy_to_string(&ud->update_strategy)); + BUG("unexpected update strategy type: %d", + ud->update_strategy.type); } if (must_die_on_failure) exit(128); @@ -2215,8 +2215,8 @@ static int run_update_command(struct update_data *ud, int subforce) ud->displaypath, ud->update_strategy.command, oid); break; default: - BUG("unexpected update strategy type: %s", - submodule_strategy_to_string(&ud->update_strategy)); + BUG("unexpected update strategy type: %d", + ud->update_strategy.type); } return 0; From patchwork Sun Aug 21 13:57:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DC92C00140 for ; Sun, 21 Aug 2022 13:59:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230445AbiHUN7z (ORCPT ); Sun, 21 Aug 2022 09:59:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230498AbiHUN7O (ORCPT ); Sun, 21 Aug 2022 09:59:14 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D298237DA for ; Sun, 21 Aug 2022 06:58:50 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id r83-20020a1c4456000000b003a5cb389944so6413868wma.4 for ; Sun, 21 Aug 2022 06:58:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=KZJsjoLXy6398SQCF5SdyTMFzZRno02MzcgjZXZlDKk=; b=PnNlPvYNta3Cqmf7CkMQw0JiAFK+najLxnP3j9Rcxq0A+pNyhZQDP273RqtSnFWIJz 5XD6mnkgzDFchsUonkl8o4NlImpCLJu1q3M80PY1mrEwa/Vsf/K3myMnRwCOzyF1NnPj eH6H/AKXFxQIZEMIIlRHa447/Yus5L+qaorbwO+OZZXKacvXAUyYqjWMGiYpQCa0FOoY tupNTbcaAMlTiOpqISnphXCDzIPYVwd8iYW+hLHlupZ7OW7cCvtOPuJ6uJqvbxH4G9IC Slc4Q/Gyde0BKLrjGymcTDJWN27FeZd0jcHASX1ZAWqdrEol6g0JCGlKMHE4NPAf3mQ8 yjnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=KZJsjoLXy6398SQCF5SdyTMFzZRno02MzcgjZXZlDKk=; b=LXdgN3ZlAtpHz+NfT/AFGaaRq6ckGJSUTeOcBW+rFS5HFdX4EaCt3NrwRHY5EcORgr +IwUR3YIoTTZBsAhHmPG1EHIwOKeiBg+OohCTE4bTzw0VjVatXLQvXklNNuKfhrslSSS +TlnLw/zJNx/vGMGh1qJXDbL50gVAf2aDZ5KGXb20afRE7C7l0pvgML6GkcYCIU0oRZt 6qYAkAmvGMh1XRgcSTJGklTQmAFhSBBfLwBLL/Vqrh8GiarExybWztG5B++oBBkzoVo2 KA2saZKQq6IdBuamw0wSr6s1WSRzFXEefCiNumb0TgS2Yg2I34vFEXHVXkfJ5xzghOZi SpYA== X-Gm-Message-State: ACgBeo1M8fTacHffcjPWvmiJHeIKTICvzyRnM88IKg7A+WMf6RViqt02 6wvBjeOe1F6NHf9VPvY4K5LmGCqEJ5vLY5oy X-Google-Smtp-Source: AA6agR6xOZ/J7vjX+VKfncmMdgN/AbpKQKePbrG760fnHvxWfZ7UaS+SNAvFGSKuZs46f2YbZ/jCDw== X-Received: by 2002:a05:600c:a199:b0:3a5:dddf:ac6d with SMTP id id25-20020a05600ca19900b003a5dddfac6dmr9578138wmb.44.1661090328152; Sun, 21 Aug 2022 06:58:48 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:47 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 22/32] submodule API: don't handle SM_..{UNSPECIFIED,COMMAND} in to_string() Date: Sun, 21 Aug 2022 15:57:31 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the submodule_strategy_to_string() function added in 3604242f080 (submodule: port init from shell to C, 2016-04-15) to really return a "const char *". In the "SM_UPDATE_COMMAND" case it would return a strbuf_detach(). Furthermore, this function would return NULL on SM_UPDATE_UNSPECIFIED, so it wasn't safe to xstrdup() its return value in the general case, or to use it in a sprintf() format as the code removed in the preceding commit did. But its callers would never call it with either SM_UPDATE_UNSPECIFIED or SM_UPDATE_COMMAND. Let's have its behavior reflect how its only user expects it to behave, and BUG() out on the rest. By doing this we can also stop needlessly xstrdup()-ing and free()-ing the memory for the config we're setting. We can instead always use constant strings. We can also use the *_tmp() variant of git_config_get_string(). Let's also rename this submodule_strategy_to_string() function to submodule_update_type_to_string(). Now that it's only tasked with returning a string version of the "enum submodule_update_type type". Before it would look at the "command" field in "struct submodule_update_strategy". Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 10 +++++----- submodule.c | 12 +++++------- submodule.h | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 75bba8621b2..c83b0897740 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -418,7 +418,8 @@ static void init_submodule(const char *path, const char *prefix, { const struct submodule *sub; struct strbuf sb = STRBUF_INIT; - char *upd = NULL, *url = NULL, *displaypath; + const char *upd; + char *url = NULL, *displaypath; displaypath = get_submodule_displaypath(path, prefix); @@ -474,14 +475,14 @@ static void init_submodule(const char *path, const char *prefix, /* Copy "update" setting when it is not set yet */ strbuf_addf(&sb, "submodule.%s.update", sub->name); - if (git_config_get_string(sb.buf, &upd) && + if (git_config_get_string_tmp(sb.buf, &upd) && sub->update_strategy.type != SM_UPDATE_UNSPECIFIED) { if (sub->update_strategy.type == SM_UPDATE_COMMAND) { fprintf(stderr, _("warning: command update mode suggested for submodule '%s'\n"), sub->name); - upd = xstrdup("none"); + upd = "none"; } else { - upd = xstrdup(submodule_strategy_to_string(&sub->update_strategy)); + upd = submodule_update_type_to_string(sub->update_strategy.type); } if (git_config_set_gently(sb.buf, upd)) @@ -490,7 +491,6 @@ static void init_submodule(const char *path, const char *prefix, strbuf_release(&sb); free(displaypath); free(url); - free(upd); } static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data) diff --git a/submodule.c b/submodule.c index 3fa5db3ecdf..1ebda30c506 100644 --- a/submodule.c +++ b/submodule.c @@ -415,10 +415,9 @@ int parse_submodule_update_strategy(const char *value, return 0; } -const char *submodule_strategy_to_string(const struct submodule_update_strategy *s) +const char *submodule_update_type_to_string(enum submodule_update_type type) { - struct strbuf sb = STRBUF_INIT; - switch (s->type) { + switch (type) { case SM_UPDATE_CHECKOUT: return "checkout"; case SM_UPDATE_MERGE: @@ -428,12 +427,11 @@ const char *submodule_strategy_to_string(const struct submodule_update_strategy case SM_UPDATE_NONE: return "none"; case SM_UPDATE_UNSPECIFIED: - return NULL; case SM_UPDATE_COMMAND: - strbuf_addf(&sb, "!%s", s->command); - return strbuf_detach(&sb, NULL); + BUG("init_submodule() should handle type %d", type); + default: + BUG("unexpected update strategy type: %d", type); } - return NULL; } void handle_ignore_submodules_arg(struct diff_options *diffopt, diff --git a/submodule.h b/submodule.h index bfaa9da1868..6a9fec6de11 100644 --- a/submodule.h +++ b/submodule.h @@ -72,7 +72,7 @@ void die_path_inside_submodule(struct index_state *istate, enum submodule_update_type parse_submodule_update_type(const char *value); int parse_submodule_update_strategy(const char *value, struct submodule_update_strategy *dst); -const char *submodule_strategy_to_string(const struct submodule_update_strategy *s); +const char *submodule_update_type_to_string(enum submodule_update_type type); void handle_ignore_submodules_arg(struct diff_options *, const char *); void show_submodule_diff_summary(struct diff_options *o, const char *path, struct object_id *one, struct object_id *two, From patchwork Sun Aug 21 13:57:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949926 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90812C00140 for ; Sun, 21 Aug 2022 13:59:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229494AbiHUN75 (ORCPT ); Sun, 21 Aug 2022 09:59:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230448AbiHUN7P (ORCPT ); Sun, 21 Aug 2022 09:59:15 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0A9A237E1 for ; Sun, 21 Aug 2022 06:58:50 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id bq11so3713088wrb.12 for ; Sun, 21 Aug 2022 06:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=TE5sRvZLSD0CeQucb1GNMKqkll0IslG4KOS3GpgN1Kk=; b=BcGLrS/1xUq29pv9qyG5g0pvwh2a6BEAmqQXZLggy95KU+UJb9n4COzvUIJNXG+rzR BdDAMMTN/YjKX0op7Zlh66bmAkwIGhQ73szb/BKOfyfOyfn4t17fdoQvZl6NSCCeUs0K LyYK+8eN99QowCUf4p/evL9+ob5BU3ManUsAOV9xbK1A5nZT6vlWlrDsObWe1jc3l262 XBsukgxBCtBmsoFpSm1UITFg5SJPi9ZJguEEaxJvCbCGEmIqRwQvHOzEWcrl4tO4Jvvm Lib8FeIwrg2gR6voVmwwB1OeZouIt5mVmObvOLtmlxGKNzua4GK0OO0QLKYFy2l/Fcc0 uUIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=TE5sRvZLSD0CeQucb1GNMKqkll0IslG4KOS3GpgN1Kk=; b=SCfPJtrmvurNreJTGXEd4efcjdi3o0TCQ5IMPlMHd/58sHu+FO/+Twu+ucI/GvcGX1 6L3Qo1333GIFoCpmyO3rIQqV6PjS5cZZh2mgxwSnk2eEgjq4WfokKHoKeDXWvonhbdrj YEDCJIz0RvwgTJH0170iznfaoXizcI62kZAZnX0kJu2dth7x+RYVMNoMCCGAj/hQUgpt /9KbgiQiWWzku6CoWxpyJiJktinOdn9YU115SAKq7lW7L/VUTD80+dzQTpTg6HO/FNsc 1WkgZfRsXIynhWXwv1UmLH+GrZ5zFesSjp04H39FtoP2NADgCoSYCKvEg7+QGeGT23mY HVqg== X-Gm-Message-State: ACgBeo15K++CDucrjBob+wabNDQdNk8aJe0YQ9iOGbyjIn8VuJzhTKD0 67aWsdu1Do/YCnJqX9rA1I2j2pJDRMKTtJvw X-Google-Smtp-Source: AA6agR5U7AILBHOA4bH35Ue/Qdq4I2H4D7i5ZvpBi2T/VCEcaLP8AjtJWmA9JxeN8gzmyjFcX8BAQg== X-Received: by 2002:a05:6000:1acb:b0:223:5de3:f8bf with SMTP id i11-20020a0560001acb00b002235de3f8bfmr8503392wry.691.1661090329229; Sun, 21 Aug 2022 06:58:49 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:48 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 23/32] submodule--helper: use "code" in run_update_command() Date: Sun, 21 Aug 2022 15:57:32 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Apply some DRY principles in run_update_command() and don't have two "switch" statements over "ud->update_strategy.type" determine the same thing. First we were setting "must_die_on_failure = 1" in all cases except "SM_UPDATE_CHECKOUT" (and we'd BUG(...) out on the rest). This code was added in c51f8f94e5b (submodule--helper: run update procedures from C, 2021-08-24). Then we'd duplicate same "switch" logic when we were using the "must_die_on_failure" variable. Let's instead have the "case" branches in that inner "switch" determine whether or not the "update must continue" by picking an exit code. This also mostly avoids hardcoding the "128" exit code, instead we can make use of the return value of the die_message() function, which we've been calling here since 55b3f12cb54 (submodule update: use die_message(), 2022-03-15). We're still hardcoding it to determine if we "exit()", but subsequent commit(s) will address that. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index c83b0897740..44b08a01c54 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2129,7 +2129,6 @@ static int run_update_command(struct update_data *ud, int subforce) { struct child_process cp = CHILD_PROCESS_INIT; char *oid = oid_to_hex(&ud->oid); - int must_die_on_failure = 0; switch (ud->update_strategy.type) { case SM_UPDATE_CHECKOUT: @@ -2143,19 +2142,16 @@ static int run_update_command(struct update_data *ud, int subforce) strvec_push(&cp.args, "rebase"); if (ud->quiet) strvec_push(&cp.args, "--quiet"); - must_die_on_failure = 1; break; case SM_UPDATE_MERGE: cp.git_cmd = 1; strvec_push(&cp.args, "merge"); if (ud->quiet) strvec_push(&cp.args, "--quiet"); - must_die_on_failure = 1; break; case SM_UPDATE_COMMAND: cp.use_shell = 1; strvec_push(&cp.args, ud->update_strategy.command); - must_die_on_failure = 1; break; default: BUG("unexpected update strategy type: %d", @@ -2166,32 +2162,35 @@ static int run_update_command(struct update_data *ud, int subforce) cp.dir = xstrdup(ud->sm_path); prepare_submodule_repo_env(&cp.env); if (run_command(&cp)) { + int ret; + switch (ud->update_strategy.type) { case SM_UPDATE_CHECKOUT: die_message(_("Unable to checkout '%s' in submodule path '%s'"), oid, ud->displaypath); + /* the command failed, but update must continue */ + ret = 1; break; case SM_UPDATE_REBASE: - die_message(_("Unable to rebase '%s' in submodule path '%s'"), - oid, ud->displaypath); + ret = die_message(_("Unable to rebase '%s' in submodule path '%s'"), + oid, ud->displaypath); break; case SM_UPDATE_MERGE: - die_message(_("Unable to merge '%s' in submodule path '%s'"), - oid, ud->displaypath); + ret = die_message(_("Unable to merge '%s' in submodule path '%s'"), + oid, ud->displaypath); break; case SM_UPDATE_COMMAND: - die_message(_("Execution of '%s %s' failed in submodule path '%s'"), - ud->update_strategy.command, oid, ud->displaypath); + ret = die_message(_("Execution of '%s %s' failed in submodule path '%s'"), + ud->update_strategy.command, oid, ud->displaypath); break; default: BUG("unexpected update strategy type: %d", ud->update_strategy.type); } - if (must_die_on_failure) - exit(128); - /* the command failed, but update must continue */ - return 1; + if (ret == 128) + exit(ret); + return ret; } if (ud->quiet) From patchwork Sun Aug 21 13:57:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E017C3F6B0 for ; Sun, 21 Aug 2022 14:00:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231221AbiHUOAA (ORCPT ); Sun, 21 Aug 2022 10:00:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230508AbiHUN7S (ORCPT ); Sun, 21 Aug 2022 09:59:18 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14D25237E2 for ; Sun, 21 Aug 2022 06:58:51 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id m17-20020a7bce11000000b003a5bedec07bso6447618wmc.0 for ; Sun, 21 Aug 2022 06:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=oWT9DEINhZAfPDN3z0lfujcDdOyfgNIqg/Mmmbh/ZSk=; b=pEYAcPpxvAgUWx7weeNXkNx1gAT8esX3tWwlYS0Ua/u04LgDtfPiPcKa+QQFodvXGu uuCc49Mw8xElpjo2Pv658MCIIifx2tzcL431V1qxSsG0F0eTvDbhDREYoWcXGC4S8iCk og/quT3CWKtwOOZoAcFzPYgFAWAAfirKcwLYT0+/obVBoKtDVeId0q5UCvUjLQNZDS0q kWJk6Vn0oit6i3GxDpAR3JBrj3gRqPr6TlanvkIB4zVYD3A025OX0ICFU8OF60A9i5NO Vx6Q2HaP/Vyzjhx34I4voCYT81wc/szDAPCcW/wgiy1q709pZkpxMsycspujt2Bz/aX/ NJZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=oWT9DEINhZAfPDN3z0lfujcDdOyfgNIqg/Mmmbh/ZSk=; b=X2oib3SPDOAe5Y+knRlmaSP6rnSxNRcKUU85h/VjbbUccCh0XwGdugF34jVChTWFGQ wDtKBZOKJdq1YDg5YCtrP7Rbn55Z/uGLkeDbuv040YFCHXpg4fiQMXhlqri6BB/CG5jK v1v0uifL8dF6IsN1IIhGF0W1cs9BH4tUyVqlgZxEg2N7xeuJSyJ8CiuyjVXKhiG6YG2X oXMcKTARGyGQmDNhjf12vUvO0HihVEAIb6CPcIiZ0bMZ3Sqw0rNt4ncITH+3VYfAd6xO 2Cc7f8ILBxZgLWhe9kuF2eq1Fn8SwL3VX+P9I7CLtPw28AzDbWf8SwUW7UiV5XULueUF 8YAg== X-Gm-Message-State: ACgBeo1GMZOL+LGZgrPE1X5ZSUCff8+RanSY86gLYsCWh/idPXcabMv5 YFPOH49Ws43vH3pEQtbBxChlA1sxxb1KL7ep X-Google-Smtp-Source: AA6agR50vrht3lyiUCGXZIenG5/ft9Bfo6CLhS3bQcgIbHJb462amb7WEmyy0ilUU1Wig3ixWEzlig== X-Received: by 2002:a05:600c:1ca5:b0:3a6:c8d:f2f9 with SMTP id k37-20020a05600c1ca500b003a60c8df2f9mr12951172wms.54.1661090330277; Sun, 21 Aug 2022 06:58:50 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:49 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 24/32] submodule--helper: don't exit() on failure, return Date: Sun, 21 Aug 2022 15:57:33 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change code downstream of module_update() to short-circuit and return to the top-level on failure, rather than calling exit(). To do so we need to diligently check whether we "must_die_on_failure", which is a pattern started in c51f8f94e5b (submodule--helper: run update procedures from C, 2021-08-24), but which hadn't been completed to the point where we could avoid calling exit() here. This introduces no functional changes, but makes it easier to both call these routines as a library in the future, and to eventually avoid leaking memory. This and similar control flow in submodule--helper.c could be made simpler by properly "libifying" it, i.e. to have it consistently return -1 on failures, and to early return on any non-success. But let's leave that larger project for now, and (mostly) emulate what were doing with the "exit(128)" before this change. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 44b08a01c54..84e5e3beeb5 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2125,7 +2125,8 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, str return run_command(&cp); } -static int run_update_command(struct update_data *ud, int subforce) +static int run_update_command(struct update_data *ud, int subforce, + int *must_die_on_failure) { struct child_process cp = CHILD_PROCESS_INIT; char *oid = oid_to_hex(&ud->oid); @@ -2189,7 +2190,7 @@ static int run_update_command(struct update_data *ud, int subforce) } if (ret == 128) - exit(ret); + *must_die_on_failure = 1; return ret; } @@ -2221,7 +2222,8 @@ static int run_update_command(struct update_data *ud, int subforce) return 0; } -static int run_update_procedure(struct update_data *ud) +static int run_update_procedure(struct update_data *ud, + int *must_die_on_failure) { int subforce = is_null_oid(&ud->suboid) || ud->force; @@ -2248,7 +2250,7 @@ static int run_update_procedure(struct update_data *ud) ud->displaypath, oid_to_hex(&ud->oid)); } - return run_update_command(ud, subforce); + return run_update_command(ud, subforce, must_die_on_failure); } static const char *remote_submodule_branch(const char *path) @@ -2384,7 +2386,8 @@ static void update_data_to_args(struct update_data *update_data, struct strvec * "--no-single-branch"); } -static int update_submodule(struct update_data *update_data) +static int update_submodule(struct update_data *update_data, + int *must_die_on_failure) { ensure_core_worktree(update_data->sm_path); @@ -2420,9 +2423,15 @@ static int update_submodule(struct update_data *update_data) free(remote_ref); } - if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) - if (run_update_procedure(update_data)) + if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) { + int ret; + + ret = run_update_procedure(update_data, must_die_on_failure); + if (*must_die_on_failure) + return ret; + if (ret) return 1; + } if (update_data->recursive) { struct child_process cp = CHILD_PROCESS_INIT; @@ -2438,14 +2447,13 @@ static int update_submodule(struct update_data *update_data) prepare_submodule_repo_env(&cp.env); update_data_to_args(&next, &cp.args); - /* die() if child process die()'d */ ret = run_command(&cp); if (!ret) return 0; die_message(_("Failed to recurse into submodule path '%s'"), update_data->displaypath); if (ret == 128) - exit(ret); + *must_die_on_failure = 1; return ret; } @@ -2478,12 +2486,19 @@ static int update_submodules(struct update_data *update_data) for (i = 0; i < suc.update_clone_nr; i++) { struct update_clone_data ucd = suc.update_clone[i]; + int must_die_on_failure = 0; + int code; oidcpy(&update_data->oid, &ucd.oid); update_data->just_cloned = ucd.just_cloned; update_data->sm_path = ucd.sub->path; - if (update_submodule(update_data)) + code = update_submodule(update_data, &must_die_on_failure); + if (code) + ret = code; + if (must_die_on_failure) + goto cleanup; + else if (code) ret = 1; } From patchwork Sun Aug 21 13:57:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949928 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B7D6C00140 for ; Sun, 21 Aug 2022 14:00:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230451AbiHUOAC (ORCPT ); Sun, 21 Aug 2022 10:00:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230394AbiHUN7W (ORCPT ); Sun, 21 Aug 2022 09:59:22 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32741237EB for ; Sun, 21 Aug 2022 06:58:52 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id e20so9799182wri.13 for ; Sun, 21 Aug 2022 06:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=suheVDeLx9/bnptyH6p1jGjr0U0Myr2tQZ/ivfgdCP0=; b=GvEWwisH4Fl/lMX7onILdgLTdlVygFJp/2Rtku3cWJB5ozP8OCGH63yD3qkRpZyggK 57rKcoq707VILQyFp9brPPGSKoQI81kPDKNHX2O3bQgF6BOAGJu82J2SVZwWLUfguKr7 tYIJukxMr9lt5hsaBRlfmy6zEU+OhrIyUqFFw8BpgG4FL1w9RtZ3Tsdmce6FSdgW4/PD Iea9m1d7lLt9c/Ud0lDB6Wx591X6mHmAS6AgPphpIjhp85p9WvvX9zCyeFQXm81yRJXB xEhlG0vl3X/DZRy1BNiDjLknHmi+jtzaBcCSFS0GluJzE3NLY9IFoG5R4Ujn9a8kOyYh M4jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=suheVDeLx9/bnptyH6p1jGjr0U0Myr2tQZ/ivfgdCP0=; b=CFtNkzMABHLXlpXtVjDy0oJtlsgQoNB6ieCBzR4JvhUlH2jsLM8KgCUDmwAxNtFiUE BQcojlKax6qzAySQUMBOy2680YcME4PHNuygn3bjZOTGtDRShXk0NO0xVGx3IRsKW0Qu rt6X9ZoTlSpb4HZp+ZzChzJSIif6lxDJBa/KA9QAcxLGYqBfnrvVA8D+k/jG7m5aij9F MwPOZDlERXH1jAh81Ju4PiH0/DsNF6SWyPgC9GAy9MznKePqhLqajpAm9rky+ncQKHCf YC3F076dAOkLfp/nlAGxVUfjcPuIJYnhCdJXDYo8c9rqtt8e4ofhCJ0ECz0/JMudfn2d +zLQ== X-Gm-Message-State: ACgBeo0cZYiVJZaNDXVqCLcHcN2xSOQOl/g3Upjbxa9aiCP2CDDoccoA DEpTRZ3xiGGtV5OitGdLr189XgFSrnizS+T6 X-Google-Smtp-Source: AA6agR6LkkBmkV7jOAHR110q7XcEPdaoMaNaojDXmsGFmkbSaGvv8pbT5lFMLY8Q0+AH//vzwbyuxg== X-Received: by 2002:adf:eb8e:0:b0:223:a1f6:26b2 with SMTP id t14-20020adfeb8e000000b00223a1f626b2mr8680894wrn.216.1661090331399; Sun, 21 Aug 2022 06:58:51 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:50 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 25/32] submodule--helper: libify determine_submodule_update_strategy() Date: Sun, 21 Aug 2022 15:57:34 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Libify the determine_submodule_update_strategy() by having it invoke die_message() rather than die(), and returning the code die_message() returns on failure. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 39 ++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 84e5e3beeb5..4d102f2b32e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1733,24 +1733,27 @@ static int module_clone(int argc, const char **argv, const char *prefix) return 0; } -static void determine_submodule_update_strategy(struct repository *r, - int just_cloned, - const char *path, - enum submodule_update_type update, - struct submodule_update_strategy *out) +static int determine_submodule_update_strategy(struct repository *r, + int just_cloned, + const char *path, + enum submodule_update_type update, + struct submodule_update_strategy *out) { const struct submodule *sub = submodule_from_path(r, null_oid(), path); char *key; const char *val; + int ret; key = xstrfmt("submodule.%s.update", sub->name); if (update) { out->type = update; } else if (!repo_config_get_string_tmp(r, key, &val)) { - if (parse_submodule_update_strategy(val, out) < 0) - die(_("Invalid update mode '%s' configured for submodule path '%s'"), - val, path); + if (parse_submodule_update_strategy(val, out) < 0) { + ret = die_message(_("Invalid update mode '%s' configured for submodule path '%s'"), + val, path); + goto cleanup; + } } else if (sub->update_strategy.type != SM_UPDATE_UNSPECIFIED) { if (sub->update_strategy.type == SM_UPDATE_COMMAND) BUG("how did we read update = !command from .gitmodules?"); @@ -1765,7 +1768,10 @@ static void determine_submodule_update_strategy(struct repository *r, out->type == SM_UPDATE_NONE)) out->type = SM_UPDATE_CHECKOUT; + ret = 0; +cleanup: free(key); + return ret; } struct update_clone_data { @@ -2389,14 +2395,22 @@ static void update_data_to_args(struct update_data *update_data, struct strvec * static int update_submodule(struct update_data *update_data, int *must_die_on_failure) { + int ret; + ensure_core_worktree(update_data->sm_path); update_data->displaypath = get_submodule_displaypath( update_data->sm_path, update_data->prefix); - determine_submodule_update_strategy(the_repository, update_data->just_cloned, - update_data->sm_path, update_data->update_default, - &update_data->update_strategy); + ret = determine_submodule_update_strategy(the_repository, + update_data->just_cloned, + update_data->sm_path, + update_data->update_default, + &update_data->update_strategy); + if (ret) { + *must_die_on_failure = 1; + return ret; + } if (update_data->just_cloned) oidcpy(&update_data->suboid, null_oid()); @@ -2424,8 +2438,6 @@ static int update_submodule(struct update_data *update_data, } if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) { - int ret; - ret = run_update_procedure(update_data, must_die_on_failure); if (*must_die_on_failure) return ret; @@ -2436,7 +2448,6 @@ static int update_submodule(struct update_data *update_data, if (update_data->recursive) { struct child_process cp = CHILD_PROCESS_INIT; struct update_data next = *update_data; - int ret; next.prefix = NULL; oidcpy(&next.oid, null_oid()); From patchwork Sun Aug 21 13:57:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949930 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A732BC32772 for ; Sun, 21 Aug 2022 14:00:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231235AbiHUOAG (ORCPT ); Sun, 21 Aug 2022 10:00:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230516AbiHUN7X (ORCPT ); Sun, 21 Aug 2022 09:59:23 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A3FD237F6 for ; Sun, 21 Aug 2022 06:58:54 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id h5so9485075wru.7 for ; Sun, 21 Aug 2022 06:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=QJOF0encA2eLRU0Gls9kTtVCQlugyvnfBFgeH1Zh2k0=; b=pBjalC9K6w2j9IuwnKDUOgPNxaIrsMIrAUjYsX0bNMvjIA2UfZ4k3RWuriImDkyckx 6FXvAYmy0QpTrt+0H5NeAX4+471S0vnZCp8opF1EmJzynjv68l54VOIqYtUTWvrjopQQ 9bdj5AyeRRBxJF4bab8Ztgi36HLQ75mQ15OR3eqx02KJJV1c4Ly/TBhhFze0d1mBoLAx cqJ5b75Z9oLtldm8p48B2NpQQFX60Zo+GqAJ/uwfiKIMCYQy3+b/LRirXc8+hG5+vHqL DxbgntMlYIaJ8G2FNlOmOeF994+xLMd24EJn9L71/390kNf/moVPLDdUtjOPNeoa7xMg +m9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=QJOF0encA2eLRU0Gls9kTtVCQlugyvnfBFgeH1Zh2k0=; b=LynkH7l4QirXrKWLgYj//mnL+NNS8RcD+NadbX1mGtNqUZvJyFOvkXdgnFxW8CnCgX KBHEMFQ7F96V8Frys0ozH18s7nLMzaWt07PG+NdAHETHRkZUY1Q7SDYQp/MBOa67D5Hj 4kk+NQBD/69kYhpDbXWKKhfGMqzRyofe2WzUw7aC2kLQDXS9vi2tlmwK8hZElAmGeZOh AzmRVo/5p2xckf+Onbt+H9pqxPR+6ev6oKjHWZGWMsXRLHh4rnZnQb2huXuW5I/AbaTr yWjUkFqGTzvVdmZrvD4ebxYCBwHae7yfXpCaqtXr6z2eMkVR2+Uy7XyRx4Ur5gKk0c7k 697g== X-Gm-Message-State: ACgBeo2En7G/9njhI54tx7NmoLxD+X1jTBejAns+wMgc4J3ni5xksWYY A+8qEDyOhpHlbATXu5nAjAik8X5g4sevBC5H X-Google-Smtp-Source: AA6agR6uJMYIvyKF/npLlj9SndB+U6Jh6Jhosg+1pX1At3OM+qd7J3eDefwi0nWffKZ6IcfKhHfScg== X-Received: by 2002:adf:c803:0:b0:225:3d30:27db with SMTP id d3-20020adfc803000000b002253d3027dbmr5701108wrh.454.1661090332648; Sun, 21 Aug 2022 06:58:52 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:51 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 26/32] submodule--helper: libify "must_die_on_failure" code paths Date: Sun, 21 Aug 2022 15:57:35 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In preceding commits the codepaths around update_submodules() were changed from using exit() or die() to ferrying up a "must_die_on_failure" in the cases where we'd exit(), and in most cases where we'd die(). We needed to do this this to ensure that we'd early exit or otherwise abort the update_submodules() processing before it was completed. Now that those preceding changes have shown that we've converted those paths, we can remove the remaining "ret == 128" special-cases, leaving the only such special-case in update_submodules(). I.e. we now know after having gone through the various codepaths that we were only returning 128 if we meant to early abort. In update_submodules() we'll for now set any non-zero non-128 exit codes to "1", but will start ferrying up the exit code as-is in a subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 45 +++++++++++++------------------------ 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 4d102f2b32e..9e9d4fe0261 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2131,8 +2131,7 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, str return run_command(&cp); } -static int run_update_command(struct update_data *ud, int subforce, - int *must_die_on_failure) +static int run_update_command(struct update_data *ud, int subforce) { struct child_process cp = CHILD_PROCESS_INIT; char *oid = oid_to_hex(&ud->oid); @@ -2195,8 +2194,6 @@ static int run_update_command(struct update_data *ud, int subforce, ud->update_strategy.type); } - if (ret == 128) - *must_die_on_failure = 1; return ret; } @@ -2228,8 +2225,7 @@ static int run_update_command(struct update_data *ud, int subforce, return 0; } -static int run_update_procedure(struct update_data *ud, - int *must_die_on_failure) +static int run_update_procedure(struct update_data *ud) { int subforce = is_null_oid(&ud->suboid) || ud->force; @@ -2256,7 +2252,7 @@ static int run_update_procedure(struct update_data *ud, ud->displaypath, oid_to_hex(&ud->oid)); } - return run_update_command(ud, subforce, must_die_on_failure); + return run_update_command(ud, subforce); } static const char *remote_submodule_branch(const char *path) @@ -2392,8 +2388,7 @@ static void update_data_to_args(struct update_data *update_data, struct strvec * "--no-single-branch"); } -static int update_submodule(struct update_data *update_data, - int *must_die_on_failure) +static int update_submodule(struct update_data *update_data) { int ret; @@ -2407,10 +2402,8 @@ static int update_submodule(struct update_data *update_data, update_data->sm_path, update_data->update_default, &update_data->update_strategy); - if (ret) { - *must_die_on_failure = 1; + if (ret) return ret; - } if (update_data->just_cloned) oidcpy(&update_data->suboid, null_oid()); @@ -2438,11 +2431,9 @@ static int update_submodule(struct update_data *update_data, } if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) { - ret = run_update_procedure(update_data, must_die_on_failure); - if (*must_die_on_failure) - return ret; + ret = run_update_procedure(update_data); if (ret) - return 1; + return ret; } if (update_data->recursive) { @@ -2459,12 +2450,9 @@ static int update_submodule(struct update_data *update_data, update_data_to_args(&next, &cp.args); ret = run_command(&cp); - if (!ret) - return 0; - die_message(_("Failed to recurse into submodule path '%s'"), - update_data->displaypath); - if (ret == 128) - *must_die_on_failure = 1; + if (ret) + die_message(_("Failed to recurse into submodule path '%s'"), + update_data->displaypath); return ret; } @@ -2497,20 +2485,19 @@ static int update_submodules(struct update_data *update_data) for (i = 0; i < suc.update_clone_nr; i++) { struct update_clone_data ucd = suc.update_clone[i]; - int must_die_on_failure = 0; int code; oidcpy(&update_data->oid, &ucd.oid); update_data->just_cloned = ucd.just_cloned; update_data->sm_path = ucd.sub->path; - code = update_submodule(update_data, &must_die_on_failure); - if (code) - ret = code; - if (must_die_on_failure) + code = update_submodule(update_data); + if (!code) + continue; + ret = code; + if (ret == 128) goto cleanup; - else if (code) - ret = 1; + ret = 1; } cleanup: From patchwork Sun Aug 21 13:57:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC43CC00140 for ; Sun, 21 Aug 2022 14:00:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230394AbiHUOAE (ORCPT ); Sun, 21 Aug 2022 10:00:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230521AbiHUN7X (ORCPT ); Sun, 21 Aug 2022 09:59:23 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 992DD237FB for ; Sun, 21 Aug 2022 06:58:55 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id k9so10321222wri.0 for ; Sun, 21 Aug 2022 06:58:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=qdHYxlsjiofcCgSdh9GvzOFpbdNNXH6ayj/L2iAD/9c=; b=QNfOu4sYc32cK+iKnYAXlRX9IjKYsHkQusJ8tBDrhR5aytHkap9O0b0zsNOaP+pdnl HrvRvX40Y+IhZwoUQySUQcgGp9xWRgkoCeisTqe/49YgKglYzBvJDv0WuP3uaJRHvqNU XWRjoojf8MrdzMCsHsZ6OAe9TzGFsPO/NY9yxDwsO6s0D2HtCFidOjQwLRtd49NhamGt 5FxuTcyQ4yDB50rkAOK1owksnN6uKopyqnGN7cOVbp6oHytpIHKsmcJqbvl+CDlzVg/2 lJCDnpLjPnQytju00+3c9l/zU1FTv0KYlOZGsAZ5TUYFVP8RG7VYyIx2QSMRX2/lt26u jZrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=qdHYxlsjiofcCgSdh9GvzOFpbdNNXH6ayj/L2iAD/9c=; b=f+wyHh7Lo3pQO8kS/nB4HCXK1YZnBGs3XGvnZwU1pOrwf+olsa1kRiUiuJgXokHntL qB77gC5yiv2tKy9TB7oemQV0eJwBwt8fKH4/GhqsiwXzr7yPOfd2Yho6fYgqoBRsblr0 jAlB9b6k+nNh7VSxOeUCTGF/pDH6RWCQpJmYXxmXfJMLz3vYK0o0ZEoU0HFzvTDkyVJT 7zyJswp9DlEZ/s3ngyDErhVVXYICeyHKc6nayPB2v6g3PRLqYwcV2MdKmUkmRENQ9Z7/ tA/yMQZ7hidXs697z5+hV6RjdmVGZ+grJkAzi18MERqp7FN7uYkqZxpKoiYb39/WVPyW aUNQ== X-Gm-Message-State: ACgBeo3CeK6AV4iRaccMhVjqSpf1s2BuVkv2RDmq6eiGx/OxYy0CmZhO 5M4mEmnKrtPrIhT/z1sQBXFxrCJZbEOpqx5/ X-Google-Smtp-Source: AA6agR5mJoPXJIntbgz9XMkcLbTymkoST8GKix7AWwboHSdqzSMcKztibOB70mT+xwDZKy9j0opFSA== X-Received: by 2002:adf:fe81:0:b0:21b:88ea:6981 with SMTP id l1-20020adffe81000000b0021b88ea6981mr9205338wrr.616.1661090333824; Sun, 21 Aug 2022 06:58:53 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:53 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 27/32] submodule--helper update: don't override 'checkout' exit code Date: Sun, 21 Aug 2022 15:57:36 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When "git submodule update" runs it might call "checkout", "merge", "rebase", or a custom command. Ever since run_update_command() was added in c51f8f94e5b (submodule--helper: run update procedures from C, 2021-08-24) we'd either exit immediately if the "submodule..update" method failed, or in the case of "checkout" continue trying to update other submodules. This code used to use the magical "2" return code, but in 55b3f12cb54 (submodule update: use die_message(), 2022-03-15) it was made to exit(128), which in preceding commits has been changed to return that 128 code to the top-level. Let's "libify" this code even more by not having it arbitrarily override the return code. In practice this doesn't change anything as the code "git checkout" would return on any normal failure is "1", but we'll now in principle properly abort the operation if "git checkout" were to exit with 128. It would make sense to follow-up this change with a change to allow the "submodule..update = !..." (SM_UPDATE_COMMAND) method the same liberties as "checkout", and perhaps to do the same with a failed "merge" or "rebase". But let's leave that for now. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 9e9d4fe0261..851000ae30e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2135,6 +2135,7 @@ static int run_update_command(struct update_data *ud, int subforce) { struct child_process cp = CHILD_PROCESS_INIT; char *oid = oid_to_hex(&ud->oid); + int ret; switch (ud->update_strategy.type) { case SM_UPDATE_CHECKOUT: @@ -2167,15 +2168,12 @@ static int run_update_command(struct update_data *ud, int subforce) cp.dir = xstrdup(ud->sm_path); prepare_submodule_repo_env(&cp.env); - if (run_command(&cp)) { - int ret; - + if ((ret = run_command(&cp))) { switch (ud->update_strategy.type) { case SM_UPDATE_CHECKOUT: die_message(_("Unable to checkout '%s' in submodule path '%s'"), oid, ud->displaypath); - /* the command failed, but update must continue */ - ret = 1; + /* No "ret" assignment, use "git checkout"'s */ break; case SM_UPDATE_REBASE: ret = die_message(_("Unable to rebase '%s' in submodule path '%s'"), @@ -2497,7 +2495,6 @@ static int update_submodules(struct update_data *update_data) ret = code; if (ret == 128) goto cleanup; - ret = 1; } cleanup: From patchwork Sun Aug 21 13:57:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63170C00140 for ; Sun, 21 Aug 2022 14:00:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230501AbiHUOAM (ORCPT ); Sun, 21 Aug 2022 10:00:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229690AbiHUN7j (ORCPT ); Sun, 21 Aug 2022 09:59:39 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E319F237EF for ; Sun, 21 Aug 2022 06:58:56 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id r16so10290008wrm.6 for ; Sun, 21 Aug 2022 06:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=OHm+UzAhPsDcKvmhDYIanNczRcyHQqDYfJzKhhcubLg=; b=Gea1baNfjMTZ+oNuYTflsXHP2jKQbdudRaWx3tW4btvoFAB/iJpbVCVK5xkcT6kdHG oks9oGorn3mJfEIQXbOtErsYq09fDHYNeiL7LqwS6ETr8rwKjLjwft5C73uAVH6e5oFE YqiBhb9DGoba0jHj+F/S48vE75Vty9cZezEBscR2PAmSIu+DgbabbYMYZwKevXppQc85 zebyN7XWR+Wch1rghpenqPKfM7mWrUc2qDjP5IyUqxn4GXyDStmiJnz5g1qmA3D5YuHW 4vXu+Z8FNybeb1iv0ymJpEoHlbd2gc5+DtHeQMrS4H8UFgsHvxyFehtDXZ4+nIqGzGg/ GIqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=OHm+UzAhPsDcKvmhDYIanNczRcyHQqDYfJzKhhcubLg=; b=7i8/Qq0lxFdYBSV8l2HaCDoe4rg7K/D8BRw6H98ZBbmAnpeKwIuH+0x5WGsYsvZsd0 kI7yxY8Cwn07kigKY/xE2I8SG9U2Uz+aF3XMAfxVRzmZOw11D07cf5ysz0j//2/vdtq0 rRGXIpnFMOPVEblWEe+2aMJd8zW7SelguqEiyz5OpNcd1SeL5A+RKiD7b0KIj8OCHDqa UVMxYMdRAon6lfLjtMuWx1hTG4x2C4ErhHzcb3MGhDOu5yLDnUpDTisbaS15HTDyLl5J av/2WhZv9KccSek2Ung0u8wVXP2OA5HL0YCozVfdWnIVP+Oh/rysadn82vK4N7RjAbOQ QF4Q== X-Gm-Message-State: ACgBeo3VvHheWbPMOVZnOAj1bbq8coUSZSmBHmkT8DC6itZfsBdN/U62 Aq6kPW2vZ22fYXuLtarhFuiT9AsmWy/cxUIB X-Google-Smtp-Source: AA6agR7uq6ukWeMN7zuppwCfoMn48Ciceg038KkWQMO8hepfPDD5jA6KFonX1QnErX7az8GeoBxMqQ== X-Received: by 2002:a5d:6da9:0:b0:225:59e4:1497 with SMTP id u9-20020a5d6da9000000b0022559e41497mr642794wrs.262.1661090335104; Sun, 21 Aug 2022 06:58:55 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:54 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 28/32] submodule--helper: libify "must_die_on_failure" code paths (for die) Date: Sun, 21 Aug 2022 15:57:37 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Continue the libification of codepaths that previously relied on "must_die_on_failure". In these cases we've always been early aborting by calling die(), but as we know that these codpaths will properly handle return codes of 128 to mean an early abort let's have them use die_message() instead. This still isn't a complete migration away from die() for these codepaths, in particular this code in update_submodule() will still call die() in some cases: char *remote_name = get_default_remote_submodule(update_data->sm_path); const char *branch = remote_submodule_branch(update_data->sm_path); But as that code is used by other callers than the "update" code let's leave converting it for a subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 851000ae30e..5f109d422ea 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2245,9 +2245,9 @@ static int run_update_procedure(struct update_data *ud) */ if (!is_tip_reachable(ud->sm_path, &ud->oid) && fetch_in_submodule(ud->sm_path, ud->depth, ud->quiet, &ud->oid)) - die(_("Fetched in submodule path '%s', but it did not " - "contain %s. Direct fetching of that commit failed."), - ud->displaypath, oid_to_hex(&ud->oid)); + return die_message(_("Fetched in submodule path '%s', but it did not " + "contain %s. Direct fetching of that commit failed."), + ud->displaypath, oid_to_hex(&ud->oid)); } return run_update_command(ud, subforce); @@ -2291,13 +2291,14 @@ static const char *remote_submodule_branch(const char *path) return branch; } -static void ensure_core_worktree(const char *path) +static int ensure_core_worktree(const char *path) { const char *cw; struct repository subrepo; if (repo_submodule_init(&subrepo, the_repository, path, null_oid())) - die(_("could not get a repository handle for submodule '%s'"), path); + return die_message(_("could not get a repository handle for submodule '%s'"), + path); if (!repo_config_get_string_tmp(&subrepo, "core.worktree", &cw)) { char *cfg_file, *abs_path; @@ -2315,6 +2316,8 @@ static void ensure_core_worktree(const char *path) free(abs_path); strbuf_release(&sb); } + + return 0; } static const char *submodule_update_type_to_label(enum submodule_update_type type) @@ -2390,7 +2393,9 @@ static int update_submodule(struct update_data *update_data) { int ret; - ensure_core_worktree(update_data->sm_path); + ret = ensure_core_worktree(update_data->sm_path); + if (ret) + return ret; update_data->displaypath = get_submodule_displaypath( update_data->sm_path, update_data->prefix); @@ -2406,8 +2411,8 @@ static int update_submodule(struct update_data *update_data) if (update_data->just_cloned) oidcpy(&update_data->suboid, null_oid()); else if (resolve_gitlink_ref(update_data->sm_path, "HEAD", &update_data->suboid)) - die(_("Unable to find current revision in submodule path '%s'"), - update_data->displaypath); + return die_message(_("Unable to find current revision in submodule path '%s'"), + update_data->displaypath); if (update_data->remote) { char *remote_name = get_default_remote_submodule(update_data->sm_path); @@ -2417,13 +2422,13 @@ static int update_submodule(struct update_data *update_data) if (!update_data->nofetch) { if (fetch_in_submodule(update_data->sm_path, update_data->depth, 0, NULL)) - die(_("Unable to fetch in submodule path '%s'"), - update_data->sm_path); + return die_message(_("Unable to fetch in submodule path '%s'"), + update_data->sm_path); } if (resolve_gitlink_ref(update_data->sm_path, remote_ref, &update_data->oid)) - die(_("Unable to find %s revision in submodule path '%s'"), - remote_ref, update_data->sm_path); + return die_message(_("Unable to find %s revision in submodule path '%s'"), + remote_ref, update_data->sm_path); free(remote_ref); } From patchwork Sun Aug 21 13:57:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEFF8C00140 for ; Sun, 21 Aug 2022 14:00:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231157AbiHUOAT (ORCPT ); Sun, 21 Aug 2022 10:00:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231127AbiHUN7l (ORCPT ); Sun, 21 Aug 2022 09:59:41 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC77B23BD0 for ; Sun, 21 Aug 2022 06:58:57 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id n4so10275185wrp.10 for ; Sun, 21 Aug 2022 06:58:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=lyvvF6qI7M7IDR7FeV1qOXZaYpmd3ZeHHnYdmFxqkMQ=; b=BEWSF+faNaq2M6zpQUV6yir8a+K+ltZLuIgGZCGTbLUz9iFkwPFdfGAN/tUYwpetHK 5T3l/ZmilJQQh8XWOmdvR6GY1YBAlS2C7euhw4HWqxv24UeUEoOyGHSC4fnOdQEJkhAE l0XLJZj6f64ylarP7uDUCeqkIq4AHdqQeVk7QQTjiPQkxuKwsxSiPG+UbVC7IS39zlnm Zy/iTkZXbVxLsK3k5UEAVf3yzaSkD9iiqDYV2m6Tv7DWcia18jI3939oAzJ/0RU5o52c boE0+IBLKLiiRyncf0M0fqgprAYFP5MITQzvW8YJoaIYGYz/hEfYyAmVNXDPA3iKZEWo VtpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=lyvvF6qI7M7IDR7FeV1qOXZaYpmd3ZeHHnYdmFxqkMQ=; b=FpW/Ha1qSoU0dk6xLi/vTbetv8i45A889iZQ0Fp4upR+lmxfrSexPkFYGshEHfTZl7 evJlS4BAGc621OjmjNJ/KbX0i648R59aWUoQIZLxfZ9FrqP7cTWSsA5Qrx+d0s8TE9tc VnmD5Mi9lfW+NnvzO2kbLAHhaT387eeJHPQTPLRb2+rhJKrF/KNXDBp9RWzoUvhFuANb /39EvFJnWnsHpQcCxeeevSZVau0FOX/G9EaiRQMIOFItoaef7uwG+gYNp4gEohA8VLE6 bvvog8MSrbft0JK+KgJ431CmuBOpsJNkbRK4uOS5qgLggTllR7UUNKjrBeEOVGNWqZ08 +a1A== X-Gm-Message-State: ACgBeo3yE9ZgVJSgZlynmHUw88/L7LnxjoNvgzxgN3Vg6JqJrhhrP5QR Mk4pu1Bc5R/RskauBgpM9Cg+yGdf6QCCzIix X-Google-Smtp-Source: AA6agR61YJXWVwQLurSpX3gJDF94mTE23DfP/DwUU571wKt4ZBF2YCye1tMi2cnYEmhS8Eccu3fNqQ== X-Received: by 2002:a5d:4305:0:b0:225:55ed:9654 with SMTP id h5-20020a5d4305000000b0022555ed9654mr1263536wrq.709.1661090336129; Sun, 21 Aug 2022 06:58:56 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:55 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 29/32] submodule--helper: check repo{_submodule,}_init() return values Date: Sun, 21 Aug 2022 15:57:38 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix code added in ce125d431aa (submodule: extract path to submodule gitdir func, 2021-09-15) and a77c3fcb5ec (submodule--helper: get remote names from any repository, 2022-03-04) which failed to check the return values of repo_init() and repo_submodule_init(). If we failed to initialize the repository or submodule we could segfault when trying to access the invalid repository structs. Let's also check that these were the only such logic errors in the codebase by making use of the "warn_unused_result" attribute. This is valid as of GCC 3.4.0 (and clang will catch it via its faking of __GNUC__ ). As the comment being added to git-compat-util.h we're piggy-backing on the LAST_ARG_MUST_BE_NULL version check out of lazyness. See 9fe3edc47f1 (Add the LAST_ARG_MUST_BE_NULL macro, 2013-07-18) for its addition. The marginal benefit of covering gcc 3.4.0..4.0.0 is near-zero (or zero) at this point. It mostly matters that we catch this somewhere. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 9 +++++++-- git-compat-util.h | 3 +++ repository.h | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 5f109d422ea..88fc01320f3 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -63,7 +63,10 @@ static char *get_default_remote_submodule(const char *module_path) { struct repository subrepo; - repo_submodule_init(&subrepo, the_repository, module_path, null_oid()); + if (repo_submodule_init(&subrepo, the_repository, module_path, + null_oid()) < 0) + die(_("could not get a repository handle for submodule '%s'"), + module_path); return repo_get_default_remote(&subrepo); } @@ -1483,7 +1486,9 @@ static int add_possible_reference_from_superproject( struct strbuf err = STRBUF_INIT; strbuf_add(&sb, odb->path, len); - repo_init(&alternate, sb.buf, NULL); + if (repo_init(&alternate, sb.buf, NULL) < 0) + die(_("could not get a repository handle for gitdir '%s'"), + sb.buf); /* * We need to end the new path with '/' to mark it as a dir, diff --git a/git-compat-util.h b/git-compat-util.h index 36a25ae252f..01d88650ba3 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -568,8 +568,11 @@ static inline int git_has_dir_sep(const char *path) /* The sentinel attribute is valid from gcc version 4.0 */ #if defined(__GNUC__) && (__GNUC__ >= 4) #define LAST_ARG_MUST_BE_NULL __attribute__((sentinel)) +/* warn_unused_result exists as of gcc 3.4.0, but be lazy and check 4.0 */ +#define RESULT_MUST_BE_USED __attribute__ ((warn_unused_result)) #else #define LAST_ARG_MUST_BE_NULL +#define RESULT_MUST_BE_USED #endif #define MAYBE_UNUSED __attribute__((__unused__)) diff --git a/repository.h b/repository.h index 797f471cce9..24316ac944e 100644 --- a/repository.h +++ b/repository.h @@ -1,6 +1,7 @@ #ifndef REPOSITORY_H #define REPOSITORY_H +#include "git-compat-util.h" #include "path.h" struct config_set; @@ -186,6 +187,7 @@ void repo_set_gitdir(struct repository *repo, const char *root, void repo_set_worktree(struct repository *repo, const char *path); void repo_set_hash_algo(struct repository *repo, int algo); void initialize_the_repository(void); +RESULT_MUST_BE_USED int repo_init(struct repository *r, const char *gitdir, const char *worktree); /* @@ -197,6 +199,7 @@ int repo_init(struct repository *r, const char *gitdir, const char *worktree); * Return 0 upon success and a non-zero value upon failure. */ struct object_id; +RESULT_MUST_BE_USED int repo_submodule_init(struct repository *subrepo, struct repository *superproject, const char *path, From patchwork Sun Aug 21 13:57:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949935 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF00FC00140 for ; Sun, 21 Aug 2022 14:01:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231284AbiHUOAX (ORCPT ); Sun, 21 Aug 2022 10:00:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231137AbiHUN7l (ORCPT ); Sun, 21 Aug 2022 09:59:41 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBA3823BE3 for ; Sun, 21 Aug 2022 06:58:58 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id r16so10290049wrm.6 for ; Sun, 21 Aug 2022 06:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=fU2rzyWEHsEDGcr/E2aK8pmPuo3K8rSeBwte8OHNQjc=; b=QD4b6n5VjvzOF5RNzE5Ale/2QDcX4FlLYaVf4yVARxW+SYta6yAxFGb+H5b5x3iGWC t7ts6FqoYLx4yqYNuwG9sQccPco8WAafcfEv/VLZSLCVl9/nhHFBHpVcqUFT8n/PZvgs mNSKkubUWcC+Vvjx9+AMkpqYgfKNroFljiEtUga0yZ2pefDnorOSJPn6Ch8Fg/YszXeN nBPbEOPCYIjPlYlfTgPtlT+LfEJN5fRcWp++3cyC4keMoGFR8VdlTcL3sJ1Fedkcrgqg wnUo/tyk0ZhZm/KPE9XVrUhvwulZaFS7MZvEo0YFrKlVlCZ4fKLxsysXDnXlUtlOQ0U1 c3zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=fU2rzyWEHsEDGcr/E2aK8pmPuo3K8rSeBwte8OHNQjc=; b=ul96/yrrQtFotzbhRQ/xFwvUVtOS87BZxZObmqKaOLUEUluXYSfkuPVV3aKGVl8BzI m6+K296bGDZUqFpkQEgkWhWhN60Mc6cGQDvT171i5XgfrroakMa89534EPNo7E3IT6BI KjPi/OBZ0rt/HkXxXOpjGab8zLGigdHIGxVA0sJcQFyKSpsbA9r5Hx+Il75FMzpi3BWm oXaCux4d8OcUU00U4LwulsGraASANp/+zbr0p4uqeScnGyWDLyr0A8zmayyT7hegfymU 8bS7f1pYImRycvaB/CPjM9qsPFkytXuDhGq/Xd7Mp/7c7Smna4nyfs6PJBq86owKGHMu TPcQ== X-Gm-Message-State: ACgBeo34GneUDcyrYt7uKgbuNGKVKYAIjjFaAKYWvrNVf4f4iaUy9A/F CoOceqrtaPUF71vND0vT5W93iFXr6cpAh8hL X-Google-Smtp-Source: AA6agR7OtyHWBpA7UilZI8YExlLyqa7PGtyD2UFVsAPl5L9Td/hFxZ2uiyfw2w7mFd+YASLIv3N/sg== X-Received: by 2002:a5d:5a9d:0:b0:225:2783:d6f1 with SMTP id bp29-20020a5d5a9d000000b002252783d6f1mr8857747wrb.385.1661090337108; Sun, 21 Aug 2022 06:58:57 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:56 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 30/32] submodule--helper: libify more "die" paths for module_update() Date: Sun, 21 Aug 2022 15:57:39 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As noted in a preceding commit the get_default_remote_submodule() and remote_submodule_branch() functions would invoke die(), and thus leave update_submodule() only partially lib-ified. Let's address the former of those cases. Change the functions to return an int exit code (non-zero on failure), while leaving the get_default_remote() function for the callers that still want the die() semantics. This change addresses 1/2 of the "die" issue in these two lines in update_submodule(): char *remote_name = get_default_remote_submodule(update_data->sm_path); const char *branch = remote_submodule_branch(update_data->sm_path); Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 58 +++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 88fc01320f3..9e4069b36cb 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -31,48 +31,57 @@ typedef void (*each_submodule_fn)(const struct cache_entry *list_item, void *cb_data); -static char *repo_get_default_remote(struct repository *repo) +static int repo_get_default_remote(struct repository *repo, char **default_remote) { - char *dest = NULL, *ret; + char *dest = NULL; struct strbuf sb = STRBUF_INIT; struct ref_store *store = get_main_ref_store(repo); const char *refname = refs_resolve_ref_unsafe(store, "HEAD", 0, NULL, NULL); if (!refname) - die(_("No such ref: %s"), "HEAD"); + return die_message(_("No such ref: %s"), "HEAD"); /* detached HEAD */ - if (!strcmp(refname, "HEAD")) - return xstrdup("origin"); + if (!strcmp(refname, "HEAD")) { + *default_remote = xstrdup("origin"); + return 0; + } if (!skip_prefix(refname, "refs/heads/", &refname)) - die(_("Expecting a full ref name, got %s"), refname); + return die_message(_("Expecting a full ref name, got %s"), + refname); strbuf_addf(&sb, "branch.%s.remote", refname); if (repo_config_get_string(repo, sb.buf, &dest)) - ret = xstrdup("origin"); + *default_remote = xstrdup("origin"); else - ret = dest; + *default_remote = dest; strbuf_release(&sb); - return ret; + return 0; } -static char *get_default_remote_submodule(const char *module_path) +static int get_default_remote_submodule(const char *module_path, char **default_remote) { struct repository subrepo; if (repo_submodule_init(&subrepo, the_repository, module_path, null_oid()) < 0) - die(_("could not get a repository handle for submodule '%s'"), - module_path); - return repo_get_default_remote(&subrepo); + return die_message(_("could not get a repository handle for submodule '%s'"), + module_path); + return repo_get_default_remote(&subrepo, default_remote); } static char *get_default_remote(void) { - return repo_get_default_remote(the_repository); + char *default_remote; + int code = repo_get_default_remote(the_repository, &default_remote); + + if (code) + exit(code); + + return default_remote; } static char *resolve_relative_url(const char *rel_url, const char *up_path, int quiet) @@ -1159,6 +1168,7 @@ static void sync_submodule(const char *path, const char *prefix, char *sub_origin_url, *super_config_url, *displaypath, *default_remote; struct strbuf sb = STRBUF_INIT; char *sub_config_path = NULL; + int code; if (!is_submodule_active(the_repository, path)) return; @@ -1198,10 +1208,9 @@ static void sync_submodule(const char *path, const char *prefix, goto cleanup; strbuf_reset(&sb); - default_remote = get_default_remote_submodule(path); - if (!default_remote) - die(_("failed to get the default remote for submodule '%s'"), - path); + code = get_default_remote_submodule(path, &default_remote); + if (code) + exit(code); remote_key = xstrfmt("remote.%s.url", default_remote); free(default_remote); @@ -2420,9 +2429,16 @@ static int update_submodule(struct update_data *update_data) update_data->displaypath); if (update_data->remote) { - char *remote_name = get_default_remote_submodule(update_data->sm_path); - const char *branch = remote_submodule_branch(update_data->sm_path); - char *remote_ref = xstrfmt("refs/remotes/%s/%s", remote_name, branch); + char *remote_name; + const char *branch; + char *remote_ref; + int code; + + code = get_default_remote_submodule(update_data->sm_path, &remote_name); + if (code) + return code; + branch = remote_submodule_branch(update_data->sm_path); + remote_ref = xstrfmt("refs/remotes/%s/%s", remote_name, branch); if (!update_data->nofetch) { if (fetch_in_submodule(update_data->sm_path, update_data->depth, From patchwork Sun Aug 21 13:57:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949932 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98D13C32772 for ; Sun, 21 Aug 2022 14:00:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231147AbiHUOAR (ORCPT ); Sun, 21 Aug 2022 10:00:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231135AbiHUN7l (ORCPT ); Sun, 21 Aug 2022 09:59:41 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF45623BDE for ; Sun, 21 Aug 2022 06:58:58 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id n7so10297998wrv.4 for ; Sun, 21 Aug 2022 06:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=+TIeCK2o8Goojyff7ZcfpHsF40olPSlEXw7G4gQfmLE=; b=bLTv14LuTDIFAEx8f2e/2QoxDBIzxN04w//s+UCpjqL0YqGMEIOCbdsRMnscNrbWc6 cZXZrxYWqEiD94CYE+g1ok8TWQRr9cS3Z8Nc5kp/U5ZSydmBXEzXmZDixgS/H/5qULNj yozqa5qYJb0EnQJE35tZz+JVae6NtJ/GCpTxtEt2PZ6OqU6ICUZxUyhfx04KLSjkdOGp RLmsatUzb5pky9z0CMEM9kJ3xZAv5mTjvsnezIyvaOIGBzojR3B8tHi0RvwNDE8j90Li XxBSDQpF12w0IpY4tFQoJId+mc3cJms+Lnw6KTt7KXf1M2QAbb19mVnpg4vhST3EUvQs Zv8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=+TIeCK2o8Goojyff7ZcfpHsF40olPSlEXw7G4gQfmLE=; b=Ei6LYk3Q91YDicbGFXQgYM6jgwtABtjCUr1zGoo6kTR7ttBjMM9VvPEIlVIwh0laCf sZcZx1pBnLm//j/7Nu1PCYW1eyVOafNhvEKl26kPqesBqvZX5v0hzA3nwI3RDcYmD2MS iHTNpmIal1YSVEIHIJTSBM0FFw/N9EsPO98+KHU+TbrfNLxjrh2OkP1MbGsWqkLHeIPL CYvTBwNx0QAxxLQ52UB3Le7QXT1dxkFKAV490olT7J5SzTid3grOT1QCSdTK6FQgK0yD +rvfxnKRgv54Unee1HItI6XdlUo01QCYtRzO+UN1NSh/qrLxr9OuuwTlRW+0sEUvrTjB CiJA== X-Gm-Message-State: ACgBeo2K3saCCgOCr90ns7evoPZsO+5aYtCshyI5Li/RWt0yh0fX2rD9 9XxoXteJNrxNNrPD52oXhX//JymH1+kO70kX X-Google-Smtp-Source: AA6agR4FqomweBU3oHymKL4q2SeQWgOrF1W5ECJJEkBmr3j9Wnjvw7DWRGj657Y1gMZVBPwXpD4GFw== X-Received: by 2002:adf:f88c:0:b0:225:4c23:6788 with SMTP id u12-20020adff88c000000b002254c236788mr2793372wrp.140.1661090338075; Sun, 21 Aug 2022 06:58:58 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:57 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 31/32] submodule--helper: libify even more "die" paths for module_update() Date: Sun, 21 Aug 2022 15:57:40 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As noted in a preceding commit the get_default_remote_submodule() and remote_submodule_branch() functions would invoke die(), and thus leave update_submodule() only partially lib-ified. We've addressed the former of those in a preceding commit, let's now address the latter. In addition to lib-ifying the function this fixes a potential (but obscure) segfault introduced by a logic error in 1012a5cbc3f (submodule--helper run-update-procedure: learn --remote, 2022-03-04): We were assuming that remote_submodule_branch() would always return on-NULL, but if the submodule_from_path() call in that function fails we'll return NULL. See its introduction in 92bbe7ccf1f (submodule--helper: add remote-branch helper, 2016-08-03). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 41 ++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 9e4069b36cb..65909255760 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2267,42 +2267,49 @@ static int run_update_procedure(struct update_data *ud) return run_update_command(ud, subforce); } -static const char *remote_submodule_branch(const char *path) +static int remote_submodule_branch(const char *path, const char **branch) { const struct submodule *sub; - const char *branch = NULL; char *key; + *branch = NULL; sub = submodule_from_path(the_repository, null_oid(), path); if (!sub) - return NULL; + return die_message(_("could not initialize submodule at path '%s'"), + path); key = xstrfmt("submodule.%s.branch", sub->name); - if (repo_config_get_string_tmp(the_repository, key, &branch)) - branch = sub->branch; + if (repo_config_get_string_tmp(the_repository, key, branch)) + *branch = sub->branch; free(key); - if (!branch) - return "HEAD"; + if (!*branch) { + *branch = "HEAD"; + return 0; + } - if (!strcmp(branch, ".")) { + if (!strcmp(*branch, ".")) { const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, NULL); if (!refname) - die(_("No such ref: %s"), "HEAD"); + return die_message(_("No such ref: %s"), "HEAD"); /* detached HEAD */ if (!strcmp(refname, "HEAD")) - die(_("Submodule (%s) branch configured to inherit " - "branch from superproject, but the superproject " - "is not on any branch"), sub->name); + return die_message(_("Submodule (%s) branch configured to inherit " + "branch from superproject, but the superproject " + "is not on any branch"), sub->name); if (!skip_prefix(refname, "refs/heads/", &refname)) - die(_("Expecting a full ref name, got %s"), refname); - return refname; + return die_message(_("Expecting a full ref name, got %s"), + refname); + + *branch = refname; + return 0; } - return branch; + /* Our "branch" is coming from repo_config_get_string_tmp() */ + return 0; } static int ensure_core_worktree(const char *path) @@ -2437,7 +2444,9 @@ static int update_submodule(struct update_data *update_data) code = get_default_remote_submodule(update_data->sm_path, &remote_name); if (code) return code; - branch = remote_submodule_branch(update_data->sm_path); + code = remote_submodule_branch(update_data->sm_path, &branch); + if (code) + return code; remote_ref = xstrfmt("refs/remotes/%s/%s", remote_name, branch); if (!update_data->nofetch) { From patchwork Sun Aug 21 13:57:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12949934 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E34DEC00140 for ; Sun, 21 Aug 2022 14:01:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231264AbiHUOAW (ORCPT ); Sun, 21 Aug 2022 10:00:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231145AbiHUN7m (ORCPT ); Sun, 21 Aug 2022 09:59:42 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDE4C23BC6 for ; Sun, 21 Aug 2022 06:58:59 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id u5so2473969wrt.11 for ; Sun, 21 Aug 2022 06:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=4ueQ3IGlJxs5Pe3SIF8DZUo8OKjXpkm5eSKbmPEzut0=; b=eiPI+Tq+4C+86+zUhoNqfLNzEYSkR+uNQIAz+PAJ2rZpp3DHymOz/GFP4HjE+RL5iY R2mvA1rfJqxqB+aX+0U4hcDimzi30s+QuqNmWrX8jd7UHilPslZcl4zNWRYNUl+nmW99 rjs25krNAccwG+mFnv8pLzmwah7DX3Rp1523j+vKW2O+W+dxMMXpbI5z0zT6JsIm7rL/ gw+F35LMQ0owFncjY8AMgLowt47QK4E5AaoKmxvj4MRbnvYC9Cl+jA/8xI9tgCterizV e7waIIBbS/b2ReLiYjucuYUGiU8bAySGqCllBzw3AJ1N5JejH0leeeTaUDx0L9COikBW +PEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=4ueQ3IGlJxs5Pe3SIF8DZUo8OKjXpkm5eSKbmPEzut0=; b=ghrwd/UGE5/o9lg6jyZf6OIKCLICmeuqkXraoCD5oTEA44vCYpo6FjuFWTk9MAO3w0 nAwTXTg0D/SrivUtRw1ltmgo/CojQ0VWUJ++yUHOYza7p6+JsaMvYne7WBRCmkqc5Ogi 8FFF4+ngJaF/Mc94S5/m1KkYe340+g4+biW9qV2AGmoMDo+OAQIpE/S4Br1I326hpWl4 5WjV6dvCw22WoeZ+rY/UMqrd9S9ynoTC/dQbflu/FDO6LmPljwVgE/Dw/3je/WH9luOd 0gix+jcVtWnGTITjt2s6GFiVCaUEF3XLl8QmuqQTIy1a2SiC4ZSGdswmGJFaw8vk8F8v qYvw== X-Gm-Message-State: ACgBeo19sW2BmZIs/4oEQ2r9ZZ7fsKNxBE1yaCjdnj0gfqOtoozxDdTx iYMkhOYcuOvjIPbZMTrMOC0khhnArauU6uxV X-Google-Smtp-Source: AA6agR4DsmfzU0PryRbHyx6eQEB/P5SAwT+5myEeXvLLvYGLhoZ+3fjyLHucxpBT93pcPvyiCUluog== X-Received: by 2002:a5d:684a:0:b0:225:4363:c4e9 with SMTP id o10-20020a5d684a000000b002254363c4e9mr3841333wrw.309.1661090339078; Sun, 21 Aug 2022 06:58:59 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o12-20020a05600c4fcc00b003a5b788993csm12624872wmq.42.2022.08.21.06.58.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Aug 2022 06:58:58 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 32/32] submodule--helper: fix bad config API usage Date: Sun, 21 Aug 2022 15:57:41 +0200 Message-Id: X-Mailer: git-send-email 2.37.2.1279.g64dec4e13cf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix bad config API usage added in a452128a36c (submodule--helper: introduce add-config subcommand, 2021-08-06). After git_config_get_string() returns successfully we know the "char **dest" will be non-NULL. A coccinelle patch that transforms this turns up a couple of other such issues, one in fetch-pack.c, and another in upload-pack.c: @@ identifier F =~ "^(repo|git)_config_get_string(_tmp)?$"; identifier V; @@ !F(..., &V) - && (V) But let's focus narrowly on submodule--helper for now, we can fix those some other time. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 65909255760..e489a0f6b10 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -3108,7 +3108,7 @@ static void configure_added_submodule(struct add_data *add_data) * is_submodule_active(), since that function needs to find * out the value of "submodule.active" again anyway. */ - if (!git_config_get_string("submodule.active", &val) && val) { + if (!git_config_get_string("submodule.active", &val)) { /* * If the submodule being added isn't already covered by the * current configured pathspec, set the submodule's active flag