From patchwork Wed Nov 2 07:53: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: 13027779 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 2272BC433FE for ; Wed, 2 Nov 2022 07:54:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229950AbiKBHyO (ORCPT ); Wed, 2 Nov 2022 03:54:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbiKBHyM (ORCPT ); Wed, 2 Nov 2022 03:54:12 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C44F2529B for ; Wed, 2 Nov 2022 00:54:11 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id y14so43099774ejd.9 for ; Wed, 02 Nov 2022 00:54:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9lsBjQ6ihJRxepmyr7aP59FTVBpgU/x7SnVh8AdxSrQ=; b=m58hXgpQ+tlJOvblYDGFCgpVhtrdnrR2baincV26vPmDC4ht8IvscMVch2YyCx+yAq y4bDNqNhydJNPl/2CIcdj5f9rswf5t3y0/ybmcfwoJDTq5L7H2xEmBcicszo8uc9Ugwf vhPtdgy73MYHt2JQxmlq22pRVW1uD0U7y4GkPiDiiMNVAOSPNE2p9bbjMdUXy9HoIaEg ZSYE8i4cywiUVei1LSUE0686DHR2v/t9NkWgClgp/pt/7vMTNt8iCbHYqVfhMTKb7vtm W0Qi0KXY8UMY3IMFR+aAZBWnCgtE+PcfDkMaFUklRwvdIewChi9IE5jpRSe7BagHyjhL zywg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9lsBjQ6ihJRxepmyr7aP59FTVBpgU/x7SnVh8AdxSrQ=; b=f52a4ylj/Pc2VoM9sVyVMjMgwF1PrMPpF86BBCvVJzSeCp/0hHGpySwZnjTi3o/Dq4 uVklSNIgF3EhGWcMuCw6b735Ux+5hGbI01Nvn3gJIvzUepKzvmJ4uayu45zmp1F9c7Uh AyLXmiwsKFhNjVXZ/XxqlMSYB0zGa83j8HGh1ibOdaLzm0Oa/ZRApCMGIhdyR/OzmKf1 s12nKC9piBfz7z+zJwGTJMNEDB4uDWL2C6kqIrH5bJrCjJzUrG7OmJaMVm04rVAtn327 l2BPNjXUFm481+UfirY5/UNJ39n/FgKXIU5ydNLEHsCqvG3y5AqhGOp1BXYWHNNpnNnr 6iMQ== X-Gm-Message-State: ACrzQf2ou/qT3gkFvYpXvtBDuDsnGyG4ovjpaiIzaxBZnuBemtCXm8/D vWbbbVYutV2VARdckutuR5p+ZkfADojnmw== X-Google-Smtp-Source: AMsMyM7QNVsMCpbc40BIMIqBPVczRzPecou+YHivs5THcLBuUqPfEDrkHuCuP+u5rXxgQPgf5MaYCA== X-Received: by 2002:a17:906:bceb:b0:7ae:75e:3929 with SMTP id op11-20020a170906bceb00b007ae075e3929mr1020264ejb.400.1667375648913; Wed, 02 Nov 2022 00:54:08 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ku11-20020a170907788b00b0073d84a321c8sm5045466ejc.166.2022.11.02.00.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 00:54:08 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Emily Shaffer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 1/8] submodule--helper: move "config" to a test-tool Date: Wed, 2 Nov 2022 08:53:58 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1280.g8136eb6fab2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As with other moves to "test-tool" in f322e9f51b5 (Merge branch 'ab/submodule-helper-prep', 2022-09-13) the "config" sub-command was only used by our own tests. Let's move it over, and while doing so make it easier to reason about by splitting up the various uses for it into separate sub-commands, so that we don't need to count arguments to see what it does. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 46 -------------- t/helper/test-submodule.c | 84 ++++++++++++++++++++++++++ t/t7411-submodule-config.sh | 28 ++++----- t/t7418-submodule-sparse-gitmodules.sh | 4 +- 4 files changed, 100 insertions(+), 62 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index a7683d35299..6250b95a6f7 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2861,51 +2861,6 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) return ret; } -static int module_config(int argc, const char **argv, const char *prefix) -{ - enum { - 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"), - CHECK_WRITEABLE), - OPT_CMDMODE(0, "unset", &command, - N_("unset the config in the .gitmodules file"), - DO_UNSET), - OPT_END() - }; - const char *const git_submodule_helper_usage[] = { - N_("git submodule--helper config []"), - N_("git submodule--helper config --unset "), - "git submodule--helper config --check-writeable", - NULL - }; - - argc = parse_options(argc, argv, prefix, module_config_options, - git_submodule_helper_usage, PARSE_OPT_KEEP_ARGV0); - - if (argc == 1 && command == CHECK_WRITEABLE) - return is_writing_gitmodules_ok() ? 0 : -1; - - /* Equivalent to ACTION_GET in builtin/config.c */ - if (argc == 2 && command != DO_UNSET) - return print_config_from_gitmodules(the_repository, argv[1]); - - /* Equivalent to ACTION_SET in builtin/config.c */ - if (argc == 3 || (argc == 2 && command == DO_UNSET)) { - const char *value = (argc == 3) ? argv[2] : NULL; - - if (!is_writing_gitmodules_ok()) - die(_("please make sure that the .gitmodules file is in the working tree")); - - return config_set_in_gitmodules_file_gently(argv[1], value); - } - - usage_with_options(git_submodule_helper_usage, module_config_options); -} - static int module_set_url(int argc, const char **argv, const char *prefix) { int quiet = 0; @@ -3424,7 +3379,6 @@ static struct cmd_struct commands[] = { {"summary", module_summary, 0}, {"push-check", push_check, 0}, {"absorbgitdirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX}, - {"config", module_config, 0}, {"set-url", module_set_url, 0}, {"set-branch", module_set_branch, 0}, {"create-branch", module_create_branch, 0}, diff --git a/t/helper/test-submodule.c b/t/helper/test-submodule.c index b7d117cd557..c7cb463a583 100644 --- a/t/helper/test-submodule.c +++ b/t/helper/test-submodule.c @@ -111,10 +111,94 @@ static int cmd__submodule_resolve_relative_url(int argc, const char **argv) return 0; } +static int cmd__submodule_config_list(int argc, const char **argv) +{ + struct option options[] = { + OPT_END() + }; + const char *const usage[] = { + "test-tool submodule config-list ", + NULL + }; + argc = parse_options(argc, argv, "test-tools", options, usage, + PARSE_OPT_KEEP_ARGV0); + + setup_git_directory(); + + if (argc == 2) + return print_config_from_gitmodules(the_repository, argv[1]); + usage_with_options(usage, options); +} + +static int cmd__submodule_config_set(int argc, const char **argv) +{ + struct option options[] = { + OPT_END() + }; + const char *const usage[] = { + "test-tool submodule config-set ", + NULL + }; + argc = parse_options(argc, argv, "test-tools", options, usage, + PARSE_OPT_KEEP_ARGV0); + + setup_git_directory(); + + /* Equivalent to ACTION_SET in builtin/config.c */ + if (argc == 3) { + if (!is_writing_gitmodules_ok()) + die(_("please make sure that the .gitmodules file is in the working tree")); + + return config_set_in_gitmodules_file_gently(argv[1], argv[2]); + } + usage_with_options(usage, options); +} + +static int cmd__submodule_config_unset(int argc, const char **argv) +{ + struct option options[] = { + OPT_END() + }; + const char *const usage[] = { + "test-tool submodule config-unset ", + NULL + }; + + setup_git_directory(); + + if (argc == 2) { + if (!is_writing_gitmodules_ok()) + die(_("please make sure that the .gitmodules file is in the working tree")); + return config_set_in_gitmodules_file_gently(argv[1], NULL); + } + usage_with_options(usage, options); +} + +static int cmd__submodule_config_writeable(int argc, const char **argv) +{ + struct option options[] = { + OPT_END() + }; + const char *const usage[] = { + "test-tool submodule config-writeable", + NULL + }; + setup_git_directory(); + + if (argc == 1) + return is_writing_gitmodules_ok() ? 0 : -1; + + usage_with_options(usage, options); +} + 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}, + { "config-list", cmd__submodule_config_list }, + { "config-set", cmd__submodule_config_set }, + { "config-unset", cmd__submodule_config_unset }, + { "config-writeable", cmd__submodule_config_writeable }, }; int cmd__submodule(int argc, const char **argv) diff --git a/t/t7411-submodule-config.sh b/t/t7411-submodule-config.sh index c583c4e373a..2f57ecd177a 100755 --- a/t/t7411-submodule-config.sh +++ b/t/t7411-submodule-config.sh @@ -140,15 +140,15 @@ test_expect_success 'error in history in fetchrecursesubmodule lets continue' ' test_expect_success 'reading submodules config from the working tree with "submodule--helper config"' ' (cd super && echo "../submodule" >expect && - git submodule--helper config submodule.submodule.url >actual && + test-tool submodule config-list submodule.submodule.url >actual && test_cmp expect actual ) ' test_expect_success 'unsetting submodules config from the working tree with "submodule--helper config --unset"' ' (cd super && - git submodule--helper config --unset submodule.submodule.url && - git submodule--helper config submodule.submodule.url >actual && + test-tool submodule config-unset submodule.submodule.url && + test-tool submodule config-list submodule.submodule.url >actual && test_must_be_empty actual ) ' @@ -157,8 +157,8 @@ test_expect_success 'unsetting submodules config from the working tree with "sub test_expect_success 'writing submodules config with "submodule--helper config"' ' (cd super && echo "new_url" >expect && - git submodule--helper config submodule.submodule.url "new_url" && - git submodule--helper config submodule.submodule.url >actual && + test-tool submodule config-set submodule.submodule.url "new_url" && + test-tool submodule config-list submodule.submodule.url >actual && test_cmp expect actual ) ' @@ -167,14 +167,14 @@ test_expect_success 'overwriting unstaged submodules config with "submodule--hel test_when_finished "git -C super checkout .gitmodules" && (cd super && echo "newer_url" >expect && - git submodule--helper config submodule.submodule.url "newer_url" && - git submodule--helper config submodule.submodule.url >actual && + test-tool submodule config-set submodule.submodule.url "newer_url" && + test-tool submodule config-list submodule.submodule.url >actual && test_cmp expect actual ) ' test_expect_success 'writeable .gitmodules when it is in the working tree' ' - git -C super submodule--helper config --check-writeable + test-tool -C super submodule config-writeable ' test_expect_success 'writeable .gitmodules when it is nowhere in the repository' ' @@ -183,7 +183,7 @@ test_expect_success 'writeable .gitmodules when it is nowhere in the repository' (cd super && git rm .gitmodules && git commit -m "remove .gitmodules from the current branch" && - git submodule--helper config --check-writeable + test-tool submodule config-writeable ) ' @@ -191,7 +191,7 @@ test_expect_success 'non-writeable .gitmodules when it is in the index but not i test_when_finished "git -C super checkout .gitmodules" && (cd super && rm -f .gitmodules && - test_must_fail git submodule--helper config --check-writeable + test_must_fail test-tool submodule config-writeable ) ' @@ -200,7 +200,7 @@ test_expect_success 'non-writeable .gitmodules when it is in the current branch test_when_finished "git -C super reset --hard $ORIG" && (cd super && git rm .gitmodules && - test_must_fail git submodule--helper config --check-writeable + test_must_fail test-tool submodule config-writeable ) ' @@ -208,11 +208,11 @@ test_expect_success 'reading submodules config from the index when .gitmodules i ORIG=$(git -C super rev-parse HEAD) && test_when_finished "git -C super reset --hard $ORIG" && (cd super && - git submodule--helper config submodule.submodule.url "staged_url" && + test-tool submodule config-set submodule.submodule.url "staged_url" && git add .gitmodules && rm -f .gitmodules && echo "staged_url" >expect && - git submodule--helper config submodule.submodule.url >actual && + test-tool submodule config-list submodule.submodule.url >actual && test_cmp expect actual ) ' @@ -223,7 +223,7 @@ test_expect_success 'reading submodules config from the current branch when .git (cd super && git rm .gitmodules && echo "../submodule" >expect && - git submodule--helper config submodule.submodule.url >actual && + test-tool submodule config-list submodule.submodule.url >actual && test_cmp expect actual ) ' diff --git a/t/t7418-submodule-sparse-gitmodules.sh b/t/t7418-submodule-sparse-gitmodules.sh index d5874200fdc..dde11ecce80 100755 --- a/t/t7418-submodule-sparse-gitmodules.sh +++ b/t/t7418-submodule-sparse-gitmodules.sh @@ -50,12 +50,12 @@ test_expect_success 'sparse checkout setup which hides .gitmodules' ' test_expect_success 'reading gitmodules config file when it is not checked out' ' echo "../submodule" >expect && - git -C super submodule--helper config submodule.submodule.url >actual && + test-tool -C super submodule config-list submodule.submodule.url >actual && test_cmp expect actual ' test_expect_success 'not writing gitmodules config file when it is not checked out' ' - test_must_fail git -C super submodule--helper config submodule.submodule.url newurl && + test_must_fail test-tool -C super submodule config-set submodule.submodule.url newurl && test_path_is_missing super/.gitmodules ' From patchwork Wed Nov 2 07:53: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: 13027780 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 7EC19C4332F for ; Wed, 2 Nov 2022 07:54:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230012AbiKBHyQ (ORCPT ); Wed, 2 Nov 2022 03:54:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbiKBHyN (ORCPT ); Wed, 2 Nov 2022 03:54:13 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 042B425283 for ; Wed, 2 Nov 2022 00:54:12 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id ud5so43125438ejc.4 for ; Wed, 02 Nov 2022 00:54:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=igsSRhnfRZbcip5u6/zolBid4FtSk2cCM2Yty0T41sg=; b=SKfyM11/x4E4TSoE4kxPBRF2wvds7RdKy2wBNMDYpu5XmEati3M399NwSXokFzdtDv 2IIBishSQH6kFjg8Nr4s/7PGp17V32X0yT6+ZxDWy7BEuxwEDbBg/VRINkHByM4wJ0G9 f40aTD01gnJgBfmXrCAWwdLVI7grv2bbJQZh+RxXcvdSrHn7QVhG7+buJBRqtF3HMLDS Vd5FI2KcHuYMHhsvzd63X8yfnptLrJY/n37PZw2FPFDUi82r3x2cBrdl2dM2G3czPY/i VRsXDkPVKB7sxVBQ9dzL/UkI5IZMKFuCikElNrSjoVldzIsHS1kopznDw+ETl+oI8OEk +SVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=igsSRhnfRZbcip5u6/zolBid4FtSk2cCM2Yty0T41sg=; b=VGpuqst3QxMM5H+AvM8mv2ok1i76MdYry1Piea3MfkuhIhDzd75E1hRp+Xm5Zn4Euk Y6gr0pkpeTeLpbVQXQ+N/nkrHDWAOa+javoqwf+Y2iN4Dyfr9jMosbyRBzvLT5glK8B1 UzSSouqz8RgyCpzrlrLOex15lPzObKc5ISu/s1fV4G6pd5ZRC3/pLWc3ncwI3HdBRANo dhc/KnAPt4NdBovRb85SMKY3a4AZpW2YNadv0l+cvsBPbNioxp2COtg/XZFT/yQ0ZN7N n/B8sZO119kqQX/zhhEyojLwq1Sf6AM8g+2odHZlOWKz+jtdnAlL+qpKUiHl85lGDEZN atYQ== X-Gm-Message-State: ACrzQf2JFggsidkHegIiP1x9mi+37iMZk5zZ57GDlm1p8XGKDT0wghze MW/lVlFsQM3cIOyjK95FBx2yk+oXLrEx1g== X-Google-Smtp-Source: AMsMyM65XlXsLhfva9OMIVbwjMuaiHQsVsw1rqnA8g6r0s8BZpQ1FM3aP76fAm40cgavUhH0ROhnzg== X-Received: by 2002:a17:907:8c81:b0:7ad:f0ae:f4b4 with SMTP id td1-20020a1709078c8100b007adf0aef4b4mr6510661ejc.563.1667375650215; Wed, 02 Nov 2022 00:54:10 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ku11-20020a170907788b00b0073d84a321c8sm5045466ejc.166.2022.11.02.00.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 00:54:09 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Emily Shaffer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 2/8] submodule tests: add tests for top-level flag output Date: Wed, 2 Nov 2022 08:53:59 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1280.g8136eb6fab2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Exhaustively test for how combining various "mixed-level" "git submodule" option works. "Mixed-level" here means options that are accepted by a mixture of the top-level "submodule" command, and e.g. the "status" sub-command. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t7400-submodule-basic.sh | 10 +++ t/t7422-submodule-output.sh | 169 ++++++++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100755 t/t7422-submodule-output.sh diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index a989aafaf57..eae6a46ef3d 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -579,6 +579,16 @@ test_expect_success 'status should be "modified" after submodule commit' ' grep "^+$rev2" list ' +test_expect_success '"submodule --cached" command forms should be identical' ' + git submodule status --cached >expect && + + git submodule --cached >actual && + test_cmp expect actual && + + git submodule --cached status >actual && + test_cmp expect actual +' + test_expect_success 'the --cached sha1 should be rev1' ' git submodule --cached status >list && grep "^+$rev1" list diff --git a/t/t7422-submodule-output.sh b/t/t7422-submodule-output.sh new file mode 100755 index 00000000000..3ac56c23f72 --- /dev/null +++ b/t/t7422-submodule-output.sh @@ -0,0 +1,169 @@ +#!/bin/sh + +test_description='submodule --cached, --quiet etc. output' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-t3100.sh + +setup_sub () { + local d="$1" && + shift && + git $@ clone . "$d" && + git $@ submodule add ./"$d" +} + +normalize_status () { + sed -e 's/-g[0-9a-f]*/-gHASH/' +} + +test_expect_success 'setup' ' + test_commit A && + test_commit B && + setup_sub S && + setup_sub S.D && + setup_sub S.C && + setup_sub S.C.D && + setup_sub X && + git add S* && + test_commit C && + + # recursive in X/ + git -C X pull && + GIT_ALLOW_PROTOCOL=file git -C X submodule update --init && + + # dirty p + for d in S.D X/S.D + do + echo dirty >S.D/A.t || return 1 + done && + + # commit (for --cached) + for d in S.C* X/S.C* + do + git -C "$d" reset --hard A || return 1 + done && + + # dirty + for d in S*.D X/S*.D + do + echo dirty >"$d/C2.t" || return 1 + done && + + for ref in A B C + do + # Not different with SHA-1 and SHA-256, just (ab)usign + # test_oid_cache as a variable bag to avoid using + # $(git rev-parse ...). + oid=$(git rev-parse $ref) && + test_oid_cache <<-EOF || return 1 + $ref sha1:$oid + $ref sha256:$oid + EOF + done +' + +for opts in "" "status" +do + test_expect_success "git submodule $opts" ' + sed -e "s/^>//" >expect <<-EOF && + > $(test_oid B) S (B) + >+$(test_oid A) S.C (A) + >+$(test_oid A) S.C.D (A) + > $(test_oid B) S.D (B) + >+$(test_oid C) X (C) + EOF + git submodule $opts >actual.raw && + normalize_status actual && + test_cmp expect actual + ' +done + +for opts in \ + "status --recursive" +do + test_expect_success "git submodule $opts" ' + sed -e "s/^>//" >expect <<-EOF && + > $(test_oid B) S (B) + >+$(test_oid A) S.C (A) + >+$(test_oid A) S.C.D (A) + > $(test_oid B) S.D (B) + >+$(test_oid C) X (C) + > $(test_oid B) X/S (B) + >+$(test_oid A) X/S.C (A) + >+$(test_oid A) X/S.C.D (A) + > $(test_oid B) X/S.D (B) + > $(test_oid B) X/X (B) + EOF + git submodule $opts >actual.raw && + normalize_status actual && + test_cmp expect actual + ' +done + +for opts in \ + "--quiet" \ + "--quiet status" \ + "status --quiet" +do + test_expect_success "git submodule $opts" ' + git submodule $opts >out && + test_must_be_empty out + ' +done + +for opts in \ + "--cached" \ + "--cached status" \ + "status --cached" +do + test_expect_success "git submodule $opts" ' + sed -e "s/^>//" >expect <<-EOF && + > $(test_oid B) S (B) + >+$(test_oid B) S.C (B) + >+$(test_oid B) S.C.D (B) + > $(test_oid B) S.D (B) + >+$(test_oid B) X (B) + EOF + git submodule $opts >actual.raw && + normalize_status actual && + test_cmp expect actual + ' +done + +for opts in \ + "--cached --quiet" \ + "--cached --quiet status" \ + "--cached status --quiet" \ + "--quiet status --cached" \ + "status --cached --quiet" +do + test_expect_success "git submodule $opts" ' + git submodule $opts >out && + test_must_be_empty out + ' +done + +for opts in \ + "status --cached --recursive" \ + "--cached status --recursive" +do + test_expect_success "git submodule $opts" ' + sed -e "s/^>//" >expect <<-EOF && + > $(test_oid B) S (B) + >+$(test_oid B) S.C (B) + >+$(test_oid B) S.C.D (B) + > $(test_oid B) S.D (B) + >+$(test_oid B) X (B) + > $(test_oid B) X/S (B) + >+$(test_oid B) X/S.C (B) + >+$(test_oid B) X/S.C.D (B) + > $(test_oid B) X/S.D (B) + > $(test_oid B) X/X (B) + EOF + git submodule $opts >actual.raw && + normalize_status actual && + test_cmp expect actual + ' +done + +test_done From patchwork Wed Nov 2 07:54: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: 13027781 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 CA09FC4332F for ; Wed, 2 Nov 2022 07:54:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230197AbiKBHyY (ORCPT ); Wed, 2 Nov 2022 03:54:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229770AbiKBHyN (ORCPT ); Wed, 2 Nov 2022 03:54:13 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4515252AF for ; Wed, 2 Nov 2022 00:54:12 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id ud5so43125511ejc.4 for ; Wed, 02 Nov 2022 00:54:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=j/tkfnNznG6MqEQMCdKJ/aQggfu4lqvjg892Rl3tKwg=; b=gS92Guk0WNaps1LPFli3KJ5mjBzcz3lmP7GsRd5KhgxQo2VvgMJyq4im8de4Rvfm1w wmJQ/j+f4XI2w2DuKeSCmAotQv6U2lzSHfGL/rU+kz4yBkQc/8FLsyOU7R3uhElzxQpu WP5VSM4geZrAqbiMI8iAZtFZdRGBIjAK4VKG/2f48fTCEIigQusht27+pJiSktEgUj62 P03rL6QTY4WgpF9bvxBfD2ooEcEh2cLKylYAMW9VOPHX3dQfbj0oLOS1snky6fjrYlu/ VjmeS0NRuc8jH0ehFK5Vp0ClB/8G6hqbaHVs0gJkBkqP9BjXbaHrF9twVRC+GeSmNqNl uzPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j/tkfnNznG6MqEQMCdKJ/aQggfu4lqvjg892Rl3tKwg=; b=QR6omAU4S5bJnlzpBcnZ/6w/MOAGvkaOo/aeIdblF7zhh59cdiQ1M3wTO36DFgCCZv LkAHa/h7c/lDlDrs6ZIFh2db83s2Mv1EtIQNLZWcf2NPVZ+Wz/a9e4rP8Q4XlytMYjwA /ZvIJLBtChpuSdIiy7JxMlNSVLEEQnD/BJRxYFzQg3pCCrgdOMjHr/Pcw0C8H6FgvYNe UFcJyf+L7qYN0xeALUX7bM1NJGEhJsuH4hda1yhCUYYP2jQvwpp2ZqMiQvi8qRSVwNqY v7kj0Y9648rC6BKHqn/cuuedYNiOJeNzgI/rgORQE8M7gw46RYrZhErcMDMFdEDqToNb NfIw== X-Gm-Message-State: ACrzQf0Oq5FG2Kx23iv08bcu4pKTOeNwOiRfWy4Bz+nNBkMc6A/5fnWf /eoeIcN9NFQcUimhMbGBdPJwoRvKraffrg== X-Google-Smtp-Source: AMsMyM742uZJ4BmT0RUnNKX/NjEBsQMTexPdPMEdUD9eQHFLQq4Hn7jkbI+uj3a41Ubn1W6sV2x4Cg== X-Received: by 2002:a17:906:8a6c:b0:7a8:2f09:d88d with SMTP id hy12-20020a1709068a6c00b007a82f09d88dmr21965046ejc.49.1667375651115; Wed, 02 Nov 2022 00:54:11 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ku11-20020a170907788b00b0073d84a321c8sm5045466ejc.166.2022.11.02.00.54.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 00:54:10 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Emily Shaffer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 3/8] submodule tests: test for a "foreach" blind-spot Date: Wed, 2 Nov 2022 08:54:00 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1280.g8136eb6fab2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We tested for "--" followed by command names, but not for "--" followed by an argument that looks like an option, let's do that. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t7407-submodule-foreach.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh index 59bd1501667..8d7b234beb8 100755 --- a/t/t7407-submodule-foreach.sh +++ b/t/t7407-submodule-foreach.sh @@ -154,6 +154,11 @@ test_expect_success 'use "submodule foreach" to checkout 2nd level submodule' ' ) ' +test_expect_success 'usage: foreach -- --not-an-option' ' + test_expect_code 1 git submodule foreach -- --not-an-option && + test_expect_code 1 git -C clone2 submodule foreach -- --not-an-option +' + test_expect_success 'use "foreach --recursive" to checkout all submodules' ' ( cd clone2 && From patchwork Wed Nov 2 07:54: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: 13027782 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 BD276C43219 for ; Wed, 2 Nov 2022 07:54:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230394AbiKBHy0 (ORCPT ); Wed, 2 Nov 2022 03:54:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229935AbiKBHyO (ORCPT ); Wed, 2 Nov 2022 03:54:14 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C74E025EB6 for ; Wed, 2 Nov 2022 00:54:13 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id bj12so42980982ejb.13 for ; Wed, 02 Nov 2022 00:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qth/4vtY+GWDUDv1yyhAF72QYNGKyQd+E2A4KecpBHk=; b=XfU0n7ocFQFbkGwRNdOt4u1YPKHhybB+XhT5U3GBBMLH6KzoS4yXsGnCEAssXS1N70 Q+CyuyksYNbh6SYct2KOZ5gDUlkTPtaKeoCp3YC0OXI7Eqpm9+zyqnJ6TLBvAo+Z30pW JpUeD22SaDkax1yHRIoVVOwutH8OjSkLN5ApylU36rrFCPjhr0gSzqyk/jzMn88MiksA c1EJtlJ5R6iog57OuAdTSIo4nRvKYHpxJV/MwNooLPdU0YC6Uhc7dOwkjYupRMfc1yR/ 1+5S6cGmHx5uYMeCtQgpR4W9K5CcdxdRwFWVMpHnrgcKlEUW9ffWwRCkJN3rNInKsEdb LNmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qth/4vtY+GWDUDv1yyhAF72QYNGKyQd+E2A4KecpBHk=; b=AC/LReOyfEvaFrfqtHcYNQF0BRg2+7gxA+JrXEmeEPVyj03B7qV0skftzKArKQUeky eah9LqvgpLCZTLqEOcF6FquF0kgcAV6WKgT2/zBD0JxOVA+c03AluWtw6u5ifxe3QGUR lh1nWeTB0eWBxxGspN95oA3JZ0YSIStbRxQ9tAgjh5Z6HIngtKJuM5ZAScTXKsSZPSco RMG07R+CzyHwppM9FLO8Jf1oUYRnSgKL8oUGFTreL7mjllzzxe9ucv8GUHyXa0e6Z9fl w+TksirmRgNZVN2mADVDefF/nYvBOnqxVliJhxT6Pu3ZkLpVkf/Sc52r3EU13B0v0/wT W6aw== X-Gm-Message-State: ACrzQf30sGC6w1PjlhIClbc4vci4+LfBRzsuHQBQKrZP24cUxalx7aAG Ltl66OtPeyi61Ao4tydG+SQe6kx0+3jKqw== X-Google-Smtp-Source: AMsMyM7LfeodOwiZEP9bLrWZiGbXPsMKfbQbPhKvqClHUCkl+RBCRxNc7ubJONGEBDv4UFgzsqVVVg== X-Received: by 2002:a17:907:d89:b0:7a8:d67d:87d3 with SMTP id go9-20020a1709070d8900b007a8d67d87d3mr21908177ejc.364.1667375651953; Wed, 02 Nov 2022 00:54:11 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ku11-20020a170907788b00b0073d84a321c8sm5045466ejc.166.2022.11.02.00.54.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 00:54:11 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Emily Shaffer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 4/8] submodule.c: refactor recursive block out of absorb function Date: Wed, 2 Nov 2022 08:54:01 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1280.g8136eb6fab2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org A move and indentation-only change to move the ABSORB_GITDIR_RECURSE_SUBMODULES case into its own function, which as we'll see makes the subsequent commit changing this code much smaller. Signed-off-by: Ævar Arnfjörð Bjarmason --- submodule.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/submodule.c b/submodule.c index b958162d286..fe1e3f03905 100644 --- a/submodule.c +++ b/submodule.c @@ -2310,6 +2310,23 @@ static void relocate_single_git_dir_into_superproject(const char *path) strbuf_release(&new_gitdir); } +static void absorb_git_dir_into_superproject_recurse(const char *path) +{ + + struct child_process cp = CHILD_PROCESS_INIT; + + cp.dir = path; + cp.git_cmd = 1; + cp.no_stdin = 1; + strvec_pushf(&cp.args, "--super-prefix=%s%s/", + get_super_prefix_or_empty(), path); + strvec_pushl(&cp.args, "submodule--helper", + "absorbgitdirs", NULL); + prepare_submodule_repo_env(&cp.env); + if (run_command(&cp)) + die(_("could not recurse into submodule '%s'"), path); +} + /* * Migrate the git directory of the submodule given by path from * having its git directory within the working tree to the git dir nested @@ -2366,21 +2383,10 @@ void absorb_git_dir_into_superproject(const char *path, strbuf_release(&gitdir); if (flags & ABSORB_GITDIR_RECURSE_SUBMODULES) { - struct child_process cp = CHILD_PROCESS_INIT; - if (flags & ~ABSORB_GITDIR_RECURSE_SUBMODULES) BUG("we don't know how to pass the flags down?"); - cp.dir = path; - cp.git_cmd = 1; - cp.no_stdin = 1; - strvec_pushf(&cp.args, "--super-prefix=%s%s/", - get_super_prefix_or_empty(), path); - strvec_pushl(&cp.args, "submodule--helper", - "absorbgitdirs", NULL); - prepare_submodule_repo_env(&cp.env); - if (run_command(&cp)) - die(_("could not recurse into submodule '%s'"), path); + absorb_git_dir_into_superproject_recurse(path); } } From patchwork Wed Nov 2 07:54: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: 13027783 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 AA715C433FE for ; Wed, 2 Nov 2022 07:54:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230224AbiKBHy1 (ORCPT ); Wed, 2 Nov 2022 03:54:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229996AbiKBHyQ (ORCPT ); Wed, 2 Nov 2022 03:54:16 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A2F32610E for ; Wed, 2 Nov 2022 00:54:14 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id 21so25178962edv.3 for ; Wed, 02 Nov 2022 00:54:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QgwdAoK4er9kojqN0MPtw6y+VWSBCJ5BhDqQA9/L0u8=; b=OlMZvEmr/Den2522baWKWsBi4kE3x7V0UpES2ltzr0DjrSR9QOT3zH8xRX9UGs+1rq InNnsUjso/f3M56If409GxsPXygmRR+pxrbItL16NDcQ7/GMaFg2seqxcOIke77jnQPn WD8hob1zj8X72lmPPVR8BGwoL4uKec0rS6BrF2ejFFmlEMOCQw8tx3Hntv/zmWLEd7UG 016KxiMJ8BZ6ec1MbcvMKZTnd+2k3TAllU5Kxu+JuJKW5I5w4v6N6kEewKrrp3rT1hI0 ekcKIaQu4fiC75cEFKK4cvmz9ExFPL0xhcm0EorpQb2V9DkdVdRGLgeFBDkuhzAYTgCD rfdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QgwdAoK4er9kojqN0MPtw6y+VWSBCJ5BhDqQA9/L0u8=; b=x+901JekMkAoZA7QatXRTWlAAnsuf75hvk9yM0Lx/h9KL2vSfo8TBdRRVeGLBJ7ss3 rh2ynIu1vbg89LhL3DlZKZyT9ly4ZIipVIfpjfSj53vFjI06XDzrv5MFuyhZbEIwUcpT RJkK8usVf4+5F9Z+CZYzpSc8M6G8sAPg6kr2Useuk4SNFNl5IeO2BFxShjNbbN/L+m// d7/TKQMF6AkIgu6Ac0HLYks5I6jrKOkAcA5JFHsHO+rvJ+CKfYlpURf3YAczTQK3KIAi v3xVgSbzOG3MXrIuNLM+9r8kcXgrSk3nRMXI/3pxXQROy1z3Acf5DvMscayIQuHQFb5v /+yQ== X-Gm-Message-State: ACrzQf0Ja9D7xfr8R/v+oLyeH/ztNLqKBwQccY3WYA+eMbyq7kaYZrc7 40wan6iTHgjP9yQaVc4z+74DIG2QvsdK8Q== X-Google-Smtp-Source: AMsMyM60rq3nwCR9r2oNGuUo001aRILK3ccYeqCrRhD63o3SXim3pNnD1syLDk7wjVKCZoairdDQbg== X-Received: by 2002:a05:6402:f24:b0:461:7c77:98c4 with SMTP id i36-20020a0564020f2400b004617c7798c4mr22538996eda.80.1667375652823; Wed, 02 Nov 2022 00:54:12 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ku11-20020a170907788b00b0073d84a321c8sm5045466ejc.166.2022.11.02.00.54.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 00:54:12 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Emily Shaffer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 5/8] submodule API & "absorbgitdirs": remove "----recursive" option Date: Wed, 2 Nov 2022 08:54:02 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1280.g8136eb6fab2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove the "----recursive" option to "git submodule--helper absorbgitdirs" (yes, with 4 dashes, not 2). This option and all the "else" when "flags & ABSORB_GITDIR_RECURSE_SUBMODULES" is false has never been used since it was added in f6f85861400 (submodule: add absorb-git-dir function, 2016-12-12), which we'd have had to do as "----recursive", a "--recursive" would have errored out. It would be nice to follow-up with an optbug() assertion to parse-options.c for such funnily named options, I manually validated that this was the only long option whose name started with "-", but let's skip adding such an assertion for now. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/rm.c | 3 +-- builtin/submodule--helper.c | 8 ++------ submodule.c | 13 +++---------- submodule.h | 4 +--- 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/builtin/rm.c b/builtin/rm.c index f0d025a4e23..05bfe20a469 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -86,8 +86,7 @@ static void submodules_absorb_gitdir_if_needed(void) continue; if (!submodule_uses_gitfile(name)) - absorb_git_dir_into_superproject(name, - ABSORB_GITDIR_RECURSE_SUBMODULES); + absorb_git_dir_into_superproject(name); } } diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 6250b95a6f7..8b4af8430dc 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1378,8 +1378,7 @@ static void deinit_submodule(const char *path, const char *prefix, ".git file by using absorbgitdirs."), displaypath); - absorb_git_dir_into_superproject(path, - ABSORB_GITDIR_RECURSE_SUBMODULES); + absorb_git_dir_into_superproject(path); } @@ -2830,13 +2829,10 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) int i; struct pathspec pathspec = { 0 }; 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"), N_("path into the working tree")), - OPT_BIT(0, "--recursive", &flags, N_("recurse into submodules"), - ABSORB_GITDIR_RECURSE_SUBMODULES), OPT_END() }; const char *const git_submodule_helper_usage[] = { @@ -2852,7 +2848,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) goto cleanup; for (i = 0; i < list.nr; i++) - absorb_git_dir_into_superproject(list.entries[i]->name, flags); + absorb_git_dir_into_superproject(list.entries[i]->name); ret = 0; cleanup: diff --git a/submodule.c b/submodule.c index fe1e3f03905..8fa2ad457b2 100644 --- a/submodule.c +++ b/submodule.c @@ -2139,8 +2139,7 @@ int submodule_move_head(const char *path, if (!(flags & SUBMODULE_MOVE_HEAD_DRY_RUN)) { if (old_head) { if (!submodule_uses_gitfile(path)) - absorb_git_dir_into_superproject(path, - ABSORB_GITDIR_RECURSE_SUBMODULES); + absorb_git_dir_into_superproject(path); } else { struct strbuf gitdir = STRBUF_INIT; submodule_name_to_gitdir(&gitdir, the_repository, @@ -2332,8 +2331,7 @@ static void absorb_git_dir_into_superproject_recurse(const char *path) * having its git directory within the working tree to the git dir nested * in its superprojects git dir under modules/. */ -void absorb_git_dir_into_superproject(const char *path, - unsigned flags) +void absorb_git_dir_into_superproject(const char *path) { int err_code; const char *sub_git_dir; @@ -2382,12 +2380,7 @@ void absorb_git_dir_into_superproject(const char *path, } strbuf_release(&gitdir); - if (flags & ABSORB_GITDIR_RECURSE_SUBMODULES) { - if (flags & ~ABSORB_GITDIR_RECURSE_SUBMODULES) - BUG("we don't know how to pass the flags down?"); - - absorb_git_dir_into_superproject_recurse(path); - } + absorb_git_dir_into_superproject_recurse(path); } int get_superproject_working_tree(struct strbuf *buf) diff --git a/submodule.h b/submodule.h index 6a9fec6de11..b52a4ff1e73 100644 --- a/submodule.h +++ b/submodule.h @@ -164,9 +164,7 @@ void submodule_unset_core_worktree(const struct submodule *sub); */ void prepare_submodule_repo_env(struct strvec *env); -#define ABSORB_GITDIR_RECURSE_SUBMODULES (1<<0) -void absorb_git_dir_into_superproject(const char *path, - unsigned flags); +void absorb_git_dir_into_superproject(const char *path); /* * Return the absolute path of the working tree of the superproject, which this From patchwork Wed Nov 2 07:54: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: 13027784 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 0BE8FC4332F for ; Wed, 2 Nov 2022 07:54:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230457AbiKBHyb (ORCPT ); Wed, 2 Nov 2022 03:54:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230047AbiKBHyX (ORCPT ); Wed, 2 Nov 2022 03:54:23 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53CEB2649F for ; Wed, 2 Nov 2022 00:54:15 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id sc25so43017396ejc.12 for ; Wed, 02 Nov 2022 00:54:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VFZ77tukz9FFlCxL0WJBIl0rwyzYulb6XeqaAAB6WsE=; b=Xihz4K8izYj2GIXxUs9LIs7Cja3V/geeXi67SKYNGmFgVrjoEYDoOb1QZ7gYlIlYVH mxeLpMFt0pB8jidyzSGf6J0naU17sHTI5k8Z+c5qkVxaoK5d9PBnSuVfA0UeUY/MO7wz wchCHwcB+n/tRgGfdO5cSKYRr/WGL8jBLNsKvyZ7ZZew+U4RVF97xcaT424x8IpgZici +nmoJ0jSjG9oJCd+OUAWv7FlxaOuQpwD4/4Zx/vCc/DqVYuCa9RXojoMqR6wYgGJJc+F sI41/RFhJNiAVLadJ3aoypMlLTnVO1qLyYMBRZISb8yWC0gZhqwV/QYzyPFGG/Bxywhj OU5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VFZ77tukz9FFlCxL0WJBIl0rwyzYulb6XeqaAAB6WsE=; b=RSSqakjupqCx8sJlcu8TQ8UoAabYG9lxSi6shmW9EN9rw7gOtpeQC4umX/HpTKG6d6 tcJlA0WK4JiMopTEjEFQC5SOmLH0IIgpAoX0WfX7ravuOnPAtuEU/eHWy61DVg38FXKt FV/8hSpJz5JRRCJHllIDmjx1rkXOVx/PFWkpY5zVh8p5W7/tLlTO+d1rdmTsskiYAGfm pBHU24oy0rS8co5vbnWQP8fClU9N8grZbmNm+pZxVqmEZaXTrnfBJ96g2NULVtelXD9R W3TsuP+lJgnt7HVuaTejjqes2ilkFQarkB7omK4TIfmYvVkR2suyu5LYnB0KA3/NQ47U 8f0Q== X-Gm-Message-State: ACrzQf1IbfuSue8g25s1UahfuxckfUelvwQms1gFHc7UP8w0N1Dw/NF4 WGUYb6UWbqZTmw8GK1Oh4bctWBQZa9Sztw== X-Google-Smtp-Source: AMsMyM6ne9U4vhxuP+4VBy2VVI68HqIvDUSVzJXjqiQdMxNTi04Gol40NRoPtvFkJQChWteYvT/XPw== X-Received: by 2002:a17:906:446:b0:7ad:f0af:5c66 with SMTP id e6-20020a170906044600b007adf0af5c66mr6807664eja.441.1667375653652; Wed, 02 Nov 2022 00:54:13 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ku11-20020a170907788b00b0073d84a321c8sm5045466ejc.166.2022.11.02.00.54.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 00:54:13 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Emily Shaffer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 6/8] submodule--helper: remove --prefix from "absorbgitdirs" Date: Wed, 2 Nov 2022 08:54:03 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1280.g8136eb6fab2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Let's pass the "-C " option instead to "absorbgitdirs" from its only caller. When it was added in f6f85861400 (submodule: add absorb-git-dir function, 2016-12-12) there were other "submodule--helper" subcommands that were invoked with "-C ", so we could have done this all along. Suggested-by: Glen Choo Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 3 --- git-submodule.sh | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 8b4af8430dc..6bbefd34374 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2830,9 +2830,6 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) struct pathspec pathspec = { 0 }; struct module_list list = MODULE_LIST_INIT; struct option embed_gitdir_options[] = { - OPT_STRING(0, "prefix", &prefix, - N_("path"), - N_("path into the working tree")), OPT_END() }; const char *const git_submodule_helper_usage[] = { diff --git a/git-submodule.sh b/git-submodule.sh index 5e5d21c010f..d359f171379 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -557,7 +557,7 @@ cmd_sync() cmd_absorbgitdirs() { - git submodule--helper absorbgitdirs --prefix "$wt_prefix" "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper absorbgitdirs "$@" } # This loop parses the command line arguments to find the From patchwork Wed Nov 2 07:54: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: 13027785 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 0554BC4332F for ; Wed, 2 Nov 2022 07:54:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230463AbiKBHye (ORCPT ); Wed, 2 Nov 2022 03:54:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230196AbiKBHyY (ORCPT ); Wed, 2 Nov 2022 03:54:24 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2402326569 for ; Wed, 2 Nov 2022 00:54:16 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id f27so43092306eje.1 for ; Wed, 02 Nov 2022 00:54:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Sp7bhXI9suWL/LjIHe8Mthr+OoQZNzzW8PMTQaf7ksY=; b=o30dZI9Y28pUgq9MQu2VW9G410Q0I27RPu+MQJZlJ9wImS2g5zzSserH6l2o9gNcIr nUcqB7qntR7pMeI9vHEidEUhnvsErieNAvPXIpAmyOldofuIwE++dpzFBgCNJLs6zZ1I KP6f/qE1PiCIFXKii87/dpdCVGLS+5wzpgXXPE7fKa/0U4omcyP8GTixX9scphAtOLiU XH3vc7yMdDH4QkVFFqWOUdo+UFGDr13a44/UEsq8tTnKlmvdn5Ft/tgQGu2QJYz1QsFs 9Jbz3+rIvyye7IQPc8oo/zp5CJ1sgx4cQQb/6rR+kEtGQGwBowfNKZObjfmfHhKBw3ME f8cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Sp7bhXI9suWL/LjIHe8Mthr+OoQZNzzW8PMTQaf7ksY=; b=pYQbl3JZWg2YSfPcgX/E6qBuH0x6o10nsVnpvgPMfYHrSCnj8QD4ilztHCQJohwfwY Ood1vuCEzaemgPJdqDpuN/NV/wRexqMUKT+n9FDGo+rJhb9lilc/c8j3vu/DHTFrpO8S oViVcwxyUhDaycKCkx06VEzAmNEuGODqT6VSBrqdUdrx279s0/YOnzGHlHl19Cp1Xfb1 xylygJZvlhlFRmcbFWaY8WGOnydZl6RxC9yt7oEclwOIoQ5OV7GA5adUNBd5feslHe2J 7oJSfrz3iT99D181PM+Zr0UA1s45bsOUm5OdQu8NHoXtla9/7qQPCX3SZQf1U3zDyzts Awrg== X-Gm-Message-State: ACrzQf2YODdAKo8jm/GTqYuBvrKLZmj5SUW3DrjKWmb3sRYTx2slZkkA dO9GepjN7buI0Dnm+59bI7Qg1OrJmTb68g== X-Google-Smtp-Source: AMsMyM6gBBNUVp6rvuxtFK1aKZjC0GE2FAYCGRUg1kW+ew0XvhKHeJ/5746jB2IXanQMFaChduhwLg== X-Received: by 2002:a17:907:3ea4:b0:78e:25e2:c33b with SMTP id hs36-20020a1709073ea400b0078e25e2c33bmr21406101ejc.603.1667375654433; Wed, 02 Nov 2022 00:54:14 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ku11-20020a170907788b00b0073d84a321c8sm5045466ejc.166.2022.11.02.00.54.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 00:54:13 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Emily Shaffer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 7/8] submodule--helper: drop "update --prefix " for "-C update" Date: Wed, 2 Nov 2022 08:54:04 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1280.g8136eb6fab2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Since 29a5e9e1ffe (submodule--helper update-clone: learn --init, 2022-03-04) we've been passing "-C " from "git-submodule.sh" whenever we pass "--prefix ", so the latter is redundant to the former. Let's drop the "--prefix" option. Suggested-by: Glen Choo Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 4 +--- git-submodule.sh | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 6bbefd34374..2012ad31d7f 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2642,9 +2642,6 @@ static int module_update(int argc, const char **argv, const char *prefix) N_("traverse submodules recursively")), OPT_BOOL('N', "no-fetch", &opt.nofetch, N_("don't fetch new objects from the remote site")), - OPT_STRING(0, "prefix", &opt.prefix, - N_("path"), - N_("path into the working tree")), OPT_SET_INT(0, "checkout", &opt.update_default, N_("use the 'checkout' update strategy (default)"), SM_UPDATE_CHECKOUT), @@ -2700,6 +2697,7 @@ static int module_update(int argc, const char **argv, const char *prefix) } opt.filter_options = &filter_options; + opt.prefix = prefix; if (opt.update_default) opt.update_strategy.type = opt.update_default; diff --git a/git-submodule.sh b/git-submodule.sh index d359f171379..9a50f2e9124 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -343,7 +343,6 @@ cmd_update() ${recursive:+--recursive} \ ${init:+--init} \ ${nofetch:+--no-fetch} \ - ${wt_prefix:+--prefix "$wt_prefix"} \ ${rebase:+--rebase} \ ${merge:+--merge} \ ${checkout:+--checkout} \ From patchwork Wed Nov 2 07:54: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: 13027786 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 DA378C4332F for ; Wed, 2 Nov 2022 07:54:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230481AbiKBHyf (ORCPT ); Wed, 2 Nov 2022 03:54:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230244AbiKBHyZ (ORCPT ); Wed, 2 Nov 2022 03:54:25 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2ADAA25C77 for ; Wed, 2 Nov 2022 00:54:17 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id d26so43024557eje.10 for ; Wed, 02 Nov 2022 00:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/CFS+sDKN0h2xdgGzHNpNjhXPY5fKNn5b/msmWClGWQ=; b=DXfgSa++FLGmRc4pS6p3jxeL8acf6wsga31O3QMVsSY/sxFPE8IikU6I7P5xKxjrwN cqLH/naNJrgTJACKjorAicfJ9SIDv8fdwfMLlhVTcD+4XijLKryAYen0ZibP4aqGvoFw FE34P0+2QvXPAizknXKm01tTNNT7pIhNgv+QgROetqF6kWie9hx1xuIU0ntpDXVkpcsO j/JoWfZIVq/Xa377feKy6BTi3kUMqiKt1uB4lITXk00TzMOEYpX5Ka8Re9zyejirD1SB lSQNIY7czdJwd5up5oFiJ/8dn2JTswA+u2XydsnOXLeSITiIp+LFyyd99D0Rn2zUtesh s4Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/CFS+sDKN0h2xdgGzHNpNjhXPY5fKNn5b/msmWClGWQ=; b=wXF4vlykYxMwUDEbktY6Q6dkITT6yZgPTIURbaX/Jc8pYbHrRIUvpqs1FiBIXx9ZXs 4p+69XAPQjvWR/+ay2WDFiscvNZhzuU47UvaheZdnXbtb/doQjpjIFPwkoqqRpv2INYa JaExeGATupF0XSGm4eCAa3oNdegvTh8i567MV+L+UF93GeJ/Toj1C2XARxh6GxtViBmn QJWJQIm+KLMpTLTjhdTzfuqJ0Kkd/lTS/QEXL/wmsaICO/xqkNZMvOwkLcox6TBZC2Oy ZcpA0UgfZgjjYH6GnZOsKRG28C1obUet4RmqXIHEe+o9DNpSFTBgBVGNb1sSOObDldxU bD4A== X-Gm-Message-State: ACrzQf35P9ErItrZBs0hvIJBc6KFd/pL7Jl/xrHrTh7dP0SG6DbVhcTX Rn7cYSQmqUfopFnGkIbc+Z1KNkdbkkMWnQ== X-Google-Smtp-Source: AMsMyM5ytGkZQ3DD6nNABB22jE7N02jZLTn9rpxW2lFw655eyBrdXj//FhmvJNYmoWIiooY6AuCStA== X-Received: by 2002:a17:906:4783:b0:780:5be5:c81b with SMTP id cw3-20020a170906478300b007805be5c81bmr22295005ejc.76.1667375655255; Wed, 02 Nov 2022 00:54:15 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id ku11-20020a170907788b00b0073d84a321c8sm5045466ejc.166.2022.11.02.00.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 00:54:14 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Emily Shaffer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 8/8] submodule--helper: use OPT_SUBCOMMAND() API Date: Wed, 2 Nov 2022 08:54:05 +0100 Message-Id: X-Mailer: git-send-email 2.38.0.1280.g8136eb6fab2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Have the cmd_submodule__helper() use the OPT_SUBCOMMAND() API introduced in fa83cc834da (parse-options: add support for parsing subcommands, 2022-08-19). This is only a marginal reduction in line count, but once we start unifying this with a yet-to-be-added "builtin/submodule.c" it'll be much easier to reason about those changes, as they'll both use OPT_SUBCOMMAND(). We don't need to worry about "argv[0]" being NULL in the die() because we'd have errored out in parse_options() as we're not using "PARSE_OPT_SUBCOMMAND_OPTIONAL". Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 78 ++++++++++++++++++------------------- git.c | 2 +- 2 files changed, 39 insertions(+), 41 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 2012ad31d7f..0bc25dcf5ae 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -3350,47 +3350,45 @@ static int module_add(int argc, const char **argv, const char *prefix) return ret; } -#define SUPPORT_SUPER_PREFIX (1<<0) - -struct cmd_struct { - const char *cmd; - int (*fn)(int, const char **, const char *); - unsigned option; -}; - -static struct cmd_struct commands[] = { - {"clone", module_clone, SUPPORT_SUPER_PREFIX}, - {"add", module_add, 0}, - {"update", module_update, SUPPORT_SUPER_PREFIX}, - {"foreach", module_foreach, SUPPORT_SUPER_PREFIX}, - {"init", module_init, 0}, - {"status", module_status, SUPPORT_SUPER_PREFIX}, - {"sync", module_sync, SUPPORT_SUPER_PREFIX}, - {"deinit", module_deinit, 0}, - {"summary", module_summary, 0}, - {"push-check", push_check, 0}, - {"absorbgitdirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX}, - {"set-url", module_set_url, 0}, - {"set-branch", module_set_branch, 0}, - {"create-branch", module_create_branch, 0}, -}; - int cmd_submodule__helper(int argc, const char **argv, const char *prefix) { - int i; - if (argc < 2 || !strcmp(argv[1], "-h")) - usage("git submodule--helper "); - - for (i = 0; i < ARRAY_SIZE(commands); i++) { - if (!strcmp(argv[1], commands[i].cmd)) { - if (get_super_prefix() && - !(commands[i].option & SUPPORT_SUPER_PREFIX)) - die(_("%s doesn't support --super-prefix"), - commands[i].cmd); - return commands[i].fn(argc - 1, argv + 1, prefix); - } - } + const char *cmd = argv[0]; + const char *subcmd; + parse_opt_subcommand_fn *fn = NULL; + const char *const usage[] = { + N_("git submodule--helper "), + NULL + }; + struct option options[] = { + OPT_SUBCOMMAND("clone", &fn, module_clone), + OPT_SUBCOMMAND("add", &fn, module_add), + OPT_SUBCOMMAND("update", &fn, module_update), + OPT_SUBCOMMAND("foreach", &fn, module_foreach), + OPT_SUBCOMMAND("init", &fn, module_init), + OPT_SUBCOMMAND("status", &fn, module_status), + OPT_SUBCOMMAND("sync", &fn, module_sync), + OPT_SUBCOMMAND("deinit", &fn, module_deinit), + OPT_SUBCOMMAND("summary", &fn, module_summary), + OPT_SUBCOMMAND("push-check", &fn, push_check), + OPT_SUBCOMMAND("absorbgitdirs", &fn, absorb_git_dirs), + OPT_SUBCOMMAND("set-url", &fn, module_set_url), + OPT_SUBCOMMAND("set-branch", &fn, module_set_branch), + OPT_SUBCOMMAND("create-branch", &fn, module_create_branch), + OPT_END() + }; + argc = parse_options(argc, argv, prefix, options, usage, 0); + subcmd = argv[0]; + + if (strcmp(subcmd, "clone") && strcmp(subcmd, "update") && + strcmp(subcmd, "foreach") && strcmp(subcmd, "status") && + strcmp(subcmd, "sync") && strcmp(subcmd, "absorbgitdirs") && + get_super_prefix()) + /* + * xstrfmt() rather than "%s %s" to keep the translated + * string identical to git.c's. + */ + die(_("%s doesn't support --super-prefix"), + xstrfmt("'%s %s'", cmd, subcmd)); - die(_("'%s' is not a valid submodule--helper " - "subcommand"), argv[1]); + return fn(argc, argv, prefix); } diff --git a/git.c b/git.c index ee7758dcb0e..fb69e605912 100644 --- a/git.c +++ b/git.c @@ -610,7 +610,7 @@ static struct cmd_struct commands[] = { { "stash", cmd_stash, RUN_SETUP | NEED_WORK_TREE }, { "status", cmd_status, RUN_SETUP | NEED_WORK_TREE }, { "stripspace", cmd_stripspace }, - { "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX | NO_PARSEOPT }, + { "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX }, { "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE }, { "symbolic-ref", cmd_symbolic_ref, RUN_SETUP }, { "tag", cmd_tag, RUN_SETUP | DELAY_PAGER_CONFIG },