From patchwork Thu Mar 3 00:57:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12766928 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 CDE76C433EF for ; Thu, 3 Mar 2022 00:57:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231203AbiCCA6d (ORCPT ); Wed, 2 Mar 2022 19:58:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231178AbiCCA62 (ORCPT ); Wed, 2 Mar 2022 19:58:28 -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 EB1DA151680 for ; Wed, 2 Mar 2022 16:57:43 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id h3-20020a628303000000b004e12f44a262so2159282pfe.21 for ; Wed, 02 Mar 2022 16:57:43 -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=O9xWLOTn9CTsP++a9NgPZoaXBmiyv4hGW8tdhOOAP0nPLYMjaweKWOu/ZSZID8jKnf Kb5LE0qYt0j1ynlijorlrmtIhA8yK71hBRGyDxhFlSAy3f4gv2+tima0CWIuLHtQMRDD /y46Yy8NFsweZ9H8a05dcRtLHOWyi9eW5DSbCi6ZHMtlaa9Lq5liYYW+sA2vjydEOlde nmITY0YG2vfXd0ZB29LBkPmdysJXeeHYXBcpyRAIIwpsdtbHipDG+wwmbJNHdbGrJNga se52Lf1N+U5onunA58vEPUa0ZE0E7qc3g/ajmM66VMpo7EF9zfjOZE8881/06EUTHSIW bp4w== 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=YtFN1sbKoVykrCkGEGFaWMLyeLKSSV/G6W9isxvSssL99BiBmIaXYG+rrGVCXb0AUy XuhL1JwlA/OtEcPUN58n5KncEZlZL6hRsEukNu0D/g1Zr25yr8hdLTIZrQFtqWbUdOrV 1bUE4PCfphsoSPucnBhNl8GHJn2BnxjUhoem0opRu4au4ZUSvYs1E/e32UQKw3vnxwG5 G266jyRU3Srsve+wr2bEdzhaWRbnJgfH0SXK04ZO0W45Viz7L16nvDIih2h+pLMHPNV2 GwP7jVqcofPFejzGYyCA7JVA0MnBe4M9ayEESb0HjMq2mcyd/ofeOhEW+pulc4JXfbS9 Kj5w== X-Gm-Message-State: AOAM5310YbEhsRtarz00JKlf927YBd1b9MZq0Tz4mVO5TwbxxSyBeOVW RsNvlFx3UdUjbewv68jg6lyuHExuPgHtYCXoiz7Hz1aacwVQ/R+WAIrqZn0emvmfEM9VMB/vmPx yoVW8ZItrZF7ry9Ah7vCIefsnFh0l0j07uaitLfIzTsCu2mxG3ELH4R3TgbAItFo= X-Google-Smtp-Source: ABdhPJyE1K3El9B7KgpUjvublZP9hFovL4G/LvFFsd29SXCjly0al0urI2NSth7WGFUZnyz5J4IOi2jbSUUL7g== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:bf04:b0:149:c5a5:5323 with SMTP id bi4-20020a170902bf0400b00149c5a55323mr33384162plb.97.1646269063228; Wed, 02 Mar 2022 16:57:43 -0800 (PST) Date: Wed, 2 Mar 2022 16:57:15 -0800 In-Reply-To: <20220303005727.69270-1-chooglen@google.com> Message-Id: <20220303005727.69270-2-chooglen@google.com> Mime-Version: 1.0 References: <20220301044132.39474-1-chooglen@google.com> <20220303005727.69270-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v3 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 Thu Mar 3 00:57: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: 12766930 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 6CF09C433EF for ; Thu, 3 Mar 2022 00:57:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231219AbiCCA6f (ORCPT ); Wed, 2 Mar 2022 19:58:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231193AbiCCA6b (ORCPT ); Wed, 2 Mar 2022 19:58:31 -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 EE4D6151C46 for ; Wed, 2 Mar 2022 16:57:45 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id d4-20020a170902f14400b001518350e5c7so1885780plb.13 for ; Wed, 02 Mar 2022 16:57: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=UH8t/E0TczNz4tziesvMRSUOID+d/VyUA9f/OELjrWw=; b=hakUbMM+cMadRYNdZVhsifWNCoEoD4X/Vqc4hiS5PhGSfCGIAfKlkbuEClO2fumHJ1 7WlT2AC4DyYj4F6O6be1xZThsqM3hEBdqjsuxoYWn8mocUWfDXV0HcNNqiOTlj3/XyY6 ZN2bUrGz0UV49nIGrAmVuGD2ukz3qYa/WfJdOryZqUYAZ8dZOAyG27ETjdYcET0nt6+Z v+oQ31sTDiqdLYi9XwG5A8o+0cLczyiY79kpef9RiyFGUrELcGJvzhDfT3BRlgOdZYLQ /qwToMFaZOMya8EcO9bU6/z5oV4HetAURUQlyQAJSk1hMFSzvv9JxGiPFP9EYk5K0ixO qPmQ== 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=hNZ2O6l/sZjgsjKaZzB8c7xCJDCPijrBRnEMpsnbE3V3jzc1qwKrOMwvEzmB5tnXpj 9yuwaWnlVwmNzI4MiR395TKjXPFxaD1aQqZjWSjkeQ90AcAmOEq74peklDALehMTyBlK 4DL9HJhSVt0zoIcM8eJyg28QCxvplrpYnT0bxVUyqpBgrtmP0e8md1MgYDM2vdyzrQoS S3Ez9nqYrzWQX+ieFtvF/3s8fW1QAcshMzNTVbrlYHY0H05Aj4kKcUi5DQXTplIxneIW zzzNHUWHtyUMXO1GfrCJklCsEULXnQ37zQ4hBm0LBl9ppxdAcmQtdU6SuFu9i9wG6ZAB juAw== X-Gm-Message-State: AOAM531psdU2p8/etJ3ZPTJhhT5+NugpspkMInOPtWvuz008tGGWgGSd /zbQ4SDfkB8a/5tgTa0wGprjp+6LreS45SGmLl4qvJpxt4QJZ2nGKCCqqx2oEX+dMW2//A4gJOH O1qWw2RIT7L3NtXiz5FLjQT/K0dOtMpfB5DZtZh4Rd2/PMd9ua7f5P0PL5g4kiis= X-Google-Smtp-Source: ABdhPJxmNbrv5dciVl870l/zhtX5JFAKikINf8qog3gQwizcnwuAYr+5WVIcA5Ri4HRYVkzBu84wecws/ozGZw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a63:1203:0:b0:374:4ee8:8f20 with SMTP id h3-20020a631203000000b003744ee88f20mr27661641pgl.294.1646269065192; Wed, 02 Mar 2022 16:57:45 -0800 (PST) Date: Wed, 2 Mar 2022 16:57:16 -0800 In-Reply-To: <20220303005727.69270-1-chooglen@google.com> Message-Id: <20220303005727.69270-3-chooglen@google.com> Mime-Version: 1.0 References: <20220301044132.39474-1-chooglen@google.com> <20220303005727.69270-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v3 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 Thu Mar 3 00:57:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12766929 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 0E83BC433F5 for ; Thu, 3 Mar 2022 00:57:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231215AbiCCA6e (ORCPT ); Wed, 2 Mar 2022 19:58:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231195AbiCCA6b (ORCPT ); Wed, 2 Mar 2022 19:58:31 -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 AF6B8151C78 for ; Wed, 2 Mar 2022 16:57:47 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id f4-20020a17090ac28400b001bc40aa09fbso4334911pjt.6 for ; Wed, 02 Mar 2022 16:57: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=ZJ9JuO2ZLBsSPC5VW54LiMsNmiMznGVzF+HcPh0t8SY=; b=lpWeoscgF/HbR+PJcJOd/gRmJGY2SqoyQP4UFUV7M1B903kZydEOw310UK/eSdOsr+ fVSQW8ymVFFwDupoeL91mWDAG+o1JLsdO/q3FpDSAXClm2ouZCOrS/DLtKV0kZ24/wIa 8KHxFMgUfY+GWaJNncR2Z6qmfCqlz0f/pIQWBhigpnrCTYAmKhA33Dse7BqNx+wHAQ4y Sq6/4JsZAxaxyFAHRxBQllpGeBU7mWYaBb6qtphvYYBnjrXnrf/Iri/u4SWRzH6zbR0Z 3JjnqEAib0Ooih3+Tk1AtoF6np+lh7hADRbu+tT72+DCPcr0+zxigvVoWZOgQeWyXi7Z iaWg== 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=iWzHGROC5CxbObJoeD+Q9uGYYIlut1Eh0Z/BmyTUkXyF/ZIWFQfJzbY0rjNcQ2aBgV IIpW7n+CY5tP0RtNBjG6rXM0QBEq9BOyuzf2jK6oqTQtoDjAtl+yzFXn9EPxuQ4KI6Fv PQtlvdo45tdTMCmMOojqpBIMfb4ihjLteggLjN390ERZG85aCO7wEFx7IfCkLQGcY9nc R4lrItG8WAmj83e8GbzfAMYG7DonOP/+T+jph5LUJQV+/Ay7zyrLwzSzWCe1lx33Vw93 qlI17HHZGv/DHNrevnoUpw9qR4PXh7TjqMIZISzfLz4nYM+Jse7s1lb1WHiZ+fH3yFIK d7AQ== X-Gm-Message-State: AOAM533VAmNJp8FhZNL8/6Wgqs3t1k7hApB5LEEdNjMMGs11Oa4La/hp leajLU5CfMJj5pOhN0TUOhbXO9/98PDKVXfm7YPVqaOOMHeYVyKN9hLq9rzCVERa2F4JiYyiNyg Jw/RSqZa1Bj6UoiNYs896t+ov7x4S9W0Avj9apwS/GTdLKCOkWCUKE40NIseyEDk= X-Google-Smtp-Source: ABdhPJzAdBQI8qPtjQ1/MaIDrcJ5HFFC779mAT9yGvG5CxvLySffW4i2Bwo2rCNwAo1BuDgdfXa2rWsuNylXVA== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:903:22c4:b0:151:99cf:66f2 with SMTP id y4-20020a17090322c400b0015199cf66f2mr4846972plg.47.1646269067092; Wed, 02 Mar 2022 16:57:47 -0800 (PST) Date: Wed, 2 Mar 2022 16:57:17 -0800 In-Reply-To: <20220303005727.69270-1-chooglen@google.com> Message-Id: <20220303005727.69270-4-chooglen@google.com> Mime-Version: 1.0 References: <20220301044132.39474-1-chooglen@google.com> <20220303005727.69270-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v3 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 Thu Mar 3 00:57:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12766931 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 1AEE7C433EF for ; Thu, 3 Mar 2022 00:57:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231221AbiCCA6l (ORCPT ); Wed, 2 Mar 2022 19:58:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231195AbiCCA6e (ORCPT ); Wed, 2 Mar 2022 19:58: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 B83A5151D09 for ; Wed, 2 Mar 2022 16:57:49 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id a12-20020a65640c000000b003756296df5cso1878438pgv.19 for ; Wed, 02 Mar 2022 16:57:49 -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=K16rjuSKGjZqYQxWjBvr0jkvjRbdpWZkMIHyx/5YB6qi1MCQF5QZF+byxQYkcksB7S oq/j2k3kJ31UNzSRWISzZYU+6g45b5FxO11d9S46n2IHbaXXEE0ik4Agi258dCzrxVdR YJjtnSWiXF/3DNlf3agozqECS1NCmFYI/stDeNgC+LaOH/krc3u3eLFoxetvmEsSmBru kYVstGzCctQNHlh3iarN2BhMtVhRaNzfC3Dx6NeEW+5m6S/ofyJfYd/0+SL5fLF4b9xw Ka1Gv3ECnYqTV31ZYShS7nSsucdWK+GoIzPpHnhBq5Z1PzRbSQOX7Kr2yBu239YydFkI Zzww== 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=T6ArXdlW7wwXumJIzcctYcq9iPRtsWLNyhROr3ZH2c7Xmo6T07zjpvU790cm7Sc8RN UeVxlKN2cc6OCm340Dl7Zz4Z9LJtAmVLR+MTSs+KLDPvcjGZv4s5LYZMDZGBduR64MGl hC46CM+KmFx0Z+9Ag5OvvylJ2QePfZWhMqnE0x3jYa8/fQHgFjpQe8E9CIEdi15D1uxm UH/UVoX7uDL9Q1/wtp8A3WsmfYr4JO65s+7RJJS1x+Xv/i281hSs0A6+PTQQfAuxbk/o HpiLhUov5nYPPuIUPUJCO/y3r9TsXmSwf0xm7Chn5gPapA9BfAqKd0I9HQ1L2cneSzJe F3rw== X-Gm-Message-State: AOAM531xBXqWKlMOMyxrP0lJwNbUcn09iPmDLnHN/41/WZ31ccnNvkIH cKFvMuNY9ys5TU9YSKwE4ZOIH6Tdbf38NOI1T4cTeq/74EM/AZmQLuIJkZ9VdY8UZwByXWDkLzY yjdetkYYHy96nSbuW+z+D5gMMAT+1WGd+KhNd8HBYOXDIegPCr3wmS4icia+OVy0= X-Google-Smtp-Source: ABdhPJwk0mcI+CjSeR6iB6Qjz8C8nFVe/UZAci2eh++aaYxeTI8Br/RbOt/CHsq+LyN7Y5ZxKQaGwgSeJD/0Ww== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:90b:f87:b0:1bc:b82b:69fc with SMTP id ft7-20020a17090b0f8700b001bcb82b69fcmr2581556pjb.236.1646269069143; Wed, 02 Mar 2022 16:57:49 -0800 (PST) Date: Wed, 2 Mar 2022 16:57:18 -0800 In-Reply-To: <20220303005727.69270-1-chooglen@google.com> Message-Id: <20220303005727.69270-5-chooglen@google.com> Mime-Version: 1.0 References: <20220301044132.39474-1-chooglen@google.com> <20220303005727.69270-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v3 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 Thu Mar 3 00:57:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12766932 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 A8B6DC433F5 for ; Thu, 3 Mar 2022 00:58:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231226AbiCCA6l (ORCPT ); Wed, 2 Mar 2022 19:58:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231220AbiCCA6i (ORCPT ); Wed, 2 Mar 2022 19:58:38 -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 3E044151D19 for ; Wed, 2 Mar 2022 16:57:52 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id t68-20020a635f47000000b003732348b971so1897004pgb.7 for ; Wed, 02 Mar 2022 16:57: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=HM/UFTvzycLuEtiSNLNKftDfScVvaGAHyX0/2+0MI0U=; b=ZAS4j6oJU6GQyERqDf9j+ivsdQexnQVTa+D4K2z6t9YjibCTy7I0uMILZGISYZsL6A aQ8S/xDuOgarr2OUApGcqFz6G4OWTUmDVOAProwenOEw8PJnLBzIn7+uoZPLSac2qozN CYFnL/SlXLUDikPWEjK8qDQUZZcMsIfnozOMyKB6V/a/CTx5UBCiyXfyTjf8j1ByPKB7 JFAnoHfAPBd3vtcJSW5XTXQbCg55ebqtYo7NTGLAKQc/fMHC5+Thvgu4BIfEg2vtiRwK eXb5QJXzGRCHnCAxY+RWzqbRR9O+tGTOvWYfH24xp+xmV8gRFM7vU0AdB8hNtWv2khve SY9Q== 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=J3auJKDvv7thJGVMiSoNqItSfb/CxE2MpVwL/LbBtYzp3tDV1j04ksnUwlcrO+RDkz FA+KueRN1aLbpzMyw8DC+5IyPJ3HHpNsSYRdpbnLs0/fi3JtKi7oD1ff1mHVMm3pf7SH 7DbBLKpV25UmV2DqIQiMmIGohRBQm7KB1zSqvdGI+luoyxIMABWEPtXbKlCbLlIjPUKw Th0AqkR+pDQTwYsMIlwtgItH8P5IIalsnaLqbWxIEHPdGCdq/i8EsEf2qeuTZuLhiEwz IKyadX34jY8N80yKYrOCziCp+mp5Msge1naSr2CUALGjOkXK+ipOKKnNzsafPHu0EEZI NSMg== X-Gm-Message-State: AOAM533VGshsOKKxDTsRBsyjtKZ/M4kLAgI4+/JDhbtwQ3omwB+kSSLM 1SoM/pmmTHxRb+3JaHy2mIWn7se1pJdyEhqUTlCBjzxi+7JMC41oAo4CzII+4tPovnGk1CZd/m0 4WcjODmnZrh9RPQMdb3pnjBh+CchojpAJ2yrmV0RNBHMzfYpIRxYhQ79b3rqLQjk= X-Google-Smtp-Source: ABdhPJxpZ1QskT39WaGrY3+7L5bSmLKM4JdvocbJrruXVJsmhG9a4Ta+rukDiy4RzVR3OkfIZ6d7ExUZAjJ0YA== 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-20020a17090b4f4300b001bc7e5ce024mr830864pjb.0.1646269071318; Wed, 02 Mar 2022 16:57:51 -0800 (PST) Date: Wed, 2 Mar 2022 16:57:19 -0800 In-Reply-To: <20220303005727.69270-1-chooglen@google.com> Message-Id: <20220303005727.69270-6-chooglen@google.com> Mime-Version: 1.0 References: <20220301044132.39474-1-chooglen@google.com> <20220303005727.69270-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v3 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 Thu Mar 3 00:57: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: 12766933 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 71BB9C433EF for ; Thu, 3 Mar 2022 00:58:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231234AbiCCA6o (ORCPT ); Wed, 2 Mar 2022 19:58:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231195AbiCCA6l (ORCPT ); Wed, 2 Mar 2022 19:58:41 -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 EF25B1520E2 for ; Wed, 2 Mar 2022 16:57:53 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id o41-20020a17090a0a2c00b001bf06e5badfso794834pjo.3 for ; Wed, 02 Mar 2022 16:57:53 -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=w0wuH61vxN7cIGWnPgt2xDcm4NacL81PL7lHRDWTnoI=; b=Rj1JWp/BkcRWZfG5IRIsJZstejV1LG4yc3y34sQ39GNCmyZ23D1dXBCOKLjrGxdtOw Lm/j7QhDyg2vhRN/z30Vbo45cdofFDIyESMrOQXL46Vi/faxQcb2GLWq6yDa/5wE7KLd oniulLMP1Xc8DJnmYQaDnqfom3bee3MQWxj9TV8VUwVxNOxjFRtxCWiwHXl8m90TvpWT VIGpPA6LxCtm/oHVt7T3Md8JQYzZhOzJHZ5rM0e882RCVAXn6YMkl9xJla8J7FOzmjli EP+epyIhTKh9OG+qvKD+D++Ii0zcJ09V5bsKcL4imaMCX+xLAE6vcZti2e/rN0mCvrCD DV5A== 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=w0wuH61vxN7cIGWnPgt2xDcm4NacL81PL7lHRDWTnoI=; b=gALIQRyyCibM0axFgFydVKb8ZRyCP4206ICZvFCvNS0eiufU4ihRIo90jAOApu1dw5 XItyxzriYQeJuNLz9kcnG2NFRTFNfCdodTxsqX+oIT7k2SqAB68a+30+WsByWJHGdwJl s1CvGBF8SwPkyDJhCf4pgzMK0Xq9Wq/EvZX51CnECSuAyUigGmlFNGUIaYN82mCfuyOT nKuv02izVmaY3VIJlNNR85SqF5WhAJbS7cuDqebG9MZF0lV03mYayy/rLv2lsRnjNbKc UmiE8v/tU1p5GEAJudjp+0w5HO6bTwx9rHvwt63bxKfZOMAanftS79r0v3zIjYU4/pz6 9gmA== X-Gm-Message-State: AOAM532xOnY+8dcFnIVJSucMLWG6a3/z5E69kbXIocHnDpPJZ99+uYCc Nz3GRx4hVlHJcrzhU90Te8GNEjnYNG5/Efjq5NNmGZYH75nTvELgub3ZJ6v509sm5Qg1FPwNFA7 KBLlbEmcPoenL7YqH85qqkw5tKy1nnxnm8MP0MKPtvyd3XaOX37acozxOF0gsv24= X-Google-Smtp-Source: ABdhPJyj28vISOVM99/CNwCXeLNiT+bC2F7hQ6xYgSBtas0ow6WlKQ8HBDNYUom46hUrxeQ48x07sjafiGA+bw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:90a:a887:b0:1bc:388a:329f with SMTP id h7-20020a17090aa88700b001bc388a329fmr2602786pjq.17.1646269073377; Wed, 02 Mar 2022 16:57:53 -0800 (PST) Date: Wed, 2 Mar 2022 16:57:20 -0800 In-Reply-To: <20220303005727.69270-1-chooglen@google.com> Message-Id: <20220303005727.69270-7-chooglen@google.com> Mime-Version: 1.0 References: <20220301044132.39474-1-chooglen@google.com> <20220303005727.69270-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v3 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 a subsequent 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 Thu Mar 3 00:57:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12766934 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 BE130C433EF for ; Thu, 3 Mar 2022 00:58:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231243AbiCCA6u (ORCPT ); Wed, 2 Mar 2022 19:58:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231228AbiCCA6l (ORCPT ); Wed, 2 Mar 2022 19:58:41 -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 4E0D01520DA for ; Wed, 2 Mar 2022 16:57:56 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id p21-20020a631e55000000b00372d919267cso1909323pgm.1 for ; Wed, 02 Mar 2022 16:57: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=gflS6XqN2dPNnSYpN0VO97t7AhA7GLgTGLUTgI03exQ=; b=cFbfzwX6vstgE4GbbhiKe3An6rpCInnSwJtabL2rVITfw21jrsUu6RLdIBPelM1OQZ oYOMqqkZ4oofsNxqc0RsG3fCF3Qyptk1rWZdzeqts12gZ27z/j+bwts+wfYqYF/crMFb CBMuS9lDoAqvRcC8C6NkdMPxBHnyIVlIm21E3zt+Fbo9EhcSa2Mu1JC7VehCRTSBlyNe PxmeK2r9OiaKcjmD+3Z13foHqdr4NedvRMjzTxefJ/fZFH3nVLpCJBpcEk0Vz5cdZSQP R9arnF4D0YL78f8Hz0SBpXSt7CL1Ov+t2gePWjWfj8ziI4PiUKb+6kKYtoJpACcLMpcv PRrg== 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=XrlIVWu7RejSmH2xLUB/yXseLMwia5CLzOjlLrYLC9fdByL4Las+A5xPUYp5ZKvPgT WdQV+GN1KzmrU6Hd4K+NVm/aSBQnAqFxBdwmvFwsPQKqktVIzXAgj6TaYz+9qDDYFZ7Z x/sA2D39/BsS+Tb9Gv3sHzlMWxiO1EWpL8uvGOUd110WSUMPwIAaJe3795h7AV+b6Wd0 +7zxJ54M2NxxetVq4GwXB2627+tl5+5Hk4jnd/cPGFPDxbmdxWdaJ557JuGz5xrkJv/F 93ctdmUXifbUagq+CHi0OQl9HerbAfVXep/SZwfvngVp3Oc5HUC7ACvxABJIbC1n+SH/ iyKg== X-Gm-Message-State: AOAM531V2FwBh+VMwtVqTC+BYQuMBQ7PuHaEmHwZ9Ap77RTiWSyaVmg1 RlUT/4Hods9vJg7qxVXeR2zuAF4jCempFOuxjrt5LjgbwtZ88V5UJtITGejb6z4AJaLeFLXIKxP NG5K+nhw+9pOh3te647R9xHHBJnwBLVGLby1dWwpv+iaeeHuMpZNMtsGefqdsBk4= X-Google-Smtp-Source: ABdhPJzvv3Mh+jXDba8YxO9vXJg/mKBQ12VZ4cWYuyz+EFuwEB95n8pQLZIzZ4mOhbpiG87/iwyF90+hr65NMw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:a40f:b0:14b:61:b19e with SMTP id p15-20020a170902a40f00b0014b0061b19emr33404777plq.20.1646269075605; Wed, 02 Mar 2022 16:57:55 -0800 (PST) Date: Wed, 2 Mar 2022 16:57:21 -0800 In-Reply-To: <20220303005727.69270-1-chooglen@google.com> Message-Id: <20220303005727.69270-8-chooglen@google.com> Mime-Version: 1.0 References: <20220301044132.39474-1-chooglen@google.com> <20220303005727.69270-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v3 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 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 Thu Mar 3 00:57: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: 12766935 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 3B83DC433F5 for ; Thu, 3 Mar 2022 00:58:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231237AbiCCA6v (ORCPT ); Wed, 2 Mar 2022 19:58:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231232AbiCCA6n (ORCPT ); Wed, 2 Mar 2022 19:58:43 -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 59F381520E2 for ; Wed, 2 Mar 2022 16:57:58 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id mt1-20020a17090b230100b001beef010919so2913865pjb.7 for ; Wed, 02 Mar 2022 16:57: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=pVUeq3Y5jSxZALpUcz7YtbpU/lAeG5FYv4uMaBelxgw=; b=mTNJWICQ+jGaUA6ug+9EHfMdqJK3tXtsyJtV4TGAsrhJ2jV8TnWBW3KwZwVcHJ9mCS ytF4Y6VXg7B5eHqAZJnPARPlFu4BV+FfhZiuaPfmoNZUM9Vw7SLZy4xjp30akMNJnVmp XiSU1AGhjm47Q5LyvY2Hw4VEfeWyqdzO+2AvGbf/aUHPsUdqoeV96k9imtYOdyGaxcVO blpTQAmX77dccHwEZkUIy5iESmOKbWp1dcR8105YiFtE82rIWAPE1cH7U6FWpD4w3vss nzBi58lSZ72Dl53ETOGzK06jcui7fSdzLuQFN/GPzNQ71beCtytBGr/9g97L4/L6o3e5 1HoQ== 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=zA8p05zYBhgwdS9KXCeKcPvUcvqw7ae4vNg9jZifsmfs7pT+Ya5tJTBZ9u7EMPrFeh y1TehD8xKSNLAb2ioI5Crg2vm2D0a24agFq3rNoUHmsFJ26tpYmL2wWNBvMPg/Sijx2o sXYXN/+pPdvRhePZja0FhpPiYEotN99BnCc+Q+aV6x+mJJHPH2hn7TGi4VMkNMSBkm8N 16IG7a8YIfnKQH6J/p/WXpkpsvp2MxWxmOfLOKAN4gVrrgk4CANBRCGo93ToJ7HYvyfA mkUCcUF8tiHmJeeRI1ZkPgp3rWIKpAoPAYdC982w3TAI9yqQDyr9T0gvO7tg6qPxmQ9S 4xMA== X-Gm-Message-State: AOAM533JCUTMGs4fIxHG3YouGttY/1+nCVoP3+QTODJfVlulXfTGW5sR sMGoIHoqWdrCcE9IZYBs3id4XiC3ErPf5mTYOeFajCyItjTC2YMp/GQ7P3c0F/bx7WMHAu1u3Nx TiD2jAD0Jrd+8POtv5iRYQQaUB78kZvX2w28ykDZYyNjCVVwk8maIqUNo59PhrnM= X-Google-Smtp-Source: ABdhPJzNHV4QD1FIeq9p/3Ru6vnKfkj5lcm6Vl4fQLgDTu425EubjOV1v4hvEl3slGl2GbXEI+zS3a9BciwEqQ== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a05:6a00:140f:b0:4e0:6995:9c48 with SMTP id l15-20020a056a00140f00b004e069959c48mr35524912pfu.59.1646269077653; Wed, 02 Mar 2022 16:57:57 -0800 (PST) Date: Wed, 2 Mar 2022 16:57:22 -0800 In-Reply-To: <20220303005727.69270-1-chooglen@google.com> Message-Id: <20220303005727.69270-9-chooglen@google.com> Mime-Version: 1.0 References: <20220301044132.39474-1-chooglen@google.com> <20220303005727.69270-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v3 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|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 Thu Mar 3 00:57:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12766936 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 9FE87C433FE for ; Thu, 3 Mar 2022 00:58:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231245AbiCCA6w (ORCPT ); Wed, 2 Mar 2022 19:58:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231195AbiCCA6t (ORCPT ); Wed, 2 Mar 2022 19:58:49 -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 0728A15470D for ; Wed, 2 Mar 2022 16:58:00 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id n63-20020a632742000000b00378b20298a2so1877848pgn.22 for ; Wed, 02 Mar 2022 16:58: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:content-transfer-encoding; bh=8EAxdsA/GfXKOQ8ZUmn1Xxfw1B6J+Y02IU6IksgGGVM=; b=bVms1hx9q+Ql5LyliSrSDtfTvhGOwzLVrssIEL9QxsIc7MgdkdKRzP9F9E2Dtj/nQ9 13MPT6kPFlNcrkv9lECXzfruUsysAiZkiwFhoRBMw3H8I41zh4JotRio0Sw1azmdK8Vq xwbuj7btG91RWQANRWSYiCZ5QVMCR9gkXi25orvcgIu2uL5inf2sSnKPztmeMOfhdH4I 1tVO5LVv53ZBjYpAu5HtSooMJ/3fP2RicSX7KQ/LyHHKoRrjc3YXAqZe5uuU2bAGeMgK JOnog7zVjPvsfn4cOsaEhTU1GsAtJ8kHMRNLsf4w+fagpyjDOHeJ5Nmj77o/709soNTy UD9A== 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=8EAxdsA/GfXKOQ8ZUmn1Xxfw1B6J+Y02IU6IksgGGVM=; b=t0xTWUzBHZwnUUNSdWM86lLm4Xl2dqNuO+2eQUQ74ngFHfBVhdbV72sMfi3Viy3Y5B jt0OSRbM2ZDyB/bpGObvaXxLa/5Ln34dRtpUMxpYAU8U1JknkE6udfNQgMjNziEwF8cd CnxqCV6yMwoZgx3H2a3pk4NbyHB2bcIuYXCDYRxtwRbNaLq/dUdqlLclVagGzmn0q7kw zzCvUZS4U6sLqY2QIYRnCdHDYxkhZqOxqDsuJG74euo9OATLG/G4OSm+s410YrxleHmZ l9PCafWHuHmSA3e9eroKwpLmFrrqxJduWlZ93Dl8qSJNGVhSauCCi2fyHFEgMAGKHUOh Rr0A== X-Gm-Message-State: AOAM532W7qPoTMmRo8aeX3BE8zIFecq44+OASE/N6JJeYTLZIoUu5X45 sTB/HQx0BwQBKhGJ8vk2QVpN1GWLffQn3Cl1S0gn4TRtUjfNmGp4uJztp6aT5v+8bUo9oy5fuHK xq8cpVqYZveEXFWOFn3W4r0kf/d34jVLWX+A7jXvOmU602oSiNgf7mINLR4aWajI= X-Google-Smtp-Source: ABdhPJw1TVQDJI/zuapU1eQelKWtoeiNguH/famB3wY53ctEh3/cTncNNXOb75+7Vz6MOmIjGPVHMzPbGt9bPQ== 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-20020a17090b4b5200b001bcb208dc5cmr830799pjb.1.1646269079755; Wed, 02 Mar 2022 16:57:59 -0800 (PST) Date: Wed, 2 Mar 2022 16:57:23 -0800 In-Reply-To: <20220303005727.69270-1-chooglen@google.com> Message-Id: <20220303005727.69270-10-chooglen@google.com> Mime-Version: 1.0 References: <20220301044132.39474-1-chooglen@google.com> <20220303005727.69270-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v3 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 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 99341fb343..e6df99a884 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -247,11 +247,10 @@ 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 +266,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 Thu Mar 3 00:57:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12766937 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 36C09C433EF for ; Thu, 3 Mar 2022 00:58:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231247AbiCCA6x (ORCPT ); Wed, 2 Mar 2022 19:58:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231236AbiCCA6t (ORCPT ); Wed, 2 Mar 2022 19:58:49 -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 A8F15154708 for ; Wed, 2 Mar 2022 16:58:02 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id a200-20020a621ad1000000b004e191fdcb4dso2204579pfa.1 for ; Wed, 02 Mar 2022 16:58: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:content-transfer-encoding; bh=SASj7Pwi9GGVLI3+2BvvPv3frQbbas3/rP7hoCwAk+E=; b=SyM7jNKstKnIwM9Tut7uJrc2vuZu5CnjPzDFePZ5mM6NULVEb5TEGg6FAFsIw8Ukl6 TqQsJF0gkI1MW6ePvv0olSfH643aJmHTUgy9f1VM8WgACF7/Ce5UihiMBw58/3vx9tyh 3eZglBh//LgUAuRhNEmYsUi1QsaC66H47AU3HubEMxyJrOQdoptEz2lJvXC2bx0SMyHC QwFAyJLraJMJ8Amf49OG+NQUxKLjHE2dYXP7DVch4W2cvnYwnE84mm4KmRrUDdrg8D2m 18A9gY5efw8qh0Zb1MH/0POA57vfH2qlhAVSgC00aikiKCnndIscvFRRdYIeafZyYEQv IDfw== 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=SASj7Pwi9GGVLI3+2BvvPv3frQbbas3/rP7hoCwAk+E=; b=ORT/8XHo4H38/fhFovVFQSAVpsulPUFcvRisczTVN8PL00atZJySObI7y0EydOD580 1YxVrEYjvLwAQnUadRxaoU+5w5WDzWiwdSWLfjG4GPztJdHOrP1NH/GtxjxGL27uB2J4 stmt8XDmzsPeOMT+Rr3jcKNkB5/bYSnchDEo7Z6+SUGose+tGhyY9JXmaIvtNdHDj2gA /uRt85dmT3P/aHJSgwMa3KLPNhouPfvMMHNXFrHfj71lAxdZ1zBOdfHKziSSjK5yYuCG CLVVN6KLNfc8B7lPO+sH+nc6Kgy4HMevw8YBWl+oByj6CnEVmkX8uF8Rs95QGTndfWuE kZuQ== X-Gm-Message-State: AOAM532hJTiphTI6BrsHBzlGhDx4WFaQEXgC56d7W9iOk+Ai+JxqyNEa Tu/AslCohxMXIQqc5bgPnqppPJgixFReLhpii5GW4iWeHjaBquPCw3jXmLqkrmjfS9qxoacIX4L ZltWpdEuUjHdOIZ3BCHVGi4bqN9VxEVjVF6a0RoKKB/YmhaDW+pXiU3VC6Bp4iQk= X-Google-Smtp-Source: ABdhPJx/bL/uJGZHydfr0Y0q1BBeMcfVRBsenToQdWs5l3VL8nIBv4OVu8l9wG1BE0cSEDY+2fUjlPRAmy8WAg== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:90b:945:b0:1bd:561e:b24d with SMTP id dw5-20020a17090b094500b001bd561eb24dmr2595795pjb.202.1646269082046; Wed, 02 Mar 2022 16:58:02 -0800 (PST) Date: Wed, 2 Mar 2022 16:57:24 -0800 In-Reply-To: <20220303005727.69270-1-chooglen@google.com> Message-Id: <20220303005727.69270-11-chooglen@google.com> Mime-Version: 1.0 References: <20220301044132.39474-1-chooglen@google.com> <20220303005727.69270-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v3 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 e6df99a884..69ada7f914 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -594,18 +594,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); @@ -679,7 +683,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 Thu Mar 3 00:57:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12766938 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 20EA9C433FE for ; Thu, 3 Mar 2022 00:58:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231252AbiCCA64 (ORCPT ); Wed, 2 Mar 2022 19:58:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231240AbiCCA6u (ORCPT ); Wed, 2 Mar 2022 19:58:50 -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 50616154D39 for ; Wed, 2 Mar 2022 16:58:05 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id x17-20020a17090ab01100b001bbffb2c5f3so4322015pjq.9 for ; Wed, 02 Mar 2022 16:58:05 -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=oh4NzP7o+omfUkI90fORdWBXZyrZR0psuZbukZiUY/E=; b=fIUbgsvN8Y6f+T6ySU7mXZNivy2Dahk388rDez4pWYs8cXoxtJtp/hj+dJ0RhQTTaa FSKPvwIkno75wsfU1klu8/wPepg3iwgidlyUeLHEqDrFQJgYApW3pFtC5b+ajY0maH64 Ehnpg+mWh/ZT+65RmEkSugp2Gnd/nIug+yCL+wElxoVX3ifkq6ofAy12i7DVn35U1rnP qd4AY7kk+YeDipKE3sqbjdmRiO/2ZHIdt3UWYvBRt1rk5oY5mctfLuesrCE67TSdTXfp FqDVH/UhQAnq+25SSZ7stFs+BJz9OnlnRisDT9QPpeW+NLvroxip4vWP1mfP+rwLRfbf QbvQ== 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=oh4NzP7o+omfUkI90fORdWBXZyrZR0psuZbukZiUY/E=; b=YVThtaEXDjK6cI9yKqAdrNLO3wry08tsMFftw3eQ0lX0HjX2GbrIuKYY82wOoQ+5/S r9ST4+HGi4CQGTVlbplPxWdxyppPtDkSYRYVQDmwQyBMzEy4pzHrp86skwdlIWFUFuqT Q2onf1632FWA3QuSj1TDE24EIjtA/DsGVwzsQl7jPd7UvqjZ7DDa2j3KzVVQe9pLkbWi 7TGHOTOgqAymax/cDXDa6aIm9cOBT7MN8rvrMQXbLv8g6p/uqQc8ZtTIWEwviZ2iHdYt XBRVHTVQAHEWEQLIHkr2E5taTSWnsU+cWnqZ6yhdeKNrvzzz2e3ZWQsLj/fimwzWCzBP X3XA== X-Gm-Message-State: AOAM531ulZ1Re6/ZNpkP3P/TLMMzhtKYCFjy/5gRDMxQ8/E5TFLulKyh 9fiGSzrEtQs2zLCwJyZWl0hTPRO8br+s5bWZZAkzX6C0/w7mUNvSmys/i9ISSYT5zB3lnB4r4vq MKdl+D2ta4X0jN9O61DbM220V3TE3uHETIORjUn0+5QTpXfuvv7wg6TY8aZM/Slw= X-Google-Smtp-Source: ABdhPJwp+bjwoMV4FRM5tqSELZQO51QdhhDSa2BVlQhlE9MZw5qtKbZ1fqu4nz4wzljd2fNoBe2SV1kOGwGSNg== 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-20020a17090b4f4300b001bc7e5ce024mr830929pjb.0.1646269084010; Wed, 02 Mar 2022 16:58:04 -0800 (PST) Date: Wed, 2 Mar 2022 16:57:25 -0800 In-Reply-To: <20220303005727.69270-1-chooglen@google.com> Message-Id: <20220303005727.69270-12-chooglen@google.com> Mime-Version: 1.0 References: <20220301044132.39474-1-chooglen@google.com> <20220303005727.69270-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v3 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 69ada7f914..296ab80bf2 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2000,6 +2000,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, \ @@ -2509,6 +2510,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")), @@ -2567,6 +2570,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 Thu Mar 3 00:57:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12766939 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 805C6C433EF for ; Thu, 3 Mar 2022 00:58:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231250AbiCCA7F (ORCPT ); Wed, 2 Mar 2022 19:59:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231230AbiCCA6v (ORCPT ); Wed, 2 Mar 2022 19:58:51 -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 24F3A1520E4 for ; Wed, 2 Mar 2022 16:58:07 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id t7-20020a634447000000b0036579648983so1904336pgk.3 for ; Wed, 02 Mar 2022 16:58:07 -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=6LHfocVCl0x5QxdLkS1NpmZZntUa5PvWBsf0u+hjqLM=; b=TmoqsX9mCo1LMeEXDz2jWjpK2RaG2D6EE9CiYaEYlYhg1npeExKpZLyvV5M1XiZpA6 IKBU2+sC6i7JH7grf33YrPh+W6YHWCjILYcTFuhaDf/pVj3MYVMkyBjbGpgizsZu6hQx R4WuScOoRDMsYTyqi+cX7SA/HxAkDA/n4fe13bmDzvnNiTLUmMg5xaeMK+o8FldnfgBl D8fxupK17xc/Bj7LcUIqNhglUJzdSTm0q/u8COKgeDciaA+EUEKOtsLXWUFrUGEvCjOJ AvPgc6ZpI3/giSpaWt4SiR4zZFfjpG0mR7DQUL+sPYj+R5Qi6rENegcaOWkQWwaaPReW P+0Q== 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=6LHfocVCl0x5QxdLkS1NpmZZntUa5PvWBsf0u+hjqLM=; b=RBJc+sIuCd1Wc6RiFnN0y437oAaAE8MHQ9rX/5+HeM69S4Plw5lRwc9ibxHR+ZdubI JOL3dMj6pWvO22Kn/69jqvmY9Zy1qXYx58GLHm2Gzc5nMhK5UzjUcnYdoEKI7t8WAc5x Fn7Oqp+66FxArNroB2GyB+FOfpZbXBEDuH/2xYJVjy7E4hGSioNdrJrq2qN5EuZeeUn5 e8VK7F5NGuoDecJGmrKEaAVg9ebWYrQoh+DWLmGh4fySPPuxgOmCHtRHtaMu/Ebj/ej4 gZd/4MDkhT/Mw20qTscY/5WKWuQYhRjQDZsZ7PuSwPqbVrrjUK/NtiuvdwAGpL4Ak3jM veKg== X-Gm-Message-State: AOAM530tkNmFp7xr1Hv3Y0No6YtRwY/8QsYQQq+m/c/SjKzuEa4tJqN5 KBE2iWeS2V07NFtPcqM4J/l9TfTY0HE2oM/++M5zIHM9Li2sgTIrj/VRSIHMbND1RX7C2vWTY2z wWYo/mlm+Y85nkzCHnCaMCoqvp0TN71RFzBdtWN3TMrIEzYgQgC0fSfLB9QE0Px8= X-Google-Smtp-Source: ABdhPJxtNfer0NirTzhpBCI7ayjNNjTMwKakD94lw4tlNhuQG42rfRsGR6QxAwZm/80SVeTlPdjYgA3LhZ7AVQ== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:db0d:b0:14f:b047:8d22 with SMTP id m13-20020a170902db0d00b0014fb0478d22mr33417430plx.90.1646269086396; Wed, 02 Mar 2022 16:58:06 -0800 (PST) Date: Wed, 2 Mar 2022 16:57:26 -0800 In-Reply-To: <20220303005727.69270-1-chooglen@google.com> Message-Id: <20220303005727.69270-13-chooglen@google.com> Mime-Version: 1.0 References: <20220301044132.39474-1-chooglen@google.com> <20220303005727.69270-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v3 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 anything while refactoring "git submodule update". Signed-off-by: Glen Choo --- t/t7406-submodule-update.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index 7764c1c3cb..000e055811 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -1071,4 +1071,16 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s ) ' +test_expect_success 'submodule update --filter requires --init' ' + test_expect_code 129 git -C super submodule update --filter blob:none +' + +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 Thu Mar 3 00:57: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: 12766940 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 865D5C433FE for ; Thu, 3 Mar 2022 00:58:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231263AbiCCA7J (ORCPT ); Wed, 2 Mar 2022 19:59:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231249AbiCCA6x (ORCPT ); Wed, 2 Mar 2022 19:58:53 -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 3EA26156785 for ; Wed, 2 Mar 2022 16:58:09 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id k130-20020a628488000000b004f362b45f28so2190158pfd.9 for ; Wed, 02 Mar 2022 16:58:09 -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=5/J/TQNvnprNfyNbTTu8oTUqdxY0t77pvG2ZrTX88sY=; b=qVlF2ZcTOv4G4cwuGfLFSx0vuaqL3A9aETwgZQveRQbZ0IX+Pw5m13i8SE9eOshFYJ cFyhAT+aC7TJAhhvZQZRcG7tR64gzUl9TPh5QaODM5dKGnzYH7BGI4Z1FF5gmG4WtKvE hdmPe7tqy3mI2XjGaooq3gS4mR3y/WaoVpbjB34wm4Fn8cpHuE+epgkfqScRPYIzXxjc kZHh2g7pGo6cBxc/qPqsSbSm6cBdWu8VOROA4/4EiO0l9l0QSd9Eg9WExQhDLLbYZHoZ emL52YEH4uTzaC+IQJzKEqyMuQkzFrUfl5Lv5UTnruCIg7panmhxPuzkky4mcyRkl9T9 9cVA== 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=5/J/TQNvnprNfyNbTTu8oTUqdxY0t77pvG2ZrTX88sY=; b=Soz6jK/l2cQc0SlmI8yKNEXAmaWpGyfP1iQmncX/15drJLEyVzeLpkGxmWxnJl/3Zn R7Mzs2i+kZnObwLumWB3Pc84JXjpxlqD+asANr4k0zcpGvy3lzpSZmLwnaN5CQtdMjiD U1lsuUV0nXNRHc93Dw1YK4GwlpT2xpZ3eY0YAK3qFk4PFUDgzqrz5pGoFEfpnPHeYv9F tKz2RDFVpknNlTBpYGWLNY21pG8krENjKIcnWPFVXfzWNu2WkrGhH95x886d/Ws++c6E GgyNO7Avy+9zz20s2dEbIJFSztAEx/0KZsRfBxdEQPRGfLrKymkXQ79Z47GF0frq0HQy tnyw== X-Gm-Message-State: AOAM5322RJ94Ldp7PkTZY7x88XUiG+9eH//RbzYT5DlIeZdrT4qOB9G1 l68BDbYCazlrtOhG1Ol4hGdGCyv1hge8nVQvSZ0CcHTszhjmMnnzbQVntfWx9VjAdaW8DAUZMhE 4HvWT5byM6xt7ogsClFQwdQ7q2GrCteDftLEbTOpsKkpYbY2MhZrZiKyKe61txsA= X-Google-Smtp-Source: ABdhPJwmXwK/5cIEmgAQFS9pFUfHfvOS8W4CAos6FOAcH7qZwNBjqsLgopOlvqaXODGNw/Jx5orE4BRedGMGjA== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a63:920f:0:b0:378:9ef8:7978 with SMTP id o15-20020a63920f000000b003789ef87978mr15068496pgd.587.1646269088614; Wed, 02 Mar 2022 16:58:08 -0800 (PST) Date: Wed, 2 Mar 2022 16:57:27 -0800 In-Reply-To: <20220303005727.69270-1-chooglen@google.com> Message-Id: <20220303005727.69270-14-chooglen@google.com> Mime-Version: 1.0 References: <20220301044132.39474-1-chooglen@google.com> <20220303005727.69270-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v3 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 --- 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 296ab80bf2..bef9ab22d4 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2545,7 +2545,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; @@ -2556,6 +2561,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} \