From patchwork Tue Mar 1 00:08:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12763919 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 B3588C433EF for ; Tue, 1 Mar 2022 00:08:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230397AbiCAAJF (ORCPT ); Mon, 28 Feb 2022 19:09:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbiCAAJD (ORCPT ); Mon, 28 Feb 2022 19:09:03 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D0C79A4CC for ; Mon, 28 Feb 2022 16:08:23 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id d5-20020a623605000000b004e01ccd08abso8570930pfa.10 for ; Mon, 28 Feb 2022 16:08:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=psWNFvxVHzRNwn7LAZ1WWs1LyNdO3zDnyzLnegifRc4=; b=WvJve62/u1B9Z6AEP1p/PUuFb3VaEH4vU2bOLZxWAUN8imx3XRFLPS+aPL8aoPqO8j w7XCPN5oiJ+hnJdIe4dF9Au/xrSpBLCrqo3OpEt//HxaoJStPjpIU8nnY5AlpgENB+jZ nepMQxl1RsHvHU+Ht9VIjQBNQhVDIbORpHU+L5fhbW1ACGIwxK9jYz+7+SD3NENl72vy 2RH8wfyvuR+40+ZQW6c3SFb4YuatKGZJi3ZzcarFGuLC6PgIIjtdQ+hwb2rB/warrrj9 3XHi3BLld/fC5T5Ujq9UHTwDtOKY53E94sJsX8cuwWDo2a/NoWJ/RIVQ4c33HdrPgmgB Jt4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=psWNFvxVHzRNwn7LAZ1WWs1LyNdO3zDnyzLnegifRc4=; b=e8ZZ1h5+bzHNMjH2fv8lF2n5x9CWPFPOYMiqfBfmV8ZVLFJePk+bIGW5LjxheTmian CuaI4wA+YVyh9+AR/2bm/b7akhw5tS/KcITRu0EYF+i8JcVo7Q8Ug07SG3buKV4UJy9F tj/9E1gxpt8XEO6CWGS7UfsIi47mucAUrpGrUryxokNTN8XgOrIha8b2x8Lun1vm4pZN KJRBP0GfVO2JxNbTooSL0V8CDBUnCiVUtXaYaSmHUB1UxeyYnOWj4zQZqaLd4KB0UWs+ 9Rc9wZCsiPt/OX69g5qkTPAzARYrBtNh8WpXlyA1W2R3Rzj4SflMgFBd8byuPlKfegbS DFTw== X-Gm-Message-State: AOAM530IUiAg/vx/Mxrg/mdNnUtQ5N/5TGY12envYC+abuccCtHdazbQ V86IDz+P9IxhOv/YpmIGYC39bLSdCqFpkl2lRhNnJqpjJbxlGa92vJWhh4iJbJuM66JxY78OVAf bNUCy6vxqsLkLWo94vBTpdHxhUguDhIu7k0ZeStIpE+WTsmT44iCtOgCHDy2Isf8= X-Google-Smtp-Source: ABdhPJxDiO21VJMEcCJplaA89gZCqnTaSzbUJ+VcOBPbBMREwqMykeMA+cZuB0I/PlZKL8OCDINE6TA7DDcG0Q== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a62:7697:0:b0:4df:34dc:d6c5 with SMTP id r145-20020a627697000000b004df34dcd6c5mr1732500pfc.9.1646093302956; Mon, 28 Feb 2022 16:08:22 -0800 (PST) Date: Mon, 28 Feb 2022 16:08:04 -0800 In-Reply-To: <20220301000816.56177-1-chooglen@google.com> Message-Id: <20220301000816.56177-2-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH 01/13] submodule tests: test for init and update failure output From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Emily Shaffer , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " , Josh Steadmon Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ævar Arnfjörð Bjarmason Amend some submodule tests to test for the failure output of "git submodule [update|init]". The lack of such tests hid a regression in an earlier version of a subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano Signed-off-by: Glen Choo --- t/t7406-submodule-update.sh | 14 ++++++++++++-- t/t7408-submodule-reference.sh | 14 +++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index 11cccbb333..7764c1c3cb 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -205,8 +205,18 @@ test_expect_success 'submodule update should fail due to local changes' ' (cd submodule && compare_head ) && - test_must_fail git submodule update submodule - ) + test_must_fail git submodule update submodule 2>../actual.raw + ) && + sed "s/^> //" >expect <<-\EOF && + > error: Your local changes to the following files would be overwritten by checkout: + > file + > Please commit your changes or stash them before you switch branches. + > Aborting + > fatal: Unable to checkout OID in submodule path '\''submodule'\'' + EOF + sed -e "s/checkout $SQ[^$SQ]*$SQ/checkout OID/" actual && + test_cmp expect actual + ' test_expect_success 'submodule update should throw away changes with --force ' ' (cd super && diff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh index a3892f494b..c3a4545510 100755 --- a/t/t7408-submodule-reference.sh +++ b/t/t7408-submodule-reference.sh @@ -193,7 +193,19 @@ test_expect_success 'missing nested submodule alternate fails clone and submodul cd supersuper-clone && check_that_two_of_three_alternates_are_used && # update of the submodule fails - test_must_fail git submodule update --init --recursive + cat >expect <<-\EOF && + fatal: submodule '\''sub'\'' cannot add alternate: path ... does not exist + Failed to clone '\''sub'\''. Retry scheduled + fatal: submodule '\''sub-dissociate'\'' cannot add alternate: path ... does not exist + Failed to clone '\''sub-dissociate'\''. Retry scheduled + fatal: submodule '\''sub'\'' cannot add alternate: path ... does not exist + Failed to clone '\''sub'\'' a second time, aborting + fatal: Failed to recurse into submodule path ... + EOF + test_must_fail git submodule update --init --recursive 2>err && + grep -e fatal: -e ^Failed err >actual.raw && + sed -e "s/path $SQ[^$SQ]*$SQ/path .../" actual && + test_cmp expect actual ) ' From patchwork Tue Mar 1 00:08:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12763920 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 C743FC433EF for ; Tue, 1 Mar 2022 00:08:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231159AbiCAAJH (ORCPT ); Mon, 28 Feb 2022 19:09:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230458AbiCAAJF (ORCPT ); Mon, 28 Feb 2022 19:09:05 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE8D99A99D for ; Mon, 28 Feb 2022 16:08:25 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id x17-20020a17090ab01100b001bbffb2c5f3so365642pjq.9 for ; Mon, 28 Feb 2022 16:08:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=UH8t/E0TczNz4tziesvMRSUOID+d/VyUA9f/OELjrWw=; b=lgBNiQlSH4SXN+Yp2yAlZcf2q6Kqv8rEPBg5FV8m0fRrMgOt2r3/BtfWTymao/j/3b TStFCj/ETcqTCghbJg60EZ4cD7h2HL88fYul5BN+WS9ewjonThXprBr2EUuUmYwDvj5m nmcbWbFtmqq8j/A3D04EwWLfr6FiBniT0GhJVNQrgEuJbknf41FuBYi/svG7EG+8uB3N 7v0kAql1NeCfs/gH2tlgSwD4PgOK+wui93WlVGrR62iDTH6UG2VwH5+g30824BjcV32u 9IPMfFizWXiyrfk81AYHUF0nnyM7bq40hqL1IM6Rx9FkppAw6TNTd2HivLSKVETISbUw IhMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=UH8t/E0TczNz4tziesvMRSUOID+d/VyUA9f/OELjrWw=; b=ZlN2IYwC4XgO88KyFhSh4U/qHkKbqK3THOZCx5Qf4CKPkJm1PFBzwLBGj4JRHTwxpF xPAYB+mwAtPm9Qg2zq+brFF3g8yLNyAVZWpPYm5Zo+cA2PLbijwCgpjqjEVtlXeDG4KF 3cPzHXdxPS4Sq0FhO7jzmiH/l5GvuJ2wfTL1MuP//UFT20vPiVtMaE3xHKwPw4bfzt8X FhkOxZUHZjsnYeFCN8AHte+Y55UiYLO3HyH4mMeRGmv9F+y8qVlK5YWDJtEVldqwP+dK 8kuAEWZ4t2uhxuEIWIHrTZGbOcPIAk8nu7RQlpGhrAa+yinCIVUHOnCheX7KbLvKgXC5 1EsA== X-Gm-Message-State: AOAM533z5EF0i01hM1oPqM9sJJ2M7YZ6BYx4KnSjfUznCLOOkNUmDLjz sbofe99kG3gAnQFIJ8ahfw/KJoiVZMdMLbBXRuHHzJeRPQJXU5uU+oCVewKMS4T/+kUHLmxMFDL rtaPIwVsE2LcUwHWIOtNCgHEum1uCkAyqeq1eiZm/b51rTKlDpTvKeUroCg1d2z8= X-Google-Smtp-Source: ABdhPJy1biFBBM2uAV5MadEaMj78idHnqPio7iaboW+67N3AEOJ2zMkhzw15jlJqrKeHdZq9c1S2o5vKbwXYxQ== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a63:86:0:b0:36c:48e8:627e with SMTP id 128-20020a630086000000b0036c48e8627emr19506515pga.53.1646093305009; Mon, 28 Feb 2022 16:08:25 -0800 (PST) Date: Mon, 28 Feb 2022 16:08:05 -0800 In-Reply-To: <20220301000816.56177-1-chooglen@google.com> Message-Id: <20220301000816.56177-3-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH 02/13] submodule--helper: remove update-module-mode From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Emily Shaffer , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " , Josh Steadmon Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This is dead code - it has not been used since c51f8f94e5 (submodule--helper: run update procedures from C, 2021-08-24). Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index eeacefcc38..c11ee1ea2b 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1957,29 +1957,6 @@ static void determine_submodule_update_strategy(struct repository *r, free(key); } -static int module_update_module_mode(int argc, const char **argv, const char *prefix) -{ - const char *path, *update = NULL; - int just_cloned; - struct submodule_update_strategy update_strategy = { .type = SM_UPDATE_CHECKOUT }; - - if (argc < 3 || argc > 4) - die("submodule--helper update-module-clone expects []"); - - just_cloned = git_config_int("just_cloned", argv[1]); - path = argv[2]; - - if (argc == 4) - update = argv[3]; - - determine_submodule_update_strategy(the_repository, - just_cloned, path, update, - &update_strategy); - fputs(submodule_strategy_to_string(&update_strategy), stdout); - - return 0; -} - struct update_clone_data { const struct submodule *sub; struct object_id oid; @@ -3430,7 +3407,6 @@ static struct cmd_struct commands[] = { {"name", module_name, 0}, {"clone", module_clone, 0}, {"add", module_add, SUPPORT_SUPER_PREFIX}, - {"update-module-mode", module_update_module_mode, 0}, {"update-clone", update_clone, 0}, {"run-update-procedure", run_update_procedure, 0}, {"ensure-core-worktree", ensure_core_worktree, 0}, From patchwork Tue Mar 1 00:08:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12763922 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 19073C433EF for ; Tue, 1 Mar 2022 00:08:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231182AbiCAAJN (ORCPT ); Mon, 28 Feb 2022 19:09:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231153AbiCAAJH (ORCPT ); Mon, 28 Feb 2022 19:09:07 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D9F89A4CF for ; Mon, 28 Feb 2022 16:08:27 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id oj16-20020a17090b4d9000b001bc9dddd9easo7371977pjb.7 for ; Mon, 28 Feb 2022 16:08:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ZJ9JuO2ZLBsSPC5VW54LiMsNmiMznGVzF+HcPh0t8SY=; b=UnStrozCus9TQCvBw+ugtOWzewUz+PZNylqJKcCzN/5BF4LoBtAyg12PVDs/8Ya4El xIsRzTJ0a6wkZdcmnRCffP0woc+eKzrMKSYsqbLu6F4RjOY7blC2XeT7MUsKjQbYRcij 1CL/5sMVYuJu4QeSqUZIR1GnvZ7rDwT+l5qzV5+nrmHtSfQmo29f3N9/qFaTgE9vTJPo K4IR+R/n/Sk34v2K07XPLk9XPsFOmxioybleisga26imhb/MOdKgCK8zX0DbmE3JdfWJ NthTBa36bt4auxJpNGzICS/0SRiL5Mw5d6v5tKBEWIhl4t3WoIQvQnOs8sF9wfjGDM5s 5IYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ZJ9JuO2ZLBsSPC5VW54LiMsNmiMznGVzF+HcPh0t8SY=; b=tzD1bfvHfGc7fSlFGVKMIV/qA1aswgnwamKxlCCziWHFuQGh4kadaep5kqMvLdZRhQ NzEp/bFRw0mYkVPcEVr4RGctmRGDKJCstSaBuGETJnB6HXZ8DRb6ojzGk393vWN4J8ax aSHiheiDfHNxXtrOsedvHnucNi1T0NH5GA00vG0IIi4OhHzbIaPmwyErChddX4JXkz29 68lPffl8R8aCLkrdGeCmulUsK9ZMhgCLpz4Y92VAd4Gr3l5glmcyKF9wvD2M0CuMLZot yDhasqo9BkqJ3t5QWgGUc7Eeq7nuE2jZb4Jfbb/ScNK/OSZVYm6cPBvImRKWo66CiESl UwrQ== X-Gm-Message-State: AOAM5327layJQVCw5viynA/ggwhCMuUe7tyQafRoVURR0EAEJStu0l8x dKM/Y5HeTiXpAXcMZvMc+PKIDUBU0VnQzB/ThZtBJqBdeni4x2/D7Nn9+7zQxmKIkG2cEnLZGD5 Jwh/P41y0rBfRDEZTNU/SdiCSAktwrSNUe4lr1/tyNMsOesQM8W9J1h2ZF4TU/+g= X-Google-Smtp-Source: ABdhPJzW//TJEsGhFmlhQeDxS1t5QEZYFc4G43aGUedIvBny6/R8J0f0fL8DGjxuPhuKaruurx9zNZkuZ8kGwA== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a62:aa19:0:b0:4f1:1cff:faa8 with SMTP id e25-20020a62aa19000000b004f11cfffaa8mr24345689pff.25.1646093306986; Mon, 28 Feb 2022 16:08:26 -0800 (PST) Date: Mon, 28 Feb 2022 16:08:06 -0800 In-Reply-To: <20220301000816.56177-1-chooglen@google.com> Message-Id: <20220301000816.56177-4-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH 03/13] submodule--helper: reorganize code for sh to C conversion From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Emily Shaffer , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " , Josh Steadmon Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Introduce a function, update_submodule2(), that will implement the functionality of run-update-procedure and its surrounding shell code in submodule.sh. This name is temporary; it will replace update_submodule() when the sh to C conversion is complete. Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index c11ee1ea2b..1b67a3887c 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2452,6 +2452,16 @@ static int do_run_update_procedure(struct update_data *ud) return run_update_command(ud, subforce); } +/* + * NEEDSWORK: As we convert "git submodule update" to C, + * update_submodule2() will invoke more and more functions, making it + * difficult to preserve the function ordering without forward + * declarations. + * + * When the conversion is complete, this forward declaration will be + * unnecessary and should be removed. + */ +static int update_submodule2(struct update_data *update_data); static void update_submodule(struct update_clone_data *ucd) { fprintf(stdout, "dummy %s %d\t%s\n", @@ -2618,11 +2628,7 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix) &update_data.update_strategy); free(prefixed_path); - - if (!oideq(&update_data.oid, &update_data.suboid) || update_data.force) - return do_run_update_procedure(&update_data); - - return 3; + return update_submodule2(&update_data); } static int resolve_relative_path(int argc, const char **argv, const char *prefix) @@ -3022,6 +3028,16 @@ static int module_create_branch(int argc, const char **argv, const char *prefix) force, reflog, quiet, track, dry_run); return 0; } + +/* NEEDSWORK: this is a temporary name until we delete update_submodule() */ +static int update_submodule2(struct update_data *update_data) +{ + if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) + return do_run_update_procedure(update_data); + + return 3; +} + struct add_data { const char *prefix; const char *branch; From patchwork Tue Mar 1 00:08:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12763921 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 8D95AC433EF for ; Tue, 1 Mar 2022 00:08:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231126AbiCAAJL (ORCPT ); Mon, 28 Feb 2022 19:09:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231173AbiCAAJJ (ORCPT ); Mon, 28 Feb 2022 19:09:09 -0500 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD2FD9AE75 for ; Mon, 28 Feb 2022 16:08:29 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id t18-20020a63dd12000000b00342725203b5so7417833pgg.16 for ; Mon, 28 Feb 2022 16:08:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=6b3Koiu50iGgu4+CvsJvU3gtyLeMDqKt6mcoMXU061M=; b=X2X1gruFX/PVXzvJI0HOZAXPDf00yApcAm1DzU1GOIzZAeIOFLVyLonHbNnCIT6qP6 bhxSXx1SAU9VNT7CCvIwttEoHrrd4hsieSWiRoDmqn6j85LwWkEkpxZlRDSutelU2+Sw A/QdrFKhKG0kkErzVpu24oaW3GFRkuPgJE/YIu6kxUXg1mPIRBtmXCSIs9ClhPb1ZuYp h88aGhEY6YxvAKucROp7fTN7qB1D4xZo9DRe59+SC57JR5rRd17Oc7FEwvLTZUlEQVQN /IrI+TxJoi5BN8fN50ZEUN9QdTTGSotSJyV0iWmBuYQScdKlmCWPbSnCxuZ4uZWovMJV O8Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=6b3Koiu50iGgu4+CvsJvU3gtyLeMDqKt6mcoMXU061M=; b=oN+F/1Hr7lAQ+k8Dhv0QH4vo8Q3ueQvHgfExQBjxE+3aUGGTjn/LfHPIDPsmC1txNj /vLoyoOoBED7SOZxWoAJZcGRb+GT9RuNFypXaxyRjlNwico1kQ9+su4sg9i4z1/heTgc WPUHN17s5fMRAZ1nShgCTDVccJ3fokaPDdR9K8wo/f6kd5D2YFoUNDGdQsGCT1mr1QVi cmvvbEzJP6bEpin3L9+scQF7X24oRbpIa+Xu6ABnBaYyUqZExaDQNowZyfGiRW6EzibF WFMTxqZPZ1TSS3YbkKf4kdJ98ExITFCb2hQ233CT3maMYppuvw5zxX1RNyuuHF/TeEEm ae0g== X-Gm-Message-State: AOAM532op/69Hws9bSsufs+n+LCay9WZ9q2b65vCTWXReTzFH9ifaBfp tO4KWwS1TVgy2CPEBXxjl9RQd8z/W0PRrYwCI219Yu/BSW0gfOpX+dGQmz3MU1sjn4kUuDnWGT4 88sQB7VhiDyNfnPEuIJIqr9DnWTnxblng9G2ZIrbRTfcVVQBz9Gf/qj+GQs6ZHHU= X-Google-Smtp-Source: ABdhPJwVoXppr973pyVI3Z/mR6/2aSd2DdbCOD0vN2hvN5ZC95KkDaHWa2MeujuZxmlDzBsS88+CfwbL/ia+aQ== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a05:6a00:d5b:b0:4e1:2007:87fb with SMTP id n27-20020a056a000d5b00b004e1200787fbmr24706393pfv.38.1646093308880; Mon, 28 Feb 2022 16:08:28 -0800 (PST) Date: Mon, 28 Feb 2022 16:08:07 -0800 In-Reply-To: <20220301000816.56177-1-chooglen@google.com> Message-Id: <20220301000816.56177-5-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH 04/13] submodule--helper run-update-procedure: remove --suboid From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Emily Shaffer , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " , Josh Steadmon Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Teach run-update-procedure to determine the oid of the submodule's HEAD instead of doing it in git-subomdule.sh. Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 9 ++++++--- git-submodule.sh | 8 +------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 1b67a3887c..77ca4270f4 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2594,9 +2594,6 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix) OPT_CALLBACK_F(0, "oid", &update_data.oid, N_("sha1"), N_("SHA1 expected by superproject"), PARSE_OPT_NONEG, parse_opt_object_id), - OPT_CALLBACK_F(0, "suboid", &update_data.suboid, N_("subsha1"), - N_("SHA1 of submodule's HEAD"), PARSE_OPT_NONEG, - parse_opt_object_id), OPT_END() }; @@ -3032,6 +3029,12 @@ static int module_create_branch(int argc, const char **argv, const char *prefix) /* NEEDSWORK: this is a temporary name until we delete update_submodule() */ static int update_submodule2(struct update_data *update_data) { + if (update_data->just_cloned) + oidcpy(&update_data->suboid, null_oid()); + else if (resolve_gitlink_ref(update_data->sm_path, "HEAD", &update_data->suboid)) + die(_("Unable to find current revision in submodule path '%s'"), + update_data->displaypath); + if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) return do_run_update_procedure(update_data); diff --git a/git-submodule.sh b/git-submodule.sh index 87772ac891..32a09302ab 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -406,14 +406,9 @@ cmd_update() displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix") - if test $just_cloned -eq 1 + if test $just_cloned -eq 0 then - subsha1= - else just_cloned= - subsha1=$(sanitize_submodule_env; cd "$sm_path" && - git rev-parse --verify HEAD) || - die "fatal: $(eval_gettext "Unable to find current revision in submodule path '\$displaypath'")" fi if test -n "$remote" @@ -441,7 +436,6 @@ cmd_update() ${update:+--update "$update"} \ ${prefix:+--recursive-prefix "$prefix"} \ ${sha1:+--oid "$sha1"} \ - ${subsha1:+--suboid "$subsha1"} \ "--" \ "$sm_path") From patchwork Tue Mar 1 00:08:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12763923 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 68AF0C433EF for ; Tue, 1 Mar 2022 00:08:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231268AbiCAAJU (ORCPT ); Mon, 28 Feb 2022 19:09:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231153AbiCAAJR (ORCPT ); Mon, 28 Feb 2022 19:09:17 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ECCB9BADD for ; Mon, 28 Feb 2022 16:08:31 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id d4-20020a170902f14400b001518350e5c7so39099plb.13 for ; Mon, 28 Feb 2022 16:08:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=HM/UFTvzycLuEtiSNLNKftDfScVvaGAHyX0/2+0MI0U=; b=qx+SyICGRgfzDzk41m7kLGqVFNJQrNgNvcGqmXVVdoLKkTw0A+JVh8ngz6GxVmjQXs WoO4A6bXC5CvcAnBQOOz0TbGjhoQJGgBN5Jy9d7oyc9M/hVZ2jPLh5td0aJUW7Ot6FCE ZtJURQK+qxZZtqvM42IBNG1sQ9Qno40ydLMLS8y9eQg45K7PF0Jp2j2qaxBvhXRWvhff 4EoHc898eVaNCD+etCdv4SaStixzs4/QikFZ9pgJXqg/U0QBdescdfErpbozpiK5uJYG C00YrLR/HczLOo35GZMpHPgs9rqLaWZprrMnZZIEr3gX04bnG7c2pAMiq+MPFOobCxF9 XSIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=HM/UFTvzycLuEtiSNLNKftDfScVvaGAHyX0/2+0MI0U=; b=uNNiz824+mbhECC2RSsoUEVwdHr7Wur63S9SDcm5b+Jd0amwAPAnAQ6kDo4eTkBmis DF41p+8+PjlkNvAJkDV5lRtf5eQOhVK23h+BmnypdLLjVQlNj0fmK/A/WsTmCRK1bce5 RldE7P5vvb56/X43LDwlgR6wzKtjF+g2m8kFGT3+jJ+9kOUue3jZhauHFew1MupCfQGh oVSEXhxHdRNjms/bo49UgwASKXBExRJMUkUVSL15gdPuJcNcslFkjppjF+Qxvx2+2ump cc4XHSjHLDbYOJGHBIOvc9XPSLN7e72G/nzhWDRXFJozOLMz/8quxFZaeFetGqUOgMRp I82w== X-Gm-Message-State: AOAM531BvFAB2qyPxWrvItBVBr4GUM3gt0nc6i4QtF7LDtrbyDeytk4o XX46ppwMuV5knvGdy4iAKshEsbbF0Um3/gTzAwKaZOKK+VicljgrmDrIiTYsWcqGdMsWXpPJIuJ s2RGLjTMOdrPb4Zr7WSrPQMK9U0CM+jdJgWqfOJrgz/Yav6ibg+a4iiijUIQq0v4= X-Google-Smtp-Source: ABdhPJyoX5H8X3g9J4UV04SnkKQNviykE5/yMoSO1UTBZS148czZm427cOSrmCMhRNPNpq5veIq0oVuWube4IQ== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:903:1c1:b0:150:12cd:a027 with SMTP id e1-20020a17090301c100b0015012cda027mr23618719plh.26.1646093310717; Mon, 28 Feb 2022 16:08:30 -0800 (PST) Date: Mon, 28 Feb 2022 16:08:08 -0800 In-Reply-To: <20220301000816.56177-1-chooglen@google.com> Message-Id: <20220301000816.56177-6-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH 05/13] submodule--helper: remove ensure-core-worktree From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Emily Shaffer , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " , Josh Steadmon Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move the logic of "git submodule--helper ensure-core-worktree" into run-update-procedure. Since the ensure-core-worktree command is obsolete, remove it. Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 12 ++---------- git-submodule.sh | 2 -- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 77ca4270f4..6b473fc0d2 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2771,17 +2771,11 @@ static int push_check(int argc, const char **argv, const char *prefix) return 0; } -static int ensure_core_worktree(int argc, const char **argv, const char *prefix) +static void ensure_core_worktree(const char *path) { - const char *path; const char *cw; struct repository subrepo; - if (argc != 2) - BUG("submodule--helper ensure-core-worktree "); - - path = argv[1]; - if (repo_submodule_init(&subrepo, the_repository, path, null_oid())) die(_("could not get a repository handle for submodule '%s'"), path); @@ -2801,8 +2795,6 @@ static int ensure_core_worktree(int argc, const char **argv, const char *prefix) free(abs_path); strbuf_release(&sb); } - - return 0; } static int absorb_git_dirs(int argc, const char **argv, const char *prefix) @@ -3029,6 +3021,7 @@ static int module_create_branch(int argc, const char **argv, const char *prefix) /* NEEDSWORK: this is a temporary name until we delete update_submodule() */ static int update_submodule2(struct update_data *update_data) { + ensure_core_worktree(update_data->sm_path); if (update_data->just_cloned) oidcpy(&update_data->suboid, null_oid()); else if (resolve_gitlink_ref(update_data->sm_path, "HEAD", &update_data->suboid)) @@ -3428,7 +3421,6 @@ static struct cmd_struct commands[] = { {"add", module_add, SUPPORT_SUPER_PREFIX}, {"update-clone", update_clone, 0}, {"run-update-procedure", run_update_procedure, 0}, - {"ensure-core-worktree", ensure_core_worktree, 0}, {"relative-path", resolve_relative_path, 0}, {"resolve-relative-url-test", resolve_relative_url_test, 0}, {"foreach", module_foreach, SUPPORT_SUPER_PREFIX}, diff --git a/git-submodule.sh b/git-submodule.sh index 32a09302ab..458ce73ac6 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -402,8 +402,6 @@ cmd_update() do die_if_unmatched "$quickabort" "$sha1" - git submodule--helper ensure-core-worktree "$sm_path" || exit 1 - displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix") if test $just_cloned -eq 0 From patchwork Tue Mar 1 00:08:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12763924 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 5B5BEC433F5 for ; Tue, 1 Mar 2022 00:08:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231189AbiCAAJW (ORCPT ); Mon, 28 Feb 2022 19:09:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231254AbiCAAJR (ORCPT ); Mon, 28 Feb 2022 19:09:17 -0500 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E172B9BB84 for ; Mon, 28 Feb 2022 16:08:33 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id z10-20020a634c0a000000b0036c5eb39076so7421121pga.18 for ; Mon, 28 Feb 2022 16:08:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=t0gS2GJJJ+/nEbuiqRGr4cv3+fBqX6X1h/kU524+UoY=; b=rOu7Rj3cXK+0HH8xZEvtI1Kl/OjqaAcfAznzTYAIZ2YWQUubFRmNxWDweRDq5OEbvb UFJcZtViLLS5MoN9DFNnUWLuMkCFB4gktqk7oKOVrpo0Cds35F1FFEiYArY2vbGR7JW2 bU3dxik72Ij+S9l0vsp6TD6l8ehB/a9xNFtin6zkukiuQtj2Zz5Gyim6R92EHLZXM+SI +TL9oNyHrhkeSHcEvpFypPPOaf4f7Le1bdjg+N2CuRz+RVDzRCAaWFMEgdpHOOHXNO5T vE/BImmunAS3gg9JuEjoKQjXUR2kPDoq6GWyYa7V++gyasgIARBStW0+wZTYo82yPyVl 8qWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=t0gS2GJJJ+/nEbuiqRGr4cv3+fBqX6X1h/kU524+UoY=; b=psXfy2sTNC7E1M+rtzOV22gQPfZyBpE6gyFfZvCZYkemvKB0XNQXUF+H4IZCE/Z86y tSCUTW5xk9AGRzRYlkS1Akq1iupeC2M5kBFVHfMWRwl8Vrrp6Na8rSGPl1JXErs+mxdS JpNc4MQ3Uw5VONir+T82Q+wgyJpYqhH2o2qmW/RubCkiocVb+NRn00t+kdzeMBHh6aJh EDKab1MOCf3DtpS1b2KgrVNiJbRckADcVLPEqZzesIghm+m6hLVWMe1G0QZpodUPTxpQ KHBA4JQQ4Y3+sS5q8Pci5HkEHW9W4epXhhzpspz+zKd6tRmt0BpR5iQEzM+JYJbC1xzA 9JTg== X-Gm-Message-State: AOAM532F0SP8dMDvzlCw1TwkfDXsZSlRw1tDI1yeiIWp1MMgZire/fF7 LXN+ijgL+u/PkiC5/saz5ekICHbhSGgEDy8ACffd66gZBBNtv60AEVtjnXk9RXMT4FMRWG5hkaT wCRHNSSTZ2SV6UouhcbqqUZBZAGyoDeh0l3l7GlwOPFknQO6jfNZA279wkmlB3Ac= X-Google-Smtp-Source: ABdhPJxoAoIRycQIxdCFIwBD1Lmpkm6QFyniqVApjHS6ijwfX1m8K8GID8hmYLwcb40uhQ7ekOQxscVU4CYukg== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:90b:c8e:b0:1bc:3481:b2b7 with SMTP id o14-20020a17090b0c8e00b001bc3481b2b7mr19166558pjz.187.1646093312916; Mon, 28 Feb 2022 16:08:32 -0800 (PST) Date: Mon, 28 Feb 2022 16:08:09 -0800 In-Reply-To: <20220301000816.56177-1-chooglen@google.com> Message-Id: <20220301000816.56177-7-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH 06/13] submodule--helper: get remote names from any repository From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Emily Shaffer , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " , Josh Steadmon , Christian Couder , Shourya Shukla Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Atharva Raykar `get_default_remote()` retrieves the name of a remote by resolving the refs from of the current repository's ref store. Thus in order to use it for retrieving the remote name of a submodule, we have to start a new subprocess which runs from the submodule directory. Let's instead introduce a function called `repo_get_default_remote()` which takes any repository object and retrieves the remote accordingly. `get_default_remote()` is then defined as a call to `repo_get_default_remote()` with 'the_repository' passed to it. Now that we have `repo_get_default_remote()`, we no longer have to start a subprocess that called `submodule--helper get-default-remote` from within the submodule directory. So let's make a function called `get_default_remote_submodule()` which takes a submodule path, and returns the default remote for that submodule, all within the same process. We can now use this function to save an unnecessary subprocess spawn in `sync_submodule()`, and also in the next patch, which will require this functionality. Mentored-by: Christian Couder Mentored-by: Shourya Shukla Helped-by: Glen Choo Signed-off-by: Atharva Raykar Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 39 +++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 6b473fc0d2..f934e33c7e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -31,11 +31,14 @@ typedef void (*each_submodule_fn)(const struct cache_entry *list_item, void *cb_data); -static char *get_default_remote(void) +static char *repo_get_default_remote(struct repository *repo) { char *dest = NULL, *ret; struct strbuf sb = STRBUF_INIT; - const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, NULL); + struct ref_store *store = get_main_ref_store(repo); + int ignore_errno; + const char *refname = refs_resolve_ref_unsafe(store, "HEAD", 0, NULL, + NULL, &ignore_errno); if (!refname) die(_("No such ref: %s"), "HEAD"); @@ -48,7 +51,7 @@ static char *get_default_remote(void) die(_("Expecting a full ref name, got %s"), refname); strbuf_addf(&sb, "branch.%s.remote", refname); - if (git_config_get_string(sb.buf, &dest)) + if (repo_config_get_string(repo, sb.buf, &dest)) ret = xstrdup("origin"); else ret = dest; @@ -57,6 +60,19 @@ static char *get_default_remote(void) return ret; } +static char *get_default_remote_submodule(const char *module_path) +{ + struct repository subrepo; + + repo_submodule_init(&subrepo, the_repository, module_path, null_oid()); + return repo_get_default_remote(&subrepo); +} + +static char *get_default_remote(void) +{ + return repo_get_default_remote(the_repository); +} + static int print_default_remote(int argc, const char **argv, const char *prefix) { char *remote; @@ -1343,9 +1359,8 @@ static void sync_submodule(const char *path, const char *prefix, { const struct submodule *sub; char *remote_key = NULL; - char *sub_origin_url, *super_config_url, *displaypath; + char *sub_origin_url, *super_config_url, *displaypath, *default_remote; struct strbuf sb = STRBUF_INIT; - struct child_process cp = CHILD_PROCESS_INIT; char *sub_config_path = NULL; if (!is_submodule_active(the_repository, path)) @@ -1384,21 +1399,15 @@ static void sync_submodule(const char *path, const char *prefix, if (!is_submodule_populated_gently(path, NULL)) goto cleanup; - prepare_submodule_repo_env(&cp.env_array); - cp.git_cmd = 1; - cp.dir = path; - strvec_pushl(&cp.args, "submodule--helper", - "print-default-remote", NULL); - strbuf_reset(&sb); - if (capture_command(&cp, &sb, 0)) + default_remote = get_default_remote_submodule(path); + if (!default_remote) die(_("failed to get the default remote for submodule '%s'"), path); - strbuf_strip_suffix(&sb, "\n"); - remote_key = xstrfmt("remote.%s.url", sb.buf); + remote_key = xstrfmt("remote.%s.url", default_remote); + free(default_remote); - strbuf_reset(&sb); submodule_to_gitdir(&sb, path); strbuf_addstr(&sb, "/config"); From patchwork Tue Mar 1 00:08:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12763925 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 154DCC433FE for ; Tue, 1 Mar 2022 00:08:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231289AbiCAAJX (ORCPT ); Mon, 28 Feb 2022 19:09:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231304AbiCAAJS (ORCPT ); Mon, 28 Feb 2022 19:09:18 -0500 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD5F99BB95 for ; Mon, 28 Feb 2022 16:08:35 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id bm16-20020a656e90000000b00372932b1d83so7431149pgb.10 for ; Mon, 28 Feb 2022 16:08:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=U3sHN7GCQX5KRbfYGK/0HSN2pSBikSSsMMhQoPIvv28=; b=BwzWpUQ4xwT0TLmFblbIgpAyOD6yuqiNDrqt19BIem3A3njHxsyCN8V2+121BdMe39 TQ1EnYliDYWuuqh/ys+OorCxhnR1F0mZvEh/U81ZzIGFPQ9Ed+xbPVc9QiSPXH5EtWRp Yz1jpLc2oYpEA8QSxsS0KrMjTXK3x02Xrtj2eHpw/Yx4jVUCL++pcP98PeCTCfB1818q iTg0drJnwMNYHBa8llsi4qm5BPekI2OTjt1cCkoS0g34FouWvJ6+GXKsMjXXgf5SW+sv dl9enRyX4V7FoTOD0pVsc3S0svpv+LP8rBIv8c4j0bgXWiXXgpHELVV65hqq9+YP5St/ VJwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=U3sHN7GCQX5KRbfYGK/0HSN2pSBikSSsMMhQoPIvv28=; b=MMC6+Frh2Fth5hTsvFNQ0AWkdfHBELHmNPNKpKmoRHoY0ugJ7lZOkPEwzGm+Kv1K76 v1DWyNCj5d7t1qLSL+hjiZBrL9Vbu+LHbm2lRvFerO2+la05m7Vju5Z0ej97jZFda6+Z wesM0um3u0zQgc9bCKY6e6HF/LD/1Q5M/Jhkp36xtBhuJ5IaRbbsguRoxmZzyWv3Yws5 lZtojedQQ28Y7lhWykenwShgtnkcvshb4L843lJ4UiicGEZD08mPkK0nH704fT/7B2eo Yg0mHaAD0Z490qTXQbVdf9yVjA3zl2ZlMZPUyulS4l6FH/IuY+otX7z30rxjHVz08S+g FiXw== X-Gm-Message-State: AOAM531iMpuxg4duqk+a81XqSd/t58YCkrxJuS9c5NRPAj820tIsOLnm 6IQzEwZb8W2LNZE2xVWfTLg0QQGKUzWBp1Bl9u0hCWxr3aYMH+ITBy+q+m7XEwDJbndp0fCKR9c qYNRAn4kkB0cmF9fohoTHQjIgisp10XGIdxJhuwgVmMdblb9qzDkwI+qkG8YJ6uw= X-Google-Smtp-Source: ABdhPJxH4reTSVqoOJJcdhesXEv+pkT192ZOj5IOUlh1pY6MfR6w1FbC8LHIQeCxeAa1tVbOVNnBrIdutdIdwg== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a63:7a16:0:b0:374:90d4:b31 with SMTP id v22-20020a637a16000000b0037490d40b31mr19558361pgc.273.1646093314865; Mon, 28 Feb 2022 16:08:34 -0800 (PST) Date: Mon, 28 Feb 2022 16:08:10 -0800 In-Reply-To: <20220301000816.56177-1-chooglen@google.com> Message-Id: <20220301000816.56177-8-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH 07/13] submodule--helper: don't use bitfield indirection for parse_options() From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Emily Shaffer , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " , Josh Steadmon Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ævar Arnfjörð Bjarmason Do away with the indirection of local variables added in c51f8f94e5b (submodule--helper: run update procedures from C, 2021-08-24). These were only needed because in C you can't get a pointer to a single bit, so we were using intermediate variables instead. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index f934e33c7e..5fbf8713db 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2024,10 +2024,10 @@ struct update_data { struct object_id suboid; struct submodule_update_strategy update_strategy; int depth; - unsigned int force: 1; - unsigned int quiet: 1; - unsigned int nofetch: 1; - unsigned int just_cloned: 1; + unsigned int force; + unsigned int quiet; + unsigned int nofetch; + unsigned int just_cloned; }; #define UPDATE_DATA_INIT { .update_strategy = SUBMODULE_UPDATE_STRATEGY_INIT } @@ -2579,16 +2579,17 @@ static int update_clone(int argc, const char **argv, const char *prefix) static int run_update_procedure(int argc, const char **argv, const char *prefix) { - int force = 0, quiet = 0, nofetch = 0, just_cloned = 0; char *prefixed_path, *update = NULL; struct update_data update_data = UPDATE_DATA_INIT; struct option options[] = { - OPT__QUIET(&quiet, N_("suppress output for update by rebase or merge")), - OPT__FORCE(&force, N_("force checkout updates"), 0), - OPT_BOOL('N', "no-fetch", &nofetch, + OPT__QUIET(&update_data.quiet, + N_("suppress output for update by rebase or merge")), + OPT__FORCE(&update_data.force, N_("force checkout updates"), + 0), + OPT_BOOL('N', "no-fetch", &update_data.nofetch, N_("don't fetch new objects from the remote site")), - OPT_BOOL(0, "just-cloned", &just_cloned, + OPT_BOOL(0, "just-cloned", &update_data.just_cloned, N_("overrides update mode in case the repository is a fresh clone")), OPT_INTEGER(0, "depth", &update_data.depth, N_("depth for shallow fetch")), OPT_STRING(0, "prefix", &prefix, @@ -2616,10 +2617,6 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix) if (argc != 1) usage_with_options(usage, options); - update_data.force = !!force; - update_data.quiet = !!quiet; - update_data.nofetch = !!nofetch; - update_data.just_cloned = !!just_cloned; update_data.sm_path = argv[0]; if (update_data.recursive_prefix) From patchwork Tue Mar 1 00:08:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12763927 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 8C319C433EF for ; Tue, 1 Mar 2022 00:08:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231512AbiCAAJ0 (ORCPT ); Mon, 28 Feb 2022 19:09:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231239AbiCAAJS (ORCPT ); Mon, 28 Feb 2022 19:09:18 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4393CC084B for ; Mon, 28 Feb 2022 16:08:37 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id g2-20020a170902740200b0014fc971527eso5304224pll.14 for ; Mon, 28 Feb 2022 16:08:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=1ALfYMdx6j4I7kPm4Vq44Cz3IGeeUu+NpRtb7yuZuMM=; b=CmK2A5ZVYKlgnlrzIfkxvL4GMVWNlcD4UWThT6jAllr+NnazRKUZB5O3HL2dWvOizO 6ClrAbcyiW/BDr1uea4vXrcRkIy+M6mkN21uYinyvT8hiKw736bcGThP1XvF89ZKz9Ef aP56w1ASF8wWFHRe3uWtU5lnaPOR7NefLg+NSSsqR21MUJgecn8Q9DpEbnTs0nT5Bogv J2j8YVlKZDXsN9ZHQ5xj4PPU/caW+cdhlpO1oSv/BghYTuBfwz9WXOUBhrwMc1yuCNz1 GxMoM0ltWiZlpUhOdgflYdsVBVGLMF4/WYZ295PULh7VDajcz9tQcYDu2OK91MwVhy8S xATg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=1ALfYMdx6j4I7kPm4Vq44Cz3IGeeUu+NpRtb7yuZuMM=; b=Tzr5XHPlAtDu2rQ16JyP+1assswq61BCDk48wMlG///95RpntMzfRwxPH2H40wQGB6 CXwE1Mf8AzxcN4FGO39eL8W1vnCgCjYagszXP5FZcgBRn3i/knc8y9N3JTmIAnrX/4i8 5AD1TRfV3QVVDSC9mUY80LwIdFglER0Z9xJUAGphkXb3i7BL7o3NwMYaY43Hu2IyZd55 uH/IhPkqe7KjMQpykWa6yUl2bCTPTXOKmW3fnOpoMcu1i46XXslaDdI8SQEd3mF5YJl8 eNK7RwAgMrE77yQ2zA+Ym3du9iV+/m3K/06ByV/YvnQXHAe4EGrxM+g1ivoqYP+Cgezq v1bA== X-Gm-Message-State: AOAM531RB1pBH5rj9AxBX1m/41KbC0QoSdwggirq04Tn2qIps1Z52HqG 8dN8qo3/2r/Pq1Qk4LJQyRXJjiqQPqCM2JcWvrK9OabdN1I8D3iYiF8E1VFW2OGdkr4skvJryVM m2cETDohREFa74z3h3smgZXsiMFpS4y+Onk2xRpLoJeLnGN+heU7OnGzkUBg3LA4= X-Google-Smtp-Source: ABdhPJxACuz8vQV4V13bA1X4v26zVGKXten1uSatLydcXeNGaO4I+QdjK/p6xOF/NjLKFqu3BTgwFUQu0C3ffg== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a65:568b:0:b0:378:86b8:9426 with SMTP id v11-20020a65568b000000b0037886b89426mr8057199pgs.70.1646093316626; Mon, 28 Feb 2022 16:08:36 -0800 (PST) Date: Mon, 28 Feb 2022 16:08:11 -0800 In-Reply-To: <20220301000816.56177-1-chooglen@google.com> Message-Id: <20220301000816.56177-9-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH 08/13] submodule--helper run-update-procedure: learn --remote From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Emily Shaffer , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " , Josh Steadmon Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Teach run-update-procedure to handle --remote instead of parsing --remote in git-submodule.sh. As a result, "git submodule--helper print-default-remote" has no more callers, so remove it. Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 39 ++++++++++++++++++++++--------------- git-submodule.sh | 30 +--------------------------- 2 files changed, 24 insertions(+), 45 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 5fbf8713db..1d4d9231ac 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -73,21 +73,6 @@ static char *get_default_remote(void) return repo_get_default_remote(the_repository); } -static int print_default_remote(int argc, const char **argv, const char *prefix) -{ - char *remote; - - if (argc != 1) - die(_("submodule--helper print-default-remote takes no arguments")); - - remote = get_default_remote(); - if (remote) - printf("%s\n", remote); - - free(remote); - return 0; -} - static int starts_with_dot_slash(const char *str) { return str[0] == '.' && is_dir_sep(str[1]); @@ -2028,6 +2013,7 @@ struct update_data { unsigned int quiet; unsigned int nofetch; unsigned int just_cloned; + unsigned int remote; }; #define UPDATE_DATA_INIT { .update_strategy = SUBMODULE_UPDATE_STRATEGY_INIT } @@ -2604,6 +2590,8 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix) OPT_CALLBACK_F(0, "oid", &update_data.oid, N_("sha1"), N_("SHA1 expected by superproject"), PARSE_OPT_NONEG, parse_opt_object_id), + OPT_BOOL(0, "remote", &update_data.remote, + N_("use SHA-1 of submodule's remote tracking branch")), OPT_END() }; @@ -3034,6 +3022,25 @@ static int update_submodule2(struct update_data *update_data) die(_("Unable to find current revision in submodule path '%s'"), update_data->displaypath); + if (update_data->remote) { + char *remote_name = get_default_remote_submodule(update_data->sm_path); + const char *branch = remote_submodule_branch(update_data->sm_path); + char *remote_ref = xstrfmt("refs/remotes/%s/%s", remote_name, branch); + + if (!update_data->nofetch) { + if (fetch_in_submodule(update_data->sm_path, update_data->depth, + 0, NULL)) + die(_("Unable to fetch in submodule path '%s'"), + update_data->sm_path); + } + + if (resolve_gitlink_ref(update_data->sm_path, remote_ref, &update_data->oid)) + die(_("Unable to find %s revision in submodule path '%s'"), + remote_ref, update_data->sm_path); + + free(remote_ref); + } + if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) return do_run_update_procedure(update_data); @@ -3432,10 +3439,10 @@ static struct cmd_struct commands[] = { {"foreach", module_foreach, SUPPORT_SUPER_PREFIX}, {"init", module_init, SUPPORT_SUPER_PREFIX}, {"status", module_status, SUPPORT_SUPER_PREFIX}, - {"print-default-remote", print_default_remote, 0}, {"sync", module_sync, SUPPORT_SUPER_PREFIX}, {"deinit", module_deinit, 0}, {"summary", module_summary, SUPPORT_SUPER_PREFIX}, + /* NEEDSWORK: remote-branch is also obsolete */ {"remote-branch", resolve_remote_submodule_branch, 0}, {"push-check", push_check, 0}, {"absorb-git-dirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX}, diff --git a/git-submodule.sh b/git-submodule.sh index 458ce73ac6..23ebd90892 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -247,20 +247,6 @@ cmd_deinit() git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${GIT_QUIET:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@" } -# usage: fetch_in_submodule [] [] -# Because arguments are positional, use an empty string to omit -# but include . -fetch_in_submodule () ( - sanitize_submodule_env && - cd "$1" && - if test $# -eq 3 - then - echo "$3" | git fetch ${GIT_QUIET:+--quiet} --stdin ${2:+"$2"} - else - git fetch ${GIT_QUIET:+--quiet} ${2:+"$2"} - fi -) - # # Update each submodule path to correct revision, using clone and checkout as needed # @@ -409,21 +395,6 @@ cmd_update() just_cloned= fi - if test -n "$remote" - then - branch=$(git submodule--helper remote-branch "$sm_path") - if test -z "$nofetch" - then - # Fetch remote before determining tracking $sha1 - fetch_in_submodule "$sm_path" $depth || - die "fatal: $(eval_gettext "Unable to fetch in submodule path '\$sm_path'")" - fi - remote_name=$(sanitize_submodule_env; cd "$sm_path" && git submodule--helper print-default-remote) - sha1=$(sanitize_submodule_env; cd "$sm_path" && - git rev-parse --verify "${remote_name}/${branch}") || - die "fatal: $(eval_gettext "Unable to find current \${remote_name}/\${branch} revision in submodule path '\$sm_path'")" - fi - out=$(git submodule--helper run-update-procedure \ ${wt_prefix:+--prefix "$wt_prefix"} \ ${GIT_QUIET:+--quiet} \ @@ -434,6 +405,7 @@ cmd_update() ${update:+--update "$update"} \ ${prefix:+--recursive-prefix "$prefix"} \ ${sha1:+--oid "$sha1"} \ + ${remote:+--remote} \ "--" \ "$sm_path") From patchwork Tue Mar 1 00:08:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12763926 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 3BA27C433F5 for ; Tue, 1 Mar 2022 00:08:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231390AbiCAAJY (ORCPT ); Mon, 28 Feb 2022 19:09:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231616AbiCAAJT (ORCPT ); Mon, 28 Feb 2022 19:09:19 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AB599A9AF for ; Mon, 28 Feb 2022 16:08:39 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id t12-20020a17090a448c00b001b9cbac9c43so421786pjg.2 for ; Mon, 28 Feb 2022 16:08:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=DgUdkc0m+74oW8xklSVkGtmzI1w7EDX7zp1aA4QbA1A=; b=FJHQFfVKDCJgeCZXyV6rTgI9xhVLgilLyFzuNPv3vhly73/CuDU6+UgRwGDusyF7+U KAhdehPcaM5Ae3qSppFMmWO3e45i0KZsNzk9Hi6SSnYusg5k/wXjjlnhqIbRO6AmWZM4 RGMFXBaGnvLzrDjs/mR6sOGEZ5Y6CJKqfCvlcxK4ArK4eIKM1vuFdoWZXQ/rT0eC8UBi eoXmcGrEQC90hNc8lF8rTqDC0BUQBg6Wx+5ev+7q62XG1hG2DFTM/PZk0j3dhGPVKtjq QZOpwqrE9kh53pXBBIIqB7mWRt51FPrpBL4uLALXO/ipYggI5rxmzLDAuOgMqwlKuzAP bUOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=DgUdkc0m+74oW8xklSVkGtmzI1w7EDX7zp1aA4QbA1A=; b=ttLljrrpBl0T3cKV24GR6syZ00pZqkzHiSZox/A9DNQzOwR04KFHOgTrvNAmb7yZyi 6PpObRHay0cUn5S9XoSf9GoApggILSUI13iEv6z9uQdVY1dlAtL2BKfLR1won1haTPFl P7M6JtQuaZfXKUeEV2K4Goo/Ee6WHN87nBt06+FOV24IUX9KVC9tv2VhMY4VFJM2YuMU Fb4lsU3Q2SPyOm75jv3N2wUBAsBBozcYbDgHRaIYYuJSVZdwZzl0BdU277BilH1liQ/Q Dzu0b+mS8CcJCKw2NJM6grlif3NA/JgQmw1xeULFcHFROsA85NjOLqpB2cL02my9QtEt bboA== X-Gm-Message-State: AOAM5328jeJ26kEcWk4Tnf/LzJd0mNhAiLntjRmgpqqLgkEirdBunAo4 Ghvc3qwRAU029zVKtByltmD3F6Sj0+rZGdQaQLAoTL0ciZoUXt+FNvs5ZLhM4V2HAUhI20t3lX6 FmUtGOJkEMqfDV6a093JTmGIQMZFWCJdKGguXVE10GFeTVb/i6jkZT+74xsb2tfY= X-Google-Smtp-Source: ABdhPJzjMHx8tImnmAtxOR3rnO3BBqxvfBKpt5KguT5AaayQVmTBKoEguUhGMoKcrXDOx5CJPemNl9JGDCkaow== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a63:7352:0:b0:375:5942:661 with SMTP id d18-20020a637352000000b0037559420661mr19361152pgn.471.1646093318931; Mon, 28 Feb 2022 16:08:38 -0800 (PST) Date: Mon, 28 Feb 2022 16:08:12 -0800 In-Reply-To: <20220301000816.56177-1-chooglen@google.com> Message-Id: <20220301000816.56177-10-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH 09/13] submodule--helper: refactor get_submodule_displaypath() From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Emily Shaffer , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " , Josh Steadmon , Christian Couder , Shourya Shukla Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Atharva Raykar We create a function called `do_get_submodule_displaypath()` that generates the display path required by several submodule functions, and takes a custom superprefix parameter, instead of reading it from the environment. We then redefine the existing `get_submodule_displaypath()` function as a call to this new function, where the superprefix is obtained from the environment. Mentored-by: Christian Couder Mentored-by: Shourya Shukla Signed-off-by: Atharva Raykar Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- builtin/submodule--helper.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 1d4d9231ac..3598069de5 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -248,11 +248,8 @@ static int resolve_relative_url_test(int argc, const char **argv, const char *pr return 0; } -/* the result should be freed by the caller. */ -static char *get_submodule_displaypath(const char *path, const char *prefix) +static char *do_get_submodule_displaypath(const char *path, const char *prefix, const char *super_prefix) { - const char *super_prefix = get_super_prefix(); - if (prefix && super_prefix) { BUG("cannot have prefix '%s' and superprefix '%s'", prefix, super_prefix); @@ -268,6 +265,13 @@ static char *get_submodule_displaypath(const char *path, const char *prefix) } } +/* the result should be freed by the caller. */ +static char *get_submodule_displaypath(const char *path, const char *prefix) +{ + const char *super_prefix = get_super_prefix(); + return do_get_submodule_displaypath(path, prefix, super_prefix); +} + static char *compute_rev_name(const char *sub_path, const char* object_id) { struct strbuf sb = STRBUF_INIT; From patchwork Tue Mar 1 00:08:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12763928 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 9A0ADC433EF for ; Tue, 1 Mar 2022 00:08:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231650AbiCAAJa (ORCPT ); Mon, 28 Feb 2022 19:09:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231255AbiCAAJW (ORCPT ); Mon, 28 Feb 2022 19:09:22 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECDD59BADD for ; Mon, 28 Feb 2022 16:08:41 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id l6-20020a170903120600b0014f43ba55f3so5317631plh.11 for ; Mon, 28 Feb 2022 16:08:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=q7VO7+zHWCqV3qOjSOPfDL0x1ypvI3q6h4rDySLILpA=; b=pZE9sQsJmbXO5EbMgPrA7qVBIa2eNoXPW9aG/FgHG0Vju9CwbJ2oLCOiquuG1y3kyh tBa59RXcBYzmSJB8sDaLLsmWEyDkBQCh98AAqmm4PxWamWMJngncES84ME4DoEYV2uoL Ggj3IQimVMgnInjeiMNGN8DeZoIYC3Z7XPFaCAq402xyUN4yZrOS3/+aJJ8eeCIvUl54 y9pWaUfvQkyTm7SMGYvPFw+KZndRM3juZEKjYfyUFE0Slnc4ujaCIk6TzcrLal+6nN5s T/o7CMey8o+efS8XE4Leec5NWFB9/FRLPSJKU6ZOgby1s2zvXBGLlgyaEFawDRQ+F+UB BIug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=q7VO7+zHWCqV3qOjSOPfDL0x1ypvI3q6h4rDySLILpA=; b=VEXAIXF99RFvkzDi+kwdD1ZE3b3tbjm39uOCaf5fkrbAgJKvAX1bPKoo/tnn2Ibd+J fak7kNV2W4pc73EEQkGim8tVnQHcsWgqgKQd5UgV49kx03lgEApP14tOdLFnC0cSRaf4 BZj4xRVpzHWm9KeB+OI5+lv5dAYW8uLu6qGd2fMGXln7g7SMQOHDwfROJH+WyZjH3/Tt zwdBC0aGilVj+vjeNPgh6mHhYYsKkQiIRVOmZ5ULEvvUbWClh5JZyuyz4bEFQ6EE1/Ve dUPr9KX+leMf9J57v15xfgbwbxNKxAYGBcXmH8F6izH4Q8nildZSi05XnIQZeOUhqKBG srdw== X-Gm-Message-State: AOAM531ni7FbNYcalcH8QxigPMSrWMfy8FFKVp3ESVjlgwo8KJVBN2sk fSwIAxygDk/Op2FcZQsZ8uuYF2KURK9fOda6VpM44we5v1AUzAYwVcDcvvAsT0da2hcgvvrrQ+A 2we3AoxkNJh+BdiCeyHwIZklil2uY3v2jGeavgVObAJPNGOF78Bj+L3BonqGOH5c= X-Google-Smtp-Source: ABdhPJz729mRQtsPs7UzfLLNLSVK3NW2WUak1No/JlbQmn7UV7voJRQ6xgxv5hVtwK58Ps7G720txCOfE+BppQ== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:90b:4f43:b0:1bc:7e5c:e024 with SMTP id pj3-20020a17090b4f4300b001bc7e5ce024mr324849pjb.0.1646093320955; Mon, 28 Feb 2022 16:08:40 -0800 (PST) Date: Mon, 28 Feb 2022 16:08:13 -0800 In-Reply-To: <20220301000816.56177-1-chooglen@google.com> Message-Id: <20220301000816.56177-11-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH 10/13] submodule--helper: allow setting superprefix for init_submodule() From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Emily Shaffer , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " , Josh Steadmon , Christian Couder , Shourya Shukla Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Atharva Raykar We allow callers of the `init_submodule()` function to optionally override the superprefix from the environment. We need to enable this option because in our conversion of the update command that will follow, the '--init' option will be handled through this API. We will need to change the superprefix at that time to ensure the display paths show correctly in the output messages. Mentored-by: Christian Couder Mentored-by: Shourya Shukla Signed-off-by: Atharva Raykar Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- builtin/submodule--helper.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 3598069de5..c3760f511d 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -593,18 +593,22 @@ static int module_foreach(int argc, const char **argv, const char *prefix) struct init_cb { const char *prefix; + const char *superprefix; unsigned int flags; }; #define INIT_CB_INIT { 0 } static void init_submodule(const char *path, const char *prefix, - unsigned int flags) + const char *superprefix, unsigned int flags) { const struct submodule *sub; struct strbuf sb = STRBUF_INIT; char *upd = NULL, *url = NULL, *displaypath; - displaypath = get_submodule_displaypath(path, prefix); + /* try superprefix from the environment, if it is not passed explicitly */ + if (!superprefix) + superprefix = get_super_prefix(); + displaypath = do_get_submodule_displaypath(path, prefix, superprefix); sub = submodule_from_path(the_repository, null_oid(), path); @@ -678,7 +682,7 @@ static void init_submodule(const char *path, const char *prefix, static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data) { struct init_cb *info = cb_data; - init_submodule(list_item->name, info->prefix, info->flags); + init_submodule(list_item->name, info->prefix, info->superprefix, info->flags); } static int module_init(int argc, const char **argv, const char *prefix) From patchwork Tue Mar 1 00:08:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12763929 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 98866C433EF for ; Tue, 1 Mar 2022 00:08:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231654AbiCAAJd (ORCPT ); Mon, 28 Feb 2022 19:09:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231304AbiCAAJX (ORCPT ); Mon, 28 Feb 2022 19:09:23 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16EB39BBBA for ; Mon, 28 Feb 2022 16:08:44 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id w1-20020a05690204e100b006244315a721so11907582ybs.0 for ; Mon, 28 Feb 2022 16:08:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=ifSK06p32C23BmYfMyrll+/iFLQK/m8pYXO3M2+HaJc=; b=F17CXjQtz4tf1Ev5b8ndPsrORN7M5LVlzw5K7Ot85b4j+OlUMwTXpzNbhbln15xY0U DlfaI3ArSWLcb3l1ghQebuJBOuHOUg4UKL0maYvt1LHpZ82La+M8+TMSWhk6Fch6p8p1 GaDj09AFOAGaehu7/b+bjeLMMO5DvVpEMColNjtrlWCwzTaxCzsxcmpd523idVcSNQSF wrK3P3SEwTZ/N2Rq7RHQY3LVSsWi7JzPtB7Szt0M18qJS6QbybhjTF+PAs3KW7xm4kXg T+AwfA8adX9EBJyC0RcDR1JyjjndsrvuK4JtryKwq3/q1Ie5fW+Jif9JcieByj8gUYuz s/yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ifSK06p32C23BmYfMyrll+/iFLQK/m8pYXO3M2+HaJc=; b=wyNsYmWCDMFc5mOm4279ziUYRGnvIIGi0y8m81J/aebZUlghgdXPbsWj5pkX5bzwwj szNfQJXtiWLGHAdAPrN2kA5aAFA1Tot5kSaPTfXNC7X9qyK8ppheeBlya9SRZcl4gJ78 4j/jdZTFsM9jQ78dqB1qpN9OguY5OdwywhTyDUKsFzw2VO85PV1rNcaUA1ZwJ1ThfgwD VXliF7oliZqC7OEtaWYlmm/2DZdvqhLXb6NQP0MY5tbaQ5wrHcysjHOk3XYrBTvxFKuh MuLk5oWyYWfNT18mDZrlYffkBRF4C/IUUEtoznXbneLov88P5L/NNDAJzC33qf/bAW4a 93fw== X-Gm-Message-State: AOAM5311NwWj3psIKkx0PJvmKwsfe5Sd3QdY/hzfTo80UmGFqGyt/3Z2 1AaFe4lcPkEf5sg5GbYdITg4s/tvyBioAsYiCeG9ZIhl2JtxS0iNQ5aLQlGbfm0S6RnB3PuVcj2 MrGlJ+0LP9uh5yGDrVx0EFwli+hIbsZkj8u1pYBPl8W9ApuD0/VFkCrA8sG3P9R8= X-Google-Smtp-Source: ABdhPJyVY3b9i2aonKLCL4rSzzo7LTfsk+PxK/bMwIOWE8avl/2h6WZj+K826L2zOpkpLjBW24eRtwfsjGmeNg== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a81:764d:0:b0:2d0:9d71:2de2 with SMTP id j13-20020a81764d000000b002d09d712de2mr22838807ywk.493.1646093323251; Mon, 28 Feb 2022 16:08:43 -0800 (PST) Date: Mon, 28 Feb 2022 16:08:14 -0800 In-Reply-To: <20220301000816.56177-1-chooglen@google.com> Message-Id: <20220301000816.56177-12-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH 11/13] submodule--helper update-clone: learn --init From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Emily Shaffer , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " , Josh Steadmon Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Teach "git submodule--helper update-clone" the `--init` flag and remove the corresponding shell code. When the `--init` flag is passed to the subcommand, we do not spawn a new subprocess and call `submodule--helper init` on the submodule paths, because the Git machinery is not able to pick up the configuration changes introduced by that init call. So we instead run the `init_submodule_cb()` callback over each submodule in the same process. [1] https://lore.kernel.org/git/CAP8UFD0NCQ5w_3GtT_xHr35i7h8BuLX4UcHNY6VHPGREmDVObA@mail.gmail.com/ Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 26 ++++++++++++++++++++++++++ git-submodule.sh | 9 +++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index c3760f511d..0fc07d35ae 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1999,6 +1999,7 @@ struct submodule_update_clone { int failed_clones_nr, failed_clones_alloc; int max_jobs; + unsigned int init; }; #define SUBMODULE_UPDATE_CLONE_INIT { \ .list = MODULE_LIST_INIT, \ @@ -2508,6 +2509,8 @@ static int update_clone(int argc, const char **argv, const char *prefix) int ret; struct option module_update_clone_options[] = { + OPT_BOOL(0, "init", &suc.init, + N_("initialize uninitialized submodules before update")), OPT_STRING(0, "prefix", &prefix, N_("path"), N_("path into the working tree")), @@ -2566,6 +2569,29 @@ static int update_clone(int argc, const char **argv, const char *prefix) if (pathspec.nr) suc.warn_if_uninitialized = 1; + if (suc.init) { + struct module_list list = MODULE_LIST_INIT; + struct init_cb info = INIT_CB_INIT; + + if (module_list_compute(argc, argv, suc.prefix, + &pathspec, &list) < 0) + return 1; + + /* + * If there are no path args and submodule.active is set then, + * by default, only initialize 'active' modules. + */ + if (!argc && git_config_get_value_multi("submodule.active")) + module_list_active(&list); + + info.prefix = suc.prefix; + info.superprefix = suc.recursive_prefix; + if (suc.quiet) + info.flags |= OPT_QUIET; + + for_each_listed_submodule(&list, init_submodule_cb, &info); + } + ret = update_submodules(&suc); list_objects_filter_release(&filter_options); return ret; diff --git a/git-submodule.sh b/git-submodule.sh index 23ebd90892..51be7c7f7e 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -361,14 +361,11 @@ cmd_update() usage fi - if test -n "$init" - then - cmd_init "--" "$@" || return - fi - { - git submodule--helper update-clone ${GIT_QUIET:+--quiet} \ + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update-clone \ + ${GIT_QUIET:+--quiet} \ ${progress:+"--progress"} \ + ${init:+--init} \ ${wt_prefix:+--prefix "$wt_prefix"} \ ${prefix:+--recursive-prefix "$prefix"} \ ${update:+--update "$update"} \ From patchwork Tue Mar 1 00:08:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12763931 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 C1A78C433F5 for ; Tue, 1 Mar 2022 00:08:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231717AbiCAAJf (ORCPT ); Mon, 28 Feb 2022 19:09:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231615AbiCAAJ3 (ORCPT ); Mon, 28 Feb 2022 19:09:29 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4DC3D4C98 for ; Mon, 28 Feb 2022 16:08:45 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id y1-20020a17090a644100b001bc901aba0dso7371081pjm.8 for ; Mon, 28 Feb 2022 16:08:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=o5nkxgDZrdwzBZ20XpsGRZ4cU+SIy1n8uBmoDWH1UMs=; b=lpkf6ZO79Kqy3GfF6ni3U10m1v8WbNTMDYIJ7essKIqwkhw+8qKg8ut3XCF5PRah1O voqTUMzfv6CCSiV6eJVEwEoaWVkNGMZ4RkMcq/4ULVfyIaGgEBU8t167pjbIozgEA0IZ Dzm4UWr2huW5dK/cbJpqffxnq3vnokVUAkyBW0JqtQnAcNqh1/kfR2g4NdvRnIG3DpLD FnnXx5qb12LuIIt4W00oTLhRKa1oMAQ0bq3eVAKnpYgfIHR6+iXrHg1Ou7spbFK5kQw8 zGAawH8iKvrIPLt8cX2UZm66EPg45C7EOdY2/sCHBiGSMR9/CARRAaNlgHa3jL80fsI6 tnVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=o5nkxgDZrdwzBZ20XpsGRZ4cU+SIy1n8uBmoDWH1UMs=; b=BTGH2aW5nLXXSUjAknEI4rQARIUJYKPKZZNAPj3Rte7PPSnbMukt55BhPIofl84CIs bSSnIS8fwdPTaVywVBEnd6p1JsxO2sbdo6PAmqoYNYo3+rkBCLMj88yh14p+AjfG0tLs A+0YOURCC/JSTnOJVmAmH7J9Jmo3ajiw7QnwIqpbYOY6Np7d9GmdhoOhGAp0JoqiAHt9 h5v4xnlM6d3BblRErCOwjG4kLiRuSHMo03TAKKFNbpcN7AYYAWP4asjMc13gxHLNwMhP zFWIOeTyoBO8uJaBQgboClC2PTHwsTVfH4NXR4NnVy8Gv3jhBZL2EvBuNN7xT6vJsK0W 7mQg== X-Gm-Message-State: AOAM530SVakZ5SY2SVYtmB+Qv02mBGDNsMKFjYOOfwNMgXbTQpQe4Ova +RNXvRnd3NqioabH2cO9W+WQaHMKB8vpj8KLxkirXoytd/l2qlGDelKQhl3GEQqIyVKW57i99+Z DPT3KSW0a6jX5ToeS8h0wmfsjl7Y0kIVAQ/sXyvp2iQha+Co9CwHz4YJHguDkRCs= X-Google-Smtp-Source: ABdhPJz8QxdNStJHKNd+n/6JKoRMw8XIaN20hbU8nGRJUL3RBd+ntcjZADvcL9aixzZMFuJIk298g6uiJVFt0w== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a63:1a51:0:b0:34d:c269:566 with SMTP id a17-20020a631a51000000b0034dc2690566mr19165417pgm.305.1646093325168; Mon, 28 Feb 2022 16:08:45 -0800 (PST) Date: Mon, 28 Feb 2022 16:08:15 -0800 In-Reply-To: <20220301000816.56177-1-chooglen@google.com> Message-Id: <20220301000816.56177-13-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH 12/13] submodule update: add tests for --filter From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Emily Shaffer , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " , Josh Steadmon Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Test the "--filter" option to make sure we don't break it while refactoring "git submodule update". Signed-off-by: Glen Choo --- t/t7406-submodule-update.sh | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index 7764c1c3cb..86616bf8c7 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -1071,4 +1071,44 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s ) ' +test_expect_success 'submodule update adds superproject gitdir to older repos' ' + (cd super && + git -C submodule config --unset submodule.superprojectGitdir && + git submodule update && + test-tool path-utils relative_path \ + "$(git rev-parse --absolute-git-dir)" \ + "$(git -C submodule rev-parse --absolute-git-dir)" >expect && + git -C submodule config submodule.superprojectGitdir >actual && + test_cmp expect actual + ) +' + +test_expect_success 'submodule update uses config.worktree if applicable' ' + (cd super && + git -C submodule config --unset submodule.superprojectGitDir && + git -C submodule config extensions.worktreeConfig true && + git submodule update && + test-tool path-utils relative_path \ + "$(git rev-parse --absolute-git-dir)" \ + "$(git -C submodule rev-parse --absolute-git-dir)" >expect && + git -C submodule config submodule.superprojectGitdir >actual && + test_cmp expect actual && + + test_file_not_empty "$(git -C submodule rev-parse --absolute-git-dir)/config.worktree" + ) +' + +test_expect_success 'submodule update --filter requires --init' ' + test_must_fail git -C super submodule update --filter blob:none 2>err && + grep "usage:" err +' + +test_expect_success 'submodule update --filter sets partial clone settings' ' + test_when_finished "rm -rf super-filter" && + git clone cloned super-filter && + git -C super-filter submodule update --init --filter blob:none && + test_cmp_config -C super-filter/submodule true remote.origin.promisor && + test_cmp_config -C super-filter/submodule blob:none remote.origin.partialclonefilter +' + test_done From patchwork Tue Mar 1 00:08:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12763932 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 7E25FC433F5 for ; Tue, 1 Mar 2022 00:09:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231547AbiCAAJp (ORCPT ); Mon, 28 Feb 2022 19:09:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231670AbiCAAJe (ORCPT ); Mon, 28 Feb 2022 19:09:34 -0500 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 540201323FD for ; Mon, 28 Feb 2022 16:08:47 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id n188-20020a6340c5000000b003747606cb0dso7437619pga.6 for ; Mon, 28 Feb 2022 16:08:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=6Gg+ZNtyyULxOoigD38bkD0NFi77mUGN0fpEUvYTLCw=; b=aMDbEN8O+fJHSU+EVhecUqTgTJ+6rEVpiqEyZ7IFrO7Qi+Gl4GCKeFY5r0SojKQaOD QRrThswp5oM/Jp0qb8gqFr6tIei1K7oEoYiQQjOE67RrvoPKgQtCuHU2ItqrB3har1EZ 7xYvT0z6xDC+nZZcZfsy+2noTWH49mV5QXsdQ29TjAxY1AH+XL0I44kE4XhS+js4MRkP xtkryJM35JFgVc9jjjkyHevYUpLkNCg13wQByTx/kqwzvutuh74bC0ZMyfgfLXCOxWo6 RJ+yUfXUT51k1SBlcKxrbZQwHCWu/04uNhIusSXwDutO3N0FyCjjTDB2crbXL3DkHOK5 dFXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=6Gg+ZNtyyULxOoigD38bkD0NFi77mUGN0fpEUvYTLCw=; b=Cxc9+fyZLAXGvpcI22RWuwyyEEsnhbY5lB+NHXJDXpYyRN4Q1NutNURGGIH+mFz6Pz sEDXWnHlwBOi6nnmhtRNg/Jb3HRFER570pIJQVni3DIVlUzytNH3aWuxDh6PaosEPxiZ Ibw4vaD6IxGiwLaQc5922bGl4ipp4FldMuKPGbrd30Wm6/U1zSbEkWcxdTNnKu4I+kI9 kioNDSJYcweohTt7qhKZAjoedsVO/wl1daWKryRBII95OvLM/eXYZLkeCYEcOlJMieeg TZZZkwVm2yRYSJHvdcLP3vfWnZQgLstOqsLfDHUR0DGFlWWrFXeIs3qpZXxeOPVWDswW khXg== X-Gm-Message-State: AOAM533EADYgKTKkvGrxiUrjT3/uIRDxcnSDqLVWBt/KXatbAZ4/syYn LCeGFYYvSlrlWj9Y8FXBbAyob2MdX+/BnZzab8Zc/VQKxXLtG+3xNpYJW9dQcTBk6iTY1zCbA/K Xm4W3dtDzbdEpTQ0mRAejHsAw5xH9TjXNnfbO9s1m4MhEIw8TqZ4NRcqzXg8La3M= X-Google-Smtp-Source: ABdhPJyPLlsv0mwkAy4QHViOcbXNdBCLbk7szUgTVtbc3VH+qnsDoQPLdF6ULrIRH+EUnm/IwGVJ42/Ko46gqg== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a63:eb0c:0:b0:373:334d:c32f with SMTP id t12-20020a63eb0c000000b00373334dc32fmr19347498pgh.358.1646093327172; Mon, 28 Feb 2022 16:08:47 -0800 (PST) Date: Mon, 28 Feb 2022 16:08:16 -0800 In-Reply-To: <20220301000816.56177-1-chooglen@google.com> Message-Id: <20220301000816.56177-14-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH 13/13] submodule--helper update-clone: check for --filter and --init From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Emily Shaffer , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " , Josh Steadmon Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org "git submodule update --filter" also requires the "--init" option. Teach update-clone to do this usage check in C and remove the check from git-submodule.sh. In addition, change update-clone's usage string so that it teaches users about "git submodule update" instead of "git submodule--helper update-clone" (the string is copied from git-submodule.sh). This should be more helpful to users since they don't invoke update-clone directly. Signed-off-by: Glen Choo --- Since we expect users to act upon the usage string, I've updated it to reflect "git submodule update" [1] (since that's what users actually invoke), but I feel a bit iffy about not being able to use usage_with_options() (because the options and usage string are for different commands). This might indicate that this is work we should put off until the conversion to C is mostly complete, but on the other hand, the usage string is still more helpful than it used to be because we never presented users with the options anyway. [1] It's not immediately obvious which command we prefer to show - some other commands use "git submodule--helper" and others use "git submodule". builtin/submodule--helper.c | 20 +++++++++++++++++++- git-submodule.sh | 5 ----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 0fc07d35ae..ea88f39fb4 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2544,7 +2544,12 @@ static int update_clone(int argc, const char **argv, const char *prefix) }; const char *const git_submodule_helper_usage[] = { - N_("git submodule--helper update-clone [--prefix=] [...]"), + N_("git submodule [--quiet] update" + "[--init [--filter=]] [--remote]" + "[-N|--no-fetch] [-f|--force]" + "[--checkout|--merge|--rebase]" + "[--[no-]recommend-shallow] [--reference ]" + "[--recursive] [--[no-]single-branch] [--] [...]"), NULL }; suc.prefix = prefix; @@ -2555,6 +2560,19 @@ static int update_clone(int argc, const char **argv, const char *prefix) memset(&filter_options, 0, sizeof(filter_options)); argc = parse_options(argc, argv, prefix, module_update_clone_options, git_submodule_helper_usage, 0); + + if (filter_options.choice && !suc.init) { + /* + * NEEDSWORK: Don't use usage_with_options() because the + * usage string is for "git submodule update", but the + * options are for "git submodule--helper update-clone". + * + * This will no longer be an issue when "update-clone" + * is replaced by "git submodule--helper update". + */ + usage(git_submodule_helper_usage[0]); + } + suc.filter_options = &filter_options; if (update) diff --git a/git-submodule.sh b/git-submodule.sh index 51be7c7f7e..aa8bdfca9d 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -356,11 +356,6 @@ cmd_update() shift done - if test -n "$filter" && test "$init" != "1" - then - usage - fi - { git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update-clone \ ${GIT_QUIET:+--quiet} \