From patchwork Tue Mar 1 04:41:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12764072 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 57915C433F5 for ; Tue, 1 Mar 2022 04:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232270AbiCAEmX (ORCPT ); Mon, 28 Feb 2022 23:42:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232277AbiCAEmT (ORCPT ); Mon, 28 Feb 2022 23:42:19 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 271D56E2BC for ; Mon, 28 Feb 2022 20:41:38 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id k130-20020a628488000000b004f362b45f28so9006444pfd.9 for ; Mon, 28 Feb 2022 20:41:38 -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=HH4/Xbq9xpXIOhLTAVxcuha1fO59qEwSHoRz5dUCZAKynAUmWaO3+5nEK9+z1bKZdq AQDYmnT6sZmiphEq7gc/PjdIsa7V7cW2vLnuDJemDTfmWR4A/Ipw0OVd3/+zmE/iOXto dnogociS0ytgkyx8M4axh2B8JS7b5jsyDXVfLGeGJtMeb9NWWyzL4CI6slEwZcfQkk9W RM1+YUW+0FCKwbl2iKCF1OrdpXdpCTyRL550wsq4Nk3yvBnUHBC7HMkGNh7jv9Zaw6F6 HJh59go+4/TVOTwWNnVL9ktRUOfm91QC7yvViQFdVZdybJV0ABFx3T5DtjL0YGr8a27c dPmg== 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=HhFx3hbgqadYDYaR7yQYZSk5eB9VzMznJGuZ/TFglkZpO91b+5npAP/e9ukSqZS3cg vAI9COft56B9Xg40wV1v7LjCHGllru1NDHXcmXPw+4659QKPfYRDOJRjytaEd2FRIzlb POsrDsGLvi56oJGApKViGVIiv/hKGkixWOGpjS6BdDK4MovvMbp9vJBmwSGQb0SJIkwa 2BrFRM53/RT2Ar/TT0lc9/R6Lnxrfjsbp3DmPw/3dphXskNy+YHh12jtD/bUmZrx1H7/ BLm8tyE5iz5uCdJV1JALF90TWKVyStFJiXIm5+ZqXVsQqx997XZnEQmBrYwIIfFWJDp7 mbFw== X-Gm-Message-State: AOAM533quOOik3Xn1UVOCKsho9N0u3DCp0G/JsXtg5jgvPNtZGnXE+rN WEZQwm+U6NLNgYfuHAaARbLK7jgb5JtvGUQqTWTUKEteSe+AiHabgeAmuo/UVolZgl+v68aRndT MSqBnPitn+Z4OAhtaAWLQI1hR2e6pj+6vQIg9p9NKbXXRBSJQYPKtDnz5gdGzO60= X-Google-Smtp-Source: ABdhPJw2WMvKqVDWmrMcoWXOgMdU0AANd+ZiIaL/Whl87f16mIDAEY3TAyLljXCxGqwQAUp1q+7SgNHAjujdsQ== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:ea02:b0:14f:fd0e:e433 with SMTP id s2-20020a170902ea0200b0014ffd0ee433mr24621306plg.24.1646109697606; Mon, 28 Feb 2022 20:41:37 -0800 (PST) Date: Mon, 28 Feb 2022 20:41:20 -0800 In-Reply-To: <20220301044132.39474-1-chooglen@google.com> Message-Id: <20220301044132.39474-2-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> <20220301044132.39474-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v2 01/13] submodule tests: test for init and update failure output From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= " , Junio C Hamano 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 04:41:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12764073 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 1608CC433F5 for ; Tue, 1 Mar 2022 04:41:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232326AbiCAEm1 (ORCPT ); Mon, 28 Feb 2022 23:42:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232238AbiCAEmU (ORCPT ); Mon, 28 Feb 2022 23:42:20 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FF1F6E352 for ; Mon, 28 Feb 2022 20:41:40 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id 97-20020a17090a09ea00b001bc54996b62so745342pjo.3 for ; Mon, 28 Feb 2022 20:41:40 -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=GxIsdbQgAQyVrq8wij/eYLOLjSjVSiUnDACjpwQoZSFONadyl5vLIdGLgneTnuLAd3 BBgQvcNEvs2CbhohyDdtYIzOWz9D/a68nzVoPFvInIgXcJ2Jv4jlZ4JWfYCjtrLsxzkd GcUfeC5k3UjuYee7zIL7Prg/BbWIMO5iu3vDdZMsCsAz5+es7PSR12XKlf+kzmkAlQNK Z9BpArLwTBceCwng0M7mLKyIcAAwNX2KOr7J388Q1MD6Q7TcXH2MiA0ONCYR84kJ9pxt 57eAGsuDH+FRTEQQ+2KnjqDSXCjUXNc38CWFmiR1oAruItiQzuYazfhTx2kLR60ib8Qr a0Ew== 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=hTXQQ1+3MEtvgtGYvrNYj+fcofj+t4TGGLzEPS9HOUe+K8KWbRvqpVuByuNv8dOpVU cQ2LyWsf8nkm2xf4Q7MkbT7ShsvmWCRmoq+5hioUZ3Walgaa/slYK8XAkegjVKlWpHZ2 qHa3Fe/70rq/kqnrOoIJhTDp7C3fvrEpwYPBNHWllVapu33lshvBJZuzZPSgMEiSsiit flEX3SdmNkonkOzo9Bbg5OSfK92LR/fiDIOkMcKnoDOrRYZgR3pR6dm5k0kB8Qe+BBn2 N96mxEj/lJVXrFo45iGAPrr+gS1XtGIDuHZ27UUl3+36YjPhedcI5cEKPQ77ZOMdS0HF IHww== X-Gm-Message-State: AOAM533vw0KtKGcMzFG91lGt+U8aJDdCagInl/STS466bhuIOFqWNNUk Eh+abzC93IOaeIss5z/2vrHfhZ9vpzFzJNG8vviolOKANYYgWBJk1vY95a2NdreinCLlmdnJ5KH djQQIkzQG2jA6ZXu4oDQriU9CpHrWqrrqgTNaY40En5E/MycZARCqs7B0Kxpxq6c= X-Google-Smtp-Source: ABdhPJw0Hz5Vy0OM2h2OLu5X50MQjkXCvdWhFvJHlzUnpUa/uYdhq5fQ2zeKnn8U24mRKtK9RLQxe1DoG6GZMw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a05:6a00:22cc:b0:4e0:58dc:e489 with SMTP id f12-20020a056a0022cc00b004e058dce489mr25421244pfj.58.1646109699730; Mon, 28 Feb 2022 20:41:39 -0800 (PST) Date: Mon, 28 Feb 2022 20:41:21 -0800 In-Reply-To: <20220301044132.39474-1-chooglen@google.com> Message-Id: <20220301044132.39474-3-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> <20220301044132.39474-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v2 02/13] submodule--helper: remove update-module-mode From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo 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 04:41:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12764075 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 DDF97C433EF for ; Tue, 1 Mar 2022 04:42:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232373AbiCAEmj (ORCPT ); Mon, 28 Feb 2022 23:42:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232313AbiCAEmY (ORCPT ); Mon, 28 Feb 2022 23:42:24 -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 0D84E6E4FF for ; Mon, 28 Feb 2022 20:41:42 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id i7-20020a170902cf0700b0015163eb319eso1973162plg.18 for ; Mon, 28 Feb 2022 20:41:42 -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=UOCTtnj2IFZVX/1u9pZYH6npz+eV+7m7YUtI7CwEKo/WaLYsgQr9O+7An0TqvgVvVT JE7ajFJ3dB/v6zuqMXr5mN/4Dn2Iw+7Fv2mCSg5GKcG+hKlHM2rewPSFg3S/B7tJLGWR JiGDsd1lf3MK1PKEgiXtxA1KnlnBrTU7FBAgOXnS0l+dFwRGQ6GoUOMAt0IuJSN1HHG2 9hj/uOAyfKFeb1M1hgPdmrei92UfJeaXp40onlhkqCH/PfYeTK5MaN2z/buF62gwL2H+ xCeNixuuy3XWU02EdlBrsA2Gdb5fskY+IneWrz4ef0+GN3Ck+mNG2MjR2apee7PKWdlF vL7Q== 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=UuWuWCYKd3qH9C4Gr941Qc3RoiRsSKcZBW/C4xKp3ZqJDk7sincf5JtU7ZL7FWe2XL WkkRu3ZE2Yrgz0OlvqeaWWBdzxUgQLnBaW4SsfjNRA0A11lVCO0W/vu0ndHSkEPIty3q rKU7ScR2hPjSddHzlOsTePPYdVVyF+G9qGF4JwYq9pHTt1jL+Tq5mqueNDd1l8kP1hyL aMm3muHaJ+cEmsRCYy8BK+sMc92SKbkD9lhhxwjluy389M+kIJ1/6vgT8ZgGnac+xcZD epivX2EQVTkxkZqnLwC+Bixn9JsKTCZHJPGMbzUH63K1fmPbJyp7c5WU15jXeBzBAnC0 ZB7Q== X-Gm-Message-State: AOAM532kKzYSCbi6BM1PGuQB6G6dUlK9fsBN/5ufUoo/pcs96BAbtSFu ZqooT3XUXcfjYHyhL9p0adFcZQdJsFmkr+gjMloM/dFdC1ao6YzHkx8KMKMJVnTY87CprHk5/cm KZsrlxvn3mm6JD6S1WzZDZhJITmMHO+xQs4lFIXycM85NgIQd7PoujqtLuU/sjQI= X-Google-Smtp-Source: ABdhPJybO0ebHQBqD9YCxreDIJSFAx3vQIxeIDMXsia6yQ068J+QdB7GyM2nhEh25UsmqAAqKqKhmU8ymMP0Yg== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:90b:4b52:b0:1bc:b208:dc5c with SMTP id mi18-20020a17090b4b5200b001bcb208dc5cmr452932pjb.1.1646109701917; Mon, 28 Feb 2022 20:41:41 -0800 (PST) Date: Mon, 28 Feb 2022 20:41:22 -0800 In-Reply-To: <20220301044132.39474-1-chooglen@google.com> Message-Id: <20220301044132.39474-4-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> <20220301044132.39474-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v2 03/13] submodule--helper: reorganize code for sh to C conversion From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo 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 04:41:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12764074 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 0FE33C433FE for ; Tue, 1 Mar 2022 04:42:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232333AbiCAEml (ORCPT ); Mon, 28 Feb 2022 23:42:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232287AbiCAEmh (ORCPT ); Mon, 28 Feb 2022 23:42:37 -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 CC54E6E36A for ; Mon, 28 Feb 2022 20:41:44 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id lp2-20020a17090b4a8200b001bc449ecbceso733435pjb.8 for ; Mon, 28 Feb 2022 20:41: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=6b3Koiu50iGgu4+CvsJvU3gtyLeMDqKt6mcoMXU061M=; b=QfHhP27et4NC9MlyCN/Rf/Gli1NoSW+oUphaB7pJNH0EOIt5HI0kUXlinE5k7pJwVM RxgVYfNQ7+j+eBQ5OvQtJx7lqh3nf5y47PGi1Sc9Nq9eWrx0AIP5ng7b0oG+hDejd+RB 7tGVCkcIeMGoqLZsgDLYoJGKP6aKxc+r/+TI8javHmo9PnzAQ/DYvLtyaK/w/PdWZXUz jmBi4w0ImGsZ592k2fNKNuCthpA0d+7Don/7mwq7chBWwu2yQewbcVhu/SnjC6PfPujJ 4X0NABmNbRjuRe57g/ACU07fQvmt6IB872zSI0QvBIYJ9Wq0KmnYcm4ILrfe3rDT1DvL jUfw== 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=N6XBOF2bFEq/iGVT+K9cV6dQ6Gn1xoDGKfmMBC33BGfZ8IE1SjL+1KBDNHL/UX6Mob QvjZAtPiS67kstc18+s0zeo7+kZOpeNuCjMGEIyvDjSRJu2MHt9q8i9Fl48cTP+UEm7m KobuzOx2WPE2VA4ZTcXE16KD69H6AG4ovNWEPP6qpctHYGnHpCK0VaqppocUCVVQLorv lhZRY2e5XlHlkhTbXwW10IU+IMia+kBrSRxMRLd+25KtnDFC6ufbtg0AnD0/4oaE67yN b7g96DDMO9UbhRtSohm0V7FVQ6MjBLDrHTf4dxTPoAKv41mCPhtUrsCKzDgZ11e9255R HmHg== X-Gm-Message-State: AOAM530x8nvvX1B3e2expzxbUJ+EnACm82EXXCefmgYNsLG9u7a6cYRd K+LZyXUhs+yVetNqwXHewb7E/NDeSpT/jEQUv4cOMaOVwaABZzVcaThoo91Zu1FN7zSKOja7MqY lBSx48lCc2E0vOEBeONVDJVRhegZvbopJEtlgGgPGzbpRQtnfyRSmkW8A3/A9EEQ= X-Google-Smtp-Source: ABdhPJzRRlN3DB/7qctrj3Vtx9sxZ1Oef4pNpFNR3PJrBdVKkiaezjuQQyaLF3AgIgdY4RtXqQLAyxf3skxt8A== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:a508:b0:14d:bfd8:58be with SMTP id s8-20020a170902a50800b0014dbfd858bemr24391079plq.10.1646109704143; Mon, 28 Feb 2022 20:41:44 -0800 (PST) Date: Mon, 28 Feb 2022 20:41:23 -0800 In-Reply-To: <20220301044132.39474-1-chooglen@google.com> Message-Id: <20220301044132.39474-5-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> <20220301044132.39474-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v2 04/13] submodule--helper run-update-procedure: remove --suboid From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo 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 04:41:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12764076 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 0E36EC433EF for ; Tue, 1 Mar 2022 04:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232358AbiCAEmn (ORCPT ); Mon, 28 Feb 2022 23:42:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232329AbiCAEmh (ORCPT ); Mon, 28 Feb 2022 23:42:37 -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 805416E8FF for ; Mon, 28 Feb 2022 20:41:46 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id w3-20020a17090ac98300b001b8b914e91aso846240pjt.0 for ; Mon, 28 Feb 2022 20:41:46 -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=LAddV+PxuYAc3lfKd72LHn29p7CMviLrsujYfKmd9CmvC50WqsRNeukaPh3cYJQolC WslRq/hNFfFvJ23z+FatYEj7YbqA5Tbk0D/vGdZM026RizJn8HN0p/kFqaVpuS4J6XNZ xq57JCHvyLaBlRTijpzFc923ZtLIPpRc1AXQzq8Lw3Uv2/Sc01i4JeSrsczyC0FE02Mc LL/x+uWNjfaJDJ9L3CXygGWs1sRi8KjGwkDIO0o92lFujgWISXN8GtbOxecouV6E0qHK zrdHQ/A0yuc3WUSRgDB+Jw9QRsTL6loXEnIV1k36vtRjDxWv/MbQzAD9GdWzswhwxWqQ sF6g== 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=cchRltmWjBqoDv4BCymoyuV6zZpo24KqGMExl1+nHdtTPK+PLHylC1SfGGg0+xGVmu 8SxUXso5eDmaVnJ3FEOmv71v8SRqmeMwVrd2f60fAG2nwgTNczWA9U4tUjTexN40/w44 kO1wd8NiUUrWnmZo8rJJOPhXzU1SfPC0zhvmGnvHf6JQqtwc61iNi82Tk4i4FUFmWQhb uOCK6tfMrdn8VEICt+s+/d8+Ctcpt1NUt68j3+mor9gEZYhVO/Osq6aAb1qAQB88m3fE rWfvhWHP+Qi06EmL3/5KjZI4mdzilmnEAXNPY9h/3VYInDTeKg7P8mKjZAIayDAipcDg lPbw== X-Gm-Message-State: AOAM533i4RIdksNSdhA3OWalu1BcyvwG9sJGgBCgEQJLcMH+tLfu/MqD jV0YTPyu0zx+do++ytmN53hfCvL3PBeYZQdjiOYCBV8WJ/sT9F8nie8RJ87v2kNT6/SRtZ2QCqr AHtHQbDDEmxIB5kHpSvUMgWbLfrgRoYsq89QBv1gW9AGu314n24Nw749OwtrLW7A= X-Google-Smtp-Source: ABdhPJzyRI+JTiBhsJPPXT2+bPh/IqBQalk8XEb3w7v/cJ2KSc1qobF+88Zz/DeAVYamlMG07Jb8KVFIZh52EA== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:ce91:b0:150:3f7:5096 with SMTP id f17-20020a170902ce9100b0015003f75096mr23264004plg.128.1646109705905; Mon, 28 Feb 2022 20:41:45 -0800 (PST) Date: Mon, 28 Feb 2022 20:41:24 -0800 In-Reply-To: <20220301044132.39474-1-chooglen@google.com> Message-Id: <20220301044132.39474-6-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> <20220301044132.39474-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v2 05/13] submodule--helper: remove ensure-core-worktree From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo 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 04:41:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12764077 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 A8BF4C433EF for ; Tue, 1 Mar 2022 04:42:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232329AbiCAEmp (ORCPT ); Mon, 28 Feb 2022 23:42:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232345AbiCAEmh (ORCPT ); Mon, 28 Feb 2022 23:42:37 -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 995AC6F4A8 for ; Mon, 28 Feb 2022 20:41:48 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id d5-20020a623605000000b004e01ccd08abso8974996pfa.10 for ; Mon, 28 Feb 2022 20:41:48 -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=7NDs+70OZEEkMdjejrX6csVwUuyqMEn+qNeIcCtIvow=; b=Sm92cdYB3qtm7qL9iOL+cClPg1WzpkDc2isewkMcjJPR2g/Z2g9i6eaZYuSFRF2v+Y MBjiMtQ5Od+QLAT/RsMyt/WfKNZ3xHTtDxX5SW5BgIB69/bcalyNoyKCTAUClJRY3MTu y3HFq3+s2QkCEY75MbQE4XLdNini4O3f1lTue+fOk9GdaUOTBL1uIruTdJJB3xakoKA5 sCV/5wLK+jSv1YHVWq+yR85gAf1ONGoX7Qlutbt9ZSF9YvL3BvHHt4ToK6ZZhyD8TxAA qUHJrddNr70VCH6xBfV2WZPI6oCg3vgJZyN1g+yT2Y1F/aNDGyOCP7xEQo5BNCue+leE voBA== 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=7NDs+70OZEEkMdjejrX6csVwUuyqMEn+qNeIcCtIvow=; b=6Llx9vU3ujketBhkSOU2glTNOEQmAIqpoXN018C/QTd2y4quSCXDZH2YYu9wbpuZmR 1TEM1NsGcy0jnEKsWftyHphlwwqXseDpkLWLxR6Zi8mrT2M77IEX0IIS7P3rR9EqO9IZ fvvUiEqdAlyVz1E8MK6N8EykquoMNcNU8TwwyHlTKgUmIiXhsvdV3ax0XQhUBfYKDlx6 NkWj3eiCW9hp9zFM0T7xrh0TzP7ZnhOouDq8pHdWWEMTtZwGyLUl7ZeI4Z1dfIndQ9M7 Ul+0oXOpmVeb2Pn/w/p+za/6ZWlj1FDopSjGluQ5TZ23OUxAQa8gqit9G9gRXZtjQggf o7Yw== X-Gm-Message-State: AOAM530gn91DZmJWo/k0NSWYKs5CxTQ5hL+g7fERAGjyKBYBbuWPpVpa bXEsugAxChIEMXfPkwjqFM0WQW2gEdR50nfzfTo8CwuSe15mLPZ7YH6vZCV1x1jXAp6C55KAMZ/ aVq5fu7DXhmwEsLPxGo76TPHv6zT+VHWsmIhlW/79fzrEfX9k6T+6t37JLYZ5jjs= X-Google-Smtp-Source: ABdhPJx5UyeBbJbpH1fD0n+5FngOcNipZnAhq0fxt7lE9JH7kc9oAUGYSB98+Qmdbor2iOxegbt9JEnJZ3atng== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:90a:cb94:b0:1bc:2e7e:535f with SMTP id a20-20020a17090acb9400b001bc2e7e535fmr19820967pju.21.1646109708059; Mon, 28 Feb 2022 20:41:48 -0800 (PST) Date: Mon, 28 Feb 2022 20:41:25 -0800 In-Reply-To: <20220301044132.39474-1-chooglen@google.com> Message-Id: <20220301044132.39474-7-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> <20220301044132.39474-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v2 06/13] submodule--helper: get remote names from any repository From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Atharva Raykar , Christian Couder , Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " , Junio C Hamano 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 | 38 ++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 6b473fc0d2..a58df3e007 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -31,11 +31,13 @@ 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); + const char *refname = refs_resolve_ref_unsafe(store, "HEAD", 0, NULL, + NULL); if (!refname) die(_("No such ref: %s"), "HEAD"); @@ -48,7 +50,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 +59,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 +1358,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 +1398,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 04:41:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12764078 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 B1003C433F5 for ; Tue, 1 Mar 2022 04:42:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232328AbiCAEmr (ORCPT ); Mon, 28 Feb 2022 23:42:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232362AbiCAEmi (ORCPT ); Mon, 28 Feb 2022 23:42:38 -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 9E98D70053 for ; Mon, 28 Feb 2022 20:41:50 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id oj16-20020a17090b4d9000b001bc9dddd9easo7703933pjb.7 for ; Mon, 28 Feb 2022 20:41:50 -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=gflS6XqN2dPNnSYpN0VO97t7AhA7GLgTGLUTgI03exQ=; b=JpNcer/OssgycD0+xoOZnotgIWbVV/zeKBXkhCbzag8resMkn3OyoNTBKylVqWZvYN L1uGkPlz8A/oAIu/6zWfQUN3+C6/7BFR+IeSD5yGF2tEBrisRTVRgupanNRv9L+6zloa 0HWUXhWq1XBK8sAvVeL/wCR+yEcoD0tevE7uCG3ALART/9XdHaBjshpa+VYkXcJfMGZk iIQx1OCIrDWbQMq46Z2btMHU0OegTCcuu6MKfIYs+nHnnwqAtbTdenXXjxrQnilFygP+ iKSh/5pHupNJXp5npxSL9L94Lc63tEIv5zYUqqCqNddC5mQ59+svoHCo2dsWVK5+EFRk XIlQ== 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=gflS6XqN2dPNnSYpN0VO97t7AhA7GLgTGLUTgI03exQ=; b=CQsscwKp3S0t2laoic6Sp+YxXnV77WbxYro+hDEPUsK7YukdtS13s3gO1lSD2VA+/L 8VxT/I2g43ilPQB8Cu/s5JyV9OusqrCSqr0MeT2E/tVd2bKRbtlNQMmArobxVKTIgCQs 2bBF/F0i9a+nXBqbMZBSg7xeDKCA2YsbQsjjNKUv1458Pj/e12dRwmmvXbUx+2XprjfP hSd28jSHQMJaUOSOHBbzFm9JEkUd6z2qPG1se44bxFhmW+3adrVys8e7tCyWzznVrN8x G/FHVT2TPBmnyJCmplL19fLCGEWtB5amO+9CzvgqFos35hFG+4l1RrWM4M/3mC7pEajy kUsQ== X-Gm-Message-State: AOAM5333Sm3Y3/Qn6f18CqMZlHqTJh+e9ZtrU92QVnNlVsAZItlpxdt0 ZG3+Fye6+NdLIpUA1dXdzMk50S8aUuGORGcGjsxpoCCLS8scKIaXAJaQq28gnn/PeUypI64X/hb sCozONZa1uppDcRd7T8vQ/xzw0ceXe+I3o+eKMoxAFPj3PyKWNLpT9ZAA8BeeWps= X-Google-Smtp-Source: ABdhPJyfiQ6HGGXIWZIaGzw0JWv3CXQGbPbmd3sCDOHG7a243yNlrJGi91EUc+WOn9CbDgl8o93KXXz1VOIPIw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:90a:ab89:b0:1bc:71a7:f93a with SMTP id n9-20020a17090aab8900b001bc71a7f93amr19983941pjq.111.1646109710100; Mon, 28 Feb 2022 20:41:50 -0800 (PST) Date: Mon, 28 Feb 2022 20:41:26 -0800 In-Reply-To: <20220301044132.39474-1-chooglen@google.com> Message-Id: <20220301044132.39474-8-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> <20220301044132.39474-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v2 07/13] submodule--helper: don't use bitfield indirection for parse_options() From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= " , Junio C Hamano 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 a58df3e007..3a96c35b86 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2023,10 +2023,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 } @@ -2578,16 +2578,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, @@ -2615,10 +2616,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 04:41:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12764079 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 034FFC433F5 for ; Tue, 1 Mar 2022 04:42:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232378AbiCAEms (ORCPT ); Mon, 28 Feb 2022 23:42:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232372AbiCAEmj (ORCPT ); Mon, 28 Feb 2022 23:42:39 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B45D570070 for ; Mon, 28 Feb 2022 20:41:52 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id d5-20020a623605000000b004e01ccd08abso8975084pfa.10 for ; Mon, 28 Feb 2022 20:41:52 -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=pVUeq3Y5jSxZALpUcz7YtbpU/lAeG5FYv4uMaBelxgw=; b=jhJCLEib3RhmEVS+TPbRG+9IXaKZPT4pihOTg4VkKangekrrnvddMezUfEfPxSQhxG 4KHQxB4YOQ101QV7nmX/odHlPGt7ttJZ0ybhJhOqznbpmGDIYcIQvsaDC8EkTn2WBnSI oIyQ94o8dWlhJvFAaltATVTRzxx09cneDCqYkPHXaB8qXxaPSChEir2N/ostrZHuacLn i0KYpnfQx2tRLDaWcp68g+PkyTdda2AKSUSI5MWNmNL/IrOy2DRlaoIp2vtWL9BrHNv2 CVju1TddzFOp9SWhgltBjGk7cv52hamGpPMwAnwPgD5s6NCy7Gh0AZSeJDOIbHe0SpCN a8vQ== 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=pVUeq3Y5jSxZALpUcz7YtbpU/lAeG5FYv4uMaBelxgw=; b=Pb86GoffKyv8Xf20E0WVr0vzYRFEERGszz4VOf8DsNIzakCqDSM8kRivCbeiX6Knj8 tVGFWUzmXKUteF60GuaSV0jjk4PkQbz/1xl/X5DuH9xKKuqP7tjwl7B37Q6F6tAA56A8 OdAmnKwcEnANwOHmEa3WE3DHzpg8jX8/JY4AXzI6uICzcaT1AqJaHVbC+cshzdOVDdPZ Pp9pEqR5oWm9hKICgGdQuX5OIDL/5eHm9bMV1WFj4ZeEi0rbBEFUK20e+pzVIji86byx M9p4kxC8MOQnjicsDc72hIhcg6BBBOPcfI7o3ZHd/duOuL8M+b7gV4ZuBewyEX4/RAjg /ReA== X-Gm-Message-State: AOAM533T8oziDGvaYmkQPif+CynthZu7cUVjSJnBFQPTEitq4UY+JB80 +d8mqWTENa+20f/T03h9QKpPH1rWxn3ZViLi07EPNY39yPMv188J1Uovf/4Eygj1HHe56RtOyMS OqwZmSRxhY/lY4xdX/oGx1RbcGsVKsz6AnkqGQ32bZN+g/6H9vOMyLGEqcwrQMVY= X-Google-Smtp-Source: ABdhPJyxADua15+1DJ67iagCcw65EO5q+26D/0h8UFHPb/d7c/+zXoLM+yRz2c6FcjFMSQnrp9SdAT2Gz4UwSg== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:90a:d816:b0:1bd:3194:70fc with SMTP id a22-20020a17090ad81600b001bd319470fcmr11451766pjv.136.1646109712081; Mon, 28 Feb 2022 20:41:52 -0800 (PST) Date: Mon, 28 Feb 2022 20:41:27 -0800 In-Reply-To: <20220301044132.39474-1-chooglen@google.com> Message-Id: <20220301044132.39474-9-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> <20220301044132.39474-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v2 08/13] submodule--helper run-update-procedure: learn --remote From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo 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|remote-branch]" have no more callers, so remove them. Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 56 +++++++++++++++---------------------- git-submodule.sh | 30 +------------------- 2 files changed, 23 insertions(+), 63 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 3a96c35b86..99341fb343 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -72,21 +72,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]); @@ -2027,6 +2012,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 } @@ -2603,6 +2589,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() }; @@ -2682,23 +2670,6 @@ static const char *remote_submodule_branch(const char *path) return branch; } -static int resolve_remote_submodule_branch(int argc, const char **argv, - const char *prefix) -{ - const char *ret; - struct strbuf sb = STRBUF_INIT; - if (argc != 2) - die("submodule--helper remote-branch takes exactly one arguments, got %d", argc); - - ret = remote_submodule_branch(argv[1]); - if (!ret) - die("submodule %s doesn't exist", argv[1]); - - printf("%s", ret); - strbuf_release(&sb); - return 0; -} - static int push_check(int argc, const char **argv, const char *prefix) { struct remote *remote; @@ -3033,6 +3004,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); @@ -3431,11 +3421,9 @@ 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}, - {"remote-branch", resolve_remote_submodule_branch, 0}, {"push-check", push_check, 0}, {"absorb-git-dirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX}, {"is-active", is_active, 0}, 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 04:41:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12764080 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 A7EABC433F5 for ; Tue, 1 Mar 2022 04:42:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232403AbiCAEmw (ORCPT ); Mon, 28 Feb 2022 23:42:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232376AbiCAEmj (ORCPT ); Mon, 28 Feb 2022 23:42:39 -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 AA1CD70077 for ; Mon, 28 Feb 2022 20:41:54 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id c15-20020a17090a674f00b001bc9019ce17so827434pjm.8 for ; Mon, 28 Feb 2022 20:41:54 -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=R4gn/Lgz/0jYl0rWTMo4SAD9i7exfSROby50q/4fVN8=; b=MOqHLVeMUN69QEpmbrR4cJOMQtf2oj8FM85+Kjf1s5Xoww8w62sUu15mHSVebITqVG UUoO3dpDp5O6dtxfC/zmBEEi69LlQvOeF625SpRe3Jtr6rakSRvyV2UghsoBij2egh+W B+qXgnjtxvQF1y914Ik41Dy5IE/hZn1wT+ybj+GFx/8R2XHjqioSftEo9f3S2zrFf2yc 21g0WJU1M4rV2pw6j4TgBCMeKKYK9PoHEwTs+/LuDvt8CImjAKnb9GLcd2i2ZGtcrtL2 FtP0uLeKRxRbo+NYSwrnwUtiYpiJe4+fupvCps7pnR1imZQmXU7Gh6+w6PDpNocJfJXD 4aig== 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=R4gn/Lgz/0jYl0rWTMo4SAD9i7exfSROby50q/4fVN8=; b=sDJ6i6UBTUphYl5UNaVbUleUE6F6/bHsGS8hSoD4/UQVOtsdzaDxg+k8purOpUwSV/ qtQDBhxFw39b3nTldZAcRMRxPgDduYR+NnBOe60D2Q4fCD0e1Cf2E0WaJ8iwajvg+KBf FQtoVpgqYP/KBPkAWCYDF+zoZkF6NFFrZMPx8XH4eCjUduwAVEyWgSAt1tEx9FYpfFLk ls3cBxPvcVmR7uOjec6rr4UzNEURY3TaVV643piPgkasCdE/dKWxVVKtIO1BqSDmZd1A Xqb8N0Ja6zmnYAv54YtI1/BW/qblpYySXJdIEf8fjl2wbplzgXo08+Xn91n3fsThbndI lU8A== X-Gm-Message-State: AOAM531u1+wXBqZBvJQ9ihuGk2p41vrYzYbE8G6YpRgVLlroL2saSeHV 01CtPdRKRouyrm+Pzpj/Fu9oOMW+9xXJyKEowP5QApIfGNl31RPwaeYB5ldHYxHrs7SArlK4X4o m0LZTN41aKE+SHXl0PYwEqyM/RjMf4WV+vY4te6/5j45tq/o0vyh47wl2n8YMMO4= X-Google-Smtp-Source: ABdhPJx04YxFDP3PA4u7TQV6d/Y1+1xEsXGB1A7e6096H/D3pSgeL7P5KrV7zC1bYO3Mjk0m6SzPAoa775x89A== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a05:6a00:1d13:b0:4e1:7958:b59d with SMTP id a19-20020a056a001d1300b004e17958b59dmr25156571pfx.68.1646109714055; Mon, 28 Feb 2022 20:41:54 -0800 (PST) Date: Mon, 28 Feb 2022 20:41:28 -0800 In-Reply-To: <20220301044132.39474-1-chooglen@google.com> Message-Id: <20220301044132.39474-10-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> <20220301044132.39474-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v2 09/13] submodule--helper: refactor get_submodule_displaypath() From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Atharva Raykar , Christian Couder , Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " , Junio C Hamano 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 99341fb343..11afdeea8a 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -247,11 +247,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); @@ -267,6 +264,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 04:41:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12764081 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 C263CC433FE for ; Tue, 1 Mar 2022 04:42:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232412AbiCAEmz (ORCPT ); Mon, 28 Feb 2022 23:42:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232383AbiCAEmj (ORCPT ); Mon, 28 Feb 2022 23:42:39 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BFFD7085B for ; Mon, 28 Feb 2022 20:41:56 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id m3-20020a17090a3f8300b001bd33af55f2so837191pjc.1 for ; Mon, 28 Feb 2022 20:41:56 -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=GyEA+1lz1JcECQYAa9X3hotxFkOrXrOERDK70avC8tM=; b=fCB9AczGoOi6LsWsdDiHOab+cygQA/ZV64WK7xtCqUrAp+ROyXmQEFWqZL3Plw6tcK 5UmjWtsuWQQ3JLx4PhFX4PHx1j+mbJsCA/n782PzVrxkQ3IyxyVXZ4Pze3ikw89o7OK/ pX60kfxC8MwurlWh5Ljrkfts6lfCsCOHSVysNOSkSSQ4QrMmBFTbeID5H7tJaAF/ZbSP mN9Djly3bSLqfqC83jF8BvFDQQ+MWiWmekNOyxaoyzlXS0XpYimeFnQ92HSgQSl3VbQ2 eab7nvEmFLIXuXcfgvY8pnk4ucTcDhFUH/GubxpoOTJoAwZWuZywV2+0RHXhj15WY4Xr pSUA== 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=GyEA+1lz1JcECQYAa9X3hotxFkOrXrOERDK70avC8tM=; b=znWyHDHVyDdrZZnzaq1c971HjVVASd4oUXBE37GYaf/uMZvLn1XrYh/DWER340li1g 86ltTra1j/yClMLylXVXPrZIod/X4fdTm+c62OgOASa/Iue7dpQDX70GmkaRI1Yd+Tjf j4nWHXV12lT4Bwt4OZKlpAeEFDnwVqoWUOAYeifjeZKUcYEXzg/QNQUJN7EULluiY+Mm 1tQ1fBhBLal7CHDjLkxdsCZCXC6A1TaaQYvnGfyP+6F5n861hZQOaH2cm1aQE5F9bVDc PFGIJMvD6EfaDzkT2Bxm2qjJ3oS0ULyZH/6FhlV5LE5kqjEGnYTZEmcHXrE6bfF6ls+l E5Rw== X-Gm-Message-State: AOAM532RoknVieHNAgLNR+uhpvoOe/j2SD3OicXtXYD2cDQxwAbvgUr8 SzYyqabw04aIzDk9s3siF44GEwPiqAS+55BId4dj7T2AUaKco+l/IzOJm72jt2nr0ve5DRpPeVP tqCdF9qMGmzn+zF67YPAkQqeg+1Yy01oguRKT4W6uFukk37JqNqC5gA5bIz7Xq3g= X-Google-Smtp-Source: ABdhPJxiTvJbi4oqFwnMqmgbB1eER1bs9pCwS0eHER6eG3u2RJ86WDT+ZD3ld+SH/UA9r0HMv9A+BgR5NJeQtw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:f242:b0:14f:e2d3:e251 with SMTP id j2-20020a170902f24200b0014fe2d3e251mr23498630plc.19.1646109716059; Mon, 28 Feb 2022 20:41:56 -0800 (PST) Date: Mon, 28 Feb 2022 20:41:29 -0800 In-Reply-To: <20220301044132.39474-1-chooglen@google.com> Message-Id: <20220301044132.39474-11-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> <20220301044132.39474-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v2 10/13] submodule--helper: allow setting superprefix for init_submodule() From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Atharva Raykar , Christian Couder , Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " , Junio C Hamano 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 11afdeea8a..052b247726 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -592,18 +592,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); @@ -677,7 +681,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 04:41:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12764083 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 91D65C433F5 for ; Tue, 1 Mar 2022 04:42:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232413AbiCAEnC (ORCPT ); Mon, 28 Feb 2022 23:43:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232384AbiCAEmj (ORCPT ); Mon, 28 Feb 2022 23:42:39 -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 EE6876E29E for ; Mon, 28 Feb 2022 20:41:58 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id u10-20020a63df0a000000b0037886b8707bso3039651pgg.23 for ; Mon, 28 Feb 2022 20:41:58 -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=eiA/gy55NgWHxnholqKVR1Lek5s+reuzIp59lub6xig=; b=iDg27KrVOLWWvQw9rLSBlSzR9+VkpgwhLYagAwOCMaKVxBWOBkjNNRDHvB9TYJ1nSP y/m/RzcExexhSLjTXjGyWH5a9PVhKj2ELr6TxBF4dRnpUUoG2Zp6b4RaEUuBZXdP4Fkx S9bZvFjSa+xm/IBbRDHQXYc+X+nnESjcZFiF8Ka/kwtkfmxKPArIQXAnyg9SDpyExS3x RWG+mQy0VCVqBFk8cOAtFlg1trmqwnFlhG7MgmV53ZgOgHb1iw23jpv7pEXKcvXSW2Wu KpcNAdcI3Ny/UFwJkoobVKghzS1u1lzFDM7ZTZpLiMmbYpy+Jgt/HOlA34r8goFXGIci fiqA== 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=eiA/gy55NgWHxnholqKVR1Lek5s+reuzIp59lub6xig=; b=LLG26MaQ2WUeweHz4W0BO+56P+J6p0Yllkx6mMofwm0Cfqm8qH4Nipv4aI0S+uaaq4 1Ee6Pte3THF2cc4r5+K5RaQkrDrnJ/OarkNmONsCGya1WSzT1c0Uo+rPjEyORKqx8gya BBKymJa7F55o4ML8Ag2jx9oFkRN8Pb1mWpIkndWpd7WVUc6wRVTVibhHmaDg8qLVHNBM 793YN/5Yt4nRnAAJaplp4dgqtY3lsBIzH5+uHrUj9miyMStMvV/k7s2o65ixrv+t192M 7MpAVJfDz0M6iXqZE4wYFISUO7Nk3y8L10ooxEmNMdNWPD+UAlRAj71qDLHgGniCuS1z dd+g== X-Gm-Message-State: AOAM531AUtWVJ3Pg+q2NFmt8XLWb6Dm+dtLffUiHCcm6zvKKwCme7h9L CmURjkIG1ddgDg3Qffq0Bgr4JyS8Jj4ZOX3TA3498IxoVqjO1jutPUMunniOABcC8yW2zBGDhL8 xx7uGlSS/cp50DmLIj0OaD9EMzeA7Dn5Ul0W977Soe8+Ru62bALaj433RwU/nRfk= X-Google-Smtp-Source: ABdhPJxd0gmFrtTbG/KdDMBQ6q27Fk7kUG29ZK5ELxyda9XmLSYC+0eWyk4phzx5WzKH0b6eMSodCDgKoMKs7A== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a05:6a00:2405:b0:4e1:5008:adcc with SMTP id z5-20020a056a00240500b004e15008adccmr25515869pfh.35.1646109718098; Mon, 28 Feb 2022 20:41:58 -0800 (PST) Date: Mon, 28 Feb 2022 20:41:30 -0800 In-Reply-To: <20220301044132.39474-1-chooglen@google.com> Message-Id: <20220301044132.39474-12-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> <20220301044132.39474-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v2 11/13] submodule--helper update-clone: learn --init From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo 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 052b247726..2ffc070319 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1998,6 +1998,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, \ @@ -2507,6 +2508,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")), @@ -2565,6 +2568,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 04:41:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12764082 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 8FC16C433F5 for ; Tue, 1 Mar 2022 04:42:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232369AbiCAEm5 (ORCPT ); Mon, 28 Feb 2022 23:42:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232388AbiCAEmk (ORCPT ); Mon, 28 Feb 2022 23:42:40 -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 ABE1C6E373 for ; Mon, 28 Feb 2022 20:42:00 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id e13-20020a17090301cd00b00150145346f9so5479185plh.23 for ; Mon, 28 Feb 2022 20:42:00 -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=mbH986E6sY3FtPk9GutpUyrvu3iKwdHEwD6Ce9zALkA=; b=Zmk7y8PURnmN8W5amTzm4AmNcYcfxDgKPKNNQ5eCVgqask0hwwCTq5e+5oZJn40zt7 d62qmHy8tjEzlJBXmpvY3+4dFgWY4arUsdQn5ZSM4Wiu4I/FiIgmYlewfbmyl5AkRGe6 F1C7Cx2dML9x2enF5GSv1bWBtFN6Uc05Ypqz/fcNH0YmPrtLPs9OvZIvGshFNkyPWyOR 7uqOwCPM0vDt6Oxyc7N1V6RwD+yc+unshc6Xp3vLoDQY7uUFBY3Ntt38aeE0MVWlSP2U cRgkqW5HZ3zsDYFrgxSJNvNZe9y+2Ly14LQ1JkpUms5DCXZcHe+W0bbrANOp67tj2LP5 pIcQ== 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=mbH986E6sY3FtPk9GutpUyrvu3iKwdHEwD6Ce9zALkA=; b=S8okSvu0hmepgXlKtOOFEtJbItRAWoknoZgOW33RmQ8YBRAsNOlN+RV7pa71lNhLXj 6YjOg56Fto29dmlZbhwdMFuO9IhDTvhwUYO/JRxxVvnfRm94TF359Xc/tm6j29r/UA1Y v01zr7D4ToOK760f6S5Eur5aeProaldPTEKbWK1fG+tJ00pOY4UyblOY2tXLV5EoyIEg cFIByz/AF1BZlcc4+3CQXzfw0FX+Uq+c592l+CRMVGyhrSbHcPP0quBse1dQR1JGRfFX SUKIrneXrsMY5R9BnpALtcJBEfbK2mOmb+gG5thb6ekrc8IEJ3hMqqXPj2z4UHtnkfoz 6fYg== X-Gm-Message-State: AOAM531de5ODA2efO73L5BKhVIFAxrhfbEOq/8hpGoahQnC7bMZxLxpU WnagyM5ZzCCYeU7qd6fWAEnGsMQyDeTmKp/G6FNIsNxwh9xar0Bw8nw9GH89BZ4Zpfn5l4V5YNU xjGyYeufAUmq4uvBYWuQfJZGJpS8LTVfkEwSokf1OHiwc4M9DKNjediMEDlMb6JM= X-Google-Smtp-Source: ABdhPJyGqKEnLJL6L5Rclf731SollOqQuptxnHfPG3p+NxQiTN03JM1UA3MG7RN4Xsq3iUo1DpjjoE48g8DOEA== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:e541:b0:151:8722:5a87 with SMTP id n1-20020a170902e54100b0015187225a87mr86490plf.71.1646109720084; Mon, 28 Feb 2022 20:42:00 -0800 (PST) Date: Mon, 28 Feb 2022 20:41:31 -0800 In-Reply-To: <20220301044132.39474-1-chooglen@google.com> Message-Id: <20220301044132.39474-13-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> <20220301044132.39474-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v2 12/13] submodule update: add tests for --filter From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Test the "--filter" option to make sure we don't break anything while refactoring "git submodule update". Signed-off-by: Glen Choo --- t/t7406-submodule-update.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index 7764c1c3cb..6cc60ff5e5 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -1071,4 +1071,17 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s ) ' +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 04:41:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12764084 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 4C4ABC433F5 for ; Tue, 1 Mar 2022 04:42:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232440AbiCAEnF (ORCPT ); Mon, 28 Feb 2022 23:43:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232389AbiCAEmo (ORCPT ); Mon, 28 Feb 2022 23:42:44 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D812E6FA33 for ; Mon, 28 Feb 2022 20:42:02 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id c192-20020a621cc9000000b004e0ff94313dso9004073pfc.17 for ; Mon, 28 Feb 2022 20:42:02 -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=SxQM2cxFgTJkz187BLMpOB9JRuL0P/ov+6eGJwePauo=; b=WeSk1R6cCb/u2AkNnG01CWEjzrxUFy2f6Z5M6qh7AjgRwioG6WVgMZjpPniM6beBEZ paBjplT678baxmjKVomo4Papc7Ks0cHnk/p3DB0XMC5dsO77okYg5PtvUHdezp2osdxw 6n1C8P/hrMecbUd+OyWsJdsGAdg2fAP0o7fG39NA0s7DptSOx4/W1TvfyWhYV1GTzXeL FxbGRzbx8t8Tb8QgcSZdeNgV80IPPBZo8xo32MFpqwSYLi9W1xId4PITK46kfBSI+Gau mCCo9eHcO4oafOjnhMiyE55h3mQJLqOJyTr2dHXFxmDzGwAmWSmCldD0L33vzO1b211N pT8g== 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=SxQM2cxFgTJkz187BLMpOB9JRuL0P/ov+6eGJwePauo=; b=6IkSQ2Y5/KYc+n9z863koDkGv8cVSiLV2xr1KtTagrzvLWX3vOixrdKGNAYue8pJR0 01iGdHPED7Xt7hbuzz+b8OK2ffVRLd7z0eCjaiswUv3GlaQdxxfMTldNO3ausGCYUDdS vsavlf572XFMLuZ4Uvm3hH2fAz4KbFis1hf9OqMcwlKmLbElzr/GuepN2E2GUH7oNMsZ L/sZh5ZkmcZZUG70TnSUXENaRoz2w7DV+OYZ03NgSjom0xoV3n9YXMkQO+azCrjVNBtY /moB+VsmSy7YTJ++8wxllVXke5TIJl+IMQNsS+9CEfAWbMm5BO8pQUQQxTNC3gngzl2D xdJw== X-Gm-Message-State: AOAM531FxMRj47RDFk95hpxbB2lZum2SNB/AOyFIX6+1O5XzgP3T2H7F UZv7zLyfJCfu2dgkur8XtFOkW2eRP5fq1GEktfJX41eqbTXasNC+EaF4w8xjd0pcy5OcoQWDNZy E/GO8NkmSz9Rt5PfDFLfwfdkkbn/KBKe7NEq0BoLWkyRp+hJHhXdIQFzDRYHAT94= X-Google-Smtp-Source: ABdhPJxxGtM2YqUgLAHP7XOJ3TF1YfnXCB8DWSXV7xkZ5wfGkblGY9VqEbJ0jT2OuJY7tL1VNaKlVTerU0xRgA== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:8f94:b0:151:64c5:7759 with SMTP id z20-20020a1709028f9400b0015164c57759mr9057509plo.4.1646109722245; Mon, 28 Feb 2022 20:42:02 -0800 (PST) Date: Mon, 28 Feb 2022 20:41:32 -0800 In-Reply-To: <20220301044132.39474-1-chooglen@google.com> Message-Id: <20220301044132.39474-14-chooglen@google.com> Mime-Version: 1.0 References: <20220301000816.56177-1-chooglen@google.com> <20220301044132.39474-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v2 13/13] submodule--helper update-clone: check for --filter and --init From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo 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 2ffc070319..3e8a05a052 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2543,7 +2543,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; @@ -2554,6 +2559,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} \