From patchwork Tue Aug 2 15:45: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: 12934777 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 0A615C19F2C for ; Tue, 2 Aug 2022 15:46:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232611AbiHBPqY (ORCPT ); Tue, 2 Aug 2022 11:46:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231286AbiHBPqV (ORCPT ); Tue, 2 Aug 2022 11:46:21 -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 AC9DC140F5 for ; Tue, 2 Aug 2022 08:46:19 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id l4so18418320wrm.13 for ; Tue, 02 Aug 2022 08:46:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=E8zyqF84uEdemwVXSztkP8PfkZ4mVwKo6YwS6kgiY+g=; b=FyJkn+QDsvUYLFEmJ4pUlrj4weU/HSGUpCUhkeGSN7kSlIeuYZIq4KhlmBSMGWn0W5 WUdWQCGl0A0hUaTyW23i5gxWblukP3xZSImH5ImsGZdf6eF7Wd8aYgtFCO7OMvxWSg3S KOnbpUyzXWaYebDO+N5mK4isQCvD4GFBpqelYA194PDOozPuBD6nG6kCOpJWfupyXFOH CSk/P/KuJ/T4wG4T2sBCe2RX/qvS6WcG40EPmYVx1Qwn5HWVO0rwoHk2YQQ3gQVEIMtS +wKxEbRXgA6QVP7ffGwa0OA5CclRJnmvk6IMDnwKz9zu7Pd7D8veCNjkvGzNrzXbYwi6 /AWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=E8zyqF84uEdemwVXSztkP8PfkZ4mVwKo6YwS6kgiY+g=; b=xv0d2IO6paO8wDGXYKxTb4nB4T9VEaNyp0g9ZhjvlgFxKHaVGf6peaam8tCIN1Ixcx ON+smkhrUpGeUKOIw9sJgaeJ2TN3eoegXhypzzhKX+kC5j9aH+hMZHv4zzboEk2evNjv lW5KtEhpMPzNg0vCx74SQCqNerI8vimc8RUq8GW8wkAdndD1iVxLK563J5BI78JFmUw9 XncdO/yd2vvk4GQJD1kvKWAlps7ZRWYsy1/0X16eXQNlBgJbf1yBoUKqMFuVqPc43A9e 7wvtcPZnbD5rP2StvTDaIqwNTQ5nKNLNEuZY7R16lqty/P4IeNWgBq0oaduaG43a7AiI kK+Q== X-Gm-Message-State: ACgBeo2QIqbVRNQQS7u8MYzg+XUsEdnKKlOu5/xzMpqBjLOsv7aivGfm gHTvyPEsMZwem04PGnYuIE61IH0M6Rm0Kw== X-Google-Smtp-Source: AA6agR7AJFXRfYp4gBIxE4pvg5nt2d+UKPe3vnp6mHjJvK7fd3aFL36IM1hUxnmoaEPu8gZ6Va52kA== X-Received: by 2002:a5d:630c:0:b0:21f:157f:f77b with SMTP id i12-20020a5d630c000000b0021f157ff77bmr12510202wru.614.1659455177947; Tue, 02 Aug 2022 08:46:17 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46:17 -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 v2 01/28] submodule tests: test usage behavior Date: Tue, 2 Aug 2022 17:45:45 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 don'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. 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 Tue Aug 2 15:45: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: 12934775 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 6E692C3F6B0 for ; Tue, 2 Aug 2022 15:46:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232483AbiHBPqX (ORCPT ); Tue, 2 Aug 2022 11:46:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231177AbiHBPqV (ORCPT ); Tue, 2 Aug 2022 11:46:21 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFDD61573B for ; Tue, 2 Aug 2022 08:46:20 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id bk11so8549761wrb.10 for ; Tue, 02 Aug 2022 08:46:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=chxJsskFM4pw3Zk2pCY3J60HA6hMmmfw2Qk963gExso=; b=Jbe2zkqQsFRW5d2hAT5C2YoOl+2qTTpRVws0NxwNThgQ9KqKmdv5qUutHj/OyP2urC Rt26W5gNGGZ9/Kkyo1NPwubi/otcK5uGynCmjWmGDWz+sIWXnpV84IExNsAkYojQRWE1 80vpt8O7QgnbR7Ebq/Ki/oDwYIvMtx03pzVXSTPFSvDPxPW4P46FPW5dyDBNgmZZ3h1r J37DYOQnm+RYk9wXpG9XX1ove4hoy5+Of6ehu026Hwc/QAmddQQvUCh08iosXRDeix4A i2koYByDeOjxSzsSKW06xikBdgdXH2tnirNkZ39TB12E9wDLXOxqVC7tn5sJEgJxT3sQ wQYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=chxJsskFM4pw3Zk2pCY3J60HA6hMmmfw2Qk963gExso=; b=H7RQ2cAxvvVl1Y8HIM3mC7gqb9st2oyL9NTJhn2vbj/Xb+NNMWlMtluc9gIdZReG6F c8QK6NMmljyYon6UdSZjsYMm9E+qCDRB0ICnaSuKDhIOkDG/+/Gjfk9Qiw939uW3jgh4 rnRuYKoQ45pHuiBDWZQUTVTphCcxk7hmaXSHIdx08irwvSvIZl6Xupn5IQV2OC5qxkvC 50QoNBMoLnMtRbVfU5TZv9zjOLtNzSW8A2dkS7LIMuhJ0UbCHJOe9CVsv52axmQQ3o2E LEDt9kCRJR2sfNIyrcwW0bHhDrDSuPtSiQGC+3bQEMLEpzsa7UFpR7GKFZdFTHk+fPSX NyGw== X-Gm-Message-State: ACgBeo3GdYP7YcpEep6Tq8QO/9GzbHpYA4oFxJMOr9rY/JANxlC5b1N+ yFAyIASPNlySBLfa/CyIDNSsc5tAHOq8lw== X-Google-Smtp-Source: AA6agR6ME8azWTRI/rYlDHjkCHcpGfKG6rm+F6O6m9Ojmd2nvs2v3j9d1tuAwlAINkeFvyVNeOkpFQ== X-Received: by 2002:a5d:5223:0:b0:21e:fc10:b818 with SMTP id i3-20020a5d5223000000b0021efc10b818mr13766017wra.676.1659455178903; Tue, 02 Aug 2022 08:46:18 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46:18 -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 v2 02/28] submodule tests: test for "add " Date: Tue, 2 Aug 2022 17:45:46 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 Tue Aug 2 15:45: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: 12934778 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 1DBCCC00140 for ; Tue, 2 Aug 2022 15:46:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232832AbiHBPq0 (ORCPT ); Tue, 2 Aug 2022 11:46:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231524AbiHBPqW (ORCPT ); Tue, 2 Aug 2022 11:46:22 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BCBB1580F for ; Tue, 2 Aug 2022 08:46:21 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id j1so10034051wrw.1 for ; Tue, 02 Aug 2022 08:46:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=VvW3WPczGfSoBgGavD27zF7Rjcor4+sXptybSynaGf4=; b=RO0+av0rNG8kSx5WbnDPmGooUpp7aIl6pbJyf1KpTaqua1ZpUZfwdnLpyk1Nx/FHzz Ok9R5X8plmmK/LzVIxTEgigh57uJPP73T/WrjyQ7WyRwfgMs365/Dvztp79KEYCNKXrC If+h05L0q8EKa4yzpqcSdRFjIr/OBaEIA1sPDcbuYOZGU9hDof4b6qg6TSMlTG456OSv DYThF1kELkXDbummiJqJGTQC10/G2qnFyXWgLbeDll+MXBpd7YkYEVHuxhoqIxt2Komy KazxZvKR3MCTS3dvwM12tZrl2ruAL8WK9GV0py2N+YuEHLsENioZCSKApHRGLO1Z/wJf H8Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=VvW3WPczGfSoBgGavD27zF7Rjcor4+sXptybSynaGf4=; b=Z+Vvvdy1IFXNZn+O1RiSOKggjhoLq4OK9X+2HsoMVXOYereWu8gvuHlDwHokwqRe78 Gl1o6mmiR0PXqowZnNuY+okKY2UBYwjoofR3h1QWEevCjlUPRzkxhWFlvnM/PNA0TgVa b7blErXxonRcWQjUpCHJRdepVaMjgfg90Ph5I5qDdvSMvKeQGGDZ1/SyLakkBXKM0jYY sDxvI0t3V+UgoCDhlzniCyAbNUljMSNybawnGN1qm5Qm450Q5eSoUhM1mfGZ+IFqnj3n pg6Uyw/2A1YbgyerWFrs0CB5FGCu7VkrIJfS/fDWJ1ak7qKHk8RCyur4Vw9rgLPEzH+2 Mjyg== X-Gm-Message-State: ACgBeo1wbnVcMxY9GV9bCvWSEI+xx2GVD2LJEi0FhLSiYHIEuauUhSJq JLFygkjLIVO88a0JU1uWIeiIj9qTS1Z0ag== X-Google-Smtp-Source: AA6agR7Es+uoUaCs/STF/aBbzPufnyQ6y/2hVkkyWh0wvYOLsQ9ttXawkp9AFxXlvM9A5Pz+H5LggQ== X-Received: by 2002:adf:fecd:0:b0:21f:d78:743f with SMTP id q13-20020adffecd000000b0021f0d78743fmr13667836wrs.704.1659455179915; Tue, 02 Aug 2022 08:46:19 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46:19 -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 v2 03/28] submodule--helper: remove unused "name" helper Date: Tue, 2 Aug 2022 17:45:47 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 fac52ade5e1..ac2553ba9d3 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; @@ -3359,7 +3341,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 Tue Aug 2 15:45: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: 12934780 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 1EF04C19F2C for ; Tue, 2 Aug 2022 15:46:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233655AbiHBPqc (ORCPT ); Tue, 2 Aug 2022 11:46:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232333AbiHBPqX (ORCPT ); Tue, 2 Aug 2022 11:46:23 -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 97C3DB7F6 for ; Tue, 2 Aug 2022 08:46:22 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id q30so13988550wra.11 for ; Tue, 02 Aug 2022 08:46: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; bh=giNR78yvsytV5FHxWOODBwS5gjO0+1NSOHS1p439ijI=; b=YLSNJrO3s1gpVDQko6FudzuK76nD5xKgpVS8Tz+X56ML3mufu1FPVdDlwNMoZ5PkQE URrnalETWWtydR0rislHuiqTmBcEE+qNfhixk15aPSOfbobqT07rUDhfvKU++n9cpLWO aaZlTqD3MjrX1kR/Zzj0CYpcKfV3dFL/BgfotkkwEvuwy5s9KMhHUIfhkYy4Vu8BlcDU e2lf0ZS8bnuSXJZ0BURVbgzsnjsPVfWinpaFQTcyQHmPdOhfvYaoAGlB8eeIHOv7BXjQ wmC3r9FgEyhGBumoniOrQ+H8Jr5vx3/TVuyMtT34f+WConGOd+I/Y8ubWirJYpSQ6aTF ecCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=giNR78yvsytV5FHxWOODBwS5gjO0+1NSOHS1p439ijI=; b=YcPt3fQypb31f9PxQZHGQrpxCrs/57QHX0FS1DsaeNe+yCG/2JmXbCU5Tt9j2H/POI AAD7AJP9/D8ET+5YetFvgsb+IrVYYTJvDgKGLnpl7EDk4TEsF/g2Pwt6aVMVExuBefDV kbsxq+V37vSmgoNtbzgvf4Xf1djOg4/1ZkfjQUtooYZGHJFwFvqTOrYLjcb002LdAPpZ Y/V2zkOjfxjMK8xL9qzsv0UsfjTAR7257NgLLQuhpNt3/OMxjfANRw1PKFth2NdO96Yl /4RVf/pbpw6ue1Qg3xuFEBi+HB8K5vy3bv+21Z7u/6mcqdaShO1Nu6a9WyFq3lGEwZbC 6HJg== X-Gm-Message-State: ACgBeo3FK3WjaT3KeCnvkwuZ/gSj/7VZQG1DdxwCElAym2xGkWgNEYjM Rfa/mD2T72S6J5XQJmI9vd5VDufgHbu+Ag== X-Google-Smtp-Source: AA6agR7sXDmBlWMciqbe+4LNqIfhWMB7uHeEdJ7nCv+7vYN7A9OB4qlvGi/QkvmTAHOcExOokdSc2w== X-Received: by 2002:a05:6000:1d84:b0:20e:5fae:6e71 with SMTP id bk4-20020a0560001d8400b0020e5fae6e71mr13489666wrb.224.1659455180856; Tue, 02 Aug 2022 08:46:20 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 04/28] submodule--helper: remove unused "list" helper Date: Tue, 2 Aug 2022 17:45:48 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 ac2553ba9d3..47ed24c6a60 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) { @@ -3340,7 +3301,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 Tue Aug 2 15:45: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: 12934779 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 51A03C00140 for ; Tue, 2 Aug 2022 15:46:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233355AbiHBPq3 (ORCPT ); Tue, 2 Aug 2022 11:46:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232246AbiHBPqX (ORCPT ); Tue, 2 Aug 2022 11:46:23 -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 8A997E03 for ; Tue, 2 Aug 2022 08:46:22 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id c22so7413698wmr.2 for ; Tue, 02 Aug 2022 08:46: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; bh=GN2s/F8Sm3KSVqeCD8Pg2q5VbVB1sDorMcenpqOct6k=; b=oosb+nEHjz/uMtW06rRdynSCeQdpDxeVAM5BbEDLhMwZYmTJb8z/SC/EitSagU13gf 6HmLnlYoNUpvS/2QsB/ty/3Cnsx56KQQHXDpN/O1vDuiKS+5QSY/PidYibC70c3lVFXY NSPEK0oC27wzkg7ijDrQ9/dER9V0weAESHQWynALUqCH4j+4lz5w6VBhAcuVk/62yKop u2HtDQWsNpKtY61QHx1sNJe8nDqUMenRho3yEPpLnWtsJyn5wp+bNwn5fGnhlQtqYbzz PhTmn/kDp2YhRh1uamQKTFFsgur1YfJk0IU/mjJC7CeZf9qcNJXmlHOLAOZwbK0Z9W3t WxEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=GN2s/F8Sm3KSVqeCD8Pg2q5VbVB1sDorMcenpqOct6k=; b=vQLeWAYhd+9VfjAbrmCaPQUvdFtpIoBjCm45Ae9oiJkFxUSMSKyA4JlZkCbCHfALx2 cGOG4O1VgnGGXbwmJw0R4vJbXvq24C87Lml7pQIUk0jkA0iJRSohgg9BEzAb6JiBqAM/ 6pLfskUJZL8yAgXPQSi5QnEx4bD+qLbj7n9c6hiv2JaFcRUiZXx8OlV3Ebkm3pnpHaob UzVI68EQkYfHGE8SoHKcLPwIP1HhJRCM532KKtM76ekvMZNrW4iA0RaGVRanJata3Sk7 3Du8iGQ2tjosDXi59vc63sfPy5U4MzK25v20Ynr0qFOQ0W8iX/JcRVu7VwIO5YavZUOp yzsA== X-Gm-Message-State: ACgBeo2uiU30QARdXGr45zgUuaLAepe0TGCycYbnTkt8YiQqsgCSeZJz b9UCXQVZsccxcrqUCDn9d8aWic/rl4/2TQ== X-Google-Smtp-Source: AA6agR6+oXSSN5+Zw0JD9E9erpKadFGjdfmIwFsnJmBSjC0bNVDQ51PV6TUvXmTy45wZ961u8HZEbQ== X-Received: by 2002:a05:600c:19c9:b0:3a3:469f:c1e7 with SMTP id u9-20020a05600c19c900b003a3469fc1e7mr43884wmq.141.1659455181832; Tue, 02 Aug 2022 08:46:21 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 05/28] test-tool submodule-config: remove unused "--url" handling Date: Tue, 2 Aug 2022 17:45:49 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 Tue Aug 2 15:45: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: 12934781 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 D16F4C00140 for ; Tue, 2 Aug 2022 15:46:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234969AbiHBPqi (ORCPT ); Tue, 2 Aug 2022 11:46:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233115AbiHBPq2 (ORCPT ); Tue, 2 Aug 2022 11:46:28 -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 95C2F1582F for ; Tue, 2 Aug 2022 08:46:24 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id z16so18344449wrh.12 for ; Tue, 02 Aug 2022 08:46: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; bh=SKXb+HV+WXf3P4kshAJidJGM5JintZzmRQPcBJ37QH0=; b=S9fhfn0EiAkdWLi/sY/X0+sl2tEnRaY/zuPk4/2NlE0t1asoRVkuPRahnGJiItOtx3 IcUSQRp0FQZ+qq7Dwsv3Mtbh53wfWO3rDA3qN6SQa1cNt8RJ9lOc/8u4gconFjEvqm3I ndzTBD28Qsb6dUd5eBlzjcLO2DP7f7XqSELQu8xqa8jmLmEgJkwzuyoRjrYqy0gY7WlK 35fXnvlEzvsYGteTdokfivVotrS6IUl0MftA+cLiNqW20z9n6gReSNY7jxQS1DUG7rcp OimjEJPvwDpvQHFUke0RuzNHaJZlzkPRmpTFr1zmuo8p1dqs95rhKz12E2bZfllJ8gjw xMdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=SKXb+HV+WXf3P4kshAJidJGM5JintZzmRQPcBJ37QH0=; b=BYvKe/5GOnDTqdxhPiqr+KR9ie9qGcZeSl14RXIsCpP91c9HfL7NwGJV3DuTXwtvAd 9p1F6ADPDYy2pS4S08uFKZwG1eMwaGYm9KJ6yta5b/kpX6FJCnXyDCBL4LReMkK7cz3J 6SvdvY7wNAo5FjOqkxTHbZJWQpiBVpmHLLgTJ10ZiTe4DFBPRwJSgfSsQyVl8tC+h7NA /gx7oJRS4TuE1bxGeW3pE2D/uwyHbN1S30dZxPkdmYbX5tPXLaLgzn0xMzR7N2pHHL5v 5x2MQ6rBDd11dHfqQ0pudq+QoWM56A8BN2sevL7j7JVwjmzqOlFiF+Kfeu609cu84G7v KeAA== X-Gm-Message-State: ACgBeo0q9AvsafDC9CDltL31XRdXPus3q7fbqFcgCYzcDbG3VWIC5vce FIO0S+wLkUZ0taQHly7bz8JKnALuhRcfxg== X-Google-Smtp-Source: AA6agR44gtN4O0KCx1SP4ROp/jQqwILTFnTroBGsuGruwgewK+O4pIfE2morzXrg8x9N7u7O5e+2xQ== X-Received: by 2002:a05:6000:18a3:b0:21f:d6a4:1aec with SMTP id b3-20020a05600018a300b0021fd6a41aecmr10129043wri.468.1659455182786; Tue, 02 Aug 2022 08:46:22 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 06/28] submodule--helper: move "is-active" to a test-tool Date: Tue, 2 Aug 2022 17:45:50 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 1624471badc..ad7fbd36885 100644 --- a/Makefile +++ b/Makefile @@ -785,6 +785,7 @@ TEST_BUILTINS_OBJS += test-strcmp-offset.o TEST_BUILTINS_OBJS += test-string-list.o TEST_BUILTINS_OBJS += test-submodule-config.o TEST_BUILTINS_OBJS += test-submodule-nested-repo-config.o +TEST_BUILTINS_OBJS += test-submodule.o TEST_BUILTINS_OBJS += test-subprocess.o TEST_BUILTINS_OBJS += test-trace2.o TEST_BUILTINS_OBJS += test-urlmatch-normalization.o diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 47ed24c6a60..b2fc732b5d8 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2728,14 +2728,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 @@ -3313,7 +3305,6 @@ static struct cmd_struct commands[] = { {"summary", module_summary, 0}, {"push-check", push_check, 0}, {"absorbgitdirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX}, - {"is-active", is_active, 0}, {"check-name", check_name, 0}, {"config", module_config, 0}, {"set-url", module_set_url, 0}, diff --git a/t/helper/test-submodule.c b/t/helper/test-submodule.c new file mode 100644 index 00000000000..494c6558d9f --- /dev/null +++ b/t/helper/test-submodule.c @@ -0,0 +1,58 @@ +#include "test-tool.h" +#include "test-tool-utils.h" +#include "cache.h" +#include "parse-options.h" +#include "submodule.h" + +#define TEST_TOOL_IS_ACTIVE_USAGE \ + "test-tool submodule is-active " +static const char *submodule_is_active_usage[] = { + TEST_TOOL_IS_ACTIVE_USAGE, + NULL +}; + +static const char *submodule_usage[] = { + TEST_TOOL_IS_ACTIVE_USAGE, + NULL +}; + +static int cmd__submodule_is_active(int argc, const char **argv) +{ + struct option options[] = { + OPT_END() + }; + argc = parse_options(argc, argv, "test-tools", options, + submodule_is_active_usage, 0); + if (argc != 1) + usage_with_options(submodule_is_active_usage, options); + + setup_git_directory(); + + return !is_submodule_active(the_repository, argv[0]); +} + +static struct test_cmd cmds[] = { + { "is-active", cmd__submodule_is_active }, +}; + +int cmd__submodule(int argc, const char **argv) +{ + struct option options[] = { + OPT_END() + }; + size_t i; + + argc = parse_options(argc, argv, "test-tools", options, submodule_usage, + PARSE_OPT_STOP_AT_NON_OPTION); + if (argc < 1) + usage_with_options(submodule_usage, options); + + for (i = 0; i < ARRAY_SIZE(cmds); i++) + if (!strcmp(cmds[i].name, argv[0])) + return cmds[i].fn(argc, argv); + + usage_msg_optf("unknown subcommand '%s'", submodule_usage, options, + argv[0]); + + return 0; +} diff --git a/t/helper/test-tool-utils.h b/t/helper/test-tool-utils.h new file mode 100644 index 00000000000..6a0e5e0074f --- /dev/null +++ b/t/helper/test-tool-utils.h @@ -0,0 +1,9 @@ +#ifndef TEST_TOOL_UTILS_H +#define TEST_TOOL_UTILS_H + +struct test_cmd { + const char *name; + int (*fn)(int argc, const char **argv); +}; + +#endif diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index 318fdbab0c3..7a6a8b88a91 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "test-tool.h" +#include "test-tool-utils.h" #include "trace2.h" #include "parse-options.h" @@ -8,11 +9,6 @@ static const char * const test_tool_usage[] = { NULL }; -struct test_cmd { - const char *name; - int (*fn)(int argc, const char **argv); -}; - static struct test_cmd cmds[] = { { "advise", cmd__advise_if_enabled }, { "bitmap", cmd__bitmap }, @@ -78,6 +74,7 @@ static struct test_cmd cmds[] = { { "simple-ipc", cmd__simple_ipc }, { "strcmp-offset", cmd__strcmp_offset }, { "string-list", cmd__string_list }, + { "submodule", cmd__submodule }, { "submodule-config", cmd__submodule_config }, { "submodule-nested-repo-config", cmd__submodule_nested_repo_config }, { "subprocess", cmd__subprocess }, diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index bb799271631..5f4f69dee81 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -68,6 +68,7 @@ int cmd__sigchain(int argc, const char **argv); int cmd__simple_ipc(int argc, const char **argv); int cmd__strcmp_offset(int argc, const char **argv); int cmd__string_list(int argc, const char **argv); +int cmd__submodule(int argc, const char **argv); int cmd__submodule_config(int argc, const char **argv); int cmd__submodule_nested_repo_config(int argc, const char **argv); int cmd__subprocess(int argc, const char **argv); diff --git a/t/t7413-submodule-is-active.sh b/t/t7413-submodule-is-active.sh index c8e7e983317..ede6f02dbd5 100755 --- a/t/t7413-submodule-is-active.sh +++ b/t/t7413-submodule-is-active.sh @@ -1,9 +1,12 @@ #!/bin/sh -test_description='Test submodule--helper is-active +test_description='Test with test-tool submodule is-active -This test verifies that `git submodue--helper is-active` correctly identifies +This test verifies that `test-tool submodule is-active` correctly identifies submodules which are "active" and interesting to the user. + +This is a unit test of the submodule.c is_submodule_active() function, +which is also indirectly tested elsewhere. ' . ./test-lib.sh @@ -25,13 +28,13 @@ test_expect_success 'setup' ' ' test_expect_success 'is-active works with urls' ' - git -C super submodule--helper is-active sub1 && - git -C super submodule--helper is-active sub2 && + test-tool -C super submodule is-active sub1 && + test-tool -C super submodule is-active sub2 && git -C super config --unset submodule.sub1.URL && - test_must_fail git -C super submodule--helper is-active sub1 && + test_must_fail test-tool -C super submodule is-active sub1 && git -C super config submodule.sub1.URL ../sub && - git -C super submodule--helper is-active sub1 + test-tool -C super submodule is-active sub1 ' test_expect_success 'is-active works with submodule..active config' ' @@ -39,11 +42,11 @@ test_expect_success 'is-active works with submodule..active config' ' test_when_finished "git -C super config submodule.sub1.URL ../sub" && git -C super config --bool submodule.sub1.active "false" && - test_must_fail git -C super submodule--helper is-active sub1 && + test_must_fail test-tool -C super submodule is-active sub1 && git -C super config --bool submodule.sub1.active "true" && git -C super config --unset submodule.sub1.URL && - git -C super submodule--helper is-active sub1 + test-tool -C super submodule is-active sub1 ' test_expect_success 'is-active works with basic submodule.active config' ' @@ -53,17 +56,17 @@ test_expect_success 'is-active works with basic submodule.active config' ' git -C super config --add submodule.active "." && git -C super config --unset submodule.sub1.URL && - git -C super submodule--helper is-active sub1 && - git -C super submodule--helper is-active sub2 + test-tool -C super submodule is-active sub1 && + test-tool -C super submodule is-active sub2 ' test_expect_success 'is-active correctly works with paths that are not submodules' ' test_when_finished "git -C super config --unset-all submodule.active" && - test_must_fail git -C super submodule--helper is-active not-a-submodule && + test_must_fail test-tool -C super submodule is-active not-a-submodule && git -C super config --add submodule.active "." && - test_must_fail git -C super submodule--helper is-active not-a-submodule + test_must_fail test-tool -C super submodule is-active not-a-submodule ' test_expect_success 'is-active works with exclusions in submodule.active config' ' @@ -72,8 +75,8 @@ test_expect_success 'is-active works with exclusions in submodule.active config' git -C super config --add submodule.active "." && git -C super config --add submodule.active ":(exclude)sub1" && - test_must_fail git -C super submodule--helper is-active sub1 && - git -C super submodule--helper is-active sub2 + test_must_fail test-tool -C super submodule is-active sub1 && + test-tool -C super submodule is-active sub2 ' test_expect_success 'is-active with submodule.active and submodule..active' ' @@ -85,8 +88,8 @@ test_expect_success 'is-active with submodule.active and submodule..active git -C super config --bool submodule.sub1.active "false" && git -C super config --bool submodule.sub2.active "true" && - test_must_fail git -C super submodule--helper is-active sub1 && - git -C super submodule--helper is-active sub2 + test_must_fail test-tool -C super submodule is-active sub1 && + test-tool -C super submodule is-active sub2 ' test_expect_success 'is-active, submodule.active and submodule add' ' From patchwork Tue Aug 2 15:45: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: 12934784 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 7E5B6C00140 for ; Tue, 2 Aug 2022 15:46:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236308AbiHBPqk (ORCPT ); Tue, 2 Aug 2022 11:46:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233263AbiHBPq2 (ORCPT ); Tue, 2 Aug 2022 11:46:28 -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 B919A15FF1 for ; Tue, 2 Aug 2022 08:46:25 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id b21-20020a05600c4e1500b003a32bc8612fso7142246wmq.3 for ; Tue, 02 Aug 2022 08:46: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; bh=bPQgxu6eeLdv8E/NpssVQzROEiUxCAW1M4qDI651Ias=; b=C/LNKgdzqflzM+8I27vHIItK+9Y3BilCSToeC2HGYPVxAjW37loYMIMs6R9ca3wDz2 5Vs7Lng4bBHM3PrF6e2VZKypDCf3FME/5wuOWa7XHMYp99I0xFF4Sk/IWKOTCSqx4vPB OS+JIb7kMSdOKrYnftJSKjWaI37NgoUqf9xCgtOowZdYSXYkocAyKfMyLMhv3ToVMu2U OaZ64xyv9eSY0TSskn4ihkT+bnKa1JonpHApwR7g9kya7mg7Y2Js/CViFEB+AqxS12zO fzEEKO1kaWfh3thKcQTN3S7VzgcVDetl72pXdXS8WULLq7dbwLUPy78mawn/K0of6e2h jQKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=bPQgxu6eeLdv8E/NpssVQzROEiUxCAW1M4qDI651Ias=; b=KHP7925l01kk9fa3NMuZbGHMZ+cxnOXoryw9NEjHHnaMHFGT1ZcKgPfcYDFIweiRRI 6OjZLh3/LIRwikvDytUOk+nE/fO+gwQsr23RIQr3KnwH8rRz5hULXtu1c5wrq4x0eV6Y dpVEvns077lzBEnGj+l2oAuCsUbku8iaN+2lCwUocKLrW9TZjv0od+1XS0zEetCdfUkp Cnah+UtbVsL+MqbbJqw7jhiEnagWNhzBQuQiK5JBeuEBeLBDEJmoy5fjsOTBas+kB08b p/dtuLroynaSZvkqSA8tFfaqWMsr8pkAN0aG/+zwwJIJub1pAkfUhDN1VTXdKC22EnHo aX5A== X-Gm-Message-State: ACgBeo1HL54065p9/3Eelr7Pn8nZAHcr8TatGlHEoRs/5MYhXmyxcGLJ jtzGnDQvabvaQfxrFOQIxbNmrPLp8WqQjg== X-Google-Smtp-Source: AA6agR5tS9IP9Z1klj6GczH4CooTcT9q4+/bkB/mXLHPJplpBCras9aCAL1lPJny7XZJVXfDdQURZg== X-Received: by 2002:a05:600c:1c96:b0:3a3:10b6:e84f with SMTP id k22-20020a05600c1c9600b003a310b6e84fmr41389wms.175.1659455183744; Tue, 02 Aug 2022 08:46:23 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 07/28] submodule--helper: move "check-name" to a test-tool Date: Tue, 2 Aug 2022 17:45:51 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 b2fc732b5d8..06307886080 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2728,29 +2728,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 { @@ -3305,7 +3282,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 Tue Aug 2 15:45: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: 12934783 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 CF730C19F2C for ; Tue, 2 Aug 2022 15:46:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233839AbiHBPqo (ORCPT ); Tue, 2 Aug 2022 11:46:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234193AbiHBPqg (ORCPT ); Tue, 2 Aug 2022 11:46:36 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA3C9165A5 for ; Tue, 2 Aug 2022 08:46:26 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id z17so13721343wrq.4 for ; Tue, 02 Aug 2022 08:46: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; bh=E/a/8QKRrQMyxQKtXn21MPc0x89nweVxpUw4fdGsMeg=; b=nRt1UuDL+5GUr5dmR0A1sbadJ9jbNCAB2q+/vvYOI4gl8L8wHo6VU4tTw+Wnto4kOz ezflDPlXbXv9lhzd3ALpREoR1jE36N1MmVG0sKotfjvD6CEShVjwxN2VIfERDs3M51uP mjlS19Gk6sMcsMRzqr+IAgeer+bpp/aqgReiFY5YQgZG24xCrpJvJoc1B7UpbUyh5UZX odvBlTS4xRSFmjo1emeRI6LtLZjmZiYxgQBuppZ+ztvOELSy38tfj8LiCV1JsfaE4NuY LI7l9ZbGE+u8VzyHEi4J/Vp8Jaj7RyvhPJXUxKAfKDT3aG0lL/guXMGZ7jL7d2fezkSS bE9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=E/a/8QKRrQMyxQKtXn21MPc0x89nweVxpUw4fdGsMeg=; b=a3DGb4pf3+7M3eS7VoikYyhLqs/Obhgrp+Q3KXFvi6emeP4ZXtxmVdh41IbqZaodyI wEyEATR8G3BmAid73aIhyvMOHH6CD/Sv5quW317YqiJ5xnhALTKFSGEAhxIYeX8S7a+w LI5O8ipQJxs6rTSIZhpmtneSmgphFV9Y+43t2MBUBZetIFRoT/dzAkTuqvmLVdk8YbD6 KuiaA7sAfVNCrRSzOdUzXLyYrZAB+wOMtAgs6WMNc6fRZny9vPBy0ktxPe235E2NBi2r NEQAXNXpfoj+/fe+9K8i+s/C4fvLjlV2YLItZM02DlmdaFg0mNHaWYJbqml6PaptNYvy HBGw== X-Gm-Message-State: ACgBeo2Om9+n7djOtlHDeyCB0JaigeLGumA9gpBRexaIdp8blpaHc1k0 ooHOcZn1KyVRFzXsHvq9DbBA8UKsqF6oZg== X-Google-Smtp-Source: AA6agR6uKI11mnrGteYbIybfQ1d5Y5eYl0vEQrxf5SJnrUIzmrk+kq6ZpvqgEWOeGVnCLqfy+rLpQw== X-Received: by 2002:a5d:6d85:0:b0:220:7084:35e9 with SMTP id l5-20020a5d6d85000000b00220708435e9mr2582660wrs.11.1659455184834; Tue, 02 Aug 2022 08:46:24 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 08/28] submodule--helper: move "resolve-relative-url-test" to a test-tool Date: Tue, 2 Aug 2022 17:45:52 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 06307886080..246457ec2e9 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) { @@ -3273,7 +3251,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 Tue Aug 2 15:45: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: 12934787 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 D5902C19F28 for ; Tue, 2 Aug 2022 15:46:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236920AbiHBPqz (ORCPT ); Tue, 2 Aug 2022 11:46:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235032AbiHBPqj (ORCPT ); Tue, 2 Aug 2022 11:46:39 -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 D093D175A2 for ; Tue, 2 Aug 2022 08:46:27 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id r1-20020a05600c35c100b003a326685e7cso762765wmq.1 for ; Tue, 02 Aug 2022 08:46:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=eaVtMQlkekBX6/mxnh+3jJjg/o/gh0wdCTUxJxh8yl4=; b=aPitNvqOnwy3rR2gREMVaYSnDPNAFrTs/FaSnW6jUUS/A/mBxo+u7x5w7oabSYshEr hjh+89xKc0fa5+bgFbZWw2mLg8uj2CgU444ZkuiAn3qiM08riNliz2+jerFN0sFd+TX0 QgH9FA61v6lI+1MVYhO4kzM8XUXulc8L3DXCIaTME+xAo+wAfDt1mVqsjMPoPfOooWhc mVv57qB8YD6cWHWNsUB6Q7SBnLOScczEqLXLDXL0omVV3BsFDoBI9lBhXn8/4COGZfpa FQMsyeZPTHvR1Nx8KsbydVRk4yJlQnjn0zgO41bD4HEsbIZZL4bN/u2j9ea/vr2Wk07E VF8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=eaVtMQlkekBX6/mxnh+3jJjg/o/gh0wdCTUxJxh8yl4=; b=IniGwYOpbMcxKkiNMxUw1QhZUbjuhvVjpUyehCiKy4CIazFbVXsilhxKir4eSCVgqG LgVeybe1L10GKJP2umO32uPHT7HDXljIu6dbaklbthc6Jzf11W1ssiPM0ETSsrEEv/Oj jDH5MWIaVfsOq/VqSDMlhVFZdrQSuW+xZNmkyaxqduMmoq2Kaz22brp470xRoeISP8U5 l9wxyffnih3NvR4EGiqW0GS1VOSmZUTIzIjMT/cj5CcYT4xn14LsZTgQrRjf1FHexAwY fn6gPb6/SrnCXBZyosq2ExGe8Tf5GSTu80MfOKvFfO3Qx2Wu79jJWg2G5pX14fDPIldZ F4cQ== X-Gm-Message-State: ACgBeo3LYuDMAhdJu4U7PxTXvg1nPApf6/ROgoaW41/xYD64U0RADlgT 14p0GXLmjZPb+fG6SHDgLsYB4Rc//7RdhA== X-Google-Smtp-Source: AA6agR6lIV4kSdjNV8N0uBbbpIzJXdOTpdtooL/R+X9d8/g5uontvrsusncwbAbj5MjqeCoxrZi4YA== X-Received: by 2002:a05:600c:2211:b0:3a3:2149:88e1 with SMTP id z17-20020a05600c221100b003a3214988e1mr78515wml.8.1659455185974; Tue, 02 Aug 2022 08:46:25 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 09/28] submodule--helper style: don't separate declared variables with \n\n Date: Tue, 2 Aug 2022 17:45:53 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 246457ec2e9..53b9e14767d 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 @@ -1082,7 +1076,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")), @@ -1094,7 +1087,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 @@ -1251,14 +1243,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 @@ -1390,14 +1380,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 @@ -1666,7 +1654,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"), @@ -1698,7 +1685,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 ] " @@ -2486,7 +2472,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, @@ -2530,7 +2515,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]" @@ -2679,7 +2663,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"), @@ -2688,7 +2671,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 @@ -2712,7 +2694,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"), @@ -2758,7 +2739,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() @@ -2789,13 +2769,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"), @@ -2830,7 +2810,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), @@ -3129,7 +3108,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")), @@ -3146,7 +3124,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 Tue Aug 2 15:45: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: 12934786 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 6EC94C00140 for ; Tue, 2 Aug 2022 15:46:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236860AbiHBPqy (ORCPT ); Tue, 2 Aug 2022 11:46:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235064AbiHBPqj (ORCPT ); Tue, 2 Aug 2022 11:46:39 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C93217E13 for ; Tue, 2 Aug 2022 08:46:28 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id v5so7419209wmj.0 for ; Tue, 02 Aug 2022 08:46:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=+zjfSt/Y5PoTEIr//LzW1kJ0b0Zhl4mqyGuR4k24GlU=; b=fgWIRgt8uA7JrpjsqFaXOQAFtD+zC9je5/L7a1pYlDpLlziQmcfz3H0j4J4obzhIRV /qtWPSGpLu6CRsH0POvAmngFBJJxSjh6qjFo6v1tJzPwo3IYJuM+gHPnqsyHobYYG+OS Fb6W0851Ae6hnOqc0Gh5oDQj4pIxc/c8b6qEITt8Xd7KQspWw7rh2+9LyAROGGkbFs/e ZaXh10ZnabsZ6LU0H0Q32QXUik9RXqY0MF/G764sw3rPuedcfUAnzI0XP8cEkPwS6UEw 2NepBWNqlTHC/omiDnmCMz5/3nWd28O3MkIvyFmmoKyQNhTat6WefGf5fOTzgE+JqaQQ lBwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=+zjfSt/Y5PoTEIr//LzW1kJ0b0Zhl4mqyGuR4k24GlU=; b=Ocr0i2/1TJPOfckYcjliISm7nRfPAwLY3sVOB4bX5PBqmYdim4x/L4PNVEgIbQNY6M ejH8pRx20JnLu1w7uydikRbt6q1nTRxRa/9cLPLXfIrT+dTja9X1U50hbJd8b7aQwsRI L5tic8TWir+tB80mn5AwxV5rbqbW6kNfQJkZi/nrGzTyDxCEkR8tdI+W7N4Oj9TRH4Dk 71sJHnw9y3VEPXUQDBygUy/hA5yNOwu0Dt+mqdorXaNqZgPeJvW/VdCS3XUt1HTi7sLG dUpqbkDsR4uplFMPdlRnYLS+5JXzqg8mfT44KrovedObSFC3a/a93wFftfF0TJRelP/O dt7g== X-Gm-Message-State: ACgBeo3aXZdEiqyo91sIoi20bNouNWVuDHMT7GfecCQFQT6lBP9OkYFj 2x2qw509WZ7pyP82Js3EKNeRJ6EAloCA7w== X-Google-Smtp-Source: AA6agR6/KA5DHdKQXQJzVH4K0fQmqUDJTYEHjxS99XHE5l/zNfLsWMlvAIoTmesDjWqtHbcHQXnUrA== X-Received: by 2002:a05:600c:4e01:b0:3a3:342:5f55 with SMTP id b1-20020a05600c4e0100b003a303425f55mr63901wmq.150.1659455186972; Tue, 02 Aug 2022 08:46:26 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 10/28] submodule--helper style: add \n\n after variable declarations Date: Tue, 2 Aug 2022 17:45:54 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 53b9e14767d..15bf89910f4 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)) { @@ -1158,6 +1164,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); @@ -1233,6 +1240,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); } @@ -1312,6 +1320,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); @@ -1348,6 +1357,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 @@ -1585,6 +1595,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); @@ -1935,6 +1946,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); } @@ -1967,6 +1979,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++; @@ -1982,6 +1995,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 ++; @@ -2005,6 +2019,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; } @@ -2016,9 +2031,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) @@ -2051,6 +2066,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; @@ -2091,6 +2107,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); } @@ -2340,6 +2357,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); } @@ -2872,8 +2890,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; @@ -3180,6 +3200,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 Tue Aug 2 15:45: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: 12934785 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 0D38EC00140 for ; Tue, 2 Aug 2022 15:46:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236017AbiHBPqv (ORCPT ); Tue, 2 Aug 2022 11:46:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235018AbiHBPqj (ORCPT ); Tue, 2 Aug 2022 11:46:39 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E54DF17E0C for ; Tue, 2 Aug 2022 08:46:28 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id j1so10034546wrw.1 for ; Tue, 02 Aug 2022 08:46:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=YN8/zi/AIprQvY9R0DohmeZAZe8BOXfMROBY86izIT0=; b=l9ee6zizO3joL8WUHQl1PipWDm2p/a5ZPTYHDJMVoSogOnV86QHWF/qRd/d3YT1APF R/JiBjk7MtUNaMHXIoYjnerabDx1ZA92eehNS7Z1a2Gvy8VUAVVQZAD4MaBi0TJsYre2 HYlGeN60eddhFfxgntFzwrdnfLseFW0/hQ5O2MWz4Mz1pF30jgR3XRAWeKX1zEiPEBfJ mPwhqq0jQkoTMmx2H6UAQgmaNP3VJg632y7X9bTilrhE7zet3suuyf5LZmbI0ykcJH6J sh+cgBqkEn7nJPFB+cXAkP3OoUlymRT2tJxdgL4iFGd12okRijwD7R0RsIHJwNugf6dt ochw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=YN8/zi/AIprQvY9R0DohmeZAZe8BOXfMROBY86izIT0=; b=ZjhTPrA+2OybWYw1nmL8OQts56JM0Z3ihRsK7h+IJDI5M4LBM1r9yIeKcyJpFfxkMV d0I7cBfpDM5fLwZue51yBSO12tX16dLmqPx6WC4b9rT+AjUmiPAovVEzKxtVjiESE4h+ 2Hzoybk0nqgSGIdDsPMZ+DBptWS9QV50FBlyJxF5b4gm6fsHfOCny9AcLo6S8PsGEuab WRyjst/YtsUPSSBnJUqYWq+0xYzQjbpwM5WB//5GBZazmwDVHBbEgC+piynw8/F3RtWM rTfS1uHX3VgfykFhK5AhTW6rGHl1Kb45Ze2MsqzAPHUjNK5Jg030AVsMxOPtkkSwXN7e jt1Q== X-Gm-Message-State: ACgBeo05J2vS2T3i1uI/QnPfYEs9u+Nv7MeppRFyenpqJwtuNP9ezIbW XlZZeoOvXcYJJxCL/ditTpJaucP7F66t6g== X-Google-Smtp-Source: AA6agR4uNfPaIaOJTpu4AXlpzUQL5TTQUDSxyS6lbwnPj2EQnswhxetyebNore3xmzeKziMGkCgS0A== X-Received: by 2002:adf:df0d:0:b0:220:5eeb:c0b with SMTP id y13-20020adfdf0d000000b002205eeb0c0bmr8412037wrl.55.1659455187985; Tue, 02 Aug 2022 08:46:27 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 11/28] submodule--helper: replace memset() with { 0 }-initialization Date: Tue, 2 Aug 2022 17:45:55 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 15bf89910f4..60165a848a2 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1664,7 +1664,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"), @@ -1704,7 +1704,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); @@ -2488,7 +2487,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), @@ -2546,7 +2545,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 Tue Aug 2 15:45: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: 12934789 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 B4D2AC19F28 for ; Tue, 2 Aug 2022 15:47:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237109AbiHBPrG (ORCPT ); Tue, 2 Aug 2022 11:47:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236599AbiHBPqu (ORCPT ); Tue, 2 Aug 2022 11:46:50 -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 4BB0617045 for ; Tue, 2 Aug 2022 08:46:31 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id v3so17488127wrp.0 for ; Tue, 02 Aug 2022 08:46:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=RyRyFnQK0UAb4/oaWKsyQAK+QbbZ/o2Q8pSMw6T4E/c=; b=lVIiDpcF6AaHIhmk5rpvwiLSUYRbkfuZta2yWUr1X+tJdqjJfB300cApLcmihtPsV6 dxfNkGqBVOaAxD27R2u7xh1KCW21G4kZWzv/gjpas8EHfvbxogSY+0Ty1J4F3XCzUXsy f7BxLgSgpJKjH+uPADKx5MOT4pmwde8rbTAotRV9f3hcoeudpZRhkg4APPA3WlQ1KL5c wGmPgpLe5M24t2EqwWbV84HdrTxKKwgT9O8efVfgamHXuiafIYrCXed2LIaBnW1AP90U KNLtOiOVrdAhhnjljgPVTQQBZG2KyZra2Degd/yX3znfTMjPOXfyDPUkMaRbTK1a09bX i8Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=RyRyFnQK0UAb4/oaWKsyQAK+QbbZ/o2Q8pSMw6T4E/c=; b=YPUnofg/R3tps7n7VPpp0o+O8aWXCJ+AjNdpioNMyxul22uJbPUf+dfIJhp49su82n mU9xpR9RTOT2k8D7Fd/7pix9ixC71rv8V66e0uQmpW5MuH5fcwWU1pRHYe/ee7ujW97I p3JBC0LCGPAKTNfhHzKRuNbgY2PC0G1vBJP6aHDnFKHGDlzgzOUzh8EEiPfkA3AA/OE8 RaNFCuaw9xTLEdcvMlMWRFOP+WbQtv2uaP/q7OR+U+DizoM3+IzFy1//9O8+N9w+/UYA VRWdz1Gdg+48RLbAV5DWEEAxmF//uIk7MhNmnP6zkl8pMQ7E8cYUffyb8wRwf8lYfQPK bKWg== X-Gm-Message-State: ACgBeo0u1kHr3Mn0Ha71joMQmhQ7POMLkFiUoXjVp7OM39CLZX+mDBrU bqzPwAPGBw1UxG45Rqd948FDgyoV95Nh8g== X-Google-Smtp-Source: AA6agR6CQq4doWm5mIUZLbDA4DX0/kiRRk1Pgi2PobKKGsA3X1K4rewlBWM+htEKcwLo/DTTDY4qmw== X-Received: by 2002:a5d:514f:0:b0:220:6b4d:f806 with SMTP id u15-20020a5d514f000000b002206b4df806mr4439167wrt.137.1659455189089; Tue, 02 Aug 2022 08:46:29 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 12/28] submodule--helper: use xstrfmt() in clone_submodule() Date: Tue, 2 Aug 2022 17:45:56 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 60165a848a2..63008970f1c 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1568,12 +1568,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 " @@ -1625,14 +1624,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 Tue Aug 2 15:45: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: 12934788 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 6E3D0C00140 for ; Tue, 2 Aug 2022 15:47:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236451AbiHBPrF (ORCPT ); Tue, 2 Aug 2022 11:47:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236476AbiHBPqu (ORCPT ); Tue, 2 Aug 2022 11:46:50 -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 CA8A218364 for ; Tue, 2 Aug 2022 08:46:30 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id q30so13989062wra.11 for ; Tue, 02 Aug 2022 08:46:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=ePft4F1GYizENYuUn+2LUiiIQoRJcMjj3TGiEojPj8Q=; b=RIibjcIgaNROaSY8NjieziCIEYSPsaIf5Q9u0sLC+SKgNo0fBbpFTPtFhhOzeCY63x Av9uftTbm4nSW/awOpWLxW4dtYpTpUnN3bMDxehEyK63OfXWFJFKKR2DZg31A2zLzJen 6zc23UX4g5f+lphFqqMe8LOAq0jYUJpNY3cZZxw3utc3YVl1VuWWzb7TmClnYlZ7IRkV v31MeyM1RdZw1JitIB15BfqwQC/g1Ft3VsZNfu7NooBrr9UcmEgIfzUnN4tHjOF98Xsj V7N8vu+Y1Qt6u3NLUFjr1k/TqNjVFIY5Xihf8z0nElpDNd9jTD3uLWUu48KZF1+MLZJG 4TRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=ePft4F1GYizENYuUn+2LUiiIQoRJcMjj3TGiEojPj8Q=; b=DFN7cNBhm257gRvhOghZRCFo7YOp6LqOHr1P65Umxd/5WkJp/VrFUg8hYrrKPJ6iel Ewo+VZPgi/Rwk1wkJiU55qaDJphSCEYgTHoFP7WxNdWVPyi2XDjCikVIE24iMNVjwTDr ybgco7MzlO47dcGKA8Gu0QqIWDgeDbf/Tv/3f2w2O8eO9Y2A5MooSwvjmva69BwucPfK H9XXa1xQVEKxW+sOztCwV1OUNfNJW7Zz7aHKSM61hN372kIuKtxwj8BXb5cuIFvDLJcQ yncQVXnfjgUTPrf2OnljBguJdcOwpxGlihfj7zIB/4j1mCt9WXZqOqifiXM+0IXuVr9n oVgQ== X-Gm-Message-State: ACgBeo2YzHXnrNQ/lNCOVwfoZeZu8K8NTgWPgmQo7RIPN7O/00m/Lx1o KvlWKgcTxw5C5UgoYJpN3pxsAfu1TXex+Q== X-Google-Smtp-Source: AA6agR40HCD+XuHaLKlzLipMgYX9I4GZeIkg9uHjEH3fCnK8e/863Fa9rtXG3Wpf9hueScwbzYN4Sg== X-Received: by 2002:adf:fd0d:0:b0:21e:f27b:10dd with SMTP id e13-20020adffd0d000000b0021ef27b10ddmr14015072wrr.295.1659455189935; Tue, 02 Aug 2022 08:46:29 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 13/28] submodule--helper: move "sb" in clone_submodule() to its own scope Date: Tue, 2 Aug 2022 17:45:57 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 63008970f1c..fe32abd45e6 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1557,16 +1557,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(), @@ -1655,7 +1663,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 Tue Aug 2 15:45: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: 12934791 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 644CDC00140 for ; Tue, 2 Aug 2022 15:47:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237205AbiHBPrQ (ORCPT ); Tue, 2 Aug 2022 11:47:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236926AbiHBPq4 (ORCPT ); Tue, 2 Aug 2022 11:46:56 -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 1E2491CFC4 for ; Tue, 2 Aug 2022 08:46:33 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id j7so18404037wrh.3 for ; Tue, 02 Aug 2022 08:46: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; bh=OQGyNUffDfNdU8jOI/BHEdz/m/0IUD5opA9lyM4N49Q=; b=fCIFOVfo3ICaINAL4ZAzQZtxVbH3+0Zcmz5FSSA8C7IEPGNCHZUGSq8aCpGj0dGlTb iglBxzkEdJSU0ATANKYIHOD5M/ajSPGMXHxefosyjP4oWYwwgl/w8XivJ3soGUuonnaG V9m5eRDWNrb54nCsVmszayEh7nvrw87szLQQ3OzcxsMGl8gUZhCnNWfwmsleq6OJFj0Z zDWzDcTch8S9GDFgdNHYAiAc5chL0QajiuxzeBWbg/i1fSpeXXVRE4kUr6M7c6XGSVmH nFRtKhQlzcZXjubzqueM2Vaeg6oVFMp7m8BVCb8hvKrZTpp7IwXTovveAcCMizyVFiVa LqpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=OQGyNUffDfNdU8jOI/BHEdz/m/0IUD5opA9lyM4N49Q=; b=P+P/RBB/niKTKMBKZbSzoWqih/8Y7hxDH+xHXHLsMG30Rpflmi0nXzZkuW/Fulb1hd YqjuXTz6lTpLSR75tBhBcqkPfExfdeUaS9iM1WVzzMDpGkyAr3SzQfOuFWtRgfJ1z/BP DaUUFgiOy7NzqnbSVkZTdhgKlLbLoY6uUdAYx//J9DFiK+gYe7WX8A5wJO2ASyhRf18a 1n5Rgh0Kr/D/HZlEsIGqbcAxBqCNyfMfhFpdG0GZVX4xPsb6T5GtGUmwQqDuksI0p3Xt aeHYnokEJdqbreCc4i40du8mHuzn+LbhW7wAN/WgXemh2bACuER1n+atbKF7pIxhi2dU cbTQ== X-Gm-Message-State: ACgBeo32znKes/ucVhAOSV7znx8UotEYOID4EqtFcKttiTtj0tyMtIAG 22cd6Nb8V/8LoQcdwOSJlp/V/GeeyLOV/A== X-Google-Smtp-Source: AA6agR5SsN89uwFp9M0XpU6F+HiF5sOjSuAIYXvVC1Zy5rQdo1qqdUhmCvO6dxC2S2iUdJAR/mrE2A== X-Received: by 2002:a05:6000:1883:b0:205:c0cb:33c6 with SMTP id a3-20020a056000188300b00205c0cb33c6mr14349828wri.39.1659455190823; Tue, 02 Aug 2022 08:46:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 14/28] submodule--helper: pass a "const struct module_clone_data" to clone_submodule() Date: Tue, 2 Aug 2022 17:45:58 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 fe32abd45e6..6b4ee8a31bb 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1434,7 +1434,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; @@ -1442,7 +1441,6 @@ struct module_clone_data { int single_branch; }; #define MODULE_CLONE_DATA_INIT { \ - .reference = STRING_LIST_INIT_NODUP, \ .single_branch = -1, \ } @@ -1569,18 +1567,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 " @@ -1590,7 +1590,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"); @@ -1600,10 +1600,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); } @@ -1622,7 +1622,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); @@ -1630,25 +1630,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); @@ -1673,6 +1673,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"), @@ -1686,7 +1687,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, @@ -1725,7 +1726,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; } @@ -2913,6 +2914,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)) { @@ -2929,6 +2931,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)) { @@ -2968,13 +2971,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 Tue Aug 2 15:45: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: 12934790 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 8661FC00140 for ; Tue, 2 Aug 2022 15:47:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236621AbiHBPrP (ORCPT ); Tue, 2 Aug 2022 11:47:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236833AbiHBPqu (ORCPT ); Tue, 2 Aug 2022 11:46:50 -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 904B919C3A for ; Tue, 2 Aug 2022 08:46:32 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id b21-20020a05600c4e1500b003a32bc8612fso7142405wmq.3 for ; Tue, 02 Aug 2022 08:46: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; bh=cyB0mlSLLQytoQq5Br7kwXLQZI2uyJwNlEeeW6EIhT0=; b=SQH5GjXScqnSegEhEcR/uOE9P+oYpBnqTVLvpArd2U03Vhgky65aCkQ0Yn8rht7vNY HL/ONIYgwHz77BLq1q6poWpeSwvazypj9LSP1dCrkbh/VwZ7VJd1O6wEgpebzGvrUz4B YNBemuAhzyL1Yi2vrqpaK8OG5g9grgmliazncgYa6ROBQNzs/1j5iRvUVDOITWzA9Twk uF6Mjhd/8liyvmBPHXsJu4x/JNYoC4QNgn8XX+e7carttZXatHuDuXKbkdQCIhEI7MIS ZFv6wAwOQEPxe/N/JqeElHC8xllt7URdnchD/sQIFv/w/TGoazRbFqUz42pNnI83F1ea l5Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=cyB0mlSLLQytoQq5Br7kwXLQZI2uyJwNlEeeW6EIhT0=; b=QlZVIWqREcB0FnVnbcYtE0fNxzmfZVkBBxBY7S1ww7IackRA40AL/SNnjrxkqHeEor C/vZ/kL4Z/Gz05d+w2GA8umzGCi9kY0UnJJYi4Kcm3RXSCkBkO3vskg/qTRUBH2Sxb81 HpT85X5xzwgbFqAFndbtIRGwctnEQjPz4hlos2rWloAE/qnKo8hEe6kyht+/BndUAz92 M8u+2v45EB8MjPtT00rWjps1M5zWOWbcca95Xphic+lVE/BczHaRn0F0L9A8mTj0GrZh /ZTsyWeqpzYbVbKDoNp1OR5nDGWGXYmNQZCCJt8gtIr6GYOrgbAl6VSibqyVGfNkczqq pb2g== X-Gm-Message-State: ACgBeo0CUPOjxR2UOuEViK5jBIU41UIalk4hhlaZ2hyLdqT+DPB++noU /R6ZFGODX4hGAeuWmIeEYEwN5WrEEKNtzg== X-Google-Smtp-Source: AA6agR4OMIsJ++lUNeVQ4J0ZixZ+U5uvooiwpHazlp8Uak52p6fm22OJh/Arih2e0bRfrvGcDTQhCA== X-Received: by 2002:a05:600c:348e:b0:3a3:5515:98b1 with SMTP id a14-20020a05600c348e00b003a3551598b1mr70338wmq.110.1659455191813; Tue, 02 Aug 2022 08:46:31 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 15/28] submodule--helper: add "const" to copy of "update_data" Date: Tue, 2 Aug 2022 17:45:59 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 6b4ee8a31bb..1391316cde2 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1777,7 +1777,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; @@ -1862,7 +1862,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 Tue Aug 2 15:46: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: 12934793 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 61304C00140 for ; Tue, 2 Aug 2022 15:47:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237353AbiHBPrb (ORCPT ); Tue, 2 Aug 2022 11:47:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233108AbiHBPq4 (ORCPT ); Tue, 2 Aug 2022 11:46:56 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB4E518369 for ; Tue, 2 Aug 2022 08:46:34 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id z12so8295998wrs.9 for ; Tue, 02 Aug 2022 08:46:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=SNemw1CHPXvRNtfpgXSs58w9pwqN0NS69vSx7kx33CM=; b=D29GAhil5B3o7TEd5CbSyylMiZnQCwVawZKmaB1mlnDNCDPNJPCGuZXujsuxO/7i+A NHT3R/ula+1IBVUJRe4JGfeAZyEw26xY684BYMgHpkKLUhQrpLDSWcVbbjNKlmYdrunQ PxYxQjZL3QykYwCjR37+f9JbCIcl/V8qR1fgWn2JYwRmIbLaU7MbZl63I5FCuphojrsk Wb6W8tras43ilF3/KVyjRkU/lqqdN67JEPfAOZIllFUJgMrR/Kv1D2NNbkUp6dNZ2j73 +kgcThLDiWqqM+nSYeHggJ7XGUyrwmOSdtkXsGcu8P3OMxI54DhtKDWKvOWyNqv4Q5bv ETPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=SNemw1CHPXvRNtfpgXSs58w9pwqN0NS69vSx7kx33CM=; b=zURbSFjACJENZXwVvXb4329hrAIvlw95lZhZr2nP5d6+bPFjKn17xcfBAGM59H/dDM /4o64TxPkWgTwwAKyvPREs/nSPWd4YZQxW6vwTyyrMg4jxtrD2KMbg33Ml+K8VKRdn8d 2vltSA+35yly0+2J3c4sfqflrO3jbJ5vbNzymS55T/1jciE30hzOQXJfKexqWnKlXFkW P/EzJ4y6rGCmRpPZWl/ll2ia0JvjdoT6V8HuOgb5rPo62vFa2c2qo95rH89ZThoSX3Ls oxVIqMc94FeHaPdatlqcIRgm/HdKL/t5XxPNtPCJaIV/U6rvljzNZIqP+1SxGlXOm1qm LEDQ== X-Gm-Message-State: ACgBeo2l+0A1UOfg8b4Cjuu4rAOvzqcne7jWwC/6gXngBxyUcMg11IIx GDN+IRfyUoAxpeKWp8aJU+jp4YJlWHeI1g== X-Google-Smtp-Source: AA6agR6rCU+0PnFyUrC7fpbsTGZWczKTwvWiLZ87uHJLl7Z9Gz7R5C0iDjw8Z30YDmMD5Ns2HzyoyA== X-Received: by 2002:a5d:584f:0:b0:21d:bcd6:5c8e with SMTP id i15-20020a5d584f000000b0021dbcd65c8emr13305735wrf.60.1659455192893; Tue, 02 Aug 2022 08:46:32 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 16/28] submodule--helper: refactor "errmsg_str" to be a "struct strbuf" Date: Tue, 2 Aug 2022 17:46:00 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 1391316cde2..5ea308273f4 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 Tue Aug 2 15:46: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: 12934792 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 04475C00140 for ; Tue, 2 Aug 2022 15:47:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237291AbiHBPr3 (ORCPT ); Tue, 2 Aug 2022 11:47:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236978AbiHBPq4 (ORCPT ); Tue, 2 Aug 2022 11:46:56 -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 8760823BC4 for ; Tue, 2 Aug 2022 08:46:34 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id v3so17488382wrp.0 for ; Tue, 02 Aug 2022 08:46:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=mtNatpiKfILw6BnDcFReiCWnNT09sukSbzSSdcx3OEM=; b=chZKUXR3+O/cNnN9WepDFNgdo/fxGbr02DC6WO6Wv+ensPIlgBvMLNM0MEv4plZfYM Mt2F3xcYlHuS/yTZcvoGkABTT4/TnlUdOhupftuXz6VYVXaRDSyCgq0zmzu5dC52DRuC N+xfIAZinT6fqs/y9oMmV0wudk+TKyg8rEO5Ig6ZKcePoUCKoH5vvaws9skkw8Xi1ksK F/VEtZbwcnBGm/Bvab4qBjyVlaXXCIAC0Zk0INDFu6wONrH/1fGY00we9M6xIMF3jegi BNjsLkLjEfO9pl0hfTOtfS2d9drf3r/LV38JP9yk7MLCmd0lF/rDYDhGUYw+EbIUWf7d z/WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=mtNatpiKfILw6BnDcFReiCWnNT09sukSbzSSdcx3OEM=; b=XxTbLvj7EtkkFNm3gpkNBv+gkZNjJelgkY0qnKq7gANrqExcXmA1O3ekzy/DFxmxIu R9GILQKKy2yxZyi8X51xAAsQWvUgYL/senPBFU2TDYTICPNuubZRF7yStdlM+uW8P7hU 11VHr6YPgBVL5CpplkoOfc4RqyWH3k7/V5rpOAUGMxa5gDFESV1HjsIkuX7o06ubYatV eGqzUPWiPrtTez+7JB7IwbXqmTMQL3Vb0PYLeiQLc4CnZyShpo14AzzZoLiWjNNAcXGg iWWqPIjOnDBZNnGrZMuosn0bHr1zTkdZF8XIlH4kZDchB9Tjei5pHF0D5dhGljLQN0V9 p5Tw== X-Gm-Message-State: ACgBeo3YQ2y8Dw3SRIhz0TnHx8cgeD/pfE6jQzcaejvbwiImKSzkKWyX hcCp7tzhVRog8rmss0gpEEMho5b8KFT2+g== X-Google-Smtp-Source: AA6agR66IwWRjMvb9MNftYVKHV5EG15trB9IIpe9rVmGmpffxSQm0zwnYs+AuZQ0PmtLmUqhtWP35w== X-Received: by 2002:adf:fecd:0:b0:21f:d78:743f with SMTP id q13-20020adffecd000000b0021f0d78743fmr13668374wrs.704.1659455193777; Tue, 02 Aug 2022 08:46:33 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 17/28] submodule--helper: don't redundantly check "else if (res)" Date: Tue, 2 Aug 2022 17:46:01 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The "res" variable must be true at this point in update_submodule(), as just a few lines above this we've unconditionally: if (!res) return 0; So we don't need to guard the "return 1" with an "else if (res)", we an return unconditionally at this point. See b3c5f5cb048 (submodule: move core cmd_update() logic to C, 2022-03-15) for the initial introduction of this code, this check of "res" has always been redundant. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 5ea308273f4..1a19723f596 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2443,8 +2443,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 Tue Aug 2 15:46: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: 12934794 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 49C46C19F28 for ; Tue, 2 Aug 2022 15:47:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237359AbiHBPrd (ORCPT ); Tue, 2 Aug 2022 11:47:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236119AbiHBPq5 (ORCPT ); Tue, 2 Aug 2022 11:46:57 -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 D49A823BF5 for ; Tue, 2 Aug 2022 08:46:35 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id b21-20020a05600c4e1500b003a32bc8612fso7142461wmq.3 for ; Tue, 02 Aug 2022 08:46: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; bh=yhZ9Lh9Fgv7nM+ZluUnhHI8lw2CMsdcCtaqEQ7/3mzA=; b=qiN6d97I+xicyevL7vWE32jiZxS7WbPsZJCsmrSH8g68vUEAzKx5wNJTmCQp4p8mJH ES2Fi2HM1vZXj7S/Vs+VZFqXJ5MUUMpQBqb8Dp0O7nwNfYpY0uC3/nIBTlwg7F7Hu4Iw nciX6dax+27/Gfn+WeRQ4P53KCKGdOR95ozYrygRAnvUEvinxSkGjdHejCntefSJXwCJ DTNpnrZfqOsawrPs+qVv4ucBiy2dmHcIciFh7US0Lmer9MokyYqCBYCqNPZZTZAGg6T7 frTePv5rGPJ1H938oUq8pYph5WTqmWYiuIVoY8xCsUt8QyVLfHMJNzpDWh/JRfFU6ENw gx8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=yhZ9Lh9Fgv7nM+ZluUnhHI8lw2CMsdcCtaqEQ7/3mzA=; b=7NY5QmIkSCvAWJvZZu/BzWw2lQ4QnpbJjqlnt4pJPQLC+DEKSpjDBBsyL3HMWLGDw+ p7/Rp6jJMt637/sCfKxF1L4N8R5LOwPDSWGXrd48ECwNIIdqzjJendSXs4I+sd9o4h9K bBlA7EJAqNQLQ0mYCreywMrZ0f0TBD9sy1E7cxKSN6B0aYbvyrT/6H1j7VJrgdrIajRG aycElDHCIYtb7d1TAi0qhX2SfqYBvemCcj+lxh5VMZSqzVL46neKeEgmacXKRACC9hDE f5r2n9gyFrkpqIsnahBAWP4VILEsOuduircT1GvKbuY5GSCOBsuIgk01west6QfMYO7t +smg== X-Gm-Message-State: ACgBeo2iuy3mHWGmfNUr2jrE/W+/ZMujYS1pt6K/mqIc/11YNZMuBYXK 41CGwT62mOIc2uGc5XD6RV/1gCNczxhRBw== X-Google-Smtp-Source: AA6agR6DVnNyoZX2SVuk2LJYmobP87OgnuIKbBOAnHM356txB3cskKYoy6ZqVXy5DUE3icYEk2BioA== X-Received: by 2002:a05:600c:4fcf:b0:3a3:40f6:4c4d with SMTP id o15-20020a05600c4fcf00b003a340f64c4dmr75082wmq.60.1659455194956; Tue, 02 Aug 2022 08:46:34 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 18/28] submodule--helper: rename "int res" to "int ret" Date: Tue, 2 Aug 2022 17:46:02 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 1a19723f596..29f3e1dd8c8 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2424,7 +2424,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()); @@ -2436,13 +2436,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; } @@ -2451,7 +2451,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; @@ -2469,7 +2469,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; } @@ -2481,12 +2481,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 Tue Aug 2 15:46: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: 12934795 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 8B14BC00140 for ; Tue, 2 Aug 2022 15:47:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237363AbiHBPrf (ORCPT ); Tue, 2 Aug 2022 11:47:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236133AbiHBPq5 (ORCPT ); Tue, 2 Aug 2022 11:46:57 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 977342409A for ; Tue, 2 Aug 2022 08:46:36 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id v5so7419370wmj.0 for ; Tue, 02 Aug 2022 08:46:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=ce+LJROouwkf2KY92Re5adtsYmwqJXTyEVtA+mPalT0=; b=jLTAvrlYeubHhVzbkWNyamn7QeTr4v8dNqazrztsQnfulMO0bbLjkQR/q5p9yfaFxb y7EKW7UkukjRQezmGhPwduaaLo5MmEuLJa5LkccNF/tohaFDlr5o5dFjvsxZpiAYtYK3 yjBmk0z5BZEFDCTn43GdKW4rxMlMJumpw76eCHMXmcqHEZ2vuhQecVI/dUK/0no4a97Z XVb+caK4uxIAZLWzPh30GA0Ef+MmiJihJe6F0emVkBHOTEhvMZHU+k63F5yPk7FuJ9Af a5AW8wObQLpxamzB4BQeOrQMLRZ2NAbeHy81h+DRs+En/kGTVyPts7G9dK6orbTtO8xj mwMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=ce+LJROouwkf2KY92Re5adtsYmwqJXTyEVtA+mPalT0=; b=24v6Ti6Wx2k++P6uNjEj91kDcscErC0efhJYENVsx2GaGjKlHIcn10nFQKY/JysQJc jINvl9Dm+7Q0o8Ma65jBeyTw/g/rhcwHipOV0qVfKSbWltaUq+3x116joAy22hXTRztS hSTi57fpilI2fyfif4KTSf48hJGJFEdD7M7v8r107vanHmMgrK6RNrB3jlz6Z64S/Rxj uga/dmmLuZazhVq9C1/+0DI64DoL12LzTkoJ+1DKyMMpFImHjs52mg4bQuDR/63s52fK Zukvs009QirDi7b2dehjJ4anCidYCV12PAis9PQvvkbtD/Wf63y8haP+K5ilK2RKsNEu SxiA== X-Gm-Message-State: ACgBeo0WyhfsVd4FvZH11/xtNRJDOFY/zkPf4n/JBF7sTrLK0dg5TWJP VObS5MziAoFUgJBGQK2DUEdto3WCWtWYIw== X-Google-Smtp-Source: AA6agR7/r6biLsrm/fX544C8kXTVA2/6oLq083AVDYUJoCw1gTLHDn1qpY7l039r9vXogwL6ZMNIpQ== X-Received: by 2002:a05:600c:41c6:b0:3a3:4cab:74c1 with SMTP id t6-20020a05600c41c600b003a34cab74c1mr40356wmh.175.1659455195814; Tue, 02 Aug 2022 08:46:35 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 19/28] submodule--helper: return "ret", not "1" from update_submodule() Date: Tue, 2 Aug 2022 17:46:03 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 29f3e1dd8c8..0fb780a724c 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2443,7 +2443,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 Tue Aug 2 15:46: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: 12934796 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 33FDDC19F28 for ; Tue, 2 Aug 2022 15:47:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237387AbiHBPrg (ORCPT ); Tue, 2 Aug 2022 11:47:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237001AbiHBPrC (ORCPT ); Tue, 2 Aug 2022 11:47:02 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 948962655D for ; Tue, 2 Aug 2022 08:46:37 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id z12so8296343wrs.9 for ; Tue, 02 Aug 2022 08:46:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=zx7/zJHy5u6GAYACiB9EAPicbrOagBHOmgAdJUjKydo=; b=AFfr4f3NLAl7xw0/JBa2O38aLYY+ILIZ96uJI8pxHWlX1TSh2g7zWmjZxRWCh01HT3 vSmp+AtIASyIEsd5t96slCD08FAzs0MtmqNMEx0iE9cVRhgBABZobrlqaQFJqWDijjJB znkfhf/Elop6ADXsTpGmI0Al1/MF9p6qf4S1bksRHZEn6hmlLafMG4mdRHbZT4ddKS1A w1eI7p6oRkJ5x6HqlVUi6EGOUt1J5SV6lvfwjuvBRaaWvdVOLXwbFH0tgOl74o2Bmr7Q 0r4idN6I1FheANyk4qGcIAFLwFA40VVoDF0uqR9wj0dxWxjFbtVi4Odoy3oFhSo9+i3S gPMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=zx7/zJHy5u6GAYACiB9EAPicbrOagBHOmgAdJUjKydo=; b=BHC5EWZFLsRiogNWNPybku4W2/XBZl27RX0j0Vu8oVkZUXzhQmE5hS1l9Yz0+jrIPw C8xRvasOGb0re49CUdrQNinrLY2R++87mxtsMwvfid2u33zTMzNBOiF/d96v1qyIa7+Z TM+CWVBhXIYM+fvfDQ6HJipXU/mbNljLneJCuPJm86a0bQ2mGUemTCAiz7FvOFZ5vy3K +VkvqujXTBluVwpKb5pZPthCizZ44kC+SjL/ZEyvOGtsiWQCF7/Tj/GirBS6iwDzFxw/ pKUmSQbcPGfWElxwK4TQuzfQ1Cbi4sgLAqwsGPg0ibZo/84APJ5FIJ66bevl+TqyH7jQ rVKA== X-Gm-Message-State: ACgBeo2kAOE9WosO9Q6ry4VQST2ymE0wPAAG2yeqInvMUc3mOQxteWRz dhULrSe2inuGB+xfbFtVatKCEWwyCshAZg== X-Google-Smtp-Source: AA6agR72/xHTN4uT+ZvuXi2MOYG2Giq/iqAIdI2PHpcBm3RGka9hUnQ72Tp4ykDNRywikppfw1U94g== X-Received: by 2002:a5d:5955:0:b0:21e:98d2:bd92 with SMTP id e21-20020a5d5955000000b0021e98d2bd92mr13482264wri.547.1659455196834; Tue, 02 Aug 2022 08:46:36 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 20/28] submodule--helper: add missing braces to "else" arm Date: Tue, 2 Aug 2022 17:46:04 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 0fb780a724c..955deb375ee 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 Tue Aug 2 15:46: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: 12934797 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 090A5C00140 for ; Tue, 2 Aug 2022 15:47:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237390AbiHBPri (ORCPT ); Tue, 2 Aug 2022 11:47:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237095AbiHBPrD (ORCPT ); Tue, 2 Aug 2022 11:47:03 -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 84AC315FF1 for ; Tue, 2 Aug 2022 08:46:39 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 8-20020a05600c024800b003a2fe343db1so7157801wmj.1 for ; Tue, 02 Aug 2022 08:46:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=OWWST2Rlt2wr1zjTd22DOWwPlFiqyWnfiRH5l2rxZ94=; b=WxADNUnF9agsjGAgfS2yfritXUBqBSvYDVl4OWZ7snqOdD/VY9vBDTRPzaX0sTY7AK Pcj563+D2VqwBftA08xKgYuRbovFl2N8wWOSz4OMSbFaIDiZNEecRU6lqJ6Fa8vh7Qyd iKZj30QF6UVcsMe1KXhLlXeJcCEYuOrmE+IYaPyEbSEXldLssj3Pvjk3vo4Fx6gO8KuN 4a/uH/NjflkhyD1iGgNyNzv/UDVaxlQrq2b3HS93fuOnJO/gf/9rV441n4lINmxwJyQ/ lzPSJcPy0K99wV2ayQ8PHEbvnN3eNTEXUvfxxyVd5TkCr6fbsBMz+w9ui45PTiSlIUku lTcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=OWWST2Rlt2wr1zjTd22DOWwPlFiqyWnfiRH5l2rxZ94=; b=eT/TqGksUiSDPJuog4k4gkBbKyuxF8Xzi6wfjLpS4mBdUDwBeBH8/zGsbSNY/LGvXJ 2a7QgnTDTxECZecX/up188V9UqPYLzbnJn5paaEROJGKn0xkg+TxFMtontOV3uADG6wk 47CWuL1lW/rPJD7ohmn0W94EPpJQqKGNsY3aYswWausDrKkGIruVKjVocdh4HzE0Huz8 QBT8fzEf0I1cLR/KLwrc26EPINRMe5hQisHdspCVlNdFVrM/Xoj2v1nv+bqeQP+O8fwa QA0zUOAd0QU6XBOs6LFDSxqBgCJH71IgieagYj4icnQRlxTUZOBHXTv1nuVpuVwO4TIl xVcg== X-Gm-Message-State: ACgBeo1QhN/8i0pmgVKuSWK/JR/tbBxlkLEXrHDzgTuhYIYXINwsayap GQ0jmKixRGNlsINPM1m4ixz9vili+K5tXg== X-Google-Smtp-Source: AA6agR5gw8cLqQIiajZ6V7gSv2CikC1eAghPENvzSQpznnoPEqVjUNjWvQb5YhLzULqQRSR9TjB1yA== X-Received: by 2002:a05:600c:19c9:b0:3a3:469f:c1e7 with SMTP id u9-20020a05600c19c900b003a3469fc1e7mr44470wmq.141.1659455197765; Tue, 02 Aug 2022 08:46:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 21/28] submodule--helper: don't call submodule_strategy_to_string() in BUG() Date: Tue, 2 Aug 2022 17:46:05 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 955deb375ee..b49528e1ba9 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2155,8 +2155,8 @@ static int run_update_command(struct update_data *ud, int subforce) must_die_on_failure = 1; break; default: - BUG("unexpected update strategy type: %s", - submodule_strategy_to_string(&ud->update_strategy)); + BUG("unexpected update strategy type: %d", + ud->update_strategy.type); } strvec_push(&cp.args, oid); @@ -2181,8 +2181,8 @@ static int run_update_command(struct update_data *ud, int subforce) ud->update_strategy.command, oid, ud->displaypath); break; default: - BUG("unexpected update strategy type: %s", - submodule_strategy_to_string(&ud->update_strategy)); + BUG("unexpected update strategy type: %d", + ud->update_strategy.type); } if (must_die_on_failure) exit(128); @@ -2212,8 +2212,8 @@ static int run_update_command(struct update_data *ud, int subforce) ud->displaypath, ud->update_strategy.command, oid); break; default: - BUG("unexpected update strategy type: %s", - submodule_strategy_to_string(&ud->update_strategy)); + BUG("unexpected update strategy type: %d", + ud->update_strategy.type); } return 0; From patchwork Tue Aug 2 15:46: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: 12934798 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 08F29C00140 for ; Tue, 2 Aug 2022 15:47:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233002AbiHBPrk (ORCPT ); Tue, 2 Aug 2022 11:47:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237086AbiHBPrD (ORCPT ); Tue, 2 Aug 2022 11:47:03 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 759E315FD1 for ; Tue, 2 Aug 2022 08:46:39 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id bk11so8551077wrb.10 for ; Tue, 02 Aug 2022 08:46:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=O72dRT+v+fTqGEg3j3bLCBOHUMqja/pFC/vJ3ldq9B8=; b=bZjMt/xQxgy4ck8YQPnYJDEuouqfFSzb60oCyBkMPn1LcBLvbplfcZ+kOs/6jmSQUu NMfPVnJ77fSgK2DUEozatlgYoNb1pLsme0zz3x3gfVdRm/ZC2zf8SIvrk271jI0LoFDi fqx0krDPU6mkEfz6kgKIU7quxncuhAKH/0igLeTtNjBSnp6cufN4qCTUXxE9P2FAXeXL Xc6pQOXK1tFnVuQfi0aSeZA9OTgnbZjFxs5W5i5LPtqy2uFLgjIpFfdsf3zsiZHKVH8P uxRVfqBZfcZ2jvKM0mUIzlLi9DtaA2PqlaswYmzEH8Fko6hzNaY/BwIvr4TLnw3yjsnJ YR+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=O72dRT+v+fTqGEg3j3bLCBOHUMqja/pFC/vJ3ldq9B8=; b=F6HYK2F0zUQTDnQeVFjDtZaYW0Q1LjT12dmtx9ZpPALZd5tFI61z+7r9ViBeDbICVF zDd3fIJacwwqoCvgYn4dr0Alg7TAFA8/bEZtODk72W3x1BpoOLYJhdsgM0FOihKqW8kQ kxV9T7PyI6sYCelpc1p+fhw5/ygq2taVYbAOwtJekfV7kIFXQZ55YuwClsRIFY0dkzgX u17RLu18JSatybOiHnlzXaXbfSgeAsAtCJxFU1wFMZrhlx3Wf2PzGxddEbebqutPQqR9 7PJEGHGZhS5tr0YHxLOi4rV/ppCxn2NbtjJuQF2A7gmnrZqBI4DJUxe4drMkyO10st8d raRg== X-Gm-Message-State: ACgBeo0pEPzLewtzF+GtdHnBKFiJhZ8angDkUDOLQxZKh82WXA3o/K56 9FeApJgQ65hcSwxPq6ERQqy0pNUFAzpkSQ== X-Google-Smtp-Source: AA6agR75dBe5dVZZwYSjg9Q2j095ieL9CawTDj2ZxiXbOXh5r3xmr+PJ7skQR91WomFSGjT0MBZTQQ== X-Received: by 2002:a5d:6d85:0:b0:220:7084:35e9 with SMTP id l5-20020a5d6d85000000b00220708435e9mr2583200wrs.11.1659455198671; Tue, 02 Aug 2022 08:46:38 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 22/28] submodule--helper: move submodule_strategy_to_string() to only user Date: Tue, 2 Aug 2022 17:46:06 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the submodule_strategy_to_string() function added in 3604242f080 (submodule: port init from shell to C, 2016-04-15) to its only user. 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 move it to a "static" helper, and have its functionality reflect how it's used, 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(). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 29 ++++++++++++++++++++++++----- submodule.c | 21 --------------------- submodule.h | 1 - 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index b49528e1ba9..d787c0fead4 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -413,12 +413,32 @@ struct init_cb { }; #define INIT_CB_INIT { 0 } +static const char *submodule_strategy_to_string(enum submodule_update_type type) +{ + switch (type) { + case SM_UPDATE_CHECKOUT: + return "checkout"; + case SM_UPDATE_MERGE: + return "merge"; + case SM_UPDATE_REBASE: + return "rebase"; + case SM_UPDATE_NONE: + return "none"; + case SM_UPDATE_UNSPECIFIED: + case SM_UPDATE_COMMAND: + BUG("init_submodule() should handle type %d", type); + default: + BUG("unexpected update strategy type: %d", type); + } +} + static void init_submodule(const char *path, const char *prefix, unsigned int flags) { 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 +494,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_strategy_to_string(sub->update_strategy.type); } if (git_config_set_gently(sb.buf, upd)) @@ -490,7 +510,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..e297d94d17f 100644 --- a/submodule.c +++ b/submodule.c @@ -415,27 +415,6 @@ int parse_submodule_update_strategy(const char *value, return 0; } -const char *submodule_strategy_to_string(const struct submodule_update_strategy *s) -{ - struct strbuf sb = STRBUF_INIT; - switch (s->type) { - case SM_UPDATE_CHECKOUT: - return "checkout"; - case SM_UPDATE_MERGE: - return "merge"; - case SM_UPDATE_REBASE: - return "rebase"; - 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); - } - return NULL; -} - void handle_ignore_submodules_arg(struct diff_options *diffopt, const char *arg) { diff --git a/submodule.h b/submodule.h index bfaa9da1868..949f67b8031 100644 --- a/submodule.h +++ b/submodule.h @@ -72,7 +72,6 @@ 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); 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 Tue Aug 2 15:46: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: 12934801 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 C4999C00140 for ; Tue, 2 Aug 2022 15:47:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237198AbiHBPr4 (ORCPT ); Tue, 2 Aug 2022 11:47:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237144AbiHBPrM (ORCPT ); Tue, 2 Aug 2022 11:47:12 -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 7B23531392 for ; Tue, 2 Aug 2022 08:46:40 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id l4so18419753wrm.13 for ; Tue, 02 Aug 2022 08:46:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=6ekCGJPlnfLqEjjNw/aTmw3KqnQZ3f7Cv+piTlnlEP0=; b=l2I3ufKKmb9QcEbOgRfPmQEtwOjgJGjYRr99PfOdyHMYGsnZHXcYVRz1Kia0SKWuKm gvhFNDRfOlCu4brPjkp0wyriggZqjeWnpIkX29izUhqOmjTwHmy9XiqFAMypEW6erK5T FQINw+aPfR+IxtQjloiRe66rCVjIDXvj8Llss2tSNz/t+wwmQy37Zdt0q6rrnH7R2thA R6Gqw5WAZw3V/p/41XCfd9JPrW7V3Kp2zdjDpmEEjULl9DpH+KM76ujAawle/OTJO5DD btBgvRlH2+HgtaVjqAmw307IlwegJm8r8xONO0A1K3MLc+caxLhFbkPtz0xQIWG8DIJP 4PLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=6ekCGJPlnfLqEjjNw/aTmw3KqnQZ3f7Cv+piTlnlEP0=; b=3D+GHr8XS1SIBPVqX1UV0w3d0X7LBCQTg3EBRz9AyxpP84YB9tcWd7iU24R05J6AGI G6hVuWbi2xBgvNMgV/b910112G4sL5WhAdoWmxY987AvI9ezcWAg3WQUo9VrR+QuqOxX Xo2XtWAsspNGvwcwJAerE+wFUeculgzOeNr9hvyHeajUkhw4Xx6uayKO1+IVKJIiOAcB v+m7QaH8SgIiIqXuiaoi8w+oHduUqHHDc0AmfUVlSLl8xRlLpLXVLA4PIJCgMUqMC9KX VBvIbBkbzeux8Fz8pB8+CLGhLzYryiJWUBNpXdVLcdFjDOUDB1QfE//qIVSEy+mm+Wgj 5jyg== X-Gm-Message-State: ACgBeo1rnFjabqxNLGGhvCnN5KCc8YXVDi4hwCZOre6UoOj/8kf7VGlG r+7I3Og4yXBwevXhe3TMwvKsptpGRWDThw== X-Google-Smtp-Source: AA6agR5ke7e6QP0+4m2JwuuydfdPFxnqLrs77i79/141cT6pz9yBAX6fuvwukrWXxgXeLQua8gZ/mA== X-Received: by 2002:adf:fe0d:0:b0:220:5df9:e5cf with SMTP id n13-20020adffe0d000000b002205df9e5cfmr8788240wrr.332.1659455199594; Tue, 02 Aug 2022 08:46:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 23/28] submodule--helper: use "code" in run_update_command() Date: Tue, 2 Aug 2022 17:46:07 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 d787c0fead4..bac45e2bab7 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2145,7 +2145,6 @@ static int run_update_command(struct update_data *ud, int subforce) { struct child_process cp = CHILD_PROCESS_INIT; char *oid = oid_to_hex(&ud->oid); - int must_die_on_failure = 0; switch (ud->update_strategy.type) { case SM_UPDATE_CHECKOUT: @@ -2159,19 +2158,16 @@ static int run_update_command(struct update_data *ud, int subforce) strvec_push(&cp.args, "rebase"); if (ud->quiet) strvec_push(&cp.args, "--quiet"); - must_die_on_failure = 1; break; case SM_UPDATE_MERGE: cp.git_cmd = 1; strvec_push(&cp.args, "merge"); if (ud->quiet) strvec_push(&cp.args, "--quiet"); - must_die_on_failure = 1; break; case SM_UPDATE_COMMAND: cp.use_shell = 1; strvec_push(&cp.args, ud->update_strategy.command); - must_die_on_failure = 1; break; default: BUG("unexpected update strategy type: %d", @@ -2182,32 +2178,35 @@ static int run_update_command(struct update_data *ud, int subforce) cp.dir = xstrdup(ud->sm_path); prepare_submodule_repo_env(&cp.env); if (run_command(&cp)) { + int ret; + switch (ud->update_strategy.type) { case SM_UPDATE_CHECKOUT: die_message(_("Unable to checkout '%s' in submodule path '%s'"), oid, ud->displaypath); + /* the command failed, but update must continue */ + ret = 1; break; case SM_UPDATE_REBASE: - die_message(_("Unable to rebase '%s' in submodule path '%s'"), - oid, ud->displaypath); + ret = die_message(_("Unable to rebase '%s' in submodule path '%s'"), + oid, ud->displaypath); break; case SM_UPDATE_MERGE: - die_message(_("Unable to merge '%s' in submodule path '%s'"), - oid, ud->displaypath); + ret = die_message(_("Unable to merge '%s' in submodule path '%s'"), + oid, ud->displaypath); break; case SM_UPDATE_COMMAND: - die_message(_("Execution of '%s %s' failed in submodule path '%s'"), - ud->update_strategy.command, oid, ud->displaypath); + ret = die_message(_("Execution of '%s %s' failed in submodule path '%s'"), + ud->update_strategy.command, oid, ud->displaypath); break; default: BUG("unexpected update strategy type: %d", ud->update_strategy.type); } - if (must_die_on_failure) - exit(128); - /* the command failed, but update must continue */ - return 1; + if (ret == 128) + exit(ret); + return ret; } if (ud->quiet) From patchwork Tue Aug 2 15:46: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: 12934799 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 AFD1BC00140 for ; Tue, 2 Aug 2022 15:47:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237113AbiHBPrx (ORCPT ); Tue, 2 Aug 2022 11:47:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237141AbiHBPrM (ORCPT ); Tue, 2 Aug 2022 11:47:12 -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 722CC3190B for ; Tue, 2 Aug 2022 08:46:41 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id z16so18345691wrh.12 for ; Tue, 02 Aug 2022 08:46:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=EcDTY4yw+3c2nTVXJecF6TldvH8mwoAj39muhZLKQZM=; b=THsqfcApgoJwl2S/YXg9c/cNiGO3jkH7arfPSAa6db7i/GwSQcmRlLmcTHIDxehWuY 3x5Sdqjt9dbh3/mDh30MT3M2YljOczBy6h9BiJLiYkhYjelgSuIqgVx1Uas8Sj+/By+N SocjJOTnPQs0TT6ci2PuPMKWaAguXoJZhJzIqwvEem5QkcMXvsKXX1q186q98v8mq3FB ealPkJrRHytWqyxl+xVNuDlRvwMgdK1bwbJJZNeUmLkL5qJB9V/s0dk5pXyPby5zkWP1 UjvYQqOcpQT7e2QqZg3Fj2Fn12Wr6o2z9AW+1n4H9qFf0H1Cx0aCOHwDolFnys1ZhfCg Q2/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=EcDTY4yw+3c2nTVXJecF6TldvH8mwoAj39muhZLKQZM=; b=0ITqrB1vk/tlGAiRIvDRqt10G376k/KtfZwqo3U4p8H+F9umQbaz+gGC+ab54Eka53 uPNuRmrqC3NgJMVaWHc5QXIT5SMRwOKeePJlYGHS+8MWvpL1W9s4UBVzqgzFCIE0sN8U Cp6BtM+QPKOIhSc3350ChZNc5Hf6JisWjZWWMsrvCKXy0aJTGgjlWxfOyhPE7/vAeHla zEBqrk0qAGMKFqNn5ZRZ2rzRLiCnLTy/Bf71BR45VGRRSVZmgVBYdHmFwQe9ScY+r/kR OONdulh9BbGW+UIA9Mh+9la3d61i6Xe48CncIfaE0sWuRFCC8bvGlsw64W5THkYbOzdl 4bog== X-Gm-Message-State: ACgBeo0ylPpxDT2pjb1Us8Ornzj8ZmGp9Vhw9vMx0AAjN0l8jA5issYP M1YYwbDO2CZOMQeh0vgjeWZ/FC0UtCLnCQ== X-Google-Smtp-Source: AA6agR4AcePheyQnIMTwr54SsrGtOB3vsWcgrhu7OEbMvIiKg3w4fQRE2DrFQtuoJC8v4wG7YPEiKA== X-Received: by 2002:a5d:64ec:0:b0:21e:9396:b0ff with SMTP id g12-20020a5d64ec000000b0021e9396b0ffmr13911137wri.411.1659455200644; Tue, 02 Aug 2022 08:46:40 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 24/28] submodule--helper: don't exit() on failure, return Date: Tue, 2 Aug 2022 17:46:08 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index bac45e2bab7..8d83f1f99d2 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2141,7 +2141,8 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, str return run_command(&cp); } -static int run_update_command(struct update_data *ud, int subforce) +static int run_update_command(struct update_data *ud, int subforce, + int *must_die_on_failure) { struct child_process cp = CHILD_PROCESS_INIT; char *oid = oid_to_hex(&ud->oid); @@ -2205,7 +2206,7 @@ static int run_update_command(struct update_data *ud, int subforce) } if (ret == 128) - exit(ret); + *must_die_on_failure = 1; return ret; } @@ -2237,7 +2238,8 @@ static int run_update_command(struct update_data *ud, int subforce) return 0; } -static int run_update_procedure(struct update_data *ud) +static int run_update_procedure(struct update_data *ud, + int *must_die_on_failure) { int subforce = is_null_oid(&ud->suboid) || ud->force; @@ -2264,7 +2266,7 @@ static int run_update_procedure(struct update_data *ud) ud->displaypath, oid_to_hex(&ud->oid)); } - return run_update_command(ud, subforce); + return run_update_command(ud, subforce, must_die_on_failure); } static const char *remote_submodule_branch(const char *path) @@ -2400,7 +2402,8 @@ static void update_data_to_args(struct update_data *update_data, struct strvec * "--no-single-branch"); } -static int update_submodule(struct update_data *update_data) +static int update_submodule(struct update_data *update_data, + int *must_die_on_failure) { ensure_core_worktree(update_data->sm_path); @@ -2436,9 +2439,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; @@ -2461,7 +2470,7 @@ static int update_submodule(struct update_data *update_data) die_message(_("Failed to recurse into submodule path '%s'"), update_data->displaypath); if (ret == 128) - exit(ret); + *must_die_on_failure = 1; return ret; } @@ -2494,12 +2503,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 Tue Aug 2 15:46: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: 12934800 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 C6C5AC3F6B0 for ; Tue, 2 Aug 2022 15:47:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236712AbiHBPrz (ORCPT ); Tue, 2 Aug 2022 11:47:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237149AbiHBPrM (ORCPT ); Tue, 2 Aug 2022 11:47:12 -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 C4C6B3191E for ; Tue, 2 Aug 2022 08:46:42 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id j7so18404849wrh.3 for ; Tue, 02 Aug 2022 08:46:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=KXhhF4qINHNwlyi3FmSPqa0snY6eaOWZqFNUgRAHoMo=; b=LTKZLpOfwbwiinbqSiFbcmGH0MGrTRsWj8+5FqEFu4wbubOTD4vQt6oR4nWlyIEtZO nhT1p0SMEDmIW0bVYEog4x502IsF/DqKZkXbm+AC26Jmx/T/phTEJOi28KPSGRHjsQTW geKOoNH5vgAaFL1n8qd4vNDh9mdRWJlVlYC2KAyarMJsuCVrJBmw/1OEOT0hsqxC3i5+ cJEyd2imDra9bsuzs5qWKy+TKtIGdjKo4Yr9ENGAs1VcvXPZ7OWdGzN+12rpqb+B7T2f Bpcg5TEa1hHF0Wf8RBQl90KFekcbp2BaN6qgda9pXnZ1/rWlMg+VZa2xUeswyhhKECpX 7Spg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=KXhhF4qINHNwlyi3FmSPqa0snY6eaOWZqFNUgRAHoMo=; b=oCazAgUeP21DcfBJ2IO4LD2GxD3pkk0Nhx7r2J0yzB/TrqV6w2edQOEKDNBI14msil DP3jzlCY/hOc+goY+Yom1kW3od1zqP2TcDKT0sjQbBstedUr7vt1gmrLkm+sA9u6PVck jqFNw87IKpK/3wWW6+E9Z46mn1r3eqW1xpHYNHUw4bqhnB+/7gHXpf76B86GumA6aSQ+ 8dkxfpGlUGNiZNGiqDzIH1UIw4c08r1jyGojYhb9XxqWWhNpGCiFROjhAeKxpZ1EGa19 Yhp6n4Twkgmm/snuJz2bR0lzLhBS8TMR9fvnrYYRvL69OYwI2qVk1HPHFhWXSSrQAT/5 W5Jg== X-Gm-Message-State: ACgBeo2JL4Pi39lPT+9smpISsQiOh9pwwQqKirpf29CXNudfEiOVKEkl KY3P6JymvLNhhx5+lT8bR4xkzrahqrQ+aQ== X-Google-Smtp-Source: AA6agR5CRIv7R/C6MJtL7CKwk5nybP8+2IcUOkLYHdlMZigr6fOYM4h8UqDEjJjgaHzIrf65QJsPwg== X-Received: by 2002:a5d:4ad2:0:b0:21f:af5:8dc7 with SMTP id y18-20020a5d4ad2000000b0021f0af58dc7mr13909289wrs.575.1659455202014; Tue, 02 Aug 2022 08:46:42 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 25/28] submodule--helper: libify determine_submodule_update_strategy() Date: Tue, 2 Aug 2022 17:46:09 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 8d83f1f99d2..2b78fa7573f 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1749,24 +1749,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?"); @@ -1781,7 +1784,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 { @@ -2405,14 +2411,22 @@ static void update_data_to_args(struct update_data *update_data, struct strvec * static int update_submodule(struct update_data *update_data, int *must_die_on_failure) { + int ret; + ensure_core_worktree(update_data->sm_path); update_data->displaypath = get_submodule_displaypath( update_data->sm_path, update_data->prefix); - determine_submodule_update_strategy(the_repository, update_data->just_cloned, - update_data->sm_path, update_data->update_default, - &update_data->update_strategy); + ret = determine_submodule_update_strategy(the_repository, + update_data->just_cloned, + update_data->sm_path, + update_data->update_default, + &update_data->update_strategy); + if (ret) { + *must_die_on_failure = 1; + return ret; + } if (update_data->just_cloned) oidcpy(&update_data->suboid, null_oid()); @@ -2440,8 +2454,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; @@ -2452,7 +2464,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 Tue Aug 2 15:46: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: 12934803 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 45F07C00140 for ; Tue, 2 Aug 2022 15:48:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237412AbiHBPr7 (ORCPT ); Tue, 2 Aug 2022 11:47:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234375AbiHBPrM (ORCPT ); Tue, 2 Aug 2022 11:47:12 -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 2E44D33435 for ; Tue, 2 Aug 2022 08:46:44 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id z16so18345809wrh.12 for ; Tue, 02 Aug 2022 08:46:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=KEjszNGS9OWPs/ST/nKsVRAPxWIreiSqpXI+cVdY4/o=; b=DwPe+V78xEo8MUOZDPxOLtLsIV3FGt5UCq2CnA3sgAbcsiVviUMceY9ElS74zGR/lB WE3ZohoG76FM25LYWs/Kul/IX9ia9zOof91UefnGiivCmlU1VgroKniEFBd9NowSrnLI nnftwtD0mI9tRUiAbGblP3q/HYoshq5MlSZNfjopyoDioUzef3hQK5Lum/A1uWAh6hgo Ia9lltSlO0FhpDkptyOgWKBUQJ0/qAvuqv20D5EGsOrYf4GuCuVuGuQsaCKXnMOCsIcZ 1y9UU2KFwkMYsqhIR8UbOvq8TzpRl3W70xJnhRzFC+jxruLNXFAf/AuWWBNA3PTlxq9L OnWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=KEjszNGS9OWPs/ST/nKsVRAPxWIreiSqpXI+cVdY4/o=; b=PUDv/YnaSff/xZoIs2hRQxcTmtuWA10sd2acaWWiz+1UdpEKeLAUJ29cep4XS6AO2O glD5Mp2ykjTBsX7STBsyTHda2xT0THWsOgNiRy+m3S+9rtTV2wUHFTa3BdCsaVTIb6d/ yb6fBblH4CIRs+G0ms/DTS7r4qj5/ZwxLJkhYU+iBXJ81eWqjRjeDMo0jgoeeRg/qpDx PivUNeUbPoGHdeQAJ/DziqosO2cwBE6HucIh0OeVQykb8mbmaZwDFeEhoe/8fOjohR66 W4vPHreFjISnT2uc9LrgW+HdalMxBPrhNESMrJKZsQ8gr67vkwMEcKF/tCmdVU/M5M8U CeZA== X-Gm-Message-State: ACgBeo0mS8xTb/CyVEP0Zi4wyOCptUZy6OlWl3e7MnyP0lQQLf/lyDaV leIZmMgUP90pgHd0uz5beOBkShl+ynHnIQ== X-Google-Smtp-Source: AA6agR4O+23o4HWgMTeczMdJRjokf78Aul7D6eyaUImzrzjnQloM4iQFHRh+80F7cCPBzWiultV2/g== X-Received: by 2002:a5d:514f:0:b0:220:6b4d:f806 with SMTP id u15-20020a5d514f000000b002206b4df806mr4439729wrt.137.1659455202883; Tue, 02 Aug 2022 08:46:42 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 26/28] submodule--helper: libify "must_die_on_failure" code paths Date: Tue, 2 Aug 2022 17:46:10 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 2b78fa7573f..79a11992d1c 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2147,8 +2147,7 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, str return run_command(&cp); } -static int run_update_command(struct update_data *ud, int subforce, - int *must_die_on_failure) +static int run_update_command(struct update_data *ud, int subforce) { struct child_process cp = CHILD_PROCESS_INIT; char *oid = oid_to_hex(&ud->oid); @@ -2211,8 +2210,6 @@ static int run_update_command(struct update_data *ud, int subforce, ud->update_strategy.type); } - if (ret == 128) - *must_die_on_failure = 1; return ret; } @@ -2244,8 +2241,7 @@ static int run_update_command(struct update_data *ud, int subforce, return 0; } -static int run_update_procedure(struct update_data *ud, - int *must_die_on_failure) +static int run_update_procedure(struct update_data *ud) { int subforce = is_null_oid(&ud->suboid) || ud->force; @@ -2272,7 +2268,7 @@ static int run_update_procedure(struct update_data *ud, ud->displaypath, oid_to_hex(&ud->oid)); } - return run_update_command(ud, subforce, must_die_on_failure); + return run_update_command(ud, subforce); } static const char *remote_submodule_branch(const char *path) @@ -2408,8 +2404,7 @@ static void update_data_to_args(struct update_data *update_data, struct strvec * "--no-single-branch"); } -static int update_submodule(struct update_data *update_data, - int *must_die_on_failure) +static int update_submodule(struct update_data *update_data) { int ret; @@ -2454,11 +2449,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) { @@ -2476,12 +2469,9 @@ static int update_submodule(struct update_data *update_data, /* 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) - *must_die_on_failure = 1; + if (ret) + die_message(_("Failed to recurse into submodule path '%s'"), + update_data->displaypath); return ret; } @@ -2514,17 +2504,16 @@ 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); + code = update_submodule(update_data); if (code) ret = code; - if (must_die_on_failure) + if (code == 128) goto cleanup; else if (code) ret = 1; From patchwork Tue Aug 2 15:46: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: 12934802 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 17F9BC19F28 for ; Tue, 2 Aug 2022 15:47:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237144AbiHBPr6 (ORCPT ); Tue, 2 Aug 2022 11:47:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237174AbiHBPrM (ORCPT ); Tue, 2 Aug 2022 11:47:12 -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 E184F2E6B1 for ; Tue, 2 Aug 2022 08:46:44 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id l4so18420003wrm.13 for ; Tue, 02 Aug 2022 08:46:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=nDmwQdOVfDoEH0zIq9ipISm+fY0SL3HfAJeCZm54nUw=; b=Fey0cjBpuCTWYa/qGrWpaMZd6Y02KCF7ODAsbudp140TVcXKqqhGwLLW48pP1nBWEk Ln6Svi5vYuCascscCrjSbrZ33nMzLmwPhzmTU6+ibV+S3q3x+9M1iMke3zUYWYOCudYp a8lV5gOeUBjjWJpcBp2RZwtOfIEasoYhcAm1is6BMuO9LCMbwNgD6gNRr5IE4iiIl6K0 /gHJiol8QylPUTD2vzEJj8X8MNSQ9rLR798C2pawkh7RK2n9pP93obDbBaLCi7doCSRz qLId4fjXINOcUEMlj+GNV1CbgmqTD7jPYpKJyj6qWI6hMQodtqjxAs7SOMhDhxt76UlA DunA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=nDmwQdOVfDoEH0zIq9ipISm+fY0SL3HfAJeCZm54nUw=; b=ZelVkyDN2r4GGhXypejACToZypa8jE8qCfpaQ6l7e5msCuTvaWysqjGmr0D9Qkluxr rIrdf1vzJBt8wWnsFqV9sfRJgWUQ6DWozIzrOWQMh7rrkivnlj1AyQs50IMHEEdBWH5G NU2SjzvwWBGjrYV3/KNBPN5raCaDpqS8q78fDIV3+Lxe5iaGabu1XXCJgBAPVyADzt9F 42gt5rNVOiPTOBssbeSdDYHkMpgEnvHLYD+99zZ1coEz9KbAEicTRze85ST17H8Cw8SY S3ikmKWFTcM1J3E3nozdCmq+H5yL3VR1bMEoRToLbuVbZWD+wTAuohaWeOTwMV5BDcPw NzaQ== X-Gm-Message-State: ACgBeo2xW6MABQ/EpLyczaajXirtelVb6KOVfPrFcbtnF4Qo0bJ3P+kn pvg5sLaW9E8N74tuRh4HPl0/uTHrKsIDtQ== X-Google-Smtp-Source: AA6agR5qDyoV8V//DEN8oPYxnZ9CjBIG+P5jkQTL7I6WjnjXCinNBRunYo1leSC246TcO5go63mJrg== X-Received: by 2002:a05:6000:1883:b0:205:c0cb:33c6 with SMTP id a3-20020a056000188300b00205c0cb33c6mr14350375wri.39.1659455204022; Tue, 02 Aug 2022 08:46:44 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 27/28] submodule--helper: libify "must_die_on_failure" code paths (for die) Date: Tue, 2 Aug 2022 17:46:11 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Continue the libification of codepaths that previously relied on "must_die_on_failure". In these cases we've always been early aborting by calling die(), but as we know that these codpaths will properly handle return codes of 128 to mean an early abort let's have them use die_message() instead. This still isn't a complete migration away from die() for these codepaths, in particular this code in update_submodule() will still call die() in some cases: char *remote_name = get_default_remote_submodule(update_data->sm_path); const char *branch = remote_submodule_branch(update_data->sm_path); But as that code is used by other callers than the "update" code let's leave converting it for now. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 79a11992d1c..4f7ece6fb05 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2263,9 +2263,9 @@ static int run_update_procedure(struct update_data *ud) */ if (!is_tip_reachable(ud->sm_path, &ud->oid) && fetch_in_submodule(ud->sm_path, ud->depth, ud->quiet, &ud->oid)) - die(_("Fetched in submodule path '%s', but it did not " - "contain %s. Direct fetching of that commit failed."), - ud->displaypath, oid_to_hex(&ud->oid)); + return die_message(_("Fetched in submodule path '%s', but it did not " + "contain %s. Direct fetching of that commit failed."), + ud->displaypath, oid_to_hex(&ud->oid)); } return run_update_command(ud, subforce); @@ -2309,13 +2309,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; @@ -2333,6 +2334,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) @@ -2408,7 +2411,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); @@ -2418,16 +2423,14 @@ 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()); 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); @@ -2437,13 +2440,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 Tue Aug 2 15:46: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: 12934804 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 3D157C19F28 for ; Tue, 2 Aug 2022 15:48:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237210AbiHBPsB (ORCPT ); Tue, 2 Aug 2022 11:48:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236949AbiHBPrQ (ORCPT ); Tue, 2 Aug 2022 11:47:16 -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 2C37537185 for ; Tue, 2 Aug 2022 08:46:46 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id l4so18420056wrm.13 for ; Tue, 02 Aug 2022 08:46:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=n4MIAzCkogt282Uh8Cshx/PYZ/+axm3sZAQnxKzmwHU=; b=o2X37BkNm3Ho+eh9Kqh8PszPTvSc0SuRYyEplkjnuInTWpbUnPJPRTGmyVKfnk4LrL uxuVo2FBg35ZDSkO7YU9YyAt9htowhDVVQ976MOq0vSFdoLPAKCs6bS2IVO94zeY1iSg AqLh8hlpdwiebRk784GtRr9LJrPIA3gAgbnKk9uVdQ/LkvCFiLdzUBE+mLK3H/2J5S+k pE89aFN+2+CFEZyIy9V46ZpzbI+QUENMC44e0d8WJJ76Asu5Gr/GWC8zzp/tFeNIOnEz vCCyL94SwfWdjG+CEcF9NQ8yhqyv4wS2gNitKIGxO9303UGiRgKcAjGiuNBlyNXjcYeE X6Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=n4MIAzCkogt282Uh8Cshx/PYZ/+axm3sZAQnxKzmwHU=; b=4lvMER8iLp2LbV1MpxBH7irthrdokvckm67xyaAIVGKjSgwBue9sRggKJT6VACZSPu xx+loelK0mgUi2btvfA5xTdnU1R4Vnm21GVW2/V8zQGvVlbZp0cFC0QdsEIyfwyGsS+K BzEAGaYqef+9MfWPKCZh/dys8szBOSpHYdBQlb9CmI6k1QnDgmwQlZkiRLi9BE7PiVpn qQ+b61otYCPbFO/3Rs3ebiswb+a26H+tZwmsrTfrIqZ5FNMljYQZRQb/AemHF5HAkSEt WFPCzHMHoieK37d2OeeaamEAGOW4h29F9ZIzLrwDjKlThZajh5bqUfaMcWZhG1lz75u4 Fv3Q== X-Gm-Message-State: ACgBeo2Hyee13DsbVdXNab8KxpVbO8j2VE7ast0/zFxmhkU2IxDr9Oc4 z3xorTImM6lv7PXzckrkDIN3eWQEhBGPTQ== X-Google-Smtp-Source: AA6agR5fN5Cjtl8j6y11tgYXw36guiLuHyVSJStuubTP+plna/RvBN7D78PypfD788jQhbuRyX3SAg== X-Received: by 2002:adf:fecd:0:b0:21f:d78:743f with SMTP id q13-20020adffecd000000b0021f0d78743fmr13668808wrs.704.1659455205008; Tue, 02 Aug 2022 08:46:45 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i18-20020a1c5412000000b003a4c6e67f01sm10599260wmb.6.2022.08.02.08.46.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 08:46: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 v2 28/28] submodule--helper: fix bad config API usage Date: Tue, 2 Aug 2022 17:46:12 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1233.ge8b09efaedc 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 4f7ece6fb05..5bc9cc41369 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -3098,7 +3098,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