From patchwork Mon Oct 17 12:09:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13008720 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 68C5FC4332F for ; Mon, 17 Oct 2022 12:09:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229802AbiJQMJf (ORCPT ); Mon, 17 Oct 2022 08:09:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229452AbiJQMJd (ORCPT ); Mon, 17 Oct 2022 08:09:33 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D54B510B73 for ; Mon, 17 Oct 2022 05:09:31 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id a10so18081172wrm.12 for ; Mon, 17 Oct 2022 05:09:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lr3rsmznHuIRnlyV5tKdPVFHEvV2rpaU/ldQlVxWV9Y=; b=L307Uj7Fz7JZ3hbTHLgY8wf0n5UNs1L0ct4TrXmMcRSnltHk3GTSt8zjKprT9i3dK+ rs4HqCgt1w1erkumDQX53DDQKlh9aJkB7kgDNOz4AGKmk5GNRQTibSYBG3yEopwEnb+m WoSr5Xe16QmcNVRVUsEM+nPINLKEflPJYhy+2Uw/7j0NqOUO6qEHdWAzc7e/SJzE5C8v paJf5RhrS8hrtkSqjXGCL603NaJeg8zB1ZRqhvQ9vS5I2K/IocVALDfoYC55eI+w9stb Ho+zBhRm/MydzPlKHpWVjN/PHfM+0U0VoVW1gqrEnmvpiOMbhK2K+ZFZeDB6AV46YFJE hCSg== 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=lr3rsmznHuIRnlyV5tKdPVFHEvV2rpaU/ldQlVxWV9Y=; b=Ft+e71/r4XCZQ8VbnXzAQhowbdyF80Tli2WJjd533UvFBvsaS2AmzlwQpMiUVrfV0+ VohBYcHttLFIQxfOby6unOVaM29HycGuBIjRNs8LZ7QXmA5N0VqXp1DaneNXnuVrWujV xAlRC53qs9DDyreUY+sHCYwLUBf5jd2z2pmEdwnkPvShyY3XmGx2YGX8xBDkLERDlV1P RSSRztF5HsrIjSSY71KSZs7HK9rFR3n33x6kNVsNnrf8JtQmxdFypFACkfw8sV0dkW/C 8ErFczoF5Ft18C/YpIVNx9nbPVKjN60TwvYiAuqK62/5riqe3Oc+LZ061MTtD1KVshjx dqYg== X-Gm-Message-State: ACrzQf3WfPJ2zLvxrbVFC30lt+1cV+967+/8Q8cpp3wf4qXestM7M1+f u2sp2oUSCIr9zHcBQAHfqxHn+b3++5Dv/A== X-Google-Smtp-Source: AMsMyM5utm8nOpLamO/fTHpXcekbo9R/4PEXQ9QpsN/voOwhiLN9QMoMW0TvD+T0qtdfrzb6QLtZqA== X-Received: by 2002:a5d:4dd0:0:b0:22e:33dc:3bf3 with SMTP id f16-20020a5d4dd0000000b0022e33dc3bf3mr6199378wru.214.1666008569854; Mon, 17 Oct 2022 05:09:29 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id z6-20020a1cf406000000b003c6deb5c1edsm10028770wma.45.2022.10.17.05.09.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 05:09:29 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Jonas Bernoulli , Jeff King , Emily Shaffer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 01/10] git-submodule.sh: create a "case" dispatch statement Date: Mon, 17 Oct 2022 14:09:16 +0200 Message-Id: X-Mailer: git-send-email 2.38.0.1091.gf9d18265e59 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Create a "case/esac" dispatch statement at the end of git-submodule.sh and move the contents of the trivial cmd_absorbgitdirs() function to it. This template will be expanded on in subsequent commits, but for now we're moving the trivial "git submodule absorb-git-dirs" to it. Signed-off-by: Ævar Arnfjörð Bjarmason --- git-submodule.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index 5e5d21c010f..b851d64aa62 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -555,11 +555,6 @@ cmd_sync() git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${quiet:+--quiet} ${recursive:+--recursive} -- "$@" } -cmd_absorbgitdirs() -{ - git submodule--helper absorbgitdirs --prefix "$wt_prefix" "$@" -} - # This loop parses the command line arguments to find the # subcommand name to dispatch. Parsing of the subcommand specific # options are primarily done by the subcommand implementations. @@ -608,4 +603,11 @@ then usage fi -"cmd_$(echo $command | sed -e s/-/_/g)" "$@" +case "$command" in +absorbgitdirs) + git submodule--helper "$command" --prefix "$wt_prefix" "$@" + ;; +*) + "cmd_$(echo $command | sed -e s/-/_/g)" "$@" + ;; +esac From patchwork Mon Oct 17 12:09:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13008721 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 77478C4332F for ; Mon, 17 Oct 2022 12:09:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229923AbiJQMJk (ORCPT ); Mon, 17 Oct 2022 08:09:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbiJQMJf (ORCPT ); Mon, 17 Oct 2022 08:09:35 -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 D4E2D11C0A for ; Mon, 17 Oct 2022 05:09:33 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id bu30so18124349wrb.8 for ; Mon, 17 Oct 2022 05:09:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q5tDlZAfs9NG7IjOyYYDM1266ReOwwGb9qNWRapPp04=; b=LBmxegU50Fh9EG+dPQYDYsV8BCaIh0YID3CeqyqsmLvgLHGYK1qvY1U4fGUGxwhgUu 4+D/hr+cJ0CksYWaT7FxUpOVPqCg3f8gnOlH29QJT1nWBj/7GTmdwQAeiqL9e6eMeY2I s0Sx5BnnXBxOEi4pFU5Kup316H+dEXUnJjmTq6jQP4GoUPdiNTMOPBLpVxybA/d/CZGw Sgq80TcF0ttuuPYWR2cKQtqqSQWAQ0xBKQfv+4nOLrH5dc57xCPkLZk0sEvLx7S8Rx+K /0EFHtWRvqhPLF+qJwzDkhd9aJC5xN81TDa+NdgAXEVbTqckcM/fQZDoSFJmXIKvz6Y2 qEGA== 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=Q5tDlZAfs9NG7IjOyYYDM1266ReOwwGb9qNWRapPp04=; b=oZPX5UrJbKx5CSbib33ctRux3BRjbzWH9rZ2TETmQ4CH0JUuiiu7EOY6kRufFb6gS+ FYVNL4POl23oRYrGBiGfvSzDZq9awWin4wi/8tSeoEMu4hB4ZZuebCN1V5U+gFymOo6D 3BJANFqlIvNkhmu1AbUDe1NjkkKsQO++sJwVfK/JiGA+xCPdjuBr9s9eLWCK3BdpbOCT BtdRkJn9WIEcIDY1NEPVD3aNauVWQhxGQPsH12GeiNYZvuLMuL6h4XUubB326ZJsPOJl cQRBSP1gCJjDNdczI1PewwAcxXAPo5jNCsbrm4Eo0vG2ttAFLwxoHSmkiAKO04vCFZjj GAiA== X-Gm-Message-State: ACrzQf0ugipBUNQOhmxHwBWsFrejiuNAnw0pigY5cNdOvMPLBXPRchpD kEOMqSlFDdr2Av26QFziPFKzz/CKo2Fu6A== X-Google-Smtp-Source: AMsMyM5+fyoBvIpD5VQjBQ2ngPKvjsLYcnkiw149Eoz8oFVCl4ILgWqXf3ZK7sNGWmTTfp3pnN+Szw== X-Received: by 2002:adf:efc5:0:b0:22e:4a6:2d5b with SMTP id i5-20020adfefc5000000b0022e04a62d5bmr6103894wrp.293.1666008572014; Mon, 17 Oct 2022 05:09:32 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id z6-20020a1cf406000000b003c6deb5c1edsm10028770wma.45.2022.10.17.05.09.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 05:09:30 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Jonas Bernoulli , Jeff King , Emily Shaffer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 02/10] git-submodule.sh: dispatch "sync" to helper Date: Mon, 17 Oct 2022 14:09:17 +0200 Message-Id: X-Mailer: git-send-email 2.38.0.1091.gf9d18265e59 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove the cmd_sync() wrapper for "git submodule--helper sync" in favor of dispatching the raw command-line directly to the helper. At this point we've already parsed out the optional "--quiet" flag that we need to support for "git submodule --quiet" (as opposed to "git submodule --quiet"). This changes the output we'll display on invalid usage for the better, before this we'd emit e.g.: $ git submodule sync --blah usage: git submodule [--quiet] [--cached] or: [...many lines of "or" usage omitted...] But now we'll emit the much more useful: $ git submodule sync --blah error: unknown option `blah' usage: git submodule sync [--quiet] [--recursive] [] -q, --quiet suppress output of synchronizing submodule url --recursive recurse into nested submodules This is because we'll now get as far as module_sync()'s failing call to parse_options() when we have invalid usage. Signed-off-by: Ævar Arnfjörð Bjarmason --- git-submodule.sh | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index b851d64aa62..3fdfe864d37 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -521,39 +521,6 @@ cmd_status() git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${quiet:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@" } -# -# Sync remote urls for submodules -# This makes the value for remote.$remote.url match the value -# specified in .gitmodules. -# -cmd_sync() -{ - while test $# -ne 0 - do - case "$1" in - -q|--quiet) - quiet=1 - shift - ;; - --recursive) - recursive=1 - shift - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - done - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${quiet:+--quiet} ${recursive:+--recursive} -- "$@" -} # This loop parses the command line arguments to find the # subcommand name to dispatch. Parsing of the subcommand specific @@ -607,6 +574,10 @@ case "$command" in absorbgitdirs) git submodule--helper "$command" --prefix "$wt_prefix" "$@" ;; +sync) + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ + ${quiet:+--quiet} "$@" + ;; *) "cmd_$(echo $command | sed -e s/-/_/g)" "$@" ;; From patchwork Mon Oct 17 12:09:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13008724 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 1EF46C43217 for ; Mon, 17 Oct 2022 12:09:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229977AbiJQMJr (ORCPT ); Mon, 17 Oct 2022 08:09:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229906AbiJQMJg (ORCPT ); Mon, 17 Oct 2022 08:09:36 -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 411851263E for ; Mon, 17 Oct 2022 05:09:35 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id f11so18120787wrm.6 for ; Mon, 17 Oct 2022 05:09:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nKO30MFC/pZjL1nxcB277ZbnXlHboD8ynvGLp4HK+NI=; b=Kt3mPezcZ0N5zkDATziw2LvYAXnvdcHgQVPtdv96KsPfuXs5/7KCBIWK7bXMlMzmjR g1e/CMbQpfBL3JpVFbrRuYMPGgPCr9yGV7d0sXhMeSmbaUpnDACzyNDOAfBpXKfBysO6 +td0dMwWnbWYY6JQF/Xw7ZAs8ep7hz9lnaYi3XHF4Xm/pUAXgvnf85JBs+CnFbXJ9r/G RQevYsswg9bjz6DNxhE0JNEaRIYapkZtHaIyEUDOl7am3QUX78P/vnFY8rnh6cTw0OUK X2t6DkHkWTS9MOp5oGKLV5ps/86NuGiHgZzt9hQfFBsc7zgTXBWXWtn9HEuy3RVoZDJG 05Dg== 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=nKO30MFC/pZjL1nxcB277ZbnXlHboD8ynvGLp4HK+NI=; b=edSJbHsrWzwGkLqf1nVGD0b3ode/O6sgUXwE7L66JU0W/CN8HuvLFMUHjRQ86IMn8K TFXFH6PD2pA3XfOoTFNNHWXanTNTGtAwTkxipzsEebMAQwVpD99+GpUUrW7SRzMh+H0x 0CsWEW1vfpWqpu6vuMlBmicEWn8KeAMQe5bLoSk2bNJy13FqLnvWDSv+SjFTaXeAqr5h DEDTKywrfSRoriPLTEr02OosyxKhKpyWZRyAc9JtVZTAKL7n0f97WXUvM94fMqM/n5NF Cw8Qeu6u0rHl0e03qRfNNjtd2Y4ShfP8YrIk+9CuCfk9PInkYYWiQV6iwdJIIuYYjit3 G+7A== X-Gm-Message-State: ACrzQf1XJHJ+uU8sNzIcwoU/KVijOh8fTftz0/XodE2GUM9RxyjqQafC cWv8BPS8Twig0o0O7KMqtmJ6OKGsnL0JnQ== X-Google-Smtp-Source: AMsMyM7+RhgnfRHYFVzgAywxIMVgaP3xP7578ctuKHPCN8GX5hJMvPT3cSFVpvwbcbp0GscfBGrYQQ== X-Received: by 2002:a05:6000:52:b0:22e:5894:e212 with SMTP id k18-20020a056000005200b0022e5894e212mr5809570wrx.266.1666008573352; Mon, 17 Oct 2022 05:09:33 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id z6-20020a1cf406000000b003c6deb5c1edsm10028770wma.45.2022.10.17.05.09.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 05:09:32 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Jonas Bernoulli , Jeff King , Emily Shaffer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 03/10] git-submodule.sh: dispatch directly to helper Date: Mon, 17 Oct 2022 14:09:18 +0200 Message-Id: X-Mailer: git-send-email 2.38.0.1091.gf9d18265e59 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the dispatching logic in "git-submodule.sh" for the "add", "init", "deinit", "set-branch", "set-url", "summary" and "status" sub-commands to do away with the argument parsing in git-submodule.sh, and instead dispatch directly to "git submodule--helper". As in a preceding commit the only functional change here should be that on invalid options we'll now emit more targeted "-h" output. The isnumber() helper function was only used in the now-removed cmd_summary(), the same goes for the $files variable. The $custom_name and $branch variables were only used in cmd_add(). Since there are no dashed commands anymore in git-submodule.sh we can get rid of the "$(echo | sed ...)" one-liner to change e.g. "set-url" to "set_url". Signed-off-by: Ævar Arnfjörð Bjarmason --- git-submodule.sh | 321 +---------------------------------------------- 1 file changed, 5 insertions(+), 316 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index 3fdfe864d37..2bdff5119c1 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -31,20 +31,17 @@ export GIT_PROTOCOL_FROM_USER command= quiet= -branch= force= reference= cached= recursive= init= require_init= -files= remote= nofetch= rebase= merge= checkout= -custom_name= depth= progress= dissociate= @@ -53,86 +50,7 @@ jobs= recommend_shallow= filter= -isnumber() -{ - n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1" -} - -# -# Add a new submodule to the working tree, .gitmodules and the index -# -# $@ = repo path -# -# optional branch is stored in global branch variable -# -cmd_add() -{ - # parse $args after "submodule ... add". - reference_path= - while test $# -ne 0 - do - case "$1" in - -b | --branch) - case "$2" in '') usage ;; esac - branch=$2 - shift - ;; - -f | --force) - force=$1 - ;; - -q|--quiet) - quiet=1 - ;; - --progress) - progress=1 - ;; - --reference) - case "$2" in '') usage ;; esac - reference_path=$2 - shift - ;; - --reference=*) - reference_path="${1#--reference=}" - ;; - --dissociate) - dissociate=1 - ;; - --name) - case "$2" in '') usage ;; esac - custom_name=$2 - shift - ;; - --depth) - case "$2" in '') usage ;; esac - depth="--depth=$2" - shift - ;; - --depth=*) - depth=$1 - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - - if test -z "$1" - then - usage - fi - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add ${quiet:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" -} -# # Execute an arbitrary command sequence in each checked out # submodule # @@ -163,73 +81,6 @@ cmd_foreach() git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${quiet:+--quiet} ${recursive:+--recursive} -- "$@" } -# -# Register submodules in .git/config -# -# $@ = requested paths (default to all) -# -cmd_init() -{ - # parse $args after "submodule ... init". - while test $# -ne 0 - do - case "$1" in - -q|--quiet) - quiet=1 - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${quiet:+--quiet} -- "$@" -} - -# -# Unregister submodules from .git/config and remove their work tree -# -cmd_deinit() -{ - # parse $args after "submodule ... deinit". - deinit_all= - while test $# -ne 0 - do - case "$1" in - -f|--force) - force=$1 - ;; - -q|--quiet) - quiet=1 - ;; - --all) - deinit_all=t - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${quiet:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@" -} - # # Update each submodule path to correct revision, using clone and checkout as needed # @@ -360,168 +211,6 @@ cmd_update() "$@" } -# -# Configures a submodule's default branch -# -# $@ = requested path -# -cmd_set_branch() { - default= - branch= - - while test $# -ne 0 - do - case "$1" in - -q|--quiet) - # we don't do anything with this but we need to accept it - ;; - -d|--default) - default=1 - ;; - -b|--branch) - case "$2" in '') usage ;; esac - branch=$2 - shift - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch ${quiet:+--quiet} ${branch:+--branch "$branch"} ${default:+--default} -- "$@" -} - -# -# Configures a submodule's remote url -# -# $@ = requested path, requested url -# -cmd_set_url() { - while test $# -ne 0 - do - case "$1" in - -q|--quiet) - quiet=1 - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url ${quiet:+--quiet} -- "$@" -} - -# -# Show commit summary for submodules in index or working tree -# -# If '--cached' is given, show summary between index and given commit, -# or between working tree and given commit -# -# $@ = [commit (default 'HEAD'),] requested paths (default all) -# -cmd_summary() { - summary_limit=-1 - for_status= - diff_cmd=diff-index - - # parse $args after "submodule ... summary". - while test $# -ne 0 - do - case "$1" in - --cached) - cached=1 - ;; - --files) - files="$1" - ;; - --for-status) - for_status="$1" - ;; - -n|--summary-limit) - summary_limit="$2" - isnumber "$summary_limit" || usage - shift - ;; - --summary-limit=*) - summary_limit="${1#--summary-limit=}" - isnumber "$summary_limit" || usage - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper summary ${files:+--files} ${cached:+--cached} ${for_status:+--for-status} ${summary_limit:+-n $summary_limit} -- "$@" -} -# -# List all submodules, prefixed with: -# - submodule not initialized -# + different revision checked out -# -# If --cached was specified the revision in the index will be printed -# instead of the currently checked out revision. -# -# $@ = requested paths (default to all) -# -cmd_status() -{ - # parse $args after "submodule ... status". - while test $# -ne 0 - do - case "$1" in - -q|--quiet) - quiet=1 - ;; - --cached) - cached=1 - ;; - --recursive) - recursive=1 - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${quiet:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@" -} - # This loop parses the command line arguments to find the # subcommand name to dispatch. Parsing of the subcommand specific # options are primarily done by the subcommand implementations. @@ -574,11 +263,11 @@ case "$command" in absorbgitdirs) git submodule--helper "$command" --prefix "$wt_prefix" "$@" ;; -sync) - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ - ${quiet:+--quiet} "$@" +foreach | update) + "cmd_$command" "$@" ;; -*) - "cmd_$(echo $command | sed -e s/-/_/g)" "$@" +add | init | deinit | set-branch | set-url | status | summary | sync) + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ + ${quiet:+--quiet} ${cached:+--cached} "$@" ;; esac From patchwork Mon Oct 17 12:09:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13008722 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 96587C4332F for ; Mon, 17 Oct 2022 12:09:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229885AbiJQMJo (ORCPT ); Mon, 17 Oct 2022 08:09:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229896AbiJQMJg (ORCPT ); Mon, 17 Oct 2022 08:09:36 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28E2E12636 for ; Mon, 17 Oct 2022 05:09:35 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id a10so18081449wrm.12 for ; Mon, 17 Oct 2022 05:09:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DwGxtHIHhVPIg+fv1qAnIT9T292NfBRVXlNSZB1a+AM=; b=XpRp3EfY2YL1oTDs014grm1WVGoV2f7wVO55lCKvnX0w2jAinPRnNE0gWDQnkUlwtb rB2BCfKXlUYrclXqD0ey4dl4wcs6uD2BpQ+DOMQ+X6cbVOKnxbJ0jmpjdWqApam3aou8 6T48UPVXTRfN7X0Znq/CX0mG5fCYFw8fS/LEMRaNmkjS8sjjscVgwjBFfSsllTapaCze Lh3V5w8tWDJMR3rIaMQv77FNL7bWtU3SV0ytNoltrQEx9nsOXlguGCRCy1hAKsJzHzoD ToE6o1ZIGfnAz0d9Xjf9wgHvROlFAJgPSstU/qIMojhpOShue5RKIx+D4NmNxSJsz7gj z26g== 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=DwGxtHIHhVPIg+fv1qAnIT9T292NfBRVXlNSZB1a+AM=; b=qh3rLKVq8f8QcX582T6aj1V/RqdJGRXWl25Y9eTqcg2VxvC+04+K/sISTIueH1XbQi DBKoixNMCAx4RHMd2MBk7tdNjEO/3lDK5bJaAng3wGLVikQ7UB3/OpMCHUpeKPHtMwYg peNIafYQS0rreDxzDd9PAdT3nc0CqCGYUulEl4JEjYW4nQObrtJOiCoFnZ9I9kDe4yDJ u/st/QbzXH2wrZ4zvek5y7bC8C5Jtbe+knz4V7kerMU0v3uxVLauN3OMxoaiuN8ozhpE T+4ZN/k/OSZyeonZ3fRfKH3ODv1wYvZAnnG1RLGGj9HBhdxU6JhQnlcd1A3j+/9hGW1s gfnQ== X-Gm-Message-State: ACrzQf3vG/vHO/VrhlGixU4WrFHZSm5S2Kw1ly1etIXSB754DKeW6ryw 3vrAOkESk0uGQHNEdtqUo6p9JatYsYv4vQ== X-Google-Smtp-Source: AMsMyM495G1hvciXkUWbpx5sqBmNRtBNU8vNkzo1e+GnSztQqXGmizrXY55tqV2GsL2944+EvVXS4g== X-Received: by 2002:a05:6000:50a:b0:225:210c:a7e4 with SMTP id a10-20020a056000050a00b00225210ca7e4mr5896284wrf.704.1666008574430; Mon, 17 Oct 2022 05:09:34 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id z6-20020a1cf406000000b003c6deb5c1edsm10028770wma.45.2022.10.17.05.09.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 05:09:33 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Jonas Bernoulli , Jeff King , Emily Shaffer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 04/10] git-submodule.sh: dispatch "foreach" to helper Date: Mon, 17 Oct 2022 14:09:19 +0200 Message-Id: X-Mailer: git-send-email 2.38.0.1091.gf9d18265e59 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Dispatch the "git submodule foreach" command directly to "git submodule--helper foreach". This case requires the addition of the PARSE_OPT_STOP_AT_NON_OPTION flag, since the shellscript was unconditionally adding "--" to the "git submodule--helper" command-line. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 3 ++- git-submodule.sh | 37 +++---------------------------------- 2 files changed, 5 insertions(+), 35 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 0b4acb442b2..d11e1003019 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -403,7 +403,8 @@ static int module_foreach(int argc, const char **argv, const char *prefix) int ret = 1; argc = parse_options(argc, argv, prefix, module_foreach_options, - git_submodule_helper_usage, 0); + git_submodule_helper_usage, + PARSE_OPT_STOP_AT_NON_OPTION); if (module_list_compute(0, NULL, prefix, &pathspec, &list) < 0) goto cleanup; diff --git a/git-submodule.sh b/git-submodule.sh index 2bdff5119c1..7874e33beea 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -50,37 +50,6 @@ jobs= recommend_shallow= filter= - -# Execute an arbitrary command sequence in each checked out -# submodule -# -# $@ = command to execute -# -cmd_foreach() -{ - # parse $args after "submodule ... foreach". - while test $# -ne 0 - do - case "$1" in - -q|--quiet) - quiet=1 - ;; - --recursive) - recursive=1 - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${quiet:+--quiet} ${recursive:+--recursive} -- "$@" -} - # # Update each submodule path to correct revision, using clone and checkout as needed # @@ -263,10 +232,10 @@ case "$command" in absorbgitdirs) git submodule--helper "$command" --prefix "$wt_prefix" "$@" ;; -foreach | update) - "cmd_$command" "$@" +update) + cmd_update "$@" ;; -add | init | deinit | set-branch | set-url | status | summary | sync) +add | foreach | init | deinit | set-branch | set-url | status | summary | sync) git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ ${quiet:+--quiet} ${cached:+--cached} "$@" ;; From patchwork Mon Oct 17 12:09:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13008726 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 C0563C43217 for ; Mon, 17 Oct 2022 12:09:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229995AbiJQMJx (ORCPT ); Mon, 17 Oct 2022 08:09:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229920AbiJQMJj (ORCPT ); Mon, 17 Oct 2022 08:09:39 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9729113E08 for ; Mon, 17 Oct 2022 05:09:37 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id j7so18144156wrr.3 for ; Mon, 17 Oct 2022 05:09:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MlRaC34O/vY7zWB/mwUeCn8WNSgsyxRbZeFEuwe/d94=; b=AhrBdiaj7N4DY/jknVQU9tWldwP5XJsGA07kQ8aMUYruBHJPg1q4BJ35P9wMMlJLVd AvMaH9WEv/G9+sHHHsWodokmxwc/XMBJS7FBMfPGj65auetdPIvK/WKsOEEJ/mlZUvZN WtSf9aI3j7V1vTfIgAwKVoJ4qGAvLJCFWvdIVe6imv/Ew9gD1WLjaxgAbYdDIOiKsUXj +aj0vaZyHy2QGMLUcDWoy4lre6ZXRaDT5gvoFyieA18joBqSSoc9N1GCIc8MngCYFbU0 EdfbN4+ZybsEzBwKhBtFUE5t4OZQMH7jPNP9gsfUWAGLAvzAMY50C841pGYeJCa6k2+y ukYw== 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=MlRaC34O/vY7zWB/mwUeCn8WNSgsyxRbZeFEuwe/d94=; b=KyvTnL7lqLmOJhWdnYGlOfTDJuCxuDvU3MTiI+0x3OTgPDe2GSk+n8AvYkZoqNwHEs ds4yOKegmo6ACE0bHeHJF2UCLoWg8g+lVzi1zbprGSHfqnV9uGjf8HQ8vaVeL/SudQM+ BOZgljjyOKlWxz65TTGjqdgoDHN9cuvxQBhqGej/5E786nsWtVsfWSFFA11F5ZBTQHU7 R52Dz9smCgoa/I408Mxw1xvkfmYX2lZ45V5d1f6e23z+JYH3/87c5CCj5Ef83jRIhME4 Vj5xTftn1+DxhhhJSziqi2vcszzjKN0PUQuvtW1G2qNvzfvEWLoDNNvo6XwgIqHZTnR6 8f6g== X-Gm-Message-State: ACrzQf2MU+cnjV7D1g54IgMiimCj2RknWbOvHG8kFp0QQeg2+nEzHftT COxDb5nj98EWV5FSoUIJZ9XN8zV3RZXWww== X-Google-Smtp-Source: AMsMyM53SQmDssu0+COUm+pCMGzCDGg7gjt8ce2batmmo0GFk228C5KziJguBgikYQnfVsZalTl/mg== X-Received: by 2002:a05:6000:1f9e:b0:22e:61fa:3f1c with SMTP id bw30-20020a0560001f9e00b0022e61fa3f1cmr5899099wrb.546.1666008575521; Mon, 17 Oct 2022 05:09:35 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id z6-20020a1cf406000000b003c6deb5c1edsm10028770wma.45.2022.10.17.05.09.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 05:09:34 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Jonas Bernoulli , Jeff King , Emily Shaffer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 05/10] git-submodule.sh: dispatch "update" to helper Date: Mon, 17 Oct 2022 14:09:20 +0200 Message-Id: X-Mailer: git-send-email 2.38.0.1091.gf9d18265e59 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Dispatch the "update" command directly to "git submodule--helper update", rather than doing our own argument parsing in git-submodule.sh. As this is the last cmd_*() function to be removed from git-submodule.sh we can do some larger cleanup of that file as a result. As noted in a preceding commit the only behavior change here should be the desirable change of better "-h" output, and that this implementation understands the "--verbose" synonym for "-v". Let's update the documentation to reflect the new "--verbose" synonym. Signed-off-by: Ævar Arnfjörð Bjarmason --- git-submodule.sh | 156 +---------------------------------------------- 1 file changed, 2 insertions(+), 154 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index 7874e33beea..ac2f95c1285 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -31,160 +31,7 @@ export GIT_PROTOCOL_FROM_USER command= quiet= -force= -reference= cached= -recursive= -init= -require_init= -remote= -nofetch= -rebase= -merge= -checkout= -depth= -progress= -dissociate= -single_branch= -jobs= -recommend_shallow= -filter= - -# -# Update each submodule path to correct revision, using clone and checkout as needed -# -# $@ = requested paths (default to all) -# -cmd_update() -{ - # parse $args after "submodule ... update". - while test $# -ne 0 - do - case "$1" in - -q|--quiet) - quiet=1 - ;; - --progress) - progress=1 - ;; - -i|--init) - init=1 - ;; - --require-init) - require_init=1 - ;; - --remote) - remote=1 - ;; - -N|--no-fetch) - nofetch=1 - ;; - -f|--force) - force=$1 - ;; - -r|--rebase) - rebase=1 - ;; - --reference) - case "$2" in '') usage ;; esac - reference="--reference=$2" - shift - ;; - --reference=*) - reference="$1" - ;; - --dissociate) - dissociate=1 - ;; - -m|--merge) - merge=1 - ;; - --recursive) - recursive=1 - ;; - --checkout) - checkout=1 - ;; - --recommend-shallow) - recommend_shallow="--recommend-shallow" - ;; - --no-recommend-shallow) - recommend_shallow="--no-recommend-shallow" - ;; - --depth) - case "$2" in '') usage ;; esac - depth="--depth=$2" - shift - ;; - --depth=*) - depth=$1 - ;; - -j|--jobs) - case "$2" in '') usage ;; esac - jobs="--jobs=$2" - shift - ;; - --jobs=*) - jobs=$1 - ;; - --single-branch) - single_branch="--single-branch" - ;; - --no-single-branch) - single_branch="--no-single-branch" - ;; - --filter) - case "$2" in '') usage ;; esac - filter="--filter=$2" - shift - ;; - --filter=*) - filter="$1" - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \ - ${quiet:+--quiet} \ - ${force:+--force} \ - ${progress:+"--progress"} \ - ${remote:+--remote} \ - ${recursive:+--recursive} \ - ${init:+--init} \ - ${nofetch:+--no-fetch} \ - ${wt_prefix:+--prefix "$wt_prefix"} \ - ${rebase:+--rebase} \ - ${merge:+--merge} \ - ${checkout:+--checkout} \ - ${reference:+"$reference"} \ - ${dissociate:+"--dissociate"} \ - ${depth:+"$depth"} \ - ${require_init:+--require-init} \ - ${dissociate:+"--dissociate"} \ - $single_branch \ - $recommend_shallow \ - $jobs \ - $filter \ - -- \ - "$@" -} - -# This loop parses the command line arguments to find the -# subcommand name to dispatch. Parsing of the subcommand specific -# options are primarily done by the subcommand implementations. -# Subcommand specific options such as --branch and --cached are -# parsed here as well, for backward compatibility. while test $# != 0 && test -z "$command" do @@ -233,7 +80,8 @@ absorbgitdirs) git submodule--helper "$command" --prefix "$wt_prefix" "$@" ;; update) - cmd_update "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ + ${quiet:+--quiet} ${wt_prefix:+--prefix "$wt_prefix"} "$@" ;; add | foreach | init | deinit | set-branch | set-url | status | summary | sync) git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ From patchwork Mon Oct 17 12:09:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13008725 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 54FF3C43217 for ; Mon, 17 Oct 2022 12:09:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229989AbiJQMJu (ORCPT ); Mon, 17 Oct 2022 08:09:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229910AbiJQMJj (ORCPT ); Mon, 17 Oct 2022 08:09:39 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73D8913D2E for ; Mon, 17 Oct 2022 05:09:37 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id a10so18081569wrm.12 for ; Mon, 17 Oct 2022 05:09:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=71EaMSuFML1IN27lnqUKy1kwQ05naBx/BIDqss6SYWY=; b=dyoRcLmA07TEkiVAJzWme1BKustzI9YII3ahaxJL4VHSE8c1N+M7VL8L9E75TXJ4kx NX5PMsBMntu6ufyQzaM0+NsvtifHr1Iv1nmBflNZ9ZUAf2dKl5XkgfJ7Rvm4Njx0buAI DtBlhzSoar1m+8SpHZ9ZKD0zz8e+/M/2f176AGDk6tvbo/ojyw9ULxTEsin7bx0MZTWA dqpnOcWzmhj/WLBeE2wTIlZfSk0VpDI/kpQ3xkk6jOV8KH68T+F0gCmE5UoaBNYFikcu zYLLwe53GTopgbAp7VV1gARWdK0BPTkrSmWgJzDKDATLlaE22Xv6dNHDxrBvtE0iUKwn vVdA== 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=71EaMSuFML1IN27lnqUKy1kwQ05naBx/BIDqss6SYWY=; b=O898BBTuS/tWwUGSKcgYNB8sAVDCjBI3HuioS/zJ5Mjfg0dNXUMU8CvGA4PxgSG5Pv sE+9ijJdNLHWCm6jbHNh5Zi91rIkG2iyD2VeU94KUUINFfqI71I1qHPejaPiX2/7tLPs 3b7ubMCqybNimrK881sGV9wR3fk2hVMiESH9RF/9nNXIkGNBIkspxy6M+fOmj/9ZFcJJ xk6A5IbFRdMKX+qqNXXEhuSTsfvq2s2MXHcHyx55qY3l1GrhE75DpG5ORl9/NU9dhAeL as9tP1julh1/F1906B+BqLur+LgCSINqRheac+ri5MJZol9C4Og9U+WqFzHPqsveC6+F 6vfg== X-Gm-Message-State: ACrzQf3B1ui8TCwviWdgwAl0txDVs4ojusq3Byj5eN2ohG1BthQxMTR4 Mr774Z2UB3RDQzqbzS2+Ds7X8/pb07z4xQ== X-Google-Smtp-Source: AMsMyM7qg+lyjmHwjWymiB12B9u4ygC+HXHJXmmFq/tMBjy0RRX/AE1BmeNENMRsJvcyu6Ru121Z8g== X-Received: by 2002:a05:6000:1882:b0:230:9595:4131 with SMTP id a2-20020a056000188200b0023095954131mr6207005wri.17.1666008576495; Mon, 17 Oct 2022 05:09:36 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id z6-20020a1cf406000000b003c6deb5c1edsm10028770wma.45.2022.10.17.05.09.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 05:09:35 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Jonas Bernoulli , Jeff King , Emily Shaffer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 06/10] git-submodule.sh: don't support top-level "--cached" Date: Mon, 17 Oct 2022 14:09:21 +0200 Message-Id: X-Mailer: git-send-email 2.38.0.1091.gf9d18265e59 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Since the preceding commit all sub-commands of "git submodule" have been dispatched to "git submodule--helper" directly, we therefore don't need to emit "usage()" if we see "--cached" without the sub-command being "status" or "summary", we can trust that parse_options() will spot that and barf on it. This does change one obscure aspect of undocumented behavior, for "status" and "summary" we supported these undocumented forms: git submodule --cached (status | summary) As noted in a preceding commit to git-submodule.sh which removed the "--branch" special-case, this comes down to emergent behavior seen in 5c08dbbdf1a (git-submodule: fix subcommand parser, 2008-01-15). I.e. we wanted to support was for subcommand-less invocations like: git submodule --cached To be synonymous with invocations that explicitly named the "status" sub-command: git submodule status --cached But we did not intend to mix the two, and allow "--cached" to be an option to the top-level "submodule" command when the "status" or "summary" sub-commands were explicitly provided. Let's remove this undocumented edge case, which makes a subsequent removal of git-submodule.sh easier to reason about. The test case added here is duplicated from the existing for-loop, except for the different and desired handling of "git submodule --cached status". Signed-off-by: Ævar Arnfjörð Bjarmason --- git-submodule.sh | 15 ++++++++------- t/t7400-submodule-basic.sh | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index ac2f95c1285..4f8f62ce981 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -43,7 +43,14 @@ do quiet=1 ;; --cached) - cached=1 + if test -z "$command" + then + cached=1 && + shift && + break + else + usage + fi ;; --) break @@ -69,12 +76,6 @@ then fi fi -# "--cached" is accepted only by "status" and "summary" -if test -n "$cached" && test "$command" != status && test "$command" != summary -then - usage -fi - case "$command" in absorbgitdirs) git submodule--helper "$command" --prefix "$wt_prefix" "$@" diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index b50db3f1031..d8f7d6ee29a 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -31,7 +31,7 @@ test_expect_success 'submodule usage: status --' ' test_expect_code 1 git submodule --end-of-options ' -for opt in '--quiet' '--cached' +for opt in '--quiet' do test_expect_success "submodule usage: status $opt" ' git submodule $opt && @@ -40,6 +40,17 @@ do ' done +for opt in '--cached' +do + test_expect_success "submodule usage: status $opt" ' + git submodule $opt && + git submodule status $opt && + test_expect_code 1 git submodule $opt status >out 2>err && + grep "^usage: git submodule" err && + test_must_be_empty out + ' +done + test_expect_success 'submodule deinit works on empty repository' ' git submodule deinit --all ' @@ -576,7 +587,7 @@ test_expect_success 'status should be "modified" after submodule commit' ' ' test_expect_success 'the --cached sha1 should be rev1' ' - git submodule --cached status >list && + git submodule status --cached >list && grep "^+$rev1" list ' From patchwork Mon Oct 17 12:09:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13008729 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 56A24C4332F for ; Mon, 17 Oct 2022 12:10:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230020AbiJQMKQ (ORCPT ); Mon, 17 Oct 2022 08:10:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229934AbiJQMKH (ORCPT ); Mon, 17 Oct 2022 08:10:07 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57DE31A213 for ; Mon, 17 Oct 2022 05:09:39 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id a3so18220945wrt.0 for ; Mon, 17 Oct 2022 05:09:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TzyHZOoywTy77IdmEqu3NglRt7Zc+HCpDjQgz+rDtlg=; b=b3JvtGDkMMltJyRDsD+/a5KfLuDWLnJBel9RHfbgp8RlFkeM9Pz3WML2kATSsackR+ ku/v+2m7IqLMXzqS+vSf8E5omIF+kpYXjS3HsN4spCEcsF12MaSatayGyKM2/YLr66ZB S97bUGIpgLlpKtCeUwzRPxtO0MZqCYbT+pi7NbQ9IiibPxKCbnScfCpUmLtCiok3iDrG Smna9o0OiHzbQnMNxrckRPm17Wh9/bSCha03zZOqQ+SFhKt6mfypGuHWTtRh6/xMZ0cJ B4MyYJELs9ilgqsoEJeR5/uN00OKBHL/TBX0oyW+Nc2mGCeh3A7qVyDYPdNflhesc6BN 1SQQ== 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=TzyHZOoywTy77IdmEqu3NglRt7Zc+HCpDjQgz+rDtlg=; b=iL4Y3TckTc8oX+6IvalY/W0HRTGmhxOPvtO80yde5c52ougwa9fKl/Eg9tBVeDgMsS 4p3TTCaThTJF166d3VEF9nZ+GOmYweqa7evCOf12K86z6iTCY/yGC8bC92U3wF1wQ+uP n1W4tR+wjKCqoNC3jDlhSqb4HbAZ+osFHi9cz60c6Jlx0RL5oyj6kXawjoXgZpnYESvE qfKrhnOEPbm4qXBTzWmncbU0xKCCfRyh/0H8Ngdh1MMm4GIZkeBCdyA9OCUcxkActUac ACWJwi3R1GZHwBgje+7PaynrXCGuY22la2TWH10kOwFanpHTvtpeNoAlRMINbnzvxCj0 FoKw== X-Gm-Message-State: ACrzQf0bv/ccfxb4/OOCcCF3OvYNJC/zyKoGRu+Y1/DUmWy721rfgk1+ RXxUNmed2zeW1RjkwFzHRgm7GdhOYfbtHQ== X-Google-Smtp-Source: AMsMyM5k2S8t9f3GwyLhCYXYjeMYtVHsyj7f9KAek1JDDl7zc3j/Rd/QIBFr4XKPNv/9NycXAtNj3w== X-Received: by 2002:adf:e70a:0:b0:22c:da3f:36ee with SMTP id c10-20020adfe70a000000b0022cda3f36eemr6249152wrm.414.1666008577724; Mon, 17 Oct 2022 05:09:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id z6-20020a1cf406000000b003c6deb5c1edsm10028770wma.45.2022.10.17.05.09.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 05:09:36 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Jonas Bernoulli , Jeff King , Emily Shaffer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 07/10] submodule: make it a built-in, remove git-submodule.sh Date: Mon, 17 Oct 2022 14:09:22 +0200 Message-Id: X-Mailer: git-send-email 2.38.0.1091.gf9d18265e59 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Replace the "git-submodule.sh" script with a built-in "builtin/submodule.c. For" now this new command is only a dumb dispatcher that uses run-command.c to invoke "git submodule--helper", just as "git-submodule.sh" used to do. This is obviously not ideal, and we should eventually follow-up and merge the "builtin/submodule--helper.c" code into "builtin/submodule.c". Doing it this way makes it easy to review that this new C implementation isn't doing anything more clever than the old shellscript implementation. This is a large win for performance, we're now more than 4x as fast as before in terms of the fixed cost of invoking any "git submodule" command[1]: $ git hyperfine -L rev HEAD~1,HEAD -s 'make CFLAGS=-O3' './git --exec-path=$PWD submodule foreach "echo \$name"' Benchmark 1: ./git --exec-path=$PWD submodule foreach "echo \$name"' in 'HEAD~1 Time (mean ± σ): 42.2 ms ± 0.4 ms [User: 34.9 ms, System: 9.1 ms] Range (min … max): 41.3 ms … 43.2 ms 70 runs Benchmark 2: ./git --exec-path=$PWD submodule foreach "echo \$name"' in 'HEAD Time (mean ± σ): 9.7 ms ± 0.1 ms [User: 7.6 ms, System: 2.2 ms] Range (min … max): 9.5 ms … 10.3 ms 282 runs Summary './git --exec-path=$PWD submodule foreach "echo \$name"' in 'HEAD' ran 4.33 ± 0.07 times faster than './git --exec-path=$PWD submodule foreach "echo \$name"' in 'HEAD~1' We're taking pains here to faithfully reproduce existing "git-submodule.sh" behavior, even when that behavior is stupid. Some of it we'll fix in subsequent commits, but let's first faithfully reproduce the behavior. One exception is the change in the behavior of the exit code stand-alone "-h" and "--" yield, see the altered tests. Returning 129 instead of 0 and 1 for "-h" and "--" respectively is a concession to basic sanity. The pattern of using "define BUILTIN_" macros here isn't needed for now, but as we'll move code out of "builtin/submodule--helper.c" we'll want to re-use these strings. See 8757b35d443 (commit-graph: define common usage with a macro, 2021-08-23) and 1e91d3faf6c (reflog: move "usage" variables and use macros, 2022-03-17) for prior art using this pattern. The "(argc < 2 || !strcmp(argv[1], "-h"))" path at the top of cmd_submodule__helper() could now be a "(argc < 2)" if not for t0012-help.sh (which invokes all built-ins manually with "-h"). Let's leave it for now, eventually we'll consolidate the two. 1. Using the "git hyperfine" wrapper for "hyperfine": https://lore.kernel.org/git/211201.86r1aw9gbd.gmgdl@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason --- Makefile | 2 +- builtin.h | 1 + builtin/submodule.c | 151 +++++++++++++++++++++++++++++++++++++ git-submodule.sh | 91 ---------------------- git.c | 1 + t/t7400-submodule-basic.sh | 12 ++- 6 files changed, 159 insertions(+), 99 deletions(-) create mode 100644 builtin/submodule.c delete mode 100755 git-submodule.sh diff --git a/Makefile b/Makefile index 6bfb62cbe94..d8e2c02ad42 100644 --- a/Makefile +++ b/Makefile @@ -635,7 +635,6 @@ SCRIPT_SH += git-merge-resolve.sh SCRIPT_SH += git-mergetool.sh SCRIPT_SH += git-quiltimport.sh SCRIPT_SH += git-request-pull.sh -SCRIPT_SH += git-submodule.sh SCRIPT_SH += git-web--browse.sh SCRIPT_LIB += git-mergetool--lib @@ -1235,6 +1234,7 @@ BUILTIN_OBJS += builtin/show-ref.o BUILTIN_OBJS += builtin/sparse-checkout.o BUILTIN_OBJS += builtin/stash.o BUILTIN_OBJS += builtin/stripspace.o +BUILTIN_OBJS += builtin/submodule.o BUILTIN_OBJS += builtin/submodule--helper.o BUILTIN_OBJS += builtin/symbolic-ref.o BUILTIN_OBJS += builtin/tag.o diff --git a/builtin.h b/builtin.h index 8901a34d6bf..475c79b6a5a 100644 --- a/builtin.h +++ b/builtin.h @@ -224,6 +224,7 @@ int cmd_sparse_checkout(int argc, const char **argv, const char *prefix); int cmd_status(int argc, const char **argv, const char *prefix); int cmd_stash(int argc, const char **argv, const char *prefix); int cmd_stripspace(int argc, const char **argv, const char *prefix); +int cmd_submodule(int argc, const char **argv, const char *prefix); int cmd_submodule__helper(int argc, const char **argv, const char *prefix); int cmd_switch(int argc, const char **argv, const char *prefix); int cmd_symbolic_ref(int argc, const char **argv, const char *prefix); diff --git a/builtin/submodule.c b/builtin/submodule.c new file mode 100644 index 00000000000..7e3499f3376 --- /dev/null +++ b/builtin/submodule.c @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2007-2022 Lars Hjemli & others + * Copyright(c) 2022 Ævar Arnfjörð Bjarmason + */ +#include "builtin.h" +#include "parse-options.h" +#include "run-command.h" +#include "strvec.h" + +#define BUILTIN_SUBMODULE_USAGE \ + "git submodule [--quiet] [--cached]" + +#define BUILTIN_SUBMODULE_ADD_USAGE \ + N_("git submodule [--quiet] add [-b ] [-f | --force] [--name ]\n" \ + " [--reference ] [--] []") + +#define BUILTIN_SUBMODULE_STATUS_USAGE \ + N_("git submodule [--quiet] status [--cached] [--recursive] [--] [...]") + +#define BUILTIN_SUBMODULE_INIT_USAGE \ + N_("git submodule [--quiet] init [--] [...]") + +#define BUILTIN_SUBMODULE_DEINIT_USAGE \ + N_("git submodule [--quiet] deinit [-f | --force] (--all | [--] ...)") + +#define BUILTIN_SUBMODULE_UPDATE_USAGE \ + N_("git submodule [--quiet] update [-v] [--init [--filter=]]\n" \ + " [--remote] [-N | --no-fetch] [-f | --force] [--checkout |--merge | --rebase]\n" \ + " [--[no-]recommend-shallow] [--reference ] [--recursive]\n" \ + " [--[no-]single-branch] [--] [...]") + +#define BUILTIN_SUBMODULE_SET_BRANCH_USAGE \ + N_("git submodule [--quiet] set-branch (--default | --branch ) [--] ") + +#define BUILTIN_SUBMODULE_SET_URL_USAGE \ + N_("git submodule [--quiet] set-url [--] ") + +#define BUILTIN_SUBMODULE_SUMMARY_USAGE \ + N_("git submodule [--quiet] summary [--cached | --files] [--summary-limit ]\n" \ + " [commit] [--] [...]") +#define BUILTIN_SUBMODULE_FOREACH_USAGE \ + N_("git submodule [--quiet] foreach [--recursive] ") + +#define BUILTIN_SUBMODULE_SYNC_USAGE \ + N_("git submodule [--quiet] sync [--recursive] [--] [...]") + +#define BUILTIN_SUBMODULE_ABSORBGITDIRS_USAGE \ + N_("git submodule [--quiet] absorbgitdirs [--] [...]") + +static const char * const git_submodule_usage[] = { + BUILTIN_SUBMODULE_USAGE, + BUILTIN_SUBMODULE_ADD_USAGE, + BUILTIN_SUBMODULE_STATUS_USAGE, + BUILTIN_SUBMODULE_INIT_USAGE, + BUILTIN_SUBMODULE_DEINIT_USAGE, + BUILTIN_SUBMODULE_UPDATE_USAGE, + BUILTIN_SUBMODULE_SET_BRANCH_USAGE, + BUILTIN_SUBMODULE_SET_URL_USAGE, + BUILTIN_SUBMODULE_SUMMARY_USAGE, + BUILTIN_SUBMODULE_FOREACH_USAGE, + BUILTIN_SUBMODULE_SYNC_USAGE, + BUILTIN_SUBMODULE_ABSORBGITDIRS_USAGE, + NULL, +}; + +static void setup_helper_args(int argc, const char **argv, const char *prefix, + int quiet, int cached, struct strvec *args, + const struct option *options) +{ + const char *cmd; + int do_quiet_cache = 1; + int do_prefix = 1; + + strvec_push(args, "submodule--helper"); + + /* No command word defaults to "status" */ + if (!argc) { + strvec_push(args, "status"); + return; + } + + /* Did we get --cached with a command? */ + if (cached) + usage_msg_optf(_("'%s' option is only supported with explicit 'status'"), + git_submodule_usage, options, "--cached"); + + + /* Either a valid command, or submodule--helper will barf! */ + cmd = argv[0]; + strvec_push(args, cmd); + argv++; + argc--; + + /* + * This is stupid, but don't support "[--]" to + * subcommand-less "git-submodule" for now. + */ + if (!strcmp(cmd, "--") || !strcmp(cmd, "--end-of-options")) + usage_msg_optf(_("need explicit sub-command name to delimit with '%s'"), + git_submodule_usage, options, cmd); + + /* Options that need to go before user-supplied options */ + if (!strcmp(cmd, "absorbgitdirs")) + do_quiet_cache = 0; + else if (!strcmp(cmd, "update")) + ; + else + do_prefix = 0; + if (do_quiet_cache) { + if (quiet) + strvec_push(args, "--quiet"); + if (cached) + strvec_push(args, "--cached"); + + if (prefix && do_prefix) + strvec_pushl(args, "--prefix", prefix, NULL); + } + + /* All commands get argv, including a "--", if any */ + strvec_pushv(args, argv); +} + +int cmd_submodule(int argc, const char **argv, const char *prefix) +{ + int opt_quiet = 0; + int opt_cached = 0; + struct child_process cp = CHILD_PROCESS_INIT; + struct option options[] = { + OPT__QUIET(&opt_quiet, N_("be quiet")), + OPT_BOOL(0, "cached", &opt_cached, + N_("print the OID of submodules")), + OPT_END() + }; + + argc = parse_options(argc, argv, prefix, options, git_submodule_usage, + PARSE_OPT_STOP_AT_NON_OPTION | PARSE_OPT_KEEP_DASHDASH); + + /* + * Tell the rest of git that any URLs we get don't come + * directly from the user, so it can apply policy as appropriate. + */ + strvec_push(&cp.env, "GIT_PROTOCOL_FROM_USER=0"); + setup_helper_args(argc, argv, prefix, opt_quiet, opt_cached, + &cp.args, options); + + cp.git_cmd = 1; + cp.no_stdin = 0; /* for git submodule foreach */ + cp.dir = startup_info->original_cwd; + + return run_command(&cp); +} diff --git a/git-submodule.sh b/git-submodule.sh deleted file mode 100755 index 4f8f62ce981..00000000000 --- a/git-submodule.sh +++ /dev/null @@ -1,91 +0,0 @@ -#!/bin/sh -# -# git-submodule.sh: add, init, update or list git submodules -# -# Copyright (c) 2007 Lars Hjemli - -dashless=$(basename "$0" | sed -e 's/-/ /') -USAGE="[--quiet] [--cached] - or: $dashless [--quiet] add [-b ] [-f|--force] [--name ] [--reference ] [--] [] - or: $dashless [--quiet] status [--cached] [--recursive] [--] [...] - or: $dashless [--quiet] init [--] [...] - or: $dashless [--quiet] deinit [-f|--force] (--all| [--] ...) - or: $dashless [--quiet] update [--init [--filter=]] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference ] [--recursive] [--[no-]single-branch] [--] [...] - or: $dashless [--quiet] set-branch (--default|--branch ) [--] - or: $dashless [--quiet] set-url [--] - or: $dashless [--quiet] summary [--cached|--files] [--summary-limit ] [commit] [--] [...] - or: $dashless [--quiet] foreach [--recursive] - or: $dashless [--quiet] sync [--recursive] [--] [...] - or: $dashless [--quiet] absorbgitdirs [--] [...]" -OPTIONS_SPEC= -SUBDIRECTORY_OK=Yes -. git-sh-setup -require_work_tree -wt_prefix=$(git rev-parse --show-prefix) -cd_to_toplevel - -# Tell the rest of git that any URLs we get don't come -# directly from the user, so it can apply policy as appropriate. -GIT_PROTOCOL_FROM_USER=0 -export GIT_PROTOCOL_FROM_USER - -command= -quiet= -cached= - -while test $# != 0 && test -z "$command" -do - case "$1" in - add | foreach | init | deinit | update | set-branch | set-url | status | summary | sync | absorbgitdirs) - command=$1 - ;; - -q|--quiet) - quiet=1 - ;; - --cached) - if test -z "$command" - then - cached=1 && - shift && - break - else - usage - fi - ;; - --) - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift -done - -# No command word defaults to "status" -if test -z "$command" -then - if test $# = 0 - then - command=status - else - usage - fi -fi - -case "$command" in -absorbgitdirs) - git submodule--helper "$command" --prefix "$wt_prefix" "$@" - ;; -update) - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ - ${quiet:+--quiet} ${wt_prefix:+--prefix "$wt_prefix"} "$@" - ;; -add | foreach | init | deinit | set-branch | set-url | status | summary | sync) - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ - ${quiet:+--quiet} ${cached:+--cached} "$@" - ;; -esac diff --git a/git.c b/git.c index da411c53822..2ad14f1e38f 100644 --- a/git.c +++ b/git.c @@ -610,6 +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", cmd_submodule, RUN_SETUP | NEED_WORK_TREE }, { "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX | NO_PARSEOPT }, { "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE }, { "symbolic-ref", cmd_symbolic_ref, RUN_SETUP }, diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index d8f7d6ee29a..19df3407ef1 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -15,20 +15,18 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh test_expect_success 'submodule usage: -h' ' - git submodule -h >out 2>err && + test_expect_code 129 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_code 129 git submodule --recursive ' test_expect_success 'submodule usage: status --' ' - test_expect_code 1 git submodule -- && - test_expect_code 1 git submodule --end-of-options + test_expect_code 129 git submodule -- && + test_expect_code 129 git submodule --end-of-options ' for opt in '--quiet' @@ -45,7 +43,7 @@ do test_expect_success "submodule usage: status $opt" ' git submodule $opt && git submodule status $opt && - test_expect_code 1 git submodule $opt status >out 2>err && + test_expect_code 129 git submodule $opt status >out 2>err && grep "^usage: git submodule" err && test_must_be_empty out ' From patchwork Mon Oct 17 12:09:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13008727 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 ABE6DC4332F for ; Mon, 17 Oct 2022 12:10:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230006AbiJQMKJ (ORCPT ); Mon, 17 Oct 2022 08:10:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229963AbiJQMJp (ORCPT ); Mon, 17 Oct 2022 08:09:45 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57C3C1A20B for ; Mon, 17 Oct 2022 05:09:40 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id l32so8520950wms.2 for ; Mon, 17 Oct 2022 05:09:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r37l8qjjqylHuf8OFZAvBm3VQ6GMlQDnnLyNl/cAid8=; b=Y77h0B23nJmii63oWoe68sDh6yjHJaC5wuVzNETskYMxG2txQqSPNY+7OD4xsg76kw 2zuD34chC3vUwLjr0Gk8uOE72EUtvYjWDFhDkcjE0+DaXtMit5nsyyrAaxpK+McVWulr 6A6s1CDowLfjFmAlFkPL8Uyy85S8zf0448y43aORyPfqvlnS9Ax+M3jOs3W6uAa9ofSy 3myWVrpWYa+729rVAXAGjYqbSGdSc2Xm0LQY0Rw2L9nyuvKVypwT4z3NVGY2xb2M7xaQ 6zw6Z7+KQxrSe9QIXRzQHGlCTE4GQh2uXEv64I7N5uBAkwQdA0UEh+NbCZ5MQ8Px73rj 4+2A== 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=r37l8qjjqylHuf8OFZAvBm3VQ6GMlQDnnLyNl/cAid8=; b=jPvQEySag/D4+rbCAMghAHjn+HsSOmP3Tu8XCM8VCNMtNULM7fIgVsHWe0Z4FJ1fkY JKYCFtlyv8WEx9TTJw30FquwbMYVFtDPvlHMj8x+ya2zNLNfoRw31xC6bifbQGILxC0s ULA6CLHzS6tALyx95XkBQ3WklBv8xHGd4vl64wnA/l7xVq0J3iX+bqvMlNG2psSgLA/O 2fFGn8EJo/fwwVbbixfcrAt7rLb46zCfFUf44PQN12B5MJ0B3nV2pLxoG/RlF2kDzTGl +FoZlBxKIY7gJiPMK6kxyAN1VuBHF0E0nllsEnLO+8z0TXRIS1gp+zDdm2kZbMFt/xXz vM7Q== X-Gm-Message-State: ACrzQf3e/6aCj0jFhmBg6YT2r+u0ueTOYNqLS2f4Mnxj9vvxyjesAZhD U/brLZFJ85Vy/fIcCKlVGv+ZrRuqHqdooA== X-Google-Smtp-Source: AMsMyM6E0kH6BtWmLNT+gOEntKW//QVF7tH7D6GurpSBtx8AvgsVi1CQm8LTAzwdkjaeK5eJKxHyDA== X-Received: by 2002:a05:600c:4fce:b0:3b4:935f:b952 with SMTP id o14-20020a05600c4fce00b003b4935fb952mr19123902wmq.197.1666008579099; Mon, 17 Oct 2022 05:09:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id z6-20020a1cf406000000b003c6deb5c1edsm10028770wma.45.2022.10.17.05.09.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 05:09:38 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Jonas Bernoulli , Jeff King , Emily Shaffer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 08/10] submodule: support "--" with no other arguments Date: Mon, 17 Oct 2022 14:09:23 +0200 Message-Id: X-Mailer: git-send-email 2.38.0.1091.gf9d18265e59 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Address an edge case that "git-submodule.sh" has had all along, but which became painfully obvious in the *.sh to *.c migration in the preceding commit. We didn't support the "--" delimiter in the argument-less invocation. Let's not bend over backwards to behave unusually in this scenario, simply accepting "--" is harmless. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-submodule.txt | 2 +- builtin/submodule.c | 12 ++---------- t/t7400-submodule-basic.sh | 4 ++-- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt index 4d3ab6b9f92..345ebcafb9c 100644 --- a/Documentation/git-submodule.txt +++ b/Documentation/git-submodule.txt @@ -9,7 +9,7 @@ git-submodule - Initialize, update or inspect submodules SYNOPSIS -------- [verse] -'git submodule' [--quiet] [--cached] +'git submodule' [--quiet] [--cached] [--] 'git submodule' [--quiet] add [] [--] [] 'git submodule' [--quiet] status [--cached] [--recursive] [--] [...] 'git submodule' [--quiet] init [--] [...] diff --git a/builtin/submodule.c b/builtin/submodule.c index 7e3499f3376..1d77f2d0964 100644 --- a/builtin/submodule.c +++ b/builtin/submodule.c @@ -8,7 +8,7 @@ #include "strvec.h" #define BUILTIN_SUBMODULE_USAGE \ - "git submodule [--quiet] [--cached]" + "git submodule [--quiet] [--cached] [--]" #define BUILTIN_SUBMODULE_ADD_USAGE \ N_("git submodule [--quiet] add [-b ] [-f | --force] [--name ]\n" \ @@ -91,14 +91,6 @@ static void setup_helper_args(int argc, const char **argv, const char *prefix, argv++; argc--; - /* - * This is stupid, but don't support "[--]" to - * subcommand-less "git-submodule" for now. - */ - if (!strcmp(cmd, "--") || !strcmp(cmd, "--end-of-options")) - usage_msg_optf(_("need explicit sub-command name to delimit with '%s'"), - git_submodule_usage, options, cmd); - /* Options that need to go before user-supplied options */ if (!strcmp(cmd, "absorbgitdirs")) do_quiet_cache = 0; @@ -133,7 +125,7 @@ int cmd_submodule(int argc, const char **argv, const char *prefix) }; argc = parse_options(argc, argv, prefix, options, git_submodule_usage, - PARSE_OPT_STOP_AT_NON_OPTION | PARSE_OPT_KEEP_DASHDASH); + PARSE_OPT_STOP_AT_NON_OPTION); /* * Tell the rest of git that any URLs we get don't come diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 19df3407ef1..c524398e805 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -25,8 +25,8 @@ test_expect_success 'submodule usage: --recursive' ' ' test_expect_success 'submodule usage: status --' ' - test_expect_code 129 git submodule -- && - test_expect_code 129 git submodule --end-of-options + git submodule -- && + git submodule --end-of-options ' for opt in '--quiet' From patchwork Mon Oct 17 12:09:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13008728 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 8244AC433FE for ; Mon, 17 Oct 2022 12:10:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230131AbiJQMKK (ORCPT ); Mon, 17 Oct 2022 08:10:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230012AbiJQMJ5 (ORCPT ); Mon, 17 Oct 2022 08:09:57 -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 57F271A21F for ; Mon, 17 Oct 2022 05:09:41 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id t4so8492078wmj.5 for ; Mon, 17 Oct 2022 05:09:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wOdtniLp5VSsE3DbQ7Z3B+oO8L/2JwdWe6JaS7fSlmQ=; b=fT6zgU7rULs+7AqjsM6HlR238IIfobrHC/zZFZoh67wIsN3MqOzmnx69wlcA/gtCFB 6DuSVyn0Uazf2V6GtiMMaSmhgJr/oKdcDClr/Kw0yR8qL2PX4FRz7u6vtGi96qZRXgba fpI+0DNWbIBZm4uHFFp9NPUuxmbwDNwlE9rK0DlPgYk3DhvHSYkLt/vwro+H3Vqe7x7m SbDFYphIidNSIXY9EpMR9FeDPvYtVAnD3WQ01q4aX5C9V39pkoLQNT/k0auBvALKrLFS B3eXi/YmKN/Pgkpq/xhJNzv7td+g/4Lxz6+je6h2yLtvM7UzbP6n5rdaEjQnxJn9xqRc HAjw== 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=wOdtniLp5VSsE3DbQ7Z3B+oO8L/2JwdWe6JaS7fSlmQ=; b=NuFduGEU6K7/ynk9wQxIk51WT0G2X94HeR3igLNejcL098d9ZK/1Dm/WQs66PJrvWP AzaLuaACX1YZIzZ5JBtJzOVOzEdaJcCjBB3aJTfXigi9pY179H7cXWthslocfRygzUqQ WwiCNitIZyP+4oluD09KqTQD10K3EvnCBAdZgDhXWDCDVoZLe7He9ydmgUXacxosokXA 3CiO4s6Yuz83WeTOOn+5Gj1hWqaAfxIWn6k9WDsmx3a+j/6+gWG1B+WMG7xo8ROKx+Vc eEcQjTnvxyicWHqBIpCyKIdHnOH7sxmjoU1NTHeKy1iSL1ziRGM/4u+cDRiQY8XAVNhL sOrg== X-Gm-Message-State: ACrzQf3P9KqydePeByGo9gHv2elNL3qzNTDJbJz0bQgAhbfEBGafmDk7 8RpC1KejU+3doOUoz5VnU8q05BP7NOJ53A== X-Google-Smtp-Source: AMsMyM4W9lnhiBMlmh816lqZV6H3ViiGGhp/fhE5N0Q7jeTKiOahVmzI0TrDLL8bYqWom+8wcv5dOg== X-Received: by 2002:a05:600c:a45:b0:3bc:c676:a573 with SMTP id c5-20020a05600c0a4500b003bcc676a573mr19397434wmq.118.1666008580073; Mon, 17 Oct 2022 05:09:40 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id z6-20020a1cf406000000b003c6deb5c1edsm10028770wma.45.2022.10.17.05.09.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 05:09:39 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Jonas Bernoulli , Jeff King , Emily Shaffer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 09/10] submodule: support sub-command-less "--recursive" option Date: Mon, 17 Oct 2022 14:09:24 +0200 Message-Id: X-Mailer: git-send-email 2.38.0.1091.gf9d18265e59 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The inability to specify "--recursive" when we're not providing a sub-command name appears to have been an omission in 15fc56a8536 (git submodule foreach: Add --recursive to recurse into nested submodules, 2009-08-19). Let's support it along with the other "status" options. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-submodule.txt | 2 +- builtin/submodule.c | 16 +++++++++++++--- t/t7400-submodule-basic.sh | 6 +----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt index 345ebcafb9c..0c918390f2f 100644 --- a/Documentation/git-submodule.txt +++ b/Documentation/git-submodule.txt @@ -9,7 +9,7 @@ git-submodule - Initialize, update or inspect submodules SYNOPSIS -------- [verse] -'git submodule' [--quiet] [--cached] [--] +'git submodule' [--quiet] [--cached] [--recursive] [--] 'git submodule' [--quiet] add [] [--] [] 'git submodule' [--quiet] status [--cached] [--recursive] [--] [...] 'git submodule' [--quiet] init [--] [...] diff --git a/builtin/submodule.c b/builtin/submodule.c index 1d77f2d0964..ca8e273b6e9 100644 --- a/builtin/submodule.c +++ b/builtin/submodule.c @@ -64,7 +64,8 @@ static const char * const git_submodule_usage[] = { }; static void setup_helper_args(int argc, const char **argv, const char *prefix, - int quiet, int cached, struct strvec *args, + int quiet, int cached, int recursive, + struct strvec *args, const struct option *options) { const char *cmd; @@ -79,10 +80,13 @@ static void setup_helper_args(int argc, const char **argv, const char *prefix, return; } - /* Did we get --cached with a command? */ + /* Did we get a forbidden top-level option with a command? */ if (cached) usage_msg_optf(_("'%s' option is only supported with explicit 'status'"), git_submodule_usage, options, "--cached"); + if (recursive) + usage_msg_optf(_("'%s' option is only supported with explicit 'status'"), + git_submodule_usage, options, "--recursive"); /* Either a valid command, or submodule--helper will barf! */ @@ -92,6 +96,9 @@ static void setup_helper_args(int argc, const char **argv, const char *prefix, argc--; /* Options that need to go before user-supplied options */ + if (!strcmp(cmd, "status") && recursive) + strvec_push(args, "--recursive"); + if (!strcmp(cmd, "absorbgitdirs")) do_quiet_cache = 0; else if (!strcmp(cmd, "update")) @@ -116,11 +123,14 @@ int cmd_submodule(int argc, const char **argv, const char *prefix) { int opt_quiet = 0; int opt_cached = 0; + int opt_recursive = 0; struct child_process cp = CHILD_PROCESS_INIT; struct option options[] = { OPT__QUIET(&opt_quiet, N_("be quiet")), OPT_BOOL(0, "cached", &opt_cached, N_("print the OID of submodules")), + OPT_BOOL(0, "recursive", &opt_recursive, + N_("recurse into nested submodules")), OPT_END() }; @@ -133,7 +143,7 @@ int cmd_submodule(int argc, const char **argv, const char *prefix) */ strvec_push(&cp.env, "GIT_PROTOCOL_FROM_USER=0"); setup_helper_args(argc, argv, prefix, opt_quiet, opt_cached, - &cp.args, options); + opt_recursive, &cp.args, options); cp.git_cmd = 1; cp.no_stdin = 0; /* for git submodule foreach */ diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index c524398e805..7cafc2e1102 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -20,10 +20,6 @@ test_expect_success 'submodule usage: -h' ' test_must_be_empty err ' -test_expect_success 'submodule usage: --recursive' ' - test_expect_code 129 git submodule --recursive -' - test_expect_success 'submodule usage: status --' ' git submodule -- && git submodule --end-of-options @@ -38,7 +34,7 @@ do ' done -for opt in '--cached' +for opt in '--cached' '--recursive' do test_expect_success "submodule usage: status $opt" ' git submodule $opt && From patchwork Mon Oct 17 12:09:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13008730 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 62C7DC433FE for ; Mon, 17 Oct 2022 12:10:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230140AbiJQMKT (ORCPT ); Mon, 17 Oct 2022 08:10:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230021AbiJQMKH (ORCPT ); Mon, 17 Oct 2022 08:10:07 -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 ADD691EAC6 for ; Mon, 17 Oct 2022 05:09:43 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id u10so18162200wrq.2 for ; Mon, 17 Oct 2022 05:09: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:subject:date :message-id:reply-to; bh=emTznePtSGl6JWuuq2u4y67G03bEQqTRv4fnOhZLO3c=; b=XctQ1gdYLk50OStNcQhhD8b9C9iimbei5NUg8AvD3fvpGSv4HJb0TgUhS1UtuvKMID 24nOABrSXTq0R2FBOUGt1MA7n0pM33IjMr5kkTdyxGvZ6xHLf8/KSfSHxMqSwIq5yTqJ ow8zC+9nk/dN6TWcQFUViAHj1rCp33wSYY/zR4f0/c1d0e2d6i/hCpSKaj+a84hvPjq2 I2ZggK1/mxqgPA7HKsHogi+JHNBMZ/C1gW42OCn9kwhS1lhWjcl3G0cbAuMxN6AebirN vnAF3M1josAwU0lnOlaqq9AF6TpWOeNjkQ5B+Ngg6wbQI8CqKaomUiMy9gSUp2l+S6e+ sj/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=emTznePtSGl6JWuuq2u4y67G03bEQqTRv4fnOhZLO3c=; b=hkIAFSvkqCZFryEDPI1L2Mhtwkk1v2sLaMxx26GqSWF0RlCAp4lUaSxzzT0GaECocc jwpUn14GJayklRrY1bMjbB8kDxVMXUZ0f5V+WJmhtdHPOWcNo/nPl+Z/iVeYzKrwyTc5 r9ZRSYhBhyJsoIjNyAwl4DNePrm/pW0IAcC+c18kDcOwbrVZnqEMxqtnXnqhklFpk/kZ iPkHxJL+TFxpu0hs0X9FcEzeMHxLxL1/1jYAcUNN8iPcVp7m3PyuZVdvFoCFQt2qPP/I MHpIviRw6artjk6hYt6IOcQnQsCxROBJFHLZf0IoxAnqVFZbW7o2ePHiIwjqeDQiR/JP KSbw== X-Gm-Message-State: ACrzQf2VQIKXc0628J2RQIJi3RPoha+Gns5dxPH3/s8Lpy/stBlf5oP2 RDhwIngDpOgQiqBGyoMLXJ644R9ew82gEw== X-Google-Smtp-Source: AMsMyM48Yyn0ioZaB4jEccOdgjKhpyTak3C6l1f5SLVwnqzki93WCEvnhMGwIAoW6rMkNsdz3hpLIA== X-Received: by 2002:a05:6000:1861:b0:232:2471:d405 with SMTP id d1-20020a056000186100b002322471d405mr6014848wri.130.1666008581021; Mon, 17 Oct 2022 05:09:41 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id z6-20020a1cf406000000b003c6deb5c1edsm10028770wma.45.2022.10.17.05.09.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 05:09:40 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Jonas Bernoulli , Jeff King , Emily Shaffer , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH 10/10] submodule: don't use a subprocess to invoke "submodule--helper" Date: Mon, 17 Oct 2022 14:09:25 +0200 Message-Id: X-Mailer: git-send-email 2.38.0.1091.gf9d18265e59 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a preceding commit we created "builtin/submodule.c" and faithfully tried to reproduce every aspect of "git-submodule.sh", including its invocation of "git submodule--helper" as a sub-process. Let's do away with the sub-process and invoke "cmd_submodule__helper()" directly. Eventually we'll want to do away with "builtin/submodule--helper.c" altogether, but let's not do that for now to avoid conflicts with other in-flight topics. Even without those conflicts the resulting diff would be large. We can leave that for a later cleanup. This speeds up invocations of all "git submodule" commands, E.g. a trivial "foreach" command on git.git is around 1.50 times faster[1]. For more expensive commands this'll make less of a difference, as the fixed cost of invoking the sub-process will be amortized away. $ git hyperfine -L rev HEAD~1,HEAD -s 'make CFLAGS=-O3' './git submodule foreach "echo \$name"' Benchmark 1: ./git submodule foreach "echo \$name"' in 'HEAD~1 Time (mean ± σ): 9.7 ms ± 0.1 ms [User: 7.6 ms, System: 2.1 ms] Range (min … max): 9.4 ms … 10.2 ms 285 runs Benchmark 2: ./git submodule foreach "echo \$name"' in 'HEAD Time (mean ± σ): 6.6 ms ± 0.1 ms [User: 5.1 ms, System: 1.5 ms] Range (min … max): 6.2 ms … 7.2 ms 414 runs Summary './git submodule foreach "echo \$name"' in 'HEAD' ran 1.48 ± 0.04 times faster than './git submodule foreach "echo \$name"' in 'HEAD~1' It's also worth noting that some users were using e.g. "git submodule--helper list" directly for performance reasons[2]. With 31955475d1c (submodule--helper: remove unused "list" helper, 2022-09-01) released with v2.38.0 the "list" command was no longer provided. Users who had to switch to "git submodule--helper foreach" were given a command that (on my system) is around 6.5x slower. Now the "foreach" is around 0.10x slower (due to the slight shell overhead), with 31955475d1c reverted on top of this: $ hyperfine './git submodule--helper list' './git submodule foreach --quiet "echo \$name"' --warmup 10 Benchmark 1: ./git submodule--helper list Time (mean ± σ): 6.4 ms ± 0.1 ms [User: 5.0 ms, System: 1.5 ms] Range (min … max): 6.2 ms … 7.2 ms 427 runs Benchmark 2: ./git submodule foreach --quiet "echo \$name" Time (mean ± σ): 7.0 ms ± 0.1 ms [User: 4.8 ms, System: 2.3 ms] Range (min … max): 6.8 ms … 7.4 ms 390 runs Summary './git submodule--helper list' ran 1.10 ± 0.03 times faster than './git submodule foreach --quiet "echo \$name"' I think it would make sense to implement a "--format" option for "git submodule foreach" to help anyone who cares about that remaining performance (and to improve the API, e.g. by supporting "-z"), but as far as performance goes this makes the runtime acceptable again. The pattern in "cmd_submodule_builtin()" of saving "struct strvec" arguments to a "struct string_list" and free()-ing them after the "argv" has been modified by "cmd_submodule__helper()" is new, without it we'd get various already-passing tests failing under SANITIZE=leak. 1. Using the "git hyperfine" wrapper for "hyperfine": https://lore.kernel.org/git/211201.86r1aw9gbd.gmgdl@evledraar.gmail.com/ 2. https://lore.kernel.org/git/87czatrpyb.fsf@bernoul.li/ Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/builtin/submodule.c b/builtin/submodule.c index ca8e273b6e9..13e7064b03f 100644 --- a/builtin/submodule.c +++ b/builtin/submodule.c @@ -119,12 +119,40 @@ static void setup_helper_args(int argc, const char **argv, const char *prefix, strvec_pushv(args, argv); } +static int cmd_submodule_builtin(struct strvec *args, const char *prefix) +{ + size_t i; + struct string_list to_free = STRING_LIST_INIT_DUP; + int ret; + + /* + * The cmd_submodule__helper() will treat the argv as + * its own and modify it, so e.g. for "git submodule + * add" the "add" argument will be removed, and we'll + * thus leak from the strvec_push()'s in + * setup_helper_args(). + * + * So in lieu of some generic "snapshot for a free" + * API for "struct strvec" squirrel away the pointers + * to free with string_list_clear() later. + */ + for (i = 0; i < args->nr; i++) + string_list_append_nodup(&to_free, (char *)args->v[i]); + + ret = cmd_submodule__helper(args->nr, args->v, prefix); + + string_list_clear(&to_free, 0); + free(strvec_detach(args)); + + return ret; +} + int cmd_submodule(int argc, const char **argv, const char *prefix) { int opt_quiet = 0; int opt_cached = 0; int opt_recursive = 0; - struct child_process cp = CHILD_PROCESS_INIT; + struct strvec args = STRVEC_INIT; struct option options[] = { OPT__QUIET(&opt_quiet, N_("be quiet")), OPT_BOOL(0, "cached", &opt_cached, @@ -141,13 +169,10 @@ int cmd_submodule(int argc, const char **argv, const char *prefix) * Tell the rest of git that any URLs we get don't come * directly from the user, so it can apply policy as appropriate. */ - strvec_push(&cp.env, "GIT_PROTOCOL_FROM_USER=0"); - setup_helper_args(argc, argv, prefix, opt_quiet, opt_cached, - opt_recursive, &cp.args, options); + xsetenv("GIT_PROTOCOL_FROM_USER", "0", 1); - cp.git_cmd = 1; - cp.no_stdin = 0; /* for git submodule foreach */ - cp.dir = startup_info->original_cwd; + setup_helper_args(argc, argv, prefix, opt_quiet, opt_cached, + opt_recursive, &args, options); - return run_command(&cp); + return cmd_submodule_builtin(&args, prefix); }