From patchwork Wed Aug 31 23:17:43 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: 12961537 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 97827ECAAD1 for ; Wed, 31 Aug 2022 23:18:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232201AbiHaXS2 (ORCPT ); Wed, 31 Aug 2022 19:18:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230168AbiHaXSY (ORCPT ); Wed, 31 Aug 2022 19:18:24 -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 03E214C636 for ; Wed, 31 Aug 2022 16:18:23 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id d5so8111671wms.5 for ; Wed, 31 Aug 2022 16:18:22 -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:subject:date; bh=+9Ce/NUO3YdqOO6NBtfUx5y12ik3ZPYt18dNfTT3yyY=; b=GXLNy3h5LedvD4Uix2F2r1/xnHH0c6ekn7Q9wQ9Xkq7Ld+LjKHBOtJwpgdjjE7rvVx ySLBR5c8dDPvGLOh9uGJn+U7d/y8toC3MgGIs9+WTrf+JgfdVyJI+Rbm99rz4jCJ8aQM /uGjMPgNPPun1XzDYRxNbVNQjFx2OP9B+9fgDxLFC/QcstmUPHYobxt7fHJuflTNv/dR aunfQ907669U9kVHVuuH0v8+hyeRdVuzBI2km33qkj6OU1phA8utG1AZYOdE+r9Fj7RG N1vpg5sCD7K/WrA2vmiCTNwYeLrowzzYVK8kA6MAgJ+etdq75EC3Hep5xE2N5DyLROt9 DFQA== 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 :subject:date; bh=+9Ce/NUO3YdqOO6NBtfUx5y12ik3ZPYt18dNfTT3yyY=; b=l42yUeoPy09TSWFe0ce0uSmXhqBP9qHwmevR0aMq1t3S5AckcgcVzgf6suuaLytZdq PiZ2KeFltDvk5UzGMND9n73Yhko1E9kdiMaAIYLN8lqoUteFplqTdn55C5Q/xsZ2p5H4 nNU0mT/8SW20GY8WVv/3gDbek6iAOBfwbwPaC64vhR4GdO++cxxjec9zu331dGD/te0y tJ5saDI7VN9VBG1ZW0eHo6uniIxIrVUVv/Czf342JybNLjqfsL8wNG3tz5PqLHaY8QWF d/MAyo5G59KsFgfKRm6EW7JvbdExiDJqi1nnHavl0Uum6NLFbKXPoCjLf+Lrv9+b7GhV iZcQ== X-Gm-Message-State: ACgBeo1gO4pTG8NI1IAQYuP8dsWvsK0eqSHBk1rTp2s2T4Z5WUe0ja7A OytRFBbkOiDJTdBP0ShTswhH+CVzRBi2ZQ== X-Google-Smtp-Source: AA6agR7B5SWritNi/KMfmk/IbnV6BKLdB7xUcygde9c9J/IH89qPDt9MWJzXz5anAetO/hixXdbAZg== X-Received: by 2002:a05:600c:502b:b0:3a5:d36a:8b93 with SMTP id n43-20020a05600c502b00b003a5d36a8b93mr3269901wmr.180.1661987901346; Wed, 31 Aug 2022 16:18:21 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18:20 -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 v4 01/33] submodule tests: test usage behavior Date: Thu, 1 Sep 2022 01:17:43 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 Wed Aug 31 23:17:44 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: 12961539 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 49D39ECAAD5 for ; Wed, 31 Aug 2022 23:18:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232745AbiHaXSf (ORCPT ); Wed, 31 Aug 2022 19:18:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232438AbiHaXSY (ORCPT ); Wed, 31 Aug 2022 19:18:24 -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 A92BDB028D for ; Wed, 31 Aug 2022 16:18:23 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id j26so8129993wms.0 for ; Wed, 31 Aug 2022 16:18:23 -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:subject:date; bh=lwUXQcRR7izX2Bon4Yk4V5Fu13Y/6sAUgfkKPWKYrgU=; b=P5bwHz/wxqAEk6ZaY0SLgnNOFEY3AaP4iKI7+Ozk+7c6gjTUx7DY4iqewXm4cgh3do cUGFS/zyr6wKcmGM6vsFTbWcbetvCKcPs6khfS7nPB0HkuhSenaB9uJINxaf/oAYZg6m opj1UiABjnfVWQV2wvyw+G9YDqyRdPK7ruuYzUtYlFUMDjcwR5+suRBDaGBxnRCtJWpu HZm0zlUjWWHwcj/kZqfknRK2YmNaw1jJPCrsqGm/OSdptMUdkwfQTA/7ks5cooYVfdVr eAKLTus0Uzeb7RP9qa8d7duZc5dbGJj0JhdeojlFtDoR4k1ok4omq5QqK83tpjh1wVUB G8NA== 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 :subject:date; bh=lwUXQcRR7izX2Bon4Yk4V5Fu13Y/6sAUgfkKPWKYrgU=; b=MnUM90kV121PGJ0Do6cJSfbza1NX6rT4BmUAPxjNRdYjtM51QXHDW6cEafrvaFM3B3 i9DnWKrOLXgWmFggSPWpDdvIEvM8jr7apxHe7Myr4AkiDacSQTixDmwehJACI1VIP5L4 4xlduNaSi5bzQOHVmwCeeoINIatryBiE0EOd6jSEZ+lhaMPugIDHkTBu/lyOyraWyuo5 YtGlnq3dA3nNoyxZhvSzbscwjhIFfa+9tFelqiHGRhPpryOWYPtMi4H45zIA7+AntY8L h7eZOy2fPW/6kGiBQev2Yc+kgRDYpCgEEG2NkXqyynzCVaNa09YrHcX9jUunsplhsoqz QDVg== X-Gm-Message-State: ACgBeo2/uIztgUfjO/olZeUyc37W8ydxoHY4JFpWKn2X7pmdc3loRCRC sR7cr8ijkowt+TWOx20y3QB34Tjnqz42cw== X-Google-Smtp-Source: AA6agR7tg+fVdEJ9GB9wKdHJG7TwhiQG7qPGshlSqqtj6nemXxnDaa+/jec8JC1DNhYCOeJNuIw5Ww== X-Received: by 2002:a05:600c:1d16:b0:3a6:1fa1:41f7 with SMTP id l22-20020a05600c1d1600b003a61fa141f7mr3160067wms.103.1661987902108; Wed, 31 Aug 2022 16:18:22 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18:21 -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 v4 02/33] submodule tests: test for "add " Date: Thu, 1 Sep 2022 01:17:44 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 Wed Aug 31 23:17:45 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: 12961540 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 04D0EC0502C for ; Wed, 31 Aug 2022 23:18:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230168AbiHaXSp (ORCPT ); Wed, 31 Aug 2022 19:18:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231873AbiHaXSZ (ORCPT ); Wed, 31 Aug 2022 19:18:25 -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 69E5D9C8E5 for ; Wed, 31 Aug 2022 16:18:24 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id az24-20020a05600c601800b003a842e4983cso452371wmb.0 for ; Wed, 31 Aug 2022 16:18:24 -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:subject:date; bh=InnZePy7Y7sqcPPEART2wCG/ftc5e+6x04/S1MVaTBY=; b=YOZ3tlLWLVRQFTw7q/zf5LaGkmb664ou8PL1PERpI1qDx/4zuZ4runGENbY9la5NAG KEQ647q+pSS1+GylhxrqYf8Z0SMw6cG1hrMWGE1X+Dsy0UmWIjLjMzPx6NMljyN2tLVr GY1ld7ZGJuxaKQdBEOjYWkXw9UHtt5MuxYRCEBj3Tp4+TjYofGf0BjG8a0q33Xq6pw8X NzHw8kEG6kA25BYOsp88srRUybm/mbpK16W8UEN0SrlK4pB7BXZxvv+8kyR/+kAgCdqw Qwr9nc8TgXfgM5xWuFkKw+2KaQVPIbkdPFd91HO03CLG5GcduIj00HEqJh4I86/mg6YV OvUA== 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 :subject:date; bh=InnZePy7Y7sqcPPEART2wCG/ftc5e+6x04/S1MVaTBY=; b=PtSjeMgzHqRK3J2yv05wSADXqVblZ6ftzerp7hLbUNdiRUxMgVkW0dpyPr/Me8YLTo dMjENac/n8mKTtAGBB68/QP8Uca0SA4jJsB7Coskz2rIDjraC0bKo+g9lhF+NDEiLJNV s1Dy8BpwlAvCyNHHqYaTnMSS3aSRJQguD5MTKO7Ifom1Bcd9eeAr4/9Q3Gk2faT2zPWi y4uhD3UumVty6UlY2qsjcVTy/2wuU391AVCGdu1DphK+CXswb0NeYAHQ7nyPMVKU5qHA 1/LUy2CYUM9vzTM//OXY7Lkv1+KBjRqQnq85qmUHqw87uhzzKjvgl+K3G2bBQ1m/nM+S bgwQ== X-Gm-Message-State: ACgBeo1Vf3vgTDlKZr3b3eq5Etx2sAMF0ti2Dc/pXeu/+kn3KVDfauvB FDuE23LpKQm4iMDFC0INvA/NrJa3/Tbi8A== X-Google-Smtp-Source: AA6agR4/PMiCxYQACZWKDrlfRCyGSkCyUjcEDjFfPNhK5wN9ct/t6orezh2BRSAaMmlazrQvytADxg== X-Received: by 2002:a05:600c:358c:b0:3a5:dac0:dc3 with SMTP id p12-20020a05600c358c00b003a5dac00dc3mr3167970wmq.60.1661987902900; Wed, 31 Aug 2022 16:18:22 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18:22 -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 v4 03/33] submodule--helper: remove unused "name" helper Date: Thu, 1 Sep 2022 01:17:45 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 Wed Aug 31 23:17:46 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: 12961541 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 04C40ECAAD1 for ; Wed, 31 Aug 2022 23:18:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232804AbiHaXSq (ORCPT ); Wed, 31 Aug 2022 19:18:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232412AbiHaXS0 (ORCPT ); Wed, 31 Aug 2022 19:18:26 -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 4F3E4A00FB for ; Wed, 31 Aug 2022 16:18:25 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id j26so8130011wms.0 for ; Wed, 31 Aug 2022 16:18:25 -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:subject:date; bh=ePoGfql8fulmTurQ/+7+GoZ75R80Tquo3+jcfAq5KWs=; b=l37AijbQFukbqd474pWY1wyhYbKQ8HmlQPjVcMv2Gj/dQJkBlI2s/qaZx+qfizydM+ CwqQ2Tve8cic/lVmT6z2S2lWLoLNOh8sDT1B+Sbgoh7nYMoRJAWXHXMt/Fl8on+G/Ii3 9ZrtibIqyKXzovIR0Bk3G2pnWCVJahFt3tnGfqEBFIgZEFE34x0G0NHF3eS+KHyyX4FG VseLdUO+Tx1nT5lIVH1bAD2e6Do8WTPfdovqd14aY3yrShQaVO+5u1c7pcuZnUKRRtN6 N3iNG2tkhYm+Z/3DE21f7OCk/iJ4rbw9u+bNmrvZ5zv6K0zVA2btOoItxEGuSXvn9kUZ VHfw== 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 :subject:date; bh=ePoGfql8fulmTurQ/+7+GoZ75R80Tquo3+jcfAq5KWs=; b=yEBT7Qr1kxkxl5/CPLzJX1tvDXJSt2u1K0j3X2Gpe4PbkWMkDLjx6GQh5vlV8qZkZB f6hCAWC1zB0kBSN4WQ4RgcLkbBDKkivFLiwMNOsBfzNq5Y5Vl6NKkjTYaWXJiuNZlT1A tvtm4/ZVgb+MXIrvdJwZkPOEjx3GlPQErt78YHq56H2jxEtCju40sKLyiNYFn2ldI8vL soVhQ7PMaBWBbaXh13N1yshDjkJ3ZSbuP/xvQXF3cDukwTXHuoblvLFaBvEm04xy7F78 UbKothZQxbfHyJW4Uxe8mGVidIni4uDHXNtE7dFZranUJAc285Ux37IvsxxWVQJS4mTr SPsQ== X-Gm-Message-State: ACgBeo0YI2JEiQztDmE9xUZq8LfNcayw9jdICqPpib2Dr/3bFKw3O/nZ dKif/kdYs6AhGkM/8tZLF9EWN72k1Ni/cw== X-Google-Smtp-Source: AA6agR6m2DRiaqf+HW5+YsmlkqcoxGDFtRe3J4IcyMSdhawtVAloVRz1dMBP3w/1goa2MGiZA/SbrA== X-Received: by 2002:a05:600c:1f1a:b0:3a6:2569:496b with SMTP id bd26-20020a05600c1f1a00b003a62569496bmr3243230wmb.176.1661987903636; Wed, 31 Aug 2022 16:18:23 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18:23 -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 v4 04/33] submodule--helper: remove unused "list" helper Date: Thu, 1 Sep 2022 01:17:46 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 Wed Aug 31 23:17:47 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: 12961542 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 09F1FECAAD5 for ; Wed, 31 Aug 2022 23:18:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232698AbiHaXSu (ORCPT ); Wed, 31 Aug 2022 19:18:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232628AbiHaXS0 (ORCPT ); Wed, 31 Aug 2022 19:18:26 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19C204C636 for ; Wed, 31 Aug 2022 16:18:26 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id e13so19221400wrm.1 for ; Wed, 31 Aug 2022 16:18:26 -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:subject:date; bh=b7L7jk7KvnSTSEBJD6g7O+ePLU2qGuW+/SP/1keNRxE=; b=qncsce6rmpeNtJSwrLAb1UnHd6h4UV7mYAx+Y8AAUY9O/HC/n8ShzwSwGOTRWT9uxR TjMCaSOw1xLREveOFhJTxfKndaHgi1HMJhp0HQvogcIPgCXClt6NTlcPOsOsZjgasj4n gYkASmuCcyBxSL1fQnkwK9F91Ew6Zl/BbkDNXib0l3/ALsouZmMQHQ5sAvnaCyNSzEhq lx6dMBtiBXp3wMUXbxsJAtQz3rk+9sb+V3EQJjhSTp0gT4R2mVT19SjNs9pcApQP4i+O 2iezvQwcbCPHCIsHaBoFvZmGkaicqgfLMlbnHUQRGszy+ZR8VkJkeJ8A4/8MbP8iK6WG uLVw== 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 :subject:date; bh=b7L7jk7KvnSTSEBJD6g7O+ePLU2qGuW+/SP/1keNRxE=; b=cOeMBjrqOVvsOEvl++YjoMuyYmypN4Sbdk+p0J0dpxfJ8oAN+0LbL9l9re1JnRLlAU qBTGhCliIkTBkDk1bXvMCSfu3EHZwkBm1WmGqWBU2LZseo+pGZrLkt0cAfGJm1jkq0zS Oyre4UTbClM1E9QM/F4Z92V4ALJpAX4Aj4Uw/PINnCzxoyggocze/juD4XSl/HlcdfGu /4soYjB2xIoakRhshxbgkDEg8fWII8fa2pyJrAcoZuS9z9b3aNA1bflj5v6PIinWxN5o epCMhxM2ubwtDPavUYKyEEssrHqfJM8dmphkpIJEwjOoqyZqi2CrJFsyPSDPDAYQ2d0t 7pWw== X-Gm-Message-State: ACgBeo2h04SZDlxaPYPEI0uNK1uHvYQlH7shjrsJT8VEP4LT7g23MOQ+ GNHnabXUWbLAcOplVl/V20znx/u8H7127Q== X-Google-Smtp-Source: AA6agR5RdP0MU6mPto+tP8PuuJ68OoIHLh6i9sQHSU8SDt8415ALB87zgpsuOLnjGO46Jk8f8gqHSg== X-Received: by 2002:adf:f7d0:0:b0:225:82fa:422c with SMTP id a16-20020adff7d0000000b0022582fa422cmr12404053wrq.349.1661987904499; Wed, 31 Aug 2022 16:18:24 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18:23 -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 v4 05/33] test-tool submodule-config: remove unused "--url" handling Date: Thu, 1 Sep 2022 01:17:47 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 Wed Aug 31 23:17:48 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: 12961548 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 73420ECAAD4 for ; Wed, 31 Aug 2022 23:19:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232792AbiHaXTB (ORCPT ); Wed, 31 Aug 2022 19:19:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230510AbiHaXS2 (ORCPT ); Wed, 31 Aug 2022 19:18:28 -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 DE3AE9F1B8 for ; Wed, 31 Aug 2022 16:18:26 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id m16so20104343wru.9 for ; Wed, 31 Aug 2022 16:18:26 -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:subject:date; bh=8WzJKAjKTZZJg2AloaeMOYJFB0/nh3T5sJd8jI3W/5Y=; b=na14QfeuqBDtWV3ODX+5N6oYqlaYakb+SL3LDqjpiHgtN89xhWJtDKx49el0knurQQ YmM5FUyzcXPils5zNGIUKNoB1H0F7UMSk86bNxpMCg8ezs6lH2bY9nyC5MgMO12O4V9Q 4hDuLkUl/IXxy/fBR1jpTEOU8QrAOwyFcb5GnNRvlQ5hnc2jKJrpD55SQkamN9y4jeNu mkdqNNeedH57ZOQeCergB284Yc0g1CG41lxeVzFoig2q2oitvyn683uaEpAsRfV9osKh +rCEt02bdQijB9z/ASP3ML28aclT6pikxx3z8GZOC0jESkPm4xVMZq+1aND/C90RqZWa tdIA== 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 :subject:date; bh=8WzJKAjKTZZJg2AloaeMOYJFB0/nh3T5sJd8jI3W/5Y=; b=zF5Vq+gDw+8zYKChHsWnVWyJiBSpTr1qH0FTMqpYcQI6iRCbeZKdlb62P+HaaP9Tdf zeSSmVQi8v3qBf31n/gBOhZsRBMh4JmDG0w7S6PxcvkEh98eLDCNSA7Fh2Y7cUJT8OYw Til68KT8FWzzyE5rRwzcj1K2qAGrrail2NYy4AcazuaE5fh6vRvA3vkfSr3kupHQ2d7j 3UyFWLEHLn+rSlmbT9OVftZB4ABz7PE/SMwo7L2oHw8COrbV7aZpE18/8QgtlDZmQXzA UbLSLWm4YfK16x4oLEpHz8p7ib5cxDQX/0CkQQ/dwZqSFDw2USeqICvN4j4DmpBoV0Q1 avnw== X-Gm-Message-State: ACgBeo1+qCuag8V6ZutPKLCkUjy9wessjPOolG/5Llg4RHfBKe4dXP9F mrsb8/dM/TqpF0Qx9dc+cpxOndAzq+hbqw== X-Google-Smtp-Source: AA6agR73TjLwl6O+ys4g2DJsnjBJXvmaKATfkoiFq9AFIwD94lsVkDJHQPD14AE5Ye9wrg51iRgj0g== X-Received: by 2002:a05:6000:168d:b0:226:da6a:6d78 with SMTP id y13-20020a056000168d00b00226da6a6d78mr9351823wrd.180.1661987905204; Wed, 31 Aug 2022 16:18:25 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18:24 -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 v4 06/33] submodule--helper: move "is-active" to a test-tool Date: Thu, 1 Sep 2022 01:17:48 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 eac30126e29..e0daec07306 100644 --- a/Makefile +++ b/Makefile @@ -786,6 +786,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 d6a560f8325..50a6ae38a7d 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 }, @@ -79,6 +75,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 21a91b10195..6921a6fc2c5 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -69,6 +69,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 Wed Aug 31 23:17:49 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: 12961543 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 E7EB2ECAAD1 for ; Wed, 31 Aug 2022 23:18:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232762AbiHaXSw (ORCPT ); Wed, 31 Aug 2022 19:18:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232082AbiHaXS2 (ORCPT ); Wed, 31 Aug 2022 19:18:28 -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 98D6AB028D for ; Wed, 31 Aug 2022 16:18:27 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id v16so17400858wrm.8 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=5k8eYK9zyJeTYgUgdzpGQxnycG1vPL2+jeZWUCaYE9o=; b=QmFNSumtqW2KO+zbqZdWf0YdTjgEZIENq4FE5ESJ/ucCqKtFMQoChPaZZkCpoNpjhR 97G3pDtKdcLJE58PuoF9Qy296LHjvyHRK85ywQLowvIxtEHF04O0NRdHCkeiLdD5mMdW wLLs5f/hOi44uOoGKw71D/zozMiDdCMyxGVRsT+gJPhuCSJ1lFl2JBN6UZw+unXrDpJA 94/Ea5jSSSkN0rrt90tt/oxl4jf5dGpRh5MaewyllsLWStbNs4VWg1MWYHq+rAbPNUmm u1H29GILFr5vbQELiyF5M4kVz3/SnIyg2Z/SU1lYoXV7BR/0AOhDj3OHalRtCVwJxOdu awrg== 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 :subject:date; bh=5k8eYK9zyJeTYgUgdzpGQxnycG1vPL2+jeZWUCaYE9o=; b=XVt/OkITdPdPLwCIa48IGORddScEJyxsr9mIqT4nJ1aUvk9YSPCbyJjHv4bKMlfVAT P2Ct1LzEJu6ww41rl5G3DYn1w0Hu4x1H6hCcyVE8F3MyquWtw8bji4MICU7C+eMj5W1n ajO/4xg8xv7S/WOAD1U1wtNS/Tf7wIK23L7se9ISGIzJrsN6rBwS7gyv03H92KcYlicj dKVKPHoN6RGRq8oggimu2eOPshaWj18QrXH7md5LcqeHaInjDKnclGxM+6AJvx5DUe2J dfkvSDsuKAr9TgGnf5doztR4CxCI7MXTAJEJaLYQlnlR41O7gHnerfx6xiCsS06FPYOl U9fA== X-Gm-Message-State: ACgBeo0YN6FH53adpujlXQ+GwZ8sbh7+OODlTsP7LmVwl9tCnrxkYko0 dxkP2oj2zCygdhSRDrFojpUbA1ji/Rjl+A== X-Google-Smtp-Source: AA6agR7vN1/HZ1arDiqb/5DLIoYsHDe0kz8/eNUlZ3YOkx6y9gEqy9i91NIxsYuZ9rmkS/XLTevoJw== X-Received: by 2002:adf:ee52:0:b0:226:f190:44d0 with SMTP id w18-20020adfee52000000b00226f19044d0mr1191216wro.503.1661987906017; Wed, 31 Aug 2022 16:18:26 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 07/33] submodule--helper: move "check-name" to a test-tool Date: Thu, 1 Sep 2022 01:17:49 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 Wed Aug 31 23:17:50 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: 12961544 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 C0319ECAAD4 for ; Wed, 31 Aug 2022 23:18:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232767AbiHaXSx (ORCPT ); Wed, 31 Aug 2022 19:18:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232310AbiHaXS3 (ORCPT ); Wed, 31 Aug 2022 19:18:29 -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 8322CB08BB for ; Wed, 31 Aug 2022 16:18:28 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id e20so20097133wri.13 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=pML3uT81R2gzSfEf6NOny1nK+miWtvP9JGYOnsbF1us=; b=afdySUtIVo+1ZwxuGXTjyhYZ2nbEFq/8bZPRJpGlKhEGMoIw7A8goPB0Yl4XRV4+5c pIfTpVd5+/iggbAYHsop7LiKyxj+p872m3TbgAxZz8UntJy3rtWwDuxkAwc/rmXhhK5C EuPo/Gwl12NCrXdDgAyfXSuEoBZMJ0jrKhrlby4rX2uvzfLIZC3q7VK/n5ZxNi9xGDCt fkLbveE3LaFRMFoTk1hCyjDbWn22JtIQrcykkSjr/yy9FkVAVJusYK/uojr+9xM80NXg QpVBaSqAzD9CefK5tBIdNWLXhqNdkZm5bBmwjOgt7tXvOIQQLntRgr++Vp3TKKjGvs0B w9QQ== 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 :subject:date; bh=pML3uT81R2gzSfEf6NOny1nK+miWtvP9JGYOnsbF1us=; b=1n9JgKG9fiKT816QyqEV9jwXvEpQkMQf9nM1XjxV7wIPYfnmley4Im1SGgpdpPFWbR zxZ59YpemA2pz8yIPVf5WYyn+A64n//6pNlcd6gPRbB2ytD67FHnPlzjonapvILaYvjf jJGOaUq3KGgCBs0GLcO42YWlIPlDyo9Zr5MEIrerMldVYHBxHHYjGpYrJbKFziMQbnMM lSWmcEWG6Lz2WrP1JfqwZ7icNIrM0RR89+0xCDF1S6kmPupWCEwUXgoBUvPqUsxHHsyj ji6k25hepGTWvV+bUkBebGZmS+XVu8XAmV0yCKljUh3lHr/wrIx+Ji6qh2w3BTRSY4kQ QPVg== X-Gm-Message-State: ACgBeo28aBvSjCIoOrAsi4WzCh1jwmJjhLKuWHsKV54sQsx5q3muI4gQ t6TsPpb8isFTkPoP2etG5Hhjgb5cawO2lg== X-Google-Smtp-Source: AA6agR7p2+ug0NV36sCUFDlHmx52tukJaGvED9ofu53hUKAb+STnuWZhPaWYjIYPg+hFTtmdlPGXCw== X-Received: by 2002:a05:6000:682:b0:226:e78d:2d7a with SMTP id bo2-20020a056000068200b00226e78d2d7amr4524382wrb.103.1661987906953; Wed, 31 Aug 2022 16:18:26 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 08/33] submodule--helper: move "resolve-relative-url-test" to a test-tool Date: Thu, 1 Sep 2022 01:17:50 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 Wed Aug 31 23:17:51 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: 12961545 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 DB13EECAAD5 for ; Wed, 31 Aug 2022 23:18:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232761AbiHaXSz (ORCPT ); Wed, 31 Aug 2022 19:18:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232656AbiHaXSb (ORCPT ); Wed, 31 Aug 2022 19:18:31 -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 54C7CB2845 for ; Wed, 31 Aug 2022 16:18:29 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id b5so20122133wrr.5 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=juIkbLCCQIuQRLGpayn4CeVsN6vEIcGJVwNQXFqLM+Q=; b=qUfKkFKIBG9+dayWkKUOQttO4PQPlgZd8Uuo/l9R1mYnMnlIdutIWVk5m8bInQoZ/+ Y9R3OWe5mZ2WiuhAwRIfUehdCB24iCMT17K0fqnp9lCVBNFPPl7gAXfvEa/8O17sjmt3 fMauR5JIpTJbgEmWVQafbLDh4vCzDdOM8d1qHClH5J9U9ZeY98Qu2dcTGa+RqShHyJy5 XZEhQlWLWvmpVvO/6W+MdNdhKCGSY/NY/ekrkw364+GYjegzI+F9TFtaztZ3NjRFDDM4 /ghJViqKYteI3cIQzykRYlzTeIhbSqSeBci+vZQ+Ih2akGCPUmcwUkK+HeA4o83W7j/A ltgw== 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 :subject:date; bh=juIkbLCCQIuQRLGpayn4CeVsN6vEIcGJVwNQXFqLM+Q=; b=jRx/DMN1rcgKcNUiU4DdXnzVjVjvu7xSzRJpNvX0Q6dD3+ySN5n98VD0TR0YbHk3wt Q1jx+eaIan33NQn0WN1YpJSYkVLYbnqQoffjJeWZ83fqugaQOFg+GMQ8M5X2Rlv/9oj9 QqZ/mINZRoVsDkEudHai/liat/KbwHyOmI0uJ5d3gdWA9GcKZjYt0NCiVl/Y4fpoVuB4 pQdI85IedpNMCfrQKpNaBJNHIvQX4DWG/oVANG4Xf08F15AtWpOPzrJ35YljlsAvk2sR +h6kKXNg3QppZrN+Zf97AIJXsVv/Nh7RUg2fR47vwfKRf9Jym68EZf/IdwmjT5YgzZ2y Avgg== X-Gm-Message-State: ACgBeo2syei69QJ+AMUOOP9C6tFWXORpe+htk6sf1Vac6ff5W2O0cVjv HF0XnyMLsIgcK1CDygNc4+Q4MAXdRa3C6A== X-Google-Smtp-Source: AA6agR5z+vnHafKIyGiLfh0rcvkVvjy9bLJhI34omIvpoIWMbsUnw9aTLWp0BDALbkPgpY5kgK+mFw== X-Received: by 2002:a5d:5983:0:b0:221:7cbd:df50 with SMTP id n3-20020a5d5983000000b002217cbddf50mr12761753wri.420.1661987907733; Wed, 31 Aug 2022 16:18:27 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 09/33] submodule--helper style: don't separate declared variables with \n\n Date: Thu, 1 Sep 2022 01:17:51 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 Wed Aug 31 23:17:52 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: 12961549 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 75C0DECAAD1 for ; Wed, 31 Aug 2022 23:19:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232830AbiHaXTE (ORCPT ); Wed, 31 Aug 2022 19:19:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232672AbiHaXSc (ORCPT ); Wed, 31 Aug 2022 19:18:32 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13785A00FB for ; Wed, 31 Aug 2022 16:18:30 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id c7so13469769wrp.11 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=5IEzgIiCsaeSKDz38WxSYB6++bcBbals46a+WKxg8Fw=; b=Wvm96l6zCgjmyP1VFDg+fB0cdtw7mZcTPqLTQ4OFOyHdV2kgssGKmOqG4Jm5yeUROi ulXkkM7ji1xv3ydnE6oml86hC9zsR3CTEgP0PrhbX0eOFjmZjXLN94YzL+N0upJCBkdG fp/XaifQ2a/O2kBCgNxmQtYMzDkzzjdCStVCmZZ7YLN78Ca5myLNbdqHIWi6HnFB+V8z BzxKwzAXtMuTwodDxNSeESvqkrdbUMj6Zd/2cQ/OIY/7W3CC1/y4FP1cOuBE69+OGiIC zY7LzeRmrviWi3YTQ9yYG9RlqBissDQMS2wAq1toH/hWPOSWNxbO649t3SiNaaNwitRV vQTw== 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 :subject:date; bh=5IEzgIiCsaeSKDz38WxSYB6++bcBbals46a+WKxg8Fw=; b=4B/MgpzzT60u8g98vzUdjsqr/SU3vp5qcWe8fgmVlQ8ze7SgVUDjpnAMO0ygOq+xLK 5LQmyJfAKXOjGBu/uvcWnDtVvL3hKT+JtxzAvWPXfM4gYwOAtFYP88INTTRHtaWVSqpk c3kfCvaLe1QpPgIeQrlvRuTJxSgYWrsl/b0HUmNhHRj51x+MwdYLH3R12Ces/BAHzsrF gQxnBJjXWrzlO5T8xZkgvqg0wTGYTReeWJ6+QkJuZGET93MDHD4Jrw7x8vtIbwP5CPUW mbmxfpR8HTdEql4Vj56alzJPeS02CXYXY1canPCW4Vym3cSZscgzZLj1xzf7g/EdpC0w V5Lg== X-Gm-Message-State: ACgBeo0yWF4QZIWoEnhwCyfDwAFRgsugxHhgK710cCaAFlczQ5eMpq7u RhXydmWYMQnvD8urlYwaE6xI/HP9HrbnmA== X-Google-Smtp-Source: AA6agR51RT6QssIuccfNlGfFnK5n17+WKgiZkAnhPxBwTsAXsdS/pWuCn7Wug+Zs/74x9QhJqRN8HQ== X-Received: by 2002:a05:6000:137b:b0:226:d465:c8a9 with SMTP id q27-20020a056000137b00b00226d465c8a9mr11450591wrz.267.1661987908484; Wed, 31 Aug 2022 16:18:28 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 10/33] submodule--helper style: add \n\n after variable declarations Date: Thu, 1 Sep 2022 01:17:52 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 Wed Aug 31 23:17:53 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: 12961547 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 303E8ECAAD1 for ; Wed, 31 Aug 2022 23:19:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232696AbiHaXS7 (ORCPT ); Wed, 31 Aug 2022 19:18:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232675AbiHaXSc (ORCPT ); Wed, 31 Aug 2022 19:18:32 -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 C666AE589D for ; Wed, 31 Aug 2022 16:18:30 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id s23so8112296wmj.4 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=BSlG/LEFH0VpL8tqc/G7wXLU2ucjGRtRJqQI76gtGSY=; b=PGuDeZNySLSnY+91hX2Pasp5YKYbDanM275Q5I+hCKlZ88Z9oX/Sz09MWK7zGLdzqH y5T1/WgiRrp+DyHD/Ln2HGMcYjXj2FRLHZWCWFi/5HULYv+JfNb5QY8Pgjr4+2yKjXIL rXT6KNIO53Tb/RLOiZRK7oV2ZG7Ca2FniQyvaihBTIgpdqiI27Rmgfr3GgGuh5eWntRm MheDpF58emjKfhxFU+yjf27SMmSsxBNZBMqEdt1TRM2pExiby1UZ8TjpPEk0CVO72a55 BXl9G3T2yq+PPMvWqhrBHr0F+GyffPCfAZ9fsDsoNswD+LVORP6JJMMc909ik4kKx8yh aaMQ== 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 :subject:date; bh=BSlG/LEFH0VpL8tqc/G7wXLU2ucjGRtRJqQI76gtGSY=; b=IZnSSqEvnIIP0nDbrDDcbOHdM7o9HzVy/sj5gFsxrgD08oRsJyZwaXc9APh3iXDec9 v7GczWdj2AChT0S80ovKyI5k9y086wKVkqHfKzTMCDAu4wkV1BUO9O6OQtZtBk1jS08A 5ENy3XR4fnlF1DREsqJONcUhvg4dlp1xHBnxEKe9shJ8l7Zt8/jG3DFMHDgIV+WWRohU 0GWMhWWz6UwhgxbUWC3nBA0vVi2/onf5jXOc7lEFQ9pZdT663MwwoXAWGfK4kJAByNid qLt2npNpRAzRZDPUpvJRy3ObrXWIXkmhNgOp0cnjkKCgHVeFgrUUQgbdMoOhluT6PiMV 1pbA== X-Gm-Message-State: ACgBeo0CV5a7zIx+KhgOy/pxXeSUX9WNvGXT8WMyQdiX3YTbgZboCFH6 1TYERfnpuAtyKuIRtBeyj/bWMdV/Bw3F3A== X-Google-Smtp-Source: AA6agR7v9MPuMb473FjV9deh01wxbUvHuoAK8ilyvUnrDHzI5REsk6H0USu1wnc6HUMYkA2x6vrRMw== X-Received: by 2002:a05:600c:2256:b0:3a5:c27d:bfb2 with SMTP id a22-20020a05600c225600b003a5c27dbfb2mr3236256wmm.102.1661987909245; Wed, 31 Aug 2022 16:18:29 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 11/33] submodule--helper: replace memset() with { 0 }-initialization Date: Thu, 1 Sep 2022 01:17:53 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 Wed Aug 31 23:17:54 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: 12961546 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 C6343ECAAD1 for ; Wed, 31 Aug 2022 23:18:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232820AbiHaXS5 (ORCPT ); Wed, 31 Aug 2022 19:18:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232678AbiHaXSc (ORCPT ); Wed, 31 Aug 2022 19:18:32 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 978784C636 for ; Wed, 31 Aug 2022 16:18:31 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id u17so865910wrp.3 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=OcIYZF5IzBdevD92f3nHXcWZ8HO3OrAOxU6KNABBfRQ=; b=EFuSBrgZv65eYzsqCdkgSkyLYxP6PLbQ842v1v6m6U+a2w9TF+/bzxwX9O944K1diS yD2II0SxqhT9viv+JekCzwMDuuO/t/8uz3YtThKGuwuy9dNFj6DNZRCcoo1gp8TsBs8x O+gD/Gi1N8hrhpdwZq36nwgq6eW5kYEfKvPxOEaVRiCVUY2yFvwHAG+P9viYZQCATm9s 4Ah9v+BMKJ+V0EgPym85qv/e2JrmMkUhEmDC9EgeAC5CHIpPw91h2idJ1WNbMoUXm9da kOIx7rXiPAodFQpE63cP8gceSVRhxrmMtZFZ2bzl2dPVmILmDBtgocxq968YWmcWPvT6 OlhA== 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 :subject:date; bh=OcIYZF5IzBdevD92f3nHXcWZ8HO3OrAOxU6KNABBfRQ=; b=Zd5iDjDKQtxzkdwfSENcBNucy8kdMDvZXmJvvb1rLhivJ528R1ha2IjlEJ4Lb1rM8d RWye/1XzZlvDUv+1NsxWhf7wek8B15Mso4SNOYy31PTaqJeCPviQJ6vgR5ZOJAnS2YXn OqgmI/dYiWHFDqIYcA3x92/f3SbPfDRKFsCOkNljIO4zdqPI/8Hgl/chiShIrS5pqVQ5 ujeGHE9Q43zEAMyI7LcA3G7uERkHQnxMjO/ozuYY92//UJwZGEnhWgtUGMX8Dsa0AfMt 1BzWTLLFMC8Z1CgC2RV55YOpTcleVFwqLMBvwctS8JFcNTh8rxiuqj+ndm16jZhoaSAm xqBg== X-Gm-Message-State: ACgBeo3n2lFieau089ZFTs9RVAdET0Dd8EGmF5UivcA7qYAKHfP/Dvu3 4ci9LiNBY6eZ52Tn7hnlaCch/YJnZEPvWA== X-Google-Smtp-Source: AA6agR4voYPeZvhpEvHN3PS/qGGUJGLR1c7+YkvQBzRpgLAU9bTOAlLP19T6ls3lBECOkPBra3uGhg== X-Received: by 2002:a05:6000:1888:b0:222:c96d:862f with SMTP id a8-20020a056000188800b00222c96d862fmr12502688wri.706.1661987910021; Wed, 31 Aug 2022 16:18:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 12/33] submodule--helper: use xstrfmt() in clone_submodule() Date: Thu, 1 Sep 2022 01:17:54 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 Wed Aug 31 23:17:55 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: 12961552 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 DA747ECAAD1 for ; Wed, 31 Aug 2022 23:19:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232839AbiHaXTJ (ORCPT ); Wed, 31 Aug 2022 19:19:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232688AbiHaXSd (ORCPT ); Wed, 31 Aug 2022 19:18:33 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 563F1CE308 for ; Wed, 31 Aug 2022 16:18:32 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id c7so13469848wrp.11 for ; Wed, 31 Aug 2022 16:18:32 -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:subject:date; bh=5rBLF7ic0qPgJOx9n9+R2A4Zr2m8hd5+1zZb6OaE3K0=; b=SsZne7sX48ptq5jQjunGLd8y9Tj0n/2otcFDXPXWJ+BAW+WzjtXq8bXtfWquA4muyY iD6IiwPkV1mnsI5EjvBxwI5u2QBS7iK7gQEkRRO3ZuQmiDZs6VtwsaZqhTkeRLJ7kZE0 WbBb8NUCnXMRi6U/1wcATNkRoFCPv+mEAhvEKH1Cn0IBjziktfOrILJuOT9WVz5NQIT+ /byk0fnGld+e7IkGgP1L2s3T5px0cZHoQ+fHuIjZpJF2g+IxCcYrvK1cT6ADpK+90MWw Fus7/MDT7c5V2VjWHJol80K6zcvX+K9NVJTQPqbnhLEnkDW+kF3LB+tF91IOHnRhx4AV 5u3Q== 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 :subject:date; bh=5rBLF7ic0qPgJOx9n9+R2A4Zr2m8hd5+1zZb6OaE3K0=; b=yKFZyDi7yKehVoC5zbeRDO2MMoJsoLzWEjkX/ej1xAznHfz1vL4xb9NkOu5lhC+9BX Nu5QYkW9hbqDpnI5RGvNxXKia/4wC3XnWALE8NsT6cXQ5UBvTGWsqFQ5Jq8yTFXtxgst /EhkmQOoX+/aKx6WHtP60E+QmwKAe38v22nw5fwYfpYKPfFkh0Zj5iyKHBMytkHkhNZQ ub/PdRawveEIloxC/DSYEHr7gQDo/3BFcKIePqdv/e8TTXR6NwXZ+6sgUvVD83mKsarL Hp5lfHIweghmKnn0osGqayGuicEdE+zQGEB2okBzlBs9zlCB9bW5HTpQSlT8xTBCqgTn 1wpQ== X-Gm-Message-State: ACgBeo1PaZEsApaQTcHt+nTNUxZupeakHWFUEedYiAJq7fBQK4fNs6VX YUePwClQLj1Zms3fGQjl4tim9f70MQGmmw== X-Google-Smtp-Source: AA6agR5Su476lHbYjl/6NbDcDhvbYgNKFo/BZETP0Ihw0522I3AhJHC2+dB/BnAGWs/K/Eh5NMRf6g== X-Received: by 2002:adf:d1c5:0:b0:222:cbe8:f9fa with SMTP id b5-20020adfd1c5000000b00222cbe8f9famr12818343wrd.383.1661987910783; Wed, 31 Aug 2022 16:18:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 13/33] submodule--helper: move "sb" in clone_submodule() to its own scope Date: Thu, 1 Sep 2022 01:17:55 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 Wed Aug 31 23:17:56 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: 12961551 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 91F32ECAAD4 for ; Wed, 31 Aug 2022 23:19:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232834AbiHaXTH (ORCPT ); Wed, 31 Aug 2022 19:19:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232711AbiHaXSe (ORCPT ); Wed, 31 Aug 2022 19:18:34 -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 1E5339C8E5 for ; Wed, 31 Aug 2022 16:18:33 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id c7so13469871wrp.11 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=LCtgE4ASrJMbEvRLL66UUywq1E1Ii7lA6Z9Gb1TVWEA=; b=HYix1xpMFEJ76O9Z/qi+0wmabu2LYyFbnXv8kBhevrUBFmekBPfP3MkNWAHrrwKrIr LtNlKPCk1whoyZWNLI2/3GZvA4Pe/47oLsFMVJmx9VSWJavhrxRC6x/hQMdVa9RmDFBR tHhQ2p8ixI7OFMAUZI/qqGU1fd45UEwVxPyaWe2zBHCYqYCWUp8QTBorfxJmrYPL7IE/ pcDd0Y7wQgmvxeeeIb2ty7V4UyLnuaVt6KizCluKxhS8A2+S+2KcrVAicC0x/+rpuqus 9cMYcrYg7X0QxiNXw36pLuY2ZXK7jRLrwhTvkqh1RAYKgNPN5uM/UGObEEcPxEITNXyt GqAA== 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 :subject:date; bh=LCtgE4ASrJMbEvRLL66UUywq1E1Ii7lA6Z9Gb1TVWEA=; b=bIKTejhcCC1fPksuPD321qhMl9OR6tAPXmoq/pdGiRgS1UL95WOVT40DwzhDK9B3Zp R/rIdVwosIJynl8UgJqLhoohZOI4C9i9k7tCxHU8Ik6wTsGxcHWiqTofrZ7v1EyCWDcV NMaUxXS0d2i6q9b7VdoLD1oQRuHqO51ayzlpy27RagqTt+CKFh1MFr3jP8DC9/+jPLXb n2d6mJWxCD62kVTvPBtrSognPHUyYp9ctV+ZUCWjcvYZBHwFtv7TKU8sU+PdqnTHrGhK K3M7/Gb1h2D2jZI+BG36LkBQ63GBTRNVfL6iRB7AtsCqbLZuyMqXmvSqdUMRVce5d8Pu FLkQ== X-Gm-Message-State: ACgBeo3XML7iYC/WA06hcIOrqofmUSrf+ASrPLQmO/MVO2Xk3f5RfE0J ypaocFYjZqPejbG1KrFUjmFHOCO+/+BaGQ== X-Google-Smtp-Source: AA6agR59O2MrCtRQYfuWby7DYoUcbL0EP1ES4B5vlwtVcl03yLdb2u+cXcuMBWSmW81OYTqLvde0/Q== X-Received: by 2002:a05:6000:1f99:b0:226:e714:c7b2 with SMTP id bw25-20020a0560001f9900b00226e714c7b2mr4765423wrb.229.1661987911521; Wed, 31 Aug 2022 16:18:31 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 14/33] submodule--helper: add "const" to passed "module_clone_data" Date: Thu, 1 Sep 2022 01:17:56 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 Wed Aug 31 23:17:57 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: 12961556 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 10058ECAAD1 for ; Wed, 31 Aug 2022 23:19:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232852AbiHaXTQ (ORCPT ); Wed, 31 Aug 2022 19:19:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232718AbiHaXSe (ORCPT ); Wed, 31 Aug 2022 19:18: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 DB8D0B028D for ; Wed, 31 Aug 2022 16:18:33 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id s7so5225655wro.2 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=YSVm/6e2Dh1Q2xXRbpUD16ZKnROrQLonB5spxrJi1EU=; b=MaYwk6Gieht9GQNaPtXeb4x2yHJ7hH+5bD5WyEGE28slru1geChoNm9vHmWKaPyX9n LaokrmYMl+8BUs8x4gq1OB+OY+wzR//co+8DAn+fej7rjeUmWsnxHYZRn9yH8bLuPxUV P0rFuhBWcjLaruG/ZBowhwXdKAvyJTafzmq4vxZ5wTc2r2gzzpJRRdU8cPgKfVs2nIno nFg3AenyiZ016B5a7enSJrB/EBWKE6PdKe0D42Oa75f8+X3L+Rf/OS3aZf8xlWOd0f94 e8HZsYCTMnzqacTcIkwIEySzMYH6wCmMVnS9nIWtnqwobUHGHHUSUFXr2Tto/i8D2lU9 KKbQ== 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 :subject:date; bh=YSVm/6e2Dh1Q2xXRbpUD16ZKnROrQLonB5spxrJi1EU=; b=naGuIsQ8P46q2IHwavn//dGi8o4URoQwS0h+qsETlXmsxHDCATm/VMrOiZlX36cAaU QXSBcMEDK03Fz+3E0teEyhha3THUtJ+HqhhLhn/w4goeH07UTtzrXt/44PJ2XaiFEOvE CTXzy0PnW5NQPaMIkUb6wtqrGGOFEwUtq4kG67dBeF6D8DY4hGq24ZJeji3jVB2DYhwN wzY9M3NrhSJ1qRVlRZSmEupNKDa5Tqv1GOBCRli/y7n0QFvOxMxlRBAr6LCEj2Ts6v5X LMJ+WGFzIMX9/a1fnWNi+nz/82LFgeHX/P7qghvF8xlk7IewuB+tawMLJNWpUdTzLJ4J w0Rw== X-Gm-Message-State: ACgBeo1fPQ3UUvuzpSZ8CWCnDryrdThBlfnINMsmXRsXocaIHbMlICut kyjK/6vuURU0c+kNWWS6/qqrSc4dP8QFBw== X-Google-Smtp-Source: AA6agR7CUK0BQE9tb6uHDtrk6KdthYDSHQ/W9nvkG2bekk9lg7QJHjz4nGLiC+RGSZuc7d19gYZHRA== X-Received: by 2002:a05:6000:1ac8:b0:220:6af3:935d with SMTP id i8-20020a0560001ac800b002206af3935dmr13003180wry.549.1661987912325; Wed, 31 Aug 2022 16:18:32 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 15/33] submodule--helper: add "const" to copy of "update_data" Date: Thu, 1 Sep 2022 01:17:57 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 Wed Aug 31 23:17:58 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: 12961550 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 385CEECAAD5 for ; Wed, 31 Aug 2022 23:19:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232832AbiHaXTG (ORCPT ); Wed, 31 Aug 2022 19:19:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232717AbiHaXSe (ORCPT ); Wed, 31 Aug 2022 19:18:34 -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 9C474A00FB for ; Wed, 31 Aug 2022 16:18:33 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id v16so17401097wrm.8 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=68b02T2ZuUBA/HDW+OC1DvbC+PwA/q6ufZIF15rjr3c=; b=nZN2Mw5WVJcHsYPuq62onsmi+SZ6y/mHZCI00ImTn6db9uRynnig9G0jYzRzL/OH31 KxmjtAOfbv+FteeyfxdZJ7yFJ7oZ0NVltbqbIacpSAwJ5qFNlacKdFMePUDLzA1XtQqj W2HxQEO4JhEC/97DFOgi2+xW0nRYS5mDjh40YjC6y1/SHmRKbZFaNhvu5/ejyIKleiYc uRvr+KltRpVhXNDIBr38nW7/jQrwQGdq1iJ7H0ElhRidQRcyU0Yga90ProP77brq5h/e W/GZZifm3H93ByI6bUI4N3IN7589mPe8hvuNozNNGy0opYozwORCIWJzwcR9ngjp8RgZ Ynsg== 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 :subject:date; bh=68b02T2ZuUBA/HDW+OC1DvbC+PwA/q6ufZIF15rjr3c=; b=xcu9i8iD1XA7cSjeypLeLKSy5TX5kPF7bHt1aNTL852dFcou4juyaGiZQCEzNp3nJN kezSyXdgm60qdYvbaAG+UuSUshIkTK7whyndDaYZDrstp6vvW6cBZXuAU2NirjATZR2h 6j7x5RiVw6AXm/10enVg2lDhGwHZqZwJduFjwdRxSB11NjVOotw9UwcBKWZiPCd9MgIY t7lB9m7PbIMXli/YWN4ZpKiqLlR/RqnYAj+yOJHFqX5Aiua9yDEHCaC8OhJjqZlO9Chr q8utZRLipjzzjzTRKo0EWQ1o8TuvrlqgscRb2dVYWZ+8rkpsiETEvYRkxc/yF9VmvLRE 8S5g== X-Gm-Message-State: ACgBeo3QMoYwWiUUGeGoik87HHN1cjK5xmxJHEfm+RuYLQACd0pVb0tK m0U1AhuO0Kd8ZWOqJdAI/TJGtJtgWk7Y4w== X-Google-Smtp-Source: AA6agR5UH1nFLNIKH5SjotDE8u9+Y2D7xiGG1S+YrmfIZIyw1FIVeENVBxfZ5cnek6lJsAP0modkAA== X-Received: by 2002:a5d:5644:0:b0:225:3ae9:e4c3 with SMTP id j4-20020a5d5644000000b002253ae9e4c3mr12665321wrw.148.1661987913080; Wed, 31 Aug 2022 16:18:33 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 16/33] submodule--helper: add "const" to passed "struct update_data" Date: Thu, 1 Sep 2022 01:17:58 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a "const" to the "struct update_data" passed to run_update_procedure(), which it in turn passes along (peeled) to is_tip_reachable() and fetch_in_submodule()). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 829a57ce8a9..4e3bb54afa2 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2083,7 +2083,7 @@ static int git_update_clone_config(const char *var, const char *value, return 0; } -static int is_tip_reachable(const char *path, struct object_id *oid) +static int is_tip_reachable(const char *path, const struct object_id *oid) { struct child_process cp = CHILD_PROCESS_INIT; struct strbuf rev = STRBUF_INIT; @@ -2102,7 +2102,8 @@ static int is_tip_reachable(const char *path, struct object_id *oid) return 1; } -static int fetch_in_submodule(const char *module_path, int depth, int quiet, struct object_id *oid) +static int fetch_in_submodule(const char *module_path, int depth, int quiet, + const struct object_id *oid) { struct child_process cp = CHILD_PROCESS_INIT; @@ -2126,7 +2127,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) +static int run_update_command(const struct update_data *ud, int subforce) { struct child_process cp = CHILD_PROCESS_INIT; char *oid = oid_to_hex(&ud->oid); @@ -2223,7 +2224,7 @@ 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(const struct update_data *ud) { int subforce = is_null_oid(&ud->suboid) || ud->force; @@ -2334,7 +2335,8 @@ static const char *submodule_update_type_to_label(enum submodule_update_type typ BUG("unreachable with type %d", type); } -static void update_data_to_args(struct update_data *update_data, struct strvec *args) +static void update_data_to_args(const struct update_data *update_data, + struct strvec *args) { enum submodule_update_type update_type = update_data->update_default; From patchwork Wed Aug 31 23:17:59 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: 12961554 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 E6BAFECAAD4 for ; Wed, 31 Aug 2022 23:19:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232847AbiHaXTN (ORCPT ); Wed, 31 Aug 2022 19:19:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232756AbiHaXSg (ORCPT ); Wed, 31 Aug 2022 19:18:36 -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 6198A4C636 for ; Wed, 31 Aug 2022 16:18:35 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id m17-20020a7bce11000000b003a5bedec07bso413051wmc.0 for ; Wed, 31 Aug 2022 16:18:35 -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:subject:date; bh=T3dQ9gtllFdH3QqagR16AV/Xyjdoeb9qS+iUt+ZUg0Y=; b=oTuhr5dzRg9sbX27DCigSqXCJXZejYVBoOw2yXbLmp9uKaAc8qxCiFthMcRTvtKWia Ib1ZElT1FysK79uq/s+CFRbIewEbhC9AZFDlJ9bmpVNAJ+le7oDvvNlkwIWwInlihTmP g7mwYxtxqQscZ9YRkNLhPed5HUTFF+/bO1t0WkcpVkJylvQED8fOB3bwrq0YdOf2985o H9iuIxsnufiHTkUi7ugxn1CZ7bqAYAIeUqGyNlUxCaLyYM+8Yl9i7WyOtKdkoToOfekG fy3zBa/YeDuTffeLCiwSEJBm5667ObBMa3MSBORh92/C+J0ROErqmoj5O5xfn+cs66AI SiVA== 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 :subject:date; bh=T3dQ9gtllFdH3QqagR16AV/Xyjdoeb9qS+iUt+ZUg0Y=; b=JDjezXM1DTdY8/sQBTYeyCaQW6YcLElY7DR/Lx8C0xOFFulyO1AYktUa0K50bJbG4W MK43ntKd8lbMIwN29mwtMoOrVkEcEAEU/8tV89r1kmcUC4Shp2M/TIoRzujGyQ1RbGkZ tKRK/IDbjY7IdqKIOdebLn8M2SuiTUj43Q5nVx0Ii//P9p2giEAhthhTL/1mDd/sE2s1 nG9U/MFAOcjVwi4Akz8RWyA56BTCyemQC88nprp7hpC9gleK3DZ8Lk6443BiV5o28HRe xWSRuzbilhkggMFPS7kw8MNRFt4h3NwvZvWdNI+vMi1GtYuGpDGmSPFhbxc80GZuhT60 zm1A== X-Gm-Message-State: ACgBeo1mcygrDUevIXXnJPuUaFXHFz3pLUL0pKFQnCW2U+/10difADNH vgr4e2f7hClq9lZhhLXNwXjtqdBTzQKGYA== X-Google-Smtp-Source: AA6agR6jvH4jseuV8wauGbGjSP+9wep3ZA9xu+kRlqYGleerQhEQdONdKHqIYmUqyehDki/MOzMdIg== X-Received: by 2002:a05:600c:1c19:b0:3a5:51aa:d041 with SMTP id j25-20020a05600c1c1900b003a551aad041mr3286118wms.172.1661987913815; Wed, 31 Aug 2022 16:18:33 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18:33 -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 v4 17/33] submodule--helper: refactor "errmsg_str" to be a "struct strbuf" Date: Thu, 1 Sep 2022 01:17:59 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 4e3bb54afa2..07a918f7373 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 Wed Aug 31 23:18:00 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: 12961555 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 92A82ECAAD5 for ; Wed, 31 Aug 2022 23:19:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232850AbiHaXTO (ORCPT ); Wed, 31 Aug 2022 19:19:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232759AbiHaXSg (ORCPT ); Wed, 31 Aug 2022 19:18:36 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 182A2B028D for ; Wed, 31 Aug 2022 16:18:36 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id k9so20176238wri.0 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=FfrI6GnAoSrICtgUM4sFV9tb+e+x671HUJS/qc8qptU=; b=aO2EmzfDwgUdlgjbuLRfjbOBNa/D/p6kuEZ4DRxIfeQBKmHl8itOlBgLPf53s0ET/j /AYPwWnQfL2C27GfXQEFS4Bts8U3LVs3RXjRajFBbhmvFlWoDUInV7E2+PcmygAaTTE5 z88Qb0VpnowaKIIXVAHoMGJNiP9d+1qTMuddkZH2C++V1YojuGRC7xjAX4VX7Pf2T64A 8eQQd6+JmNNYqI0UYHR3CX4fV5LCuX1tLwttNQRrAcCUTXUnZRdGp56UhAANB6R+n/CB nVrHfTRBXpzRkdAjgal0/ehzbws3ONZxgv7ft8oHErb18M15E5mZ/Cgmui4/0du14vmH B4Qg== 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 :subject:date; bh=FfrI6GnAoSrICtgUM4sFV9tb+e+x671HUJS/qc8qptU=; b=3oawdVaYqiurUN6qpV6uGZUS3MA258jd8Rcklid93S6uIwAk56/P6uhsf0bswRdwvg HXHMDssuvBRFomUEoaLg0Dv6aM6UDjgsHuZvXnJu9l6um51+WVwf3MWpbCEY4Lm9ABCj AWopVLa1xQFW/b+Y66O8RfOpmYKO4or9FM0JHcDgktPmh4+0HHrazTI9qSqO71Ix66l7 IuzwKJIIN0HSjxNHMFLNwBKqkwXeeewhA4YYERWpO8C0lL3+YMp6Wf9pTNy55xaci3OX GVX334DsmdkrGUnMKHf+xYRWW0Tm7BYad5MxUhq61TariB65t2sTOLJU2UtZR2B5qzuv jjKA== X-Gm-Message-State: ACgBeo3LnQDPK6wyawfiDzKNsTWVvpcT+G0l5kLGhdm01WyUd9afnOlQ m5qlLYsSkDA7YhSutTJvLFiQDNnO7HlcsQ== X-Google-Smtp-Source: AA6agR5ZekWohqbhv6gEYFlioXUnGtFhEIyN8L81+hgc37tKayDqnkRJFeug1Lul62VsyHGZbERAiQ== X-Received: by 2002:a5d:6911:0:b0:226:f5d9:d545 with SMTP id t17-20020a5d6911000000b00226f5d9d545mr220925wru.469.1661987914523; Wed, 31 Aug 2022 16:18:34 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 18/33] submodule--helper: don't redundantly check "else if (res)" Date: Thu, 1 Sep 2022 01:18:00 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 can 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 07a918f7373..93ab49defb1 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2448,8 +2448,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 Wed Aug 31 23:18:01 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: 12961553 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 01EFBECAAD1 for ; Wed, 31 Aug 2022 23:19:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232787AbiHaXTL (ORCPT ); Wed, 31 Aug 2022 19:19:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232760AbiHaXSg (ORCPT ); Wed, 31 Aug 2022 19:18:36 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B84D9F1B8 for ; Wed, 31 Aug 2022 16:18:36 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id u17so866099wrp.3 for ; Wed, 31 Aug 2022 16:18:35 -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:subject:date; bh=l4jyzwIcTiQTBNvs3QkL5KkVdT3b+LabYwWg/+7J91Q=; b=lpsf39/1y8lbMlBzDO+MMt8QuTqzWFfaQCX7YAn7YhEfPbF3pznTa+Jjs8CISQJcaO VY2bTVC5jQTYAuqcyBRS9doHc9Yd9B5T/Os3Yv0wZ/cY/Kx6wVHxeJqAufOChflkuyXc XcHbzqWDEBuwzXfssOEZx6Fon4ppKaShqsdjIjCOCEscJbapW8rMk3YoZhyH8s/fVOhH Gk9u3FLKfkMl1jjihwmpjY0C3FHIyu3ni6q5m40USGSFN0KmFUSwlQ3AQE9dpBqGrVNU PzOxXvu7HPEket8raF0OsxG8yhaJVOFNnVDNTRGXxFJgh2wV/ANdb8HqP7OYqjoNYsgN OiRg== 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 :subject:date; bh=l4jyzwIcTiQTBNvs3QkL5KkVdT3b+LabYwWg/+7J91Q=; b=swKWVXUGw62KMu2jnzk37ewYjJBpRQS+VBhagBtwOWF3/SOcjGl4MY2j6edgagpzrR HUGSWHEqbvxq+c7+ZiooiP8Ko6Q0Y0iPL1+p+P8SVTgt6rxUWBrR58CeT8Hhalaqh9t+ //u0ScbQGFbVcNjoNg+B9dcizeFYYy3FefkhLwRARaL0iMKnQqEopI6RIpptSbifoBDt Dwq3UmcvMT1JCYKfMCHOcgKhK/juffJmw6rUYiZq614UtjHPYVTbVku/Lsc0pGoFTv9D ztIeVUb/k1ecsk95DQ21dYVwKZdhY6dzFeKmfkSPZvQqpiT4b7Cy/6a9byIVl6ZKMWtV Ptfw== X-Gm-Message-State: ACgBeo0iI5retNGuNkHbtwtUo+7sR2sp9OQk/c+96ajCUqlzNnXRrKQl w+wk3rMYrqMzsw7CRMsIJWM7K+mZ5Hykmw== X-Google-Smtp-Source: AA6agR6MLhspA+HZDKg8dQLVyebS8g27IBQWLceJ6G3bH9RAwZpdsr9nht1GVZbp3BVNmDW3ZY4peg== X-Received: by 2002:a05:6000:813:b0:226:da5a:84a9 with SMTP id bt19-20020a056000081300b00226da5a84a9mr9544492wrb.309.1661987915488; Wed, 31 Aug 2022 16:18:35 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 19/33] submodule--helper: rename "int res" to "int ret" Date: Thu, 1 Sep 2022 01:18:01 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 93ab49defb1..4fbbffb4637 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2429,7 +2429,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()); @@ -2441,13 +2441,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; } @@ -2456,7 +2456,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; @@ -2474,7 +2474,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; } @@ -2486,12 +2486,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 Wed Aug 31 23:18:02 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: 12961559 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 02F57ECAAD4 for ; Wed, 31 Aug 2022 23:19:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232819AbiHaXTT (ORCPT ); Wed, 31 Aug 2022 19:19:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232771AbiHaXSi (ORCPT ); Wed, 31 Aug 2022 19:18:38 -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 D84109C8E5 for ; Wed, 31 Aug 2022 16:18:37 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id ay39-20020a05600c1e2700b003a5503a80cfso433500wmb.2 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=0deIMqRssHJnhF+97Hb/RsRCpTEMFfSZNWXu0YUuhZU=; b=Fd1rJhcSbRbLda8BASBre+JVAvrucK2KdGRY4+R1R/3WLxhuaCEFmFLRTKMGfZxdRY VTLVctiBEAwEo3araidwFLqVC4v7AUzBqWdF6YC+SMgAgg4h/c7PUDfNPIz4QwhuCuRy +Or/JsbvMQqppTtCL1VLyykjF8nF7Tb5tOLyOLU2X5O5MzxoxZN3IBZksk9xF5pho9bG wTufHWaPzixcijzHLsEOOKMN2wL+EaJw1C8UEMfZ82HsvE7E8tm/0XF0wP80kAGrslqu VoU2n4J3P8uzHpNjFtpRtkh/2Z6TeXA6SB31q++R7JQcCGMThbPaAUi4oYmg+2OkF9aX j2BA== 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 :subject:date; bh=0deIMqRssHJnhF+97Hb/RsRCpTEMFfSZNWXu0YUuhZU=; b=0jlMQ3JVU8YY+bK/q00pvfGcG/xXtMToBLrQwDSlOf5J1MjIdFg+AKyEXS0rUhYpUp XvhZ73M1U1NMK4TZ5DMgLWBM/GcxgJzrbPIPlF2qYZDZ68+OChmFs+fu9uC9+7PsyNSq u+K2mcOrqO032tM7J0GAGbXx/BXmdqq81HaoOPTd40uUzT5gj27txztndxM8KvltezEc cPZH5cHAEjWNpwlPpD+Mpdx5UfvkLVfmc9luL5/D8RXTm0joTJWWMGTQJb40TpU4mlH2 7YKfJb1nmRRRFYN8blvCYxwnhIAcrCIhflrdbtNE5lFy9RvvrvRSMmchx+dvTliOBweZ 4h3A== X-Gm-Message-State: ACgBeo0dDdurArxb2fDIiPYX9Qx88aEZP2URG++hR9xvvgstB5QMLT1u XA3/i4YzxLGZ82m2GVWo6L1PhFmP9A4O8w== X-Google-Smtp-Source: AA6agR79DYJ9gHmS0jwNYPlwh5BgnPO4MDMppN6KzvpjO/D+JD8roE2845ljem078xZGe1NGQH+Jmg== X-Received: by 2002:a05:600c:2f88:b0:3a5:4014:4b47 with SMTP id t8-20020a05600c2f8800b003a540144b47mr3302876wmn.96.1661987916337; Wed, 31 Aug 2022 16:18:36 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 20/33] submodule--helper: return "ret", not "1" from update_submodule() Date: Thu, 1 Sep 2022 01:18:02 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 4fbbffb4637..59c3a9afe6e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2448,7 +2448,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 Wed Aug 31 23:18:03 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: 12961557 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 D086CECAAD5 for ; Wed, 31 Aug 2022 23:19:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232853AbiHaXTR (ORCPT ); Wed, 31 Aug 2022 19:19:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232768AbiHaXSi (ORCPT ); Wed, 31 Aug 2022 19:18:38 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95B064C636 for ; Wed, 31 Aug 2022 16:18:37 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id k9so20176325wri.0 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=GomI5uZ4aQ1wFZgZhCpM5/jtzhNLGeIGmNPH4JilbnY=; b=MskdPHP+N8fDvYw/22J+mXOhvHHnMTvdbC9WSwmJCvqKvHcjfBDwzdnpAB55UaJs1Z qmYomOF+bBiU3sbl/YK5QlUC/Ur7DibPcrx/5rbVE2Nt0WVE2b/EC/9bwo56sg5WcYJx cpo/VVCvkc1UJfLKa6oLcARjXw46kAA6JL0NOavoEk2XIkMQ87k2006u1jPgPCdww8HD ZZsG1pHmjHkqlIUBO8cQej1s9C/xhsC/vf7EJ/MQ1kx22J0F3vaqXc3XyZ3is8DfNqN4 P4Rm0vE1JPLoIGP2UnhxzYXNZxjfS3CMYo+pgwPmTF7Axhf7tt3IsV0YIrqyc6SDp8eH QTHw== 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 :subject:date; bh=GomI5uZ4aQ1wFZgZhCpM5/jtzhNLGeIGmNPH4JilbnY=; b=iSOqoI++0lDXyJwi6YKERekXoyPPM1XJ3Z88x3lYiTgemtl10ooPN1qsbuwtcQcCCQ hSRi1YKxzKVknEAFY/rnJ9z/uSdqXQFqdSzAzFVIHtzjqBHSJVIQT6lEgWDjxyjf8jfk RRyyOq9DKwCpR2ZBl8dnepXdFkdjVkWVHhXX2CwgdxbyxOJlTzS/ZMRvSgyA7lGcmdIv YTfvK1IGU0EGVxKRWwYRqnYFO13zAUwRMAggFBoVZIVnrbtzEtd8ABHxktn7RDQPDg4p spyeH0/9c0IRuPeSb21mRjLGqh/bVZCj3al6QYouqwfTkJKINFsHVbbBT2Y6L3iWSi5t LQzA== X-Gm-Message-State: ACgBeo0r0KpHfJPhplZYsu9pEchcuOvx25c/ZNttmC4olB41d7KCm5Rj 1wjlYTjXYrLzgGjlaaxY+Pd/GtFwMmaUWg== X-Google-Smtp-Source: AA6agR670VbbqkHFCe7Ywwqu9T0wKxswUcKvPteepU9JYTRY8/gSp7C+aKjUj31fJM6mlnpU3k+K8A== X-Received: by 2002:a05:6000:178c:b0:223:141:8a14 with SMTP id e12-20020a056000178c00b0022301418a14mr13228835wrg.629.1661987917094; Wed, 31 Aug 2022 16:18:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 21/33] submodule--helper: add missing braces to "else" arm Date: Thu, 1 Sep 2022 01:18:03 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 59c3a9afe6e..6c40be3170f 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 Wed Aug 31 23:18:04 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: 12961558 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 35969C0502C for ; Wed, 31 Aug 2022 23:19:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232859AbiHaXTS (ORCPT ); Wed, 31 Aug 2022 19:19:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232776AbiHaXSj (ORCPT ); Wed, 31 Aug 2022 19:18:39 -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 6E7EAA00FB for ; Wed, 31 Aug 2022 16:18:38 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id v16so17401261wrm.8 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=qbyGlxngVgIzQasfNvWqkh0fgMjNTSF0KfpDS4yWhUc=; b=eqxo80j0Eg7bVcTPDinNP9BgSlm4cQ61iFsnqRURBmwD5OhKALcE4Gh+xjP3uD4FK6 TMRC0z1H1K8sBHGiwjI5ZVgvM+71wJl7ZrLNw8R6oXg5f0SLD5mFpB7Sgxs7HkCBti/z 8GHWq5QXOHHyN1nkGuqh2YTYmiA7B+O5pldHpHnUgAIYERaasDa5ojGp0JTm2u9p45tA /vywty/2aT0U9JyLtgmsubZ/zq5NZxVG/UFiAKrFDFhG8bZ2ev5zfKOCopUfINon2lzu brKYgy35y6ZOtah9CMEwntlLdfhuGFZLZvd9teM0c8wyLohbHIlFUFeTfh2FMEEELKGq NBZg== 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 :subject:date; bh=qbyGlxngVgIzQasfNvWqkh0fgMjNTSF0KfpDS4yWhUc=; b=eBmPvUJa0cblkmBwt15jruPRCqfAHYwiHz9F5aNX7aAdMeBajJK/Wb7CARfE6ZsL3O NkiENM8+fIT1oqTwsmKviGv5Sg4bLR4QWg18vcBW8HCBGfDGFjlgj4ZlONGFrGLO1Xik xOHr5ujim2uYNEG0ARC61c8pyfQjcr5A96WxGBLtp6l0XykR8nDd7PwHJlM3rhV4qrZA MvrrpldFCqQwzVXtOFUMVT+wbYgk5LtM8FyDyAccRTbjR+7rcDxo5h+xUfWk2YPocYvu 9AFpjLXuxFLKpZ4ByNi2C/8HYJ3X2gAOtMUI3TCUKwlEUmoUSkKXP79rM+qH2T+RMTXn 7/nQ== X-Gm-Message-State: ACgBeo15HgOxdT71Xp0KTbMu3If4Mez5ULMvkDaRkywFcFb2Y01qDp5Z luW60MCetYnnmOVm1g3PWz9cEpgp8H2mIg== X-Google-Smtp-Source: AA6agR4qF3Zp8/A+NZtkblNwaVIY/EYZY8BkZ1CqK/AWl6lXJbGo6Fa0HlJeF5r+b7afKPFX/QUHRQ== X-Received: by 2002:a5d:47a8:0:b0:226:f124:ad74 with SMTP id 8-20020a5d47a8000000b00226f124ad74mr1407190wrb.18.1661987917871; Wed, 31 Aug 2022 16:18:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 22/33] submodule--helper: don't call submodule_strategy_to_string() in BUG() Date: Thu, 1 Sep 2022 01:18:04 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 6c40be3170f..965196a005d 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2159,8 +2159,8 @@ static int run_update_command(const 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); @@ -2185,8 +2185,8 @@ static int run_update_command(const 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); @@ -2216,8 +2216,8 @@ static int run_update_command(const 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 Wed Aug 31 23:18:05 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: 12961560 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 0698CECAAD1 for ; Wed, 31 Aug 2022 23:19:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232864AbiHaXTV (ORCPT ); Wed, 31 Aug 2022 19:19:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232781AbiHaXSk (ORCPT ); Wed, 31 Aug 2022 19:18:40 -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 33EBD4C636 for ; Wed, 31 Aug 2022 16:18:39 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id s7so5225854wro.2 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=jLGnDA05jM1kKA+Us9LI/1yvfDX1KqtqYdb/PpOyae0=; b=Qe9gnegHX2QfQQkiJHrD7x/ZjZPXS7lgfeK3qCpkDDRFtGhlHbPthOWcyuM7vT3ol5 d7bqxGtiPoIdurEIg1VAPNTLba0wrz5GD+9YKnHLK1v4QgE0TQdQvPJzyi+8GzRHmLvw xbVCBo7A1ZzQjMsTukFBrgq/mQllQG7XGmX1Nwbt2FIPNMDNfiSxVhDkPo61KpDOIQH3 GrZ/U/ISxipbzEuj1QoHdiwQRDJkPCCYhNglGJ6zsfjgz1ZqUFpdSSlARTWvArhM/e2D 9Agf8D5+JhcS4I8KMJ//yricoEsGNCH/yNO8Vy30qrtuh3+xzbhuZGtWOuQC2ZzgHown voVQ== 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 :subject:date; bh=jLGnDA05jM1kKA+Us9LI/1yvfDX1KqtqYdb/PpOyae0=; b=obGXg/MUpw15dPPP/Ks9kuw2/WdOht44fpOA2YE9eP+BbvOyM6sVAnE41TvUkTAcZC 4b6IyFIuN0H1KT431ZhmUzTLiNDppVpf+z9Wvv0hiLhDTmEkgMhHdjIDLoGBBL6kCeFm gQc1/cZZMSoIX3S/kDvHxleJ30PjUkIPE2VVILk2+ksQvbd7kfJ5TA8r4G+9ZXBIcROW pz1ws58bgZAX4ERvjDW768RmHv8MqYVw1fhCwHPX7b5zmcSJMHYH1okva9msR3BXXApv iDVNFWKpNPamPsCTNGRBcgNDJcKcUKQStyAnc8l40pELAukmVrz61V4PR40iJ4rgm2On hMHA== X-Gm-Message-State: ACgBeo3My8//JydZcjRuKg2I1YP1SojCjlQ0mOCplt6HehXxkS85RvjW dkIsxwT14kN66faOOOusUnThwSsW9RffCA== X-Google-Smtp-Source: AA6agR5fPt7/KsekhLdJlOlt2OCm4R4UlZnniyuTusZQ+V5wzCbj7hQ+2o7W/+t+eAy1iEWtd/PFxg== X-Received: by 2002:a5d:6f0c:0:b0:226:eda7:ee93 with SMTP id ay12-20020a5d6f0c000000b00226eda7ee93mr2607781wrb.657.1661987918664; Wed, 31 Aug 2022 16:18:38 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 23/33] submodule API: don't handle SM_..{UNSPECIFIED,COMMAND} in to_string() Date: Thu, 1 Sep 2022 01:18:05 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 965196a005d..35989c81603 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 Wed Aug 31 23:18:06 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: 12961561 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 10EEDECAAD1 for ; Wed, 31 Aug 2022 23:19:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232866AbiHaXTY (ORCPT ); Wed, 31 Aug 2022 19:19:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232789AbiHaXSl (ORCPT ); Wed, 31 Aug 2022 19:18: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 147149C8E5 for ; Wed, 31 Aug 2022 16:18:40 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id b5so20122520wrr.5 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=wk4NVQgjtyvUjYHUGzbVeAh7j96d89m1arHwjDBzi18=; b=BBGtflmZK3Q8Kiuhw0Teg36X+yhB4IYCAKwIJ+lRmyr/+3bkf6RdJi3ECdml5Or8qZ b5POaLdYjjuunQlbJNQTO6iru213t16jO3XwSgY681AAA7UmQe8o4cbfDwtdVjTw/s0e NMBO8Fv56MlnBXJdZ+7+xNlw0HhxTLcjkzznsYb3RNRmPWCIE1m6LlNarBeMZwrE2oTd qb/7xUlYaMljwobGHX8bTegCvaKi0T8M8eJSICZFvSVyURnxsbnIEtSOhhXs4TpDndl8 73RW9f0/Nj3jBYia6/SeMUYRrDXwYsSdqoO45IL/h/Sn7WWQMyxeseTtiGkrC5+zM5I9 +IBA== 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 :subject:date; bh=wk4NVQgjtyvUjYHUGzbVeAh7j96d89m1arHwjDBzi18=; b=WahWSEbG7A581BCmqhQCUYaRYB2Ty2klIJJSxpvpW2RjJZOD34IejQ+FKuG+IAy/PN hkIO+noR4IwMp5uuFRy7jYCCfK0TczvmSKxV0e/NXan0/0H2tp0PFrkI1BTnunjhO9jd 4rv6LXNvlV5UJJ6X26I0nY+pHeQAkf6h/hTsDXUFAbIzPBoGZFOtVqF0AQDNePwhyrn3 oJxRLQxtFgtd7MiLSf+u1L0McKKB8ErSbZkaH7WKrppkQGv/y7ZVtxsktYorS5fpgutz UHbUxdElpSJiaK24QqbsExuJ4tnmf5WcvvOttfW2zpROGgIOA0gxDlHqVkZ8VbnFVz1S 4uOA== X-Gm-Message-State: ACgBeo2Zvut+MPfrWKq9cseWhLDjF931/NCDt0O1LvolKNJPoDhnn9b0 oAToZ5SwJVlRHJzfuvHqtMR86ndKLmunug== X-Google-Smtp-Source: AA6agR6XySRvXE4nXMNxc2/KmJ/KXvzO0WOG8t7CMmIRxZ4uOOHJ1h4L+3b6zuN+Xs6X75VkferMGw== X-Received: by 2002:a5d:48c5:0:b0:225:59cc:9b04 with SMTP id p5-20020a5d48c5000000b0022559cc9b04mr13144477wrs.338.1661987919534; Wed, 31 Aug 2022 16:18:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 24/33] submodule--helper: use "code" in run_update_command() Date: Thu, 1 Sep 2022 01:18:06 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 35989c81603..234f1f993e1 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2130,7 +2130,6 @@ static int run_update_command(const 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: @@ -2144,19 +2143,16 @@ static int run_update_command(const 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", @@ -2167,32 +2163,35 @@ static int run_update_command(const 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 Wed Aug 31 23:18:07 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: 12961564 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 B61A6ECAAD1 for ; Wed, 31 Aug 2022 23:19:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232766AbiHaXTc (ORCPT ); Wed, 31 Aug 2022 19:19:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232724AbiHaXSn (ORCPT ); Wed, 31 Aug 2022 19:18:43 -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 120639F1B8 for ; Wed, 31 Aug 2022 16:18:42 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id z14-20020a7bc7ce000000b003a5db0388a8so2391311wmk.1 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=pKB2GxjzCuPjNcbC+icEYbJm5RAPkXe+Q+iQKWq9cQ0=; b=G31kE3ZSHCtU9X15kiHW0r7/sj0cdgCHzYkEOy6h2Jbq2FtV99r0lJX+k3N9PGAYDm lbbCS6G0aMD3YMLCwBihczDPFh3wa4TTP9jNH/ThBro7wa6inDd/rl/6DlW5rT7NIUuf QZ1IOtm9zUi/NSwe27bV5kZ+Wz1iNLTvoutUXZNX1TLQrHOrG9DuNeHXhp6mIsKRETXC uqshqEmImCd2NRIQwQ16OCX4GerMCVX8TN1LW+fzdM5gIfceT11pDhTDhxXPOR6OD40X JteB/7z5pp4H2is25wXkBEesi96BYaG0A1uBbMBgYS760zVTc0U+72xYyfPTgT38/ktY IzRQ== 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 :subject:date; bh=pKB2GxjzCuPjNcbC+icEYbJm5RAPkXe+Q+iQKWq9cQ0=; b=0eT/9ncYY5vPM6ad4A0HkCOAl66ImbuvABvok679OhFj9+GKENwJi4nwSfL/jmBF+8 ORboZrkzoCt0LHsbnb8aX4rSViPUVC9Dh+eeAbJV0DOU+RdA5PIAoAqFmtRCcUz+r3l7 cllZDmnT9sU3I3xx9DXQ+bslIyvJnboqvyhBR/60z8/JgeicASvQ9xmjDhzm27ZhvuyQ X69x/tw5Mqqpe4Baua6sLHkDdUwXDsJY+dHm/mdLE82HhvzKWvH7+xTVOzejdOWVxYwT tijOW/tI+wiZTzjjEpo0L16YecyAaTy14kxYme3PS9SOOvLGQ1FwlSGvFAO7zyYwarDM f3dA== X-Gm-Message-State: ACgBeo3Z3LR/SJIQbAcbyRA2LfCtHXcLsij1XCbpvcyT0MKvJPUi82BC I2AeeNASXs4yY1f9r6mLu2n6zoyFNXZEKQ== X-Google-Smtp-Source: AA6agR4nQawlV8vocaCOaFMVizsFU31XHxEJpyK8NtBcFTyZOPSlamZMczzVXN5MCcJPBAr0FhqbyQ== X-Received: by 2002:a05:600c:3ac3:b0:3a5:e1de:5994 with SMTP id d3-20020a05600c3ac300b003a5e1de5994mr3353335wms.133.1661987920368; Wed, 31 Aug 2022 16:18:40 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 25/33] submodule--helper: don't exit() on failure, return Date: Thu, 1 Sep 2022 01:18:07 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 234f1f993e1..166c6aaccb2 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2126,7 +2126,8 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, return run_command(&cp); } -static int run_update_command(const struct update_data *ud, int subforce) +static int run_update_command(const 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); @@ -2190,7 +2191,7 @@ static int run_update_command(const struct update_data *ud, int subforce) } if (ret == 128) - exit(ret); + *must_die_on_failure = 1; return ret; } @@ -2222,7 +2223,8 @@ static int run_update_command(const struct update_data *ud, int subforce) return 0; } -static int run_update_procedure(const struct update_data *ud) +static int run_update_procedure(const struct update_data *ud, + int *must_die_on_failure) { int subforce = is_null_oid(&ud->suboid) || ud->force; @@ -2249,7 +2251,7 @@ static int run_update_procedure(const 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) @@ -2386,7 +2388,8 @@ static void update_data_to_args(const struct update_data *update_data, "--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); @@ -2422,9 +2425,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; @@ -2440,14 +2449,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; } @@ -2480,12 +2488,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 Wed Aug 31 23:18:08 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: 12961562 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 4DCACECAAD1 for ; Wed, 31 Aug 2022 23:19:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232868AbiHaXT0 (ORCPT ); Wed, 31 Aug 2022 19:19:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232798AbiHaXSn (ORCPT ); Wed, 31 Aug 2022 19:18:43 -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 D0DEE9C8E5 for ; Wed, 31 Aug 2022 16:18:41 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id m17-20020a7bce11000000b003a5bedec07bso413142wmc.0 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=nQIz+mioS3ddGaOOQaZMYNsXzT4AlZA16+3TEwHqWF0=; b=n/yi4WUAMRzyVaBRBQR6wdRm1jXDK63XjkcAi96qEV9JMXAilEkzP8/cbRHuOAGMpW vs04gm4Q8wHyBdSV25rm5jfwXrU/zQMVLpaj41cXcI0tppHypgPBJ/23XVfpDDG1mX80 Sq2bmwQv/jT0gLD1fT1yvgMILy5/DqDd/RIr9Mma1dJX10wi6iu9yj/XHju7RFtnBLlk PK4gM06inT5a1dzKIAeAbr0eJy2e9MbyaHhhIQdUb3lfa/vHzjVelPAisBKnttCha0WR HxNoQk1/AhBDCTYsd5CJch+nbZ7jqM0SsHmrGfibl4R+YZh4rHXpyun8lY1cFbVdQYmC P2vQ== 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 :subject:date; bh=nQIz+mioS3ddGaOOQaZMYNsXzT4AlZA16+3TEwHqWF0=; b=TZDzv2VDIncHBG6W9mmihQr3WMjmxf5bgFfDaypTDFbqZsWaV2l3NoL/U2eCpmwtac bgQhBtH9nsq3uL7CIISt7U+SFqH8IFQHVscZAVHUPxX7ER4lpr53OVKVAXNXLndJWvSZ nPoIAG6HjG9JItrz1zIJ8uEzVmpHvm3I6B3IdB1EhHpXXVdKLkCw903Z5regq81MYoTV E+5rwDW5U5qih3H2ymFyujWP4zCKyyQbVHP6fTZ0PgCDZZRy505gfc5kOgAmEEB5NHoY +A7PKnIN8MYaUUVWx0vCTn3FmT0u41JuGeiWa52k4Cuf8TxoiOhkHWm8HkztS2AtkQVd f7bA== X-Gm-Message-State: ACgBeo0pXWSLgrCzUOIqgdsasDZz2t8IhBQjCR6nCzPmHWgRzb3Wf0SV YlhcAMm33xMYlHw7vFMqd3B5uLeL89ug+w== X-Google-Smtp-Source: AA6agR6lY9L669v5b38pyvI2xCFM+JVn29vX67ZI1111svGMu9LutTqQ+FTaW0fIgqpo6f5PNOxHHw== X-Received: by 2002:a7b:ce05:0:b0:3a5:c069:25b3 with SMTP id m5-20020a7bce05000000b003a5c06925b3mr3313410wmc.87.1661987921298; Wed, 31 Aug 2022 16:18:41 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 26/33] submodule--helper: libify determine_submodule_update_strategy() Date: Thu, 1 Sep 2022 01:18:08 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 166c6aaccb2..2f78529736d 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 { @@ -2391,14 +2397,22 @@ static void update_data_to_args(const struct update_data *update_data, 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()); @@ -2426,8 +2440,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; @@ -2438,7 +2450,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 Wed Aug 31 23:18:09 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: 12961563 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 ADED8ECAAD1 for ; Wed, 31 Aug 2022 23:19:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232877AbiHaXT2 (ORCPT ); Wed, 31 Aug 2022 19:19:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232786AbiHaXSp (ORCPT ); Wed, 31 Aug 2022 19:18:45 -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 CB11EDC5EA for ; Wed, 31 Aug 2022 16:18:43 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id c7so13470226wrp.11 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=IlbUbe8IscZDZUVsmEpmoGpgoxhBcWD3DoxD2otXQpw=; b=eFJfGBlIlP/Wzv8H05PUmVxJAFP1SRWDB4QEZKAHmxsPjXTwyWuW7gH7024BcavREU S17QCjeJcoN+4alSHzaggjORdfwn6eMHhZFplzdcf3oKsCVnSgC6FYhJ1y+VxdUCVcgL Wx/vzh0HXSXx4Z6xprI6MwbskMKHhsV2KXcOs84sY2qg7D5Wl/MiefxBOojgRipq4tYz AYWIf3uj6NkKc/qGhr5zNn/KM6ckgLc5Txo3Ce27nIRjYmPOzT0wZfHms2bLiDBOUsn4 f6329+f5Yt+LoRv/97j4x2igQpxeUAbYe/di6hxnUsE/k1FDiYZBBG7WK1ifKmPy9sLF K1ZA== 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 :subject:date; bh=IlbUbe8IscZDZUVsmEpmoGpgoxhBcWD3DoxD2otXQpw=; b=O37r8H7cSBS5EWyrhZngPv6lpLLMm1nlFkmyubz04ahHzJ/DQgS3oW8IRb3lWQEW+G Emo+b4UaoGdUo7Dr1L1VxJhihfgMd/F/othkwvuGl2RdZ+VtCtCt+jZZZU0tsEdib996 NgdrQiPNjxNew3HCBACR/8dhB6JzhmlgaeOgWWZwH2SeIW+j+hi3uzKGw+LPIveoH6nm SAe5kw/j8jbKssTqx3yuznEWwSuYK7w1cxSLsr6syFs7rhHsM7wP1p4svx3vA4NaNNQ3 ZXcOVTh340V6geQYkZA3gkh7bq3jzwVDz4SD/prHqFgmiisH4zwLSoelgmmck6GBf8kQ h8Pg== X-Gm-Message-State: ACgBeo32dDEe2TZq3jzOqlI16gSHG0vUFBcA9ZQAIuJ3EE1bhP9+3oD+ yZTswVA5VXGJcWw1QOhcK/JqQlUc4LR4Mw== X-Google-Smtp-Source: AA6agR7Byki+wdSymLjCwkUmBZJUFZJEh/HzVFQg3YoOvQJbUTs/5pBRwhP3vNhnD0AVI4EqbHj+fQ== X-Received: by 2002:a5d:6da5:0:b0:222:4634:6a4e with SMTP id u5-20020a5d6da5000000b0022246346a4emr13215076wrs.172.1661987922154; Wed, 31 Aug 2022 16:18:42 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 27/33] submodule--helper: libify "must_die_on_failure" code paths Date: Thu, 1 Sep 2022 01:18:09 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 2f78529736d..8a086723ba6 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2132,8 +2132,7 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, return run_command(&cp); } -static int run_update_command(const struct update_data *ud, int subforce, - int *must_die_on_failure) +static int run_update_command(const struct update_data *ud, int subforce) { struct child_process cp = CHILD_PROCESS_INIT; char *oid = oid_to_hex(&ud->oid); @@ -2196,8 +2195,6 @@ static int run_update_command(const struct update_data *ud, int subforce, ud->update_strategy.type); } - if (ret == 128) - *must_die_on_failure = 1; return ret; } @@ -2229,8 +2226,7 @@ static int run_update_command(const struct update_data *ud, int subforce, return 0; } -static int run_update_procedure(const struct update_data *ud, - int *must_die_on_failure) +static int run_update_procedure(const struct update_data *ud) { int subforce = is_null_oid(&ud->suboid) || ud->force; @@ -2257,7 +2253,7 @@ static int run_update_procedure(const 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) @@ -2394,8 +2390,7 @@ static void update_data_to_args(const struct update_data *update_data, "--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; @@ -2409,10 +2404,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()); @@ -2440,11 +2433,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) { @@ -2461,12 +2452,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; } @@ -2499,20 +2487,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 Wed Aug 31 23:18: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: 12961565 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 856D8ECAAD4 for ; Wed, 31 Aug 2022 23:19:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232821AbiHaXTf (ORCPT ); Wed, 31 Aug 2022 19:19:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232800AbiHaXSp (ORCPT ); Wed, 31 Aug 2022 19:18:45 -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 5CE73E97DE for ; Wed, 31 Aug 2022 16:18:44 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id n23-20020a7bc5d7000000b003a62f19b453so383181wmk.3 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=UC4ZjamO8mbHyoA8batub7PKen7iAmW+PkYG7gM/B5I=; b=QhLh+iAp2FJy74cajiPGpwSI0xfEuFJ9Mk3CostaBvQqPDfKlp67enHhaT6H2CxCQ9 Kb0MBSyw8DPdJXyiTyrUiuQpctPjNld5ShtrnOAifGHdJG/mld9V7/4Qx0A9WLtN4bYj hI7YzWFBo25Mm1eZFfhiyLVbfiMJ2k5BvOu6Gc1fwjvjHroTQAuC6IZ49N3O7TKwXzj7 eNxAfYi55pLZvC2UAoWeYuJEg6qzDDkYzhFEKD0yIRWYdR+pr8ZlLj15mfk6e3ZBEkor 3lBQkcfsu4Qejbr208fdSFpiI3dwU6ELXl/KGnuXx+wYrYqWxEo97dG4gLx7gopn+jvh XVOg== 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 :subject:date; bh=UC4ZjamO8mbHyoA8batub7PKen7iAmW+PkYG7gM/B5I=; b=qG1LQECNAr3ap76N4szFHoJrAzmg/FaBQ+aMR2uDMmYUozVAsGYs1eWNlxM4VbvVmD XCtQL4BXv44nt8uf9tDx+D0NLCPE2p2Ddq8wLIG0j6b9iKQHANqR9wJLmUUe6bPbXVQm vjP9/tW71P6HLNpN2bM2ct0O4U6NGOyHtDBxz/9G8gaY18DofRhxy4zGGTBLAOMngsxG IIKaIIxqINCR0g2cGXAJtSI/VqWMTJXR0eT7s/WW0Nlhvx7dGFOlkTdfzYPReD9ikXgh iptZlKHM05o/Rv2M/UpuXPyVNTMLExbneY5j1b0UwnkjBNkA6tgXnF9zeyI4I3KuUoxp 2khw== X-Gm-Message-State: ACgBeo2rcZ+M5QJeB+o8ImZUGvEYYyNG/RWi9n1yQSMguCjCeAcc6LH8 2QxIlZvV8NJLq0TdE8Ki8nuJptKcBUuTNQ== X-Google-Smtp-Source: AA6agR6dSlAiSYX4Nf65K5yyOO0mMi5gscsvAouBxaux3ZEgxmW3QxiLTVi/pJQT+S04mNRSSZa1bw== X-Received: by 2002:a1c:c91a:0:b0:3a6:38bf:2c36 with SMTP id f26-20020a1cc91a000000b003a638bf2c36mr3344440wmb.38.1661987922825; Wed, 31 Aug 2022 16:18:42 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 28/33] submodule--helper update: don't override 'checkout' exit code Date: Thu, 1 Sep 2022 01:18:10 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 8a086723ba6..4252b6d864c 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2136,6 +2136,7 @@ static int run_update_command(const 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: @@ -2168,15 +2169,12 @@ static int run_update_command(const 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'"), @@ -2499,7 +2497,6 @@ static int update_submodules(struct update_data *update_data) ret = code; if (ret == 128) goto cleanup; - ret = 1; } cleanup: From patchwork Wed Aug 31 23:18: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: 12961566 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 D9DFBECAAD1 for ; Wed, 31 Aug 2022 23:19:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232827AbiHaXTg (ORCPT ); Wed, 31 Aug 2022 19:19:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232803AbiHaXSq (ORCPT ); Wed, 31 Aug 2022 19:18:46 -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 5709BFB0E7 for ; Wed, 31 Aug 2022 16:18:45 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id b16so12509569wru.7 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=Ey7RZ3n/NNCC3mghYHrYzQHuAt1guOeZ82/2Y0XEeqo=; b=CfZn8DH/QPYjji3qP0WOOQNbsOVbDapHO2S4UYEcAfUoOfAaihvAiLX0+gRMfr6Y9M H2iejDZ+CG4BCcDsq/TSwhrFWbUvkarqI6vBmd86JKhmBGDk6u2+54INQP1nsxfj/5Io 2npcw2D6hQIGU9+4hpalz7K5LNg5QMXVg9Kruy8c89zOc4pd3+KzuJBRLFwLXQWJmdK2 ekjzlownrKb6BIk3coh8Se/xQevyCl6hzuGFwDB1fcWqVw5smkT475oHdtPjjaDz7RUq zIGNlgGRWzin/qG87xz+/LYLBWrwA9sIaq7o9QkHMKB9aqBihAhCwsrMTEbYwq6EiVug TylA== 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 :subject:date; bh=Ey7RZ3n/NNCC3mghYHrYzQHuAt1guOeZ82/2Y0XEeqo=; b=ROMkVxIiOYK83L7Rk1H9HwiNk86Kf5IEpc4vCdGn5+xAsxf3++AQuu7JoyBH+98sMp guE5rjKVIzT1Nb2Wmo3kXzZfSbhHneYnS89hrfk6DOIP9gsQWnwVEgFQPHUmxIQU9czL YWk7U1skHo1K2HuAnoCURkRIvUKDhlknozyUqHO6bAX/zLR0yZ9Zt4TGe1Q2CgY/59VR j6UtBaV+8lsbkhKNqo82iPY6EBtv/pMKHo9PUCtJuik+jQBtJJDQ2c6te9PG26jCy6NW rP3vRqFXeERykZj2aU/JIMaLinLV0ioNOnsJ/uyhILfC6fFuoiNdpNDlvbih+ExjzqHC 44ng== X-Gm-Message-State: ACgBeo1o9GEnY9b7vI85KDjKVolkNnMgqmCv1CCa88xObV9og3qWcAE3 eKT5+YtKBPnhlLQJopouIwc0XCAdWXTAnA== X-Google-Smtp-Source: AA6agR4G6U5mtiMG9yehNQPukeCtsk61qE87ygqej+D9+xwzhWhXI4pWuk8cUSO6SAgn2yF7vGbVJA== X-Received: by 2002:adf:d1e4:0:b0:221:6c37:277e with SMTP id g4-20020adfd1e4000000b002216c37277emr13392841wrd.498.1661987923585; Wed, 31 Aug 2022 16:18:43 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 29/33] submodule--helper: libify "must_die_on_failure" code paths (for die) Date: Thu, 1 Sep 2022 01:18:11 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 codepaths 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 4252b6d864c..b99fb7a244e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2246,9 +2246,9 @@ static int run_update_procedure(const 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); @@ -2292,13 +2292,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; @@ -2316,6 +2317,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) @@ -2392,7 +2395,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); @@ -2408,8 +2413,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); @@ -2419,13 +2424,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 Wed Aug 31 23:18: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: 12961567 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 F13BEECAAD5 for ; Wed, 31 Aug 2022 23:19:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232897AbiHaXTj (ORCPT ); Wed, 31 Aug 2022 19:19:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232807AbiHaXSr (ORCPT ); Wed, 31 Aug 2022 19:18:47 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06C049C8E5 for ; Wed, 31 Aug 2022 16:18:46 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id az24-20020a05600c601800b003a842e4983cso452735wmb.0 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=SS7w0G1W7I9X3+yMaX12gVHMTuMHeLtsAhcXqbY58ao=; b=VBf0I+zWBRa8W2GZ2zUt8vD5PTKJ7cb1NIs9Re+Z+AuesbhqditKIhRMKzDwXwNFko JoSWzP6Fi7bropH/OOd/OtVDTuus3UxCgYbFB23V7++Xs3R8LEThUCFjxxToof5ARKSV MON9YpDN/3sd2X1l4xtAcKYYcfTos5EZ+AbJ834Df6NnHq6CWQZ8gKYRXJeImVDsn2xR YYfICrddFsG67wbTIMnJvjuu54MqHTIgZOLvYgBnycxwqi5AxCtDAPgsCrQtQ2QdlpY+ NAeiO9h3LYJzOBQO52fm31YHkuE7H9rXuLH4H/j8766h0tC9xsiYBINQKEgKat8XP3ED GgHg== 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 :subject:date; bh=SS7w0G1W7I9X3+yMaX12gVHMTuMHeLtsAhcXqbY58ao=; b=DptB+gPWz7h8FmJRMrW1tecIbd9Kxfb0lnrEJoUJQ7xLqK8NcpuxnE/tomn+O/fcub WODugnvo41WYmFWYJGLLPtTgFpP9LGbhU9ghp515ZjdVQSdtDmim3htAOp74OLvSfERI NHJUAQc5ujJBO2MXmYX/mC5Sb+WYUNJo5GmKUkQyeqz20K8uf9UwYJgeDVN7E1emSTY/ Z+Ie2A2RNdzwhWhJUeOGCgpEtL/x0EjJn3mn/ArMBvzUHA7+elfMgL0EajktjuMKDYae BfEb1OrEH+6JE9aZYoZa1aEqIw3JZrAABRcCbuix/YVT+vo2+rKWZM3piFKK1GE2XwRx VXEg== X-Gm-Message-State: ACgBeo2fjxGWtwnuCqz8FZeTA9GwAIC9oiRKttnD1XqpsyfND86dZvJG UcRNmNFvifVLdXMsQ6CP6HW+2OBnnu00Qg== X-Google-Smtp-Source: AA6agR5RzoWrkN/TYwHauit1s+hGSqhqpSnO5z7zdT2jlNzOXI5NTgIteW02Ueunv1t3BV7vIfO6Bw== X-Received: by 2002:a05:600c:a09:b0:3a6:8900:c651 with SMTP id z9-20020a05600c0a0900b003a68900c651mr3290479wmp.145.1661987924407; Wed, 31 Aug 2022 16:18:44 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 30/33] submodule--helper: check repo{_submodule,}_init() return values Date: Thu, 1 Sep 2022 01:18:12 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 b99fb7a244e..dfd71f0f2b2 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 4e51a1c48bc..7ebae122d40 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -569,8 +569,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 Wed Aug 31 23:18: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: 12961569 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 788A2ECAAD1 for ; Wed, 31 Aug 2022 23:19:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232905AbiHaXTo (ORCPT ); Wed, 31 Aug 2022 19:19:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232778AbiHaXSw (ORCPT ); Wed, 31 Aug 2022 19:18:52 -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 159DF1037D0 for ; Wed, 31 Aug 2022 16:18:46 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id u18so7465108wrq.10 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=A/84xM0zF+mQqXYyVHmSpgTf/ySnQI6v8lZMHTM1K5s=; b=Tdgo9ZjFFKHnnRas/hDDR/13ophtAQN7w+o94u08bGRdrQ+9UMTKSmG2Xjh52DlNoc i1aLL+iz+OK1QX93ADCsDOMHzNPsK6L8yoGZRb86bcfagjwpDBFn7QxgFyU0RzK0xBNI difcNu6g0MZHd03pQPyz+BpVknHPpZeoFq5DzpvcNTkpyFNfwvLad/ay2fpw+tdfxJOv a9n5DNp+0DDxhUxYEJG93XebxhD80EvzOCEa1sBwbxY2opRlvfCFUHSNishjqD2oWwOU RfGF8t5ZZx1u6tEjO52MnZi+PtFq8slWnnQMMxx2AH1rRnT7J1GeifwB4b5YgiEjY7wg 6O/Q== 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 :subject:date; bh=A/84xM0zF+mQqXYyVHmSpgTf/ySnQI6v8lZMHTM1K5s=; b=62V+3hZEQM1taXKYk0AhdyBtDt7d2bIO7o1LI5oAfsKpsvnHLIpQNZOs4rc1VzfWkF D9GI3Ztt2Alm03a5pdLvgmhlNCHbLOYOuhesp4+sHPAe56akpCCJ4+17mqEqljfVtbeF OAN+UJXHXE0mUFdPEd/YaFV1iYnIStgsC0q0uTyjcUlOc9zEy4wG9cs3iXJdOwl2PpmL XXNhA8aycWCgO0eejx1Jqk3WpMBkwlOQisvueZL1e65DjmZlDgHW11VVFHfCnHaZzNXB BxznJV8mPWrAcn0ZDaFf5jMV9TgmwHlX7X9WD7hgbJB9Goym0vyfA413xjlJYKH8PLC1 wVIA== X-Gm-Message-State: ACgBeo25U4LUprVxIK9z3MzD7yRRCnBiuovZcLRxmBriOtDFkBSRkRM4 RzOuACzSiN3J9k7E7RNrxz8O3XNJvOTaxQ== X-Google-Smtp-Source: AA6agR4Ze6pNZXyixtGOgrMS3pRIrJ6ADmCZ3hQ+qMvkKTl3y1lXyVJEIYP0QiqzgkK1u3DePSqWQQ== X-Received: by 2002:a5d:47cd:0:b0:220:70a2:5383 with SMTP id o13-20020a5d47cd000000b0022070a25383mr13052393wrc.258.1661987925200; Wed, 31 Aug 2022 16:18:45 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 31/33] submodule--helper: libify more "die" paths for module_update() Date: Thu, 1 Sep 2022 01:18:13 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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); We can safely remove the "!default_remote" case from sync_submodule(), because our get_default_remote_submodule() function now returns a die_message() on failure, so we can have it an dother callers check if the exit code should be non-zero instead. 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 dfd71f0f2b2..9de3a3c921a 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); @@ -2422,9 +2431,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 Wed Aug 31 23:18: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: 12961568 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 93FBFECAAD4 for ; Wed, 31 Aug 2022 23:19:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232901AbiHaXTm (ORCPT ); Wed, 31 Aug 2022 19:19:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232774AbiHaXSw (ORCPT ); Wed, 31 Aug 2022 19:18:52 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E0AA1037E1 for ; Wed, 31 Aug 2022 16:18:47 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id e13so19222147wrm.1 for ; Wed, 31 Aug 2022 16:18:47 -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:subject:date; bh=Uq0C+dZrVb4mtBQ15qg+F6gPAcsIySojqkrl3I8Lz14=; b=N6e0RFTYAhBrexDHnVAeQqtY4XRV8vOF+9+jHs7s/4W+i1pAse80tSlU4CldCjMwRB 9tMPCz7VuGw0ylSoNb/w8fqbZLqfXKqJd29qcoyYjiuFnCwTX9s+WCZsXALnTfEWllPE 798afTG74WF9gRn1pNhDYwA63JFEn394vA+za5Bi2oBqgSU/hG3bmD9fBdPfGpMA7Jn6 dzQKfUaUeEpVqMcqvz3oxFBDQWB+lM8tupO/PTVmgY7VjAz/B614svNRIm/6ehp9/ouf 3x2gpSw3FuQFICW51u+s6F5LhWHb3DIMMP9+fORSh7LCty/03StzMEf306nt90H5Aos9 TmuQ== 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 :subject:date; bh=Uq0C+dZrVb4mtBQ15qg+F6gPAcsIySojqkrl3I8Lz14=; b=T9w7r6LyeJsTN4EfvBGye/0tYkdtTHB+nyeqEjwpb+qd3geVy0nWC4xhWiRjHaxmLc 9mcG/+cEx+mQWOTTIAx/SwmrfG7QcEYVYTr2oB/ih9giVcAHgYwtRN/Oh/d8g7PhdSgQ zpnMqtALGChewCz/pS1RJFhW3hh+1zkEQPznflvl1p4DpQCbd1L/3llTEXtH7tHbz68v s/3iNWt+5yO6U5jXjiwPShUFVuEdHYkCg7UQ6PPLdUnPzujZ1yTBse1Nni+/ktPWMQcu L9GOhmxyztFSOEyV2Hc5yKbQMhBzne2HnSA8BEA3aXWKxQcNJyb6JVD34lBqYKErx7C2 q70Q== X-Gm-Message-State: ACgBeo2ivH2pi6pvUpNVlzaoyU+xUOTGfccobllnaRZbmzNdr/R7I1tH M/pzX1ZoDwLl6MxKjxKjwgcTzgmzKSvqJg== X-Google-Smtp-Source: AA6agR6Q4o3+BxFROTU6coBPqyJBRW3rC/+dJwScZMAXK6cUTN71i/kr5EYlb5BC0ifrVLB/yj/Hyg== X-Received: by 2002:a5d:47a9:0:b0:226:e849:4373 with SMTP id 9-20020a5d47a9000000b00226e8494373mr4238942wrb.57.1661987925998; Wed, 31 Aug 2022 16:18:45 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 32/33] submodule--helper: libify even more "die" paths for module_update() Date: Thu, 1 Sep 2022 01:18:14 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 non-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). I.e. we'd previously have segfaulted in the xstrfmt() call in update_submodule() seen in the context. 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 9de3a3c921a..3f822eac3a1 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2268,42 +2268,49 @@ static int run_update_procedure(const 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) @@ -2439,7 +2446,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 Wed Aug 31 23:18: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: 12961570 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 76AEEECAAD4 for ; Wed, 31 Aug 2022 23:19:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232907AbiHaXTq (ORCPT ); Wed, 31 Aug 2022 19:19:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232797AbiHaXSx (ORCPT ); Wed, 31 Aug 2022 19:18:53 -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 6CEB010401A for ; Wed, 31 Aug 2022 16:18:48 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id az24-20020a05600c601800b003a842e4983cso452782wmb.0 for ; Wed, 31 Aug 2022 16:18: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:subject:date; bh=iqKhvC+nrpAqv1FBqeosjwlMO0oh/ExwTBL5ZR/T8V4=; b=Mr0CZq7ApAhZD5Fl6t0vMSD0MNxGbFK4EeBVkXO7CaF/zGM19+ds1RqExQjUyA7ZtU jODKZGm3nMkdKLl/l/2x1J3GOdTTOeZPIvzo20azLws2t1O2o3izRB1sJvlT/UIC0aCo s9gfbTqZkSCDFa6+96fwmdZqCI2BEB83ZCHu7TwnY6Vv8E6fS4B4uP4UqOIKr36JRQjd A/OubGIKvEpbPOc08wJmyJ1hiMn7lgud5DV//+aDVt4VTbsZhEKPGHcCfSAkMbke7wVY XRNewr95YQ+SS9zKAzjl3oT5y6VWq1eKss3/POOQ593fJV7yEoR65acTuZ5Vwdtqijth Fyig== 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 :subject:date; bh=iqKhvC+nrpAqv1FBqeosjwlMO0oh/ExwTBL5ZR/T8V4=; b=Z0Fjibi9mJKSbxRh4G6KD62EhqrM0Y2+7zHYVUL8ne7KeZKiJPNXohivlkMSiPHb0O Rf8QAH5cMf3VAqr64bV4z9Td3phtak+/LeR4RtXH0A+vbsvp0xoYMG4uUupk3cdjCwn2 nNYh8cPMNQ6VK4X/CNU3ofqaKQhm6dIv+xAuyX2Kc4i7o73yg1b0Aw27IOEN63riS6gd 5jLNUS3kjVcMKumU3EWX2IDyZq0mnVJDYrT2E9XUWdfGQi0q0QQx9nN23LQleqUULkM5 yvdXOIXleunqUUZWh4FHAZG1SVmN+mH2kqdVNYz2yDVxpWp+hQY7aUBFPLUsse07xyJJ szeA== X-Gm-Message-State: ACgBeo3XWQ2fdK08Ci62RcExeJ6gDvBQVfCYil+nXzRsFJ7ovS/o6+Wl 8kw6sAmq3zCfy+vBS4LH0vJSq48G6spD8A== X-Google-Smtp-Source: AA6agR6B6xHQ2BrlfDqkqtCkKnbS2koHmDX/8DT+KsFeHvwLy8cpiUcfKjuxGIsCJhtay2h+pNyM4w== X-Received: by 2002:a05:600c:1e1c:b0:3a5:b668:4e2 with SMTP id ay28-20020a05600c1e1c00b003a5b66804e2mr3309646wmb.112.1661987926796; Wed, 31 Aug 2022 16:18:46 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003a5a5069107sm3317903wmq.24.2022.08.31.16.18.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 16:18: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 v4 33/33] submodule--helper: fix bad config API usage Date: Thu, 1 Sep 2022 01:18:15 +0200 Message-Id: X-Mailer: git-send-email 2.37.3.1420.g76f8a3d556c 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 3f822eac3a1..c4149f11e7f 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -3110,7 +3110,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