From patchwork Sat Mar 5 00:13:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12770119 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 000BEC433EF for ; Sat, 5 Mar 2022 00:14:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230131AbiCEAPp (ORCPT ); Fri, 4 Mar 2022 19:15:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229521AbiCEAPn (ORCPT ); Fri, 4 Mar 2022 19:15:43 -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 B237724317C for ; Fri, 4 Mar 2022 16:14:54 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id z10-20020a170902708a00b0014fc3888923so5386774plk.22 for ; Fri, 04 Mar 2022 16:14: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=psWNFvxVHzRNwn7LAZ1WWs1LyNdO3zDnyzLnegifRc4=; b=OhhjEzjQR2Kqu2do+0He7X9JLlLuzriIiHGA4qhCSEYa7uS//go7EBV1sVeygWTxW/ tGcH0TfAwfDeWUyoZ7lkZBA2VNg96kWj9Ppv0grj9LPaQCxJCZhKUCOKDc8wx4tj15uN W9Cc7mipO74R5zE4utKPLzXYBQ9nEHa2pOy+fOMwhxOOFv+asKxVSengc013efdMzbSo Qz1sZ/BzPZe+/eajfRXqS1Sb46pqJJC6ktAMa0ABB0t7bxE/7v1rH4GgyuQNztCISqzC tGY34ym/zRkspUWe4OPF5/V/1peD9iHeUx3472hZYt73ewsATMvy6X/hwHt3UGsdB39F QCaQ== 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=37y+SXeb51ZFu9CbUbYWy9zZWT0c7B9w95A3GS/qBCaV4rnSyZX4N+Q6a+TOzErt4r AtFctI8v8Ev+FJsIEvJyFBqSXlUzsDsbKPYr2ziPgMagUUyg9zCDluTT4dJsY7jdMvCt sgAGb3Kw6mJNBm/SxpTRXbFtGpt6jdoJTqKjIb7U5KniYNIc16V//nUtIOy8brJzrYMy FVj1B9zCi3YX376potNuw1dqtju1+lHayYQEMlzNTG6ugsHseEmjZFnE5vjvUn/ZvpDY n6RHcCQG5wDI6ThmM5/u3sQv0MMuFWz0KUHURXk2Vkeq72OhoiuGZoyvpyjnqXpYFxiC +SNQ== X-Gm-Message-State: AOAM532OD35N4rkZ5Nk7IzV1RMVLFq6/zfZpkgDjU/u63K4esm+HInoD LF0rb2h4hd+eqUZ2YLu13WZ6kjkCdCX9EtdX3xnMhIBO+0oI/hO9rK+mqASMUTZ0AZxr0ukK1Dy ibMrUzx6slVSioGD7xF9sgrDw/e0noCx1yU5FL6ZQjrHnN1akHbOZtMc3wX5z5p4= X-Google-Smtp-Source: ABdhPJwxTiN2YxFNOasJ28Oe1EKm+XR+r1zRFJ8uK0PJny8tB9iBBMkRAzyXz1PrzqHH1q0U90EL6rfoW957rw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:e805:b0:14f:d33b:b769 with SMTP id u5-20020a170902e80500b0014fd33bb769mr997979plg.24.1646439294081; Fri, 04 Mar 2022 16:14:54 -0800 (PST) Date: Fri, 4 Mar 2022 16:13:49 -0800 In-Reply-To: <20220305001401.20888-1-chooglen@google.com> Message-Id: <20220305001401.20888-2-chooglen@google.com> Mime-Version: 1.0 References: <20220303005727.69270-1-chooglen@google.com> <20220305001401.20888-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v4 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 Sat Mar 5 00:13:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12770122 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 57797C4332F for ; Sat, 5 Mar 2022 00:15:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230146AbiCEAPw (ORCPT ); Fri, 4 Mar 2022 19:15:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230121AbiCEAPp (ORCPT ); Fri, 4 Mar 2022 19:15:45 -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 D48A924317C for ; Fri, 4 Mar 2022 16:14:56 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id t18-20020a63dd12000000b00342725203b5so5279634pgg.16 for ; Fri, 04 Mar 2022 16:14: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; bh=UH8t/E0TczNz4tziesvMRSUOID+d/VyUA9f/OELjrWw=; b=Men7xyLM44UuSxdBmFXksCEsl/dYMad4Qqt4Bz7uJ8m3AcXn6dSMrvCR9J4lZwNmby IqvA2rsDcfj36Q6AFxcElcrFXOsJ5oE4FmAH6kfqEsuFfEx6oQXTnTvYMsqGLJ+Xucl5 03yJc9MREo3FgYrG7t6Xxbod7KKcyu0Z48kd4YFR9s2/8ziPhQa0fjJ8vEz6FbdqjcSL BFxxUhcE+ItM1/TPWwBhS8QHb2tQjJR4Io2S5M+9YwwyHAkH2f9UYrKPjCfx+M5uFcyk YqgtgVByPKw4MB1sl84vR4TlVZbRf6C9NxdQsnhxpGXVr4wO/lUrkeKcl0ktXPUI0RXV KM4w== 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=sG4IqufscTsNvJeuIShZoDtNWzOIUt8OgTR9lbGJEWupvoR+Uv4WeRJGFktymS5ujm XCgUfezSi4n7zbI58sfMUN8Tw3R4vKcdTg8PQvf/fW1bj165kTiMHoMN0NxabW45fmBo 1gqYXJKInOqfTbIecINQuOlDSKR5N54VRax8G8A/qYhLyC3gOQrObJobXzXe1MtQNNQZ pwhLfUSauY4Q2GQYWyPrvCektLw+cR1ORFZ6ivYjqkR77mRWlCxzPSHLQxprvpCXvzs/ 5IMWhdfoU3/Xt+AUfW/aop/V0eozuS0YvcN5jA1LbYaEHdNQdNRU2l6tx1Lr4HWG6L43 WRqA== X-Gm-Message-State: AOAM532TDOoeCJz2TMLbbXR4dtqRA+g/30XvEnmBiOs3t23KzQ6Ycvcs 5dpSnkmaQTbXzqe3dPNm/6u/elRrZLcoYpXnvRlOzAf4jZ5zVJ7WiSlf1+V3Wsu8S2HhEdbQLtc 7ziVqJfY7H2lWaFSLvvvJFJ5TRMO77UVHaQMGrcA627NF1RfR2Lwuh8rYP5p3qfg= X-Google-Smtp-Source: ABdhPJw5bPaMRDUJh39NIPIDv0vsRJh8Hn3hWO4w2kd6W81rIE28y78C67nv0Mis0Tbqf2bkIdjpeJDSaQlZ+Q== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:903:22c1:b0:150:ca1:bfda with SMTP id y1-20020a17090322c100b001500ca1bfdamr869079plg.115.1646439296067; Fri, 04 Mar 2022 16:14:56 -0800 (PST) Date: Fri, 4 Mar 2022 16:13:50 -0800 In-Reply-To: <20220305001401.20888-1-chooglen@google.com> Message-Id: <20220305001401.20888-3-chooglen@google.com> Mime-Version: 1.0 References: <20220303005727.69270-1-chooglen@google.com> <20220305001401.20888-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v4 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 Sat Mar 5 00:13:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12770121 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 44A19C433EF for ; Sat, 5 Mar 2022 00:15:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230148AbiCEAPy (ORCPT ); Fri, 4 Mar 2022 19:15:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229521AbiCEAPr (ORCPT ); Fri, 4 Mar 2022 19:15:47 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4656244A02 for ; Fri, 4 Mar 2022 16:14:58 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2d2d45c0df7so85464777b3.1 for ; Fri, 04 Mar 2022 16:14: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=ZJ9JuO2ZLBsSPC5VW54LiMsNmiMznGVzF+HcPh0t8SY=; b=EVBA4K9Xc37rlYtd0UIINOLY1lOleUPylVJC6WfpFcfryRaF4h+B83yXnEWD0DSoSq FKtsaMEEmdxxohg9ZFYZvHyH8Zr1EWB7N/6rq3gCmP8s7veePVRM6eH14twMk+7n50Ep CNDA2RegS/FbCwEucgvRB3ffXPfMeJBshLELRR9QUU2Jsc4Gzj+K5JZjIrenU24f16LY Nezy7kRdFVbnkjsdsslk1cSjAD7nv2roE0Ex8yY1qwq2WAhp7z6iCgsnSqkLETSFuOLM aGsaQ7fKZWQ4gsaa9PFQuNbILfwG0LiY0P3JEexPWK6lt97G0xaVQhranwwCzX+yW5F6 kpUA== 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=1+GInKeccqd7lkxsfAoq5uVP7hXSIiZ3TwSA6te6k+AZa/uLz1XocavPCOJUmx2uWs iY76fXH4j1BSBHhCTKMjKPIuFfcfAv9alRW6h9sx7i3+MfDrwPb1R+OwZJ1m5DeYR4j4 qyajV+hf6NNfFfOf+3Rzh7PDGYuSWO+XTAkDzYNqXoD7JZyLnHTF9RlhfwtU0Mez1QBo fCicktiHaYE+6qJISknMCZnACJMW0ClIuCcxkMlMoj2wBacEr1s+gZBA2AaYUpShQ4F/ SbogeK+nZyG/FVInx+O0JDYkFOMsJ3chBNgEhJ6wbCu9xsDW07sBBgQIC+iKiNV/x+DA 34nQ== X-Gm-Message-State: AOAM53183i9ySOooRegddSdRNwiYEBxUns7nzr7FS7JpOuFMHnuYlnrY iA17RmmH9qhU2F7iJXgUdFGwwRAIxEn7wBkwGmAsUSkEFnWUA0x0VAfGRRQoo1eHVWGUhYcMrlQ cle30BvDFX0nbVvMwVYgsaggAVknl71y12MWz/VAUhWbLn8ee0hMui/+HDh9r9Co= X-Google-Smtp-Source: ABdhPJzcDlnVjkAqwRgH5AhaQaBRe8apukXIR4eS/0M+LmG187G9dtrsrqfIAd9cMM4qWO19TJVkDCJASCF8sw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a05:6902:107:b0:622:942e:3959 with SMTP id o7-20020a056902010700b00622942e3959mr941630ybh.280.1646439298013; Fri, 04 Mar 2022 16:14:58 -0800 (PST) Date: Fri, 4 Mar 2022 16:13:51 -0800 In-Reply-To: <20220305001401.20888-1-chooglen@google.com> Message-Id: <20220305001401.20888-4-chooglen@google.com> Mime-Version: 1.0 References: <20220303005727.69270-1-chooglen@google.com> <20220305001401.20888-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v4 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 Sat Mar 5 00:13:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12770120 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 236F8C433F5 for ; Sat, 5 Mar 2022 00:15:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230161AbiCEAPz (ORCPT ); Fri, 4 Mar 2022 19:15:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230145AbiCEAPt (ORCPT ); Fri, 4 Mar 2022 19:15:49 -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 5F430244A01 for ; Fri, 4 Mar 2022 16:15:01 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id lj1-20020a17090b344100b001bf2d53a2feso1416462pjb.5 for ; Fri, 04 Mar 2022 16:15:01 -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=LEvv4KLPlmLJnGFaMlTpr54E3wbXX/ErQGbx/l49qxA=; b=ogfUG8tD0SBU3qReunK2OiOhNxJ3/6cTflJOdpPLGn9fXLfcz/cSGGEP3CpCQIfj/N hTgC7fUKXX5jr8hcWQkYRqmarsPhEu1BO4X7rlJFxs1cYvTsBWPaaioaxCzHlH2pY9pU wJ3103Vm0ROQTiwJkwE2Vx5kAWlxw5hfGep/meABI6W1THnJ0lknBumBvca/g6ezIFjq X5VERYPRCQ40xbpJzDg0Wx565PcH3sfERDwSh0p8zGpC/hKL+8CVMIkBzbi3u2FrHFZC UhiCz0z500s2SZ+Me5W4YI+2pBKCEdt6srp9xMSqFWX7G0aXIWD/ohFGxNB0ZE5eC4Nn Q6yQ== 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=LEvv4KLPlmLJnGFaMlTpr54E3wbXX/ErQGbx/l49qxA=; b=jHSJz6NJABQkXSf+HG1SZfjhlcTpiVgaXBmm7kM5dwr80sMZVgSgdTWKMWQhBL4G7Z 4PyTlONvnH+9NEV/GxWWQjl75IzTaVIy4zzYhqfIt4A2eEGuCeZMThB0+06WooNSGzd+ h/FLpz7olCa45vkv3/N4gX5ROx2VYXGZZvxS2EUr1M4IVPAzyGzymPkmdcXr7rFMnC0i I+2wJmnD2OneITEh2xevAaloKLldGnI/U1jaQXurw18Ed59W0Ew+l41PpNdw6oNNtjU2 AMZmQuMEsTqkXTGuFkZV2OM4qOY9/1PWLDAD7OoWOuXzOt5Q2d15dZw3vgLTrxdym1LM +9Ow== X-Gm-Message-State: AOAM532ba+74W1T+e8q9ORKFBN8IJTMwikHq5yu2JFZGL/vXF4OcymJO TV5iUteJboEs1qOk6PcjVpQOX6n/Y7UWt8JbP7QP1aJC+v8t1Lt4gK8sFWYuQuGnPwSFKGQAjVl 53iHNBZ5RI20EY6ofXuEnA+Aa2hMihailRljx+4AyXPfYNm7kJNt1lWaWjUSpYk0= X-Google-Smtp-Source: ABdhPJw2zH7OLUbwG4MRa6G3C+l37BnINvkCRqCJYZPRdPJjYVfSfHRAhnsL7+Z76JKUQfA8X7QUWt2NBrnzLw== 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-20020a17090b4f4300b001bc7e5ce024mr766747pjb.0.1646439299929; Fri, 04 Mar 2022 16:14:59 -0800 (PST) Date: Fri, 4 Mar 2022 16:13:52 -0800 In-Reply-To: <20220305001401.20888-1-chooglen@google.com> Message-Id: <20220305001401.20888-5-chooglen@google.com> Mime-Version: 1.0 References: <20220303005727.69270-1-chooglen@google.com> <20220305001401.20888-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v4 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-submodule.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 Sat Mar 5 00:13:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12770123 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 8060EC433FE for ; Sat, 5 Mar 2022 00:15:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230165AbiCEAP5 (ORCPT ); Fri, 4 Mar 2022 19:15:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230153AbiCEAPv (ORCPT ); Fri, 4 Mar 2022 19:15:51 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A3D7244A2B for ; Fri, 4 Mar 2022 16:15:03 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2dbbb248ca1so84890757b3.14 for ; Fri, 04 Mar 2022 16:15:03 -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=c0NZ1lg7J+sfRCOL5dR0fwLxNk/+aZfgyZK4qhepnd4=; b=E8eZ9sdM8OjcbzB7wY6tHodXvaeKqHlA4zewAKT4W0ipFzOHeYeMyMaW78SX1BmBfZ 0wlAsfRcgCI9+dZ7FWEO4i5dSDrDq+Atgt3ivpYEC2JLxzLLAIXZbECU9+h3sYRnkzsR P9zwS1gPtIvyFe4x6UUnfSi8wWtT7v1hoAnktPgg1f6RU1tXB+gnECBuQQl1pqzXCfVy 5aJ7ROpspPSg5nKwTd7iolfREae0c5YqH54qxdSB2UmVqZbSMsKun4hQ5b9TgZ4o0bbf 2f6x4Xo8JQTjyBJ+ZaGBvHQG9KXutWDvQdF6bnHDA/0o/Au9s0c9ZiIVKDFnGy2LPdl5 +Svg== 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=c0NZ1lg7J+sfRCOL5dR0fwLxNk/+aZfgyZK4qhepnd4=; b=DI337zNtIOQTEhO/hvCLnGUwlaMU86Js4Rciu9OaabtPxhkFPMP7k6bBSYurdz6SlJ Jyr/sOA/45e0XHcbQrKyFAsglB5TjYNlpbQ6tw3S7pMAU8+C5iLne5PwN4KqJUUJGOCr ot/avOEjiTbEMWzUcu4w+6AHSMHNI4FHMZUe41/v/YUlBS/P+PSQTDcyy4t88J5GbX1E gk2lYFj/zCu0qzPYfTfZFgtFbw2AhJrIejnecQaAsqKw+qoX7VIuE6iSpm45BQA/qCc1 u5AJala+1cO6/F3go6qEx4MMYq9+Bdk+0K4mXBssDrTy4dkZ8kqtfYt/GY6AxXHnDzQY KZbw== X-Gm-Message-State: AOAM531r2ikE6yjMmYA05r/VgYoot64+xda/6sOmBsAj4sXHRz+gk9MA acUiW7LlDttZs/s10mpz9CE3q22PTDorUJBBTHDq9QtV23iA4Do2EpdskE0A6HgGCgwb9771Kb/ cE52KPZE/7Ch/C8Aim5MhXEEXKz90NHMOWMJC7cZ5f3RAYHt5hwlZnddGN87t/ZE= X-Google-Smtp-Source: ABdhPJzgVFwKaeQ/oPkgZFOxjDPypW+MelzJeEM1zz5cOK5GDTgA1aamlR9dfyYU7b5M6nyrjbakv6pzIW2DPw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a0d:ddc4:0:b0:2dc:4496:378e with SMTP id g187-20020a0dddc4000000b002dc4496378emr1046777ywe.299.1646439302260; Fri, 04 Mar 2022 16:15:02 -0800 (PST) Date: Fri, 4 Mar 2022 16:13:53 -0800 In-Reply-To: <20220305001401.20888-1-chooglen@google.com> Message-Id: <20220305001401.20888-6-chooglen@google.com> Mime-Version: 1.0 References: <20220303005727.69270-1-chooglen@google.com> <20220305001401.20888-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v4 05/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 77ca4270f4..b5a2d83029 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 Sat Mar 5 00:13:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12770124 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 27C30C433F5 for ; Sat, 5 Mar 2022 00:15:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230174AbiCEAP7 (ORCPT ); Fri, 4 Mar 2022 19:15:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230151AbiCEAPx (ORCPT ); Fri, 4 Mar 2022 19:15:53 -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 174B0244A01 for ; Fri, 4 Mar 2022 16:15:04 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id j9-20020a170903024900b0015195e68490so5383714plh.19 for ; Fri, 04 Mar 2022 16:15:04 -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=AuVbI191/O5fPuaIwnxwbQn3XJU3aiYUEwW2YMjR/sg=; b=pbHmkdVpgAyJDswo6R/xBOMJgnZXHrd1U+KFByqM6l6Qk6ceoCyfZw7wPOhlJ1g+1a rALtA6RewmfGvUsdI/vgdphimRU2wQDZfQz7q8KnlGM7X31yQvSCjFfdy0cJg1qoPOSd NA/ZhQisfj37K/C0qKDsZN09Z3koI8NRIRtnABW0M1u1OtlymAW5QTUCb3GybU80K4mp /y/WupNrT6PreBAEW0XRtXdATjqDwxwqoppkKn3Vv3OvYzXaJU59jpFhbqdF2q/X7e3n 6LaiGT3ak5sg94teTX00JtxlO82VbRfGBu/OqoCS4So4nhH94uB0CWR465HElzAATG5X mY/A== 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=AuVbI191/O5fPuaIwnxwbQn3XJU3aiYUEwW2YMjR/sg=; b=DhcZ04UqprfueRR6SBo4GCgJ1/QCH0ycWrFErhOahQ11QH0bFYVUW9VyiBBHKB4sx7 LiK8BgHG+6WsMYCMLH6SGg5kL0Vufav2vyyYzXCdkvQGs8h9Us1kMl1Cq7SHWNAk1YVu uqBnxWvSYS8Lbr/syup4gTkIlR99k6i+bCrGHQUW0fGXy3JYmfS70dAvrRvvw3AqJnzn 6aK1i/SW5dVJUeqUjP5xMDlYTOIXPajGBfAbHCEE3+SYFqRE3uVt3Hj9AuclZgR6fdE7 mNnhmMLf2DQsm98lW/xPVRolZQIEzxC/iicwm3BDk2I7C5nJX1iwqpV7luf1z8cTG82S waAQ== X-Gm-Message-State: AOAM530OhL39S7Vwo4guwA8I1zllDLT13U5CXcKrbEHaJ4VBb0nBr6Za aNzdSSYpE42r+Rx3KNe/OuFyACDzi6cSRnM88QEk17L+RtH4URBLa8j3oeeBhsZ1XGnEDryZ0av 4h7Zp1aJVGB7IjVJwAEU0/cH3uzpmUwectXRx+95sEZZbYoz+552PE3QQ2vJbmW0= X-Google-Smtp-Source: ABdhPJw4PL7BhZqHDFZEyvSemQYhqxxovAhI7AbuwkpKrNCNO14bWrGlqz7b2/jBKT8cmHbU30JVJ79w+Du1gQ== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:f54c:b0:151:4cff:3f28 with SMTP id h12-20020a170902f54c00b001514cff3f28mr846323plf.125.1646439304194; Fri, 04 Mar 2022 16:15:04 -0800 (PST) Date: Fri, 4 Mar 2022 16:13:54 -0800 In-Reply-To: <20220305001401.20888-1-chooglen@google.com> Message-Id: <20220305001401.20888-7-chooglen@google.com> Mime-Version: 1.0 References: <20220303005727.69270-1-chooglen@google.com> <20220305001401.20888-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v4 06/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 b5a2d83029..3832dccae5 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 Sat Mar 5 00:13:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12770125 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 08928C433F5 for ; Sat, 5 Mar 2022 00:15:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230183AbiCEAQB (ORCPT ); Fri, 4 Mar 2022 19:16:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230159AbiCEAPz (ORCPT ); Fri, 4 Mar 2022 19:15:55 -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 B86D2244A16 for ; Fri, 4 Mar 2022 16:15:06 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id n8-20020a654508000000b003783b1e9834so5329210pgq.0 for ; Fri, 04 Mar 2022 16:15:06 -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=T/Iz4J+V1wAzPoe3joFAEsv2MKAKPMbyTHFpG6YlcAo=; b=qCurjJHqG7FV9Mtg4sCvXlPVWV4XjXM2mYNhvcLeA1Y0MTCuqaTcB4D9Q1fuOVEFfb lfuYPhATv5GFyO/jP9IFYRmGkt3/RszT5McL5uJ0NkLKiGp31VARepoX6Gq6kQsb4You EnF59otBErsyyBL1U7D1wXaaAOTQFauiOrGr1vehiG6sz6rc0h9RE6UqJXgBjZtUk9cl WKxAvhZkt1uGM73nV3rpeHKNNYUHl3t63EPUDjog9VJE27c6qW2mNYusP9xyBXZ5eBnu eJ1hKtNAU8Xj8FKAwg3nbcckJZlAwnOrO65xX2fVh0fdp2tAhw4LOG7g+m2mJL1hggih xbTg== 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=T/Iz4J+V1wAzPoe3joFAEsv2MKAKPMbyTHFpG6YlcAo=; b=IU0f/NhsFLOzZDSV6VpxgrUCYUc4pOd9hvQt4Ig7E12iK3TzE1foUD5N4aQjXHx0Ci fnkhhCkpd6TSwUK9du4SjUTp9TdfwwCbbrhoz6ikw5r5AEtukoEqykTpc2s2Tp9+zc/l v7Zf2TMAuzHgbcJ06q8mdklOdYX0uL6scgrR4RpbV/wSBB4D3wIxPzi5bUmZShEaaHDA LrYgb9RgHv08agA8epTN2nkVAfbTSkIPXLAXfSChnP9IWM3BLXXgdTuRriYjSXofCeL/ jeLce8rCXSwANzXgE9EDIer4QlkCiIhbDLWuPWnXaKvZT2/46c0prB6QWyYja9VfUnKg tIfw== X-Gm-Message-State: AOAM531xeMcRbNXLDnwRaEQ7pnHq+ZpqElUnz0UGrt6XYcthpy9HupIk JU6KNX+cuTq1bVsI/INIHsombyR8NOcrpJfHeANSdN8n6kxUijKNa+/mS+DtstBoVK5qzzuY30S vqGlQ23hnjBu/omXrRNJ8Bso5Cc9sRibHbpYHumiyfUKrmN5LdZVwgd5qycFCeWc= X-Google-Smtp-Source: ABdhPJzVCdS6sco0yjRFUVWbLeVzlpR5Ur3MrGjGT9Glk0MqXrcx2oAePqXrq4LKVPENrOAs9eCnuSYBOoA8oQ== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a05:6a00:890:b0:4f6:686e:a8a9 with SMTP id q16-20020a056a00089000b004f6686ea8a9mr986762pfj.83.1646439306165; Fri, 04 Mar 2022 16:15:06 -0800 (PST) Date: Fri, 4 Mar 2022 16:13:55 -0800 In-Reply-To: <20220305001401.20888-1-chooglen@google.com> Message-Id: <20220305001401.20888-8-chooglen@google.com> Mime-Version: 1.0 References: <20220303005727.69270-1-chooglen@google.com> <20220305001401.20888-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v4 07/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 3832dccae5..f673f7ebbf 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; @@ -3040,6 +3011,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); @@ -3439,11 +3429,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 32a09302ab..882bf097d5 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 # @@ -411,21 +397,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} \ @@ -436,6 +407,7 @@ cmd_update() ${update:+--update "$update"} \ ${prefix:+--recursive-prefix "$prefix"} \ ${sha1:+--oid "$sha1"} \ + ${remote:+--remote} \ "--" \ "$sm_path") From patchwork Sat Mar 5 00:13:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12770126 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 70539C433EF for ; Sat, 5 Mar 2022 00:15:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230185AbiCEAQE (ORCPT ); Fri, 4 Mar 2022 19:16:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230166AbiCEAP5 (ORCPT ); Fri, 4 Mar 2022 19:15:57 -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 94BFB246355 for ; Fri, 4 Mar 2022 16:15:08 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id j19-20020a17090a841300b001bedbb1a120so7967308pjn.4 for ; Fri, 04 Mar 2022 16:15:08 -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=M1aokkmgyUv58OLH+XTfzmmBZ9zFIbZIpt2C/IJDq+Y=; b=lRoRQZ6BCcWQpvYh9pAxux/AknILpo6dMigaehmGL/8bfvr9QseBd8Vt/mKrGEmRaZ luJgO+nOGPIYdIix9H2J2f2Nv0nRCdTI33kLxKfzsdXg9Jb3bnzxUUNSjj0QpjY4YLEb CyuSj+WnkdtDjb3c43YeCY9O/DSbtUJ91zTJBNQFXFJryoMMVa1W9NF38XdO+NX93aC9 VgKAGQY/xyRwjYG0p5g7rNMe9BNw8h7kt0t+Nn0EPzV+ZP89ii5/6Q9e9+Nazs6nXQ2L jzwJRV1mUsf3S0gdl1GVbZflUr1UEd3KV47Z0QF1RMvNGkM64TF1wC3/YIYB7CisBYB6 QGsg== 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=M1aokkmgyUv58OLH+XTfzmmBZ9zFIbZIpt2C/IJDq+Y=; b=SCAzlxrDE+dOezdI4zuVOlRJnqIX/U+FCbGZgcXIh62Ja9Rdd3wsh8zFehogGqE8hq aOnPiBUar2IYaZrMpr5OEdyRTBwFVDf7oGCNiuScwXfuB5tJu74gFl64Oug9a+UJRq5E azKQXQAnUQJgJSnXAPNTZ7yBOKAuy/7RMdV5iWnr8jh3kX8HHRwdWt5z64ngBrgpanO0 dPsbaaI9ETsOrOEsAfgSuYsx3p0sRlFncjYN9ntxHZSXQbo+m8tHxKiLJ/fQC/lxCI6z IgWnp/GAUVG7Imyr702RG5MkdyDDwXji6lay/rtB3f88v7VlOejBpineZAxXt2MUjYKS wSZw== X-Gm-Message-State: AOAM5315rXHwbiBpjqh5/HhhuIrxYFZmdH+kP74rFJmMdR2wTuDbfL8V qLFvdogu3jF0bPcBUWhFkAWoaszWGH/TJPVodL6Rxbcz2EijHlE0AOIznpqYjTDjhZZbLI0FSYR qwNXrLuyAEUzg3buT1YzVdovmnX9oGlKMQUOKVc1pyQM1DMcgbmj5S8D45s2N2xA= X-Google-Smtp-Source: ABdhPJxkzHa4ctwVy8+pDXOq+rOmsxVEw/ACMlmpMEwgIpHAI/bSxkH7NbzCLpbSe9xrv4Y42zJ21+qBXWlJdA== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:e54b:b0:150:241d:c564 with SMTP id n11-20020a170902e54b00b00150241dc564mr873781plf.61.1646439307938; Fri, 04 Mar 2022 16:15:07 -0800 (PST) Date: Fri, 4 Mar 2022 16:13:56 -0800 In-Reply-To: <20220305001401.20888-1-chooglen@google.com> Message-Id: <20220305001401.20888-9-chooglen@google.com> Mime-Version: 1.0 References: <20220303005727.69270-1-chooglen@google.com> <20220305001401.20888-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v4 08/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 f673f7ebbf..52d4f47ffc 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 Sat Mar 5 00:13:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12770127 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 64053C433EF for ; Sat, 5 Mar 2022 00:15:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230206AbiCEAQP (ORCPT ); Fri, 4 Mar 2022 19:16:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230171AbiCEAP7 (ORCPT ); Fri, 4 Mar 2022 19:15:59 -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 63415244A05 for ; Fri, 4 Mar 2022 16:15:10 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id m3-20020a17090a3f8300b001bd33af55f2so5544181pjc.1 for ; Fri, 04 Mar 2022 16:15:10 -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=KjG9drFUSjVnAJXDX3J5ZcaU+aLEydMBrQXjn+fFjOs=; b=bl9CkeuxEdKR7XOOLIxGro3Ci9007TYfEmbfK9TVPsG6d23g9WfiY4C8JhCT2I8F6G SikEjFNp2x8viOnSQfisWmJZzaFOKrfqRILabuxiry3MNOwkj/iBP7gdFeg/DCIHAF6Y J/JYO+ir1vdNI08SWuuVkJ+WYw/i+1LbUPGA8R7Am0vONgPUK35SXsoiyL9uktta3hGv 87GbVZd/IEZLIFLpOT+RCehFIb8kGXA/PnXn7VYmVkhPRBPygzXUsCzHpGLk/BgrypoJ aR3VswC90hbCFiNf0/KYLpAg6FFJxgpQ4bPnXK8BvVXL+3wFTqqv0DUKeF0bX1ctDA5m Mhjw== 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=KjG9drFUSjVnAJXDX3J5ZcaU+aLEydMBrQXjn+fFjOs=; b=MtAX09Yj+1uARIpCNKGzKZQLfZnSzGObtJgsciexoR7VKwAmInSAzVSG1/aEcFlLTv MB0ierX7zr62rj6PAfNl5FmwdJ3+tAfy0fop+/K1K2TpA+ud0Zx1s513t76KfEqzditH gvcINNJx5p9xf+ypJeO3f8/G/RT1bba66dkLR7s4DEDzQrlNKs6KqAdowu9mDy5qHu5e JILjBo8iZ+GTk43oUL0zmg/SHk6s51WyPkgAMRg09f+jBfCujkx98cMOIytmdXbuTtio QKT1Fs0TWiaU96Yf6AH1vVPpQyncaOTIzf/ZcnCQMLeGxW4oZBXqgiuV7Ax3B+vT/MkI fNxw== X-Gm-Message-State: AOAM533871nehBbJUtGjjD8PTDq5Snv3l44pT5kfJQ8dLcdGC6vFZYkR q+fvu+3XJFEXjVCK0Gz37IMIzFsmeeWpgWYnvHQIoE2eAYFUFqACL7XD6WDTBTnLl+7XfdMX3ON U5oQDpxVJjlqj42RBe2JeL4w7iW6tKuMcUqGswie906kRMjbfJesXAxs25ttUDgk= X-Google-Smtp-Source: ABdhPJxtInt3SbXgm3hVwK/KbxsnJkailxdIvqeaxCaIy7teXU1ElivgyRM1YRXIguiPVvv8V7x4ZDQKbnmflQ== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a05:6a00:a1d:b0:4f6:d122:cd08 with SMTP id p29-20020a056a000a1d00b004f6d122cd08mr1189915pfh.68.1646439309816; Fri, 04 Mar 2022 16:15:09 -0800 (PST) Date: Fri, 4 Mar 2022 16:13:57 -0800 In-Reply-To: <20220305001401.20888-1-chooglen@google.com> Message-Id: <20220305001401.20888-10-chooglen@google.com> Mime-Version: 1.0 References: <20220303005727.69270-1-chooglen@google.com> <20220305001401.20888-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v4 09/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 52d4f47ffc..c6df64bf6a 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 Sat Mar 5 00:13:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12770128 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 37DA7C433F5 for ; Sat, 5 Mar 2022 00:15:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230252AbiCEAQQ (ORCPT ); Fri, 4 Mar 2022 19:16:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230177AbiCEAQB (ORCPT ); Fri, 4 Mar 2022 19:16:01 -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 4DBBF244A24 for ; Fri, 4 Mar 2022 16:15:12 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id y28-20020aa793dc000000b004e160274e3eso5946743pff.18 for ; Fri, 04 Mar 2022 16:15:12 -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=Qu1Wfiut7OJ2NsIP33OWXJdu2Nsx4/zQgXfZHvrR/+A=; b=YUBzhCT8DcauRLtuW6m+Q8qId45dCOyCCNF8J7KmT0IYXD2s0rkAydo2OH70nI5pEV 5s9xBJ3CESSzYm7yBKnIxIKBc2MZzMuy8Hd6n9v2bwh6A7Kw1N8RBYssdvVXkOGyJ6op bUAZpfjYx1A0vN/AN84vLnuMlZ3ZdhA/ALTqp6gA5Y5MecanAzetE+eDyJJD5T+efWGS guEXI9/4tKHYmApY2xx1xHWww9Q5qf7jtnXWjdtIMCHkxzMqSZK65ba7bIxUPB3W1XM8 4AJEVzxf6NZ7AB3smPr6Y7f3zv0V9KboPtme203yd7+lF3TVX/GzKcdLs9YKFUWQpeMc bq1Q== 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=Qu1Wfiut7OJ2NsIP33OWXJdu2Nsx4/zQgXfZHvrR/+A=; b=A+Wi9263Kk/ZTEu8F2XrKiUmCjIg1xhGjjTKa9hi+IDq82jmt4i7O6Hp2XZWSokB3Y r+St9djM9LrFFfeCJKCMT8zjKvSyaDok8L8yAUufAS7yxSuoOUUx59fZXhd/8xFkmrL6 /8wkE/vXnYd7/35QO7nkKks8bnsAxGmeFDEFkj79j7/yHGuCQx3hpEtIJwYW1aE38pex Z9UoBamwK0chYFrGCW9O7STfL+TGxAViuaE6oJ+/WtRRY7PJBdh8MihL4QwU6qwHK6Ns fYcxj50dTpOSCAkezasprIXdXw1umWu/2Avn+VIFebJXYtQrDqWuMmBO975NArw8MJqh V8PQ== X-Gm-Message-State: AOAM531qBXe9uWBtJEDzufyXAxKX7p0S0wTMzESLS8/vuA7J8B7mJCPo sJ1dT+uAdu2U9XZXo3fSnZqG3yo6mXN61O5CYo+CxiDs+NW/qaWr6xUB/NE4EmryuS9pyXp7t5y gp88lf0tSkJ/rCwjC2Xbgyt776z4q/bh66D8XPHZJqRade1cVH5V7YgUhvFU0QR8= X-Google-Smtp-Source: ABdhPJwxdKPlOuYzHKWdOEG4P8+HJfROV9OnxI0T63zhKdb0mD5FYOc7rcIXxKwquBIzTtVNlTleQlitRukbeA== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:e803:b0:150:1cb0:e0a4 with SMTP id u3-20020a170902e80300b001501cb0e0a4mr878827plg.65.1646439311615; Fri, 04 Mar 2022 16:15:11 -0800 (PST) Date: Fri, 4 Mar 2022 16:13:58 -0800 In-Reply-To: <20220305001401.20888-1-chooglen@google.com> Message-Id: <20220305001401.20888-11-chooglen@google.com> Mime-Version: 1.0 References: <20220303005727.69270-1-chooglen@google.com> <20220305001401.20888-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v4 10/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 c6df64bf6a..17dabf3d12 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 882bf097d5..16dea0ca59 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 Sat Mar 5 00:13:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12770129 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 1ABE5C433EF for ; Sat, 5 Mar 2022 00:15:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230149AbiCEAQR (ORCPT ); Fri, 4 Mar 2022 19:16:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230187AbiCEAQM (ORCPT ); Fri, 4 Mar 2022 19:16:12 -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 D93CD27D10B for ; Fri, 4 Mar 2022 16:15:13 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id t12-20020a17090a448c00b001b9cbac9c43so5544343pjg.2 for ; Fri, 04 Mar 2022 16:15:13 -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=nTv75O1QKj0WxuZ+P8y/vCHMWsMU3KY2RDJ5GuiS2jM=; b=ncSWkA3SUveHUKpEwW9PuTaXz8XgXFSmLh4pQ8BSKTEwzEGZFhJ+uQCq1qMDcLnUOy bDrSwi0wThTT8bRZxqa2CxOU8jUHD6nn4/SZQmlq3U4fV/B6u67lAW5eBtRDTMrRMmVe NHxTXFOXzIaWuNvKNKZ0ZtJIZmTvqD5k8qYQ31lmqx4CjNfJcSOt11s9EhHnQKHq3ZJV HkjXIt8D7oFmrB22rknmOXStxZSMCtiw7/H8llR8mJDb9cz87sq2dlvxVh4bCSUZFRL0 HEzrtfmXI7xRKDtC992FdYxWEIkmBO/3eOJSDYxdTdg4Uohiw6pgEna3I1p2EB+U2BJg 2T0A== 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=nTv75O1QKj0WxuZ+P8y/vCHMWsMU3KY2RDJ5GuiS2jM=; b=ENieZLm5eP7K6hP1vCknKc8F0jSN/kRzxnkD0t9X+GEsA78H5GRiOCcj/uqT2Mw5MX XsWeyhkKQND7W/Bt/Lotw9v3E2TblphaUGFoleSQUobDBHdIxKJYDbhNe1ToF9QVcCzh gyKqPCSSVEUXxB7hZu4+eemmfW4IPBffvNuhKV7bCOi+Tzuxk0UWkm479L8bPahltyef Vl7K4du460mOoYYlPvPfMU7DgAkGAjC8eT4N0JUGGu/UYgo7Y/2BhZn0iyz1/aWQg54B tsOHlokXVT/wQs3e9pk9R4MgvFD6fam4FCtOqjvmBB5EEKC/PjCb/eHeiM+8D8Xd+kSw aZYw== X-Gm-Message-State: AOAM5314PzQvnbfRavhHDfpOAzLVOyhfhq3djPf9/20ciWhUgamtVsax VxuO5F5ISrN1SVTrx8KFWfgVxTi3TV8ngCxwdEhG2869E1ds2kjO517t6At6E9fq1R5z/VaszZQ diJDGCr0Ptkam3ZkPe3hiLiJNF+wRNO34gyOtLCVFdEv8nIkGancIa8SnNUcyK4I= X-Google-Smtp-Source: ABdhPJwvwY1OWCGVP+iA+buwyHiupw+Af+5Ppp2GT4041pLYjrHoAmvGIoNmeoMJhBT2AhJjwaOSGf881KhRRQ== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:aa7:83c5:0:b0:4f6:3575:140 with SMTP id j5-20020aa783c5000000b004f635750140mr985961pfn.57.1646439313291; Fri, 04 Mar 2022 16:15:13 -0800 (PST) Date: Fri, 4 Mar 2022 16:13:59 -0800 In-Reply-To: <20220305001401.20888-1-chooglen@google.com> Message-Id: <20220305001401.20888-12-chooglen@google.com> Mime-Version: 1.0 References: <20220303005727.69270-1-chooglen@google.com> <20220305001401.20888-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v4 11/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, and since this makes the ensure-core-worktree command obsolete, remove it. As a result, the order of two operations in git-submodule.sh is reversed: 'set the value of core.worktree' now happens after the call to "git submodule--helper relative-path". This is safe - "relative-path" does not depend on the value of core.worktree. 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 17dabf3d12..296ab80bf2 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2783,17 +2783,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); @@ -2813,8 +2807,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) @@ -3041,6 +3033,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)) @@ -3459,7 +3452,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 16dea0ca59..51be7c7f7e 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -385,8 +385,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 Sat Mar 5 00:14:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12770131 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 D6239C433EF for ; Sat, 5 Mar 2022 00:15:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230192AbiCEAQX (ORCPT ); Fri, 4 Mar 2022 19:16:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230196AbiCEAQN (ORCPT ); Fri, 4 Mar 2022 19:16:13 -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 A770E27C78C for ; Fri, 4 Mar 2022 16:15:15 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id v4-20020a63f844000000b003745fd0919aso5287863pgj.20 for ; Fri, 04 Mar 2022 16:15:15 -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=FJMNIjjptwKhdPvnWIgtwk5wYY5tbTCf7M/9QblXbW0BmxFM9rBSfs5VTlw59Z/PTR GThd/VEu0sbLGZT6byHi28BGoOctl4FvZaToqn5bjGMKqpdb0KJz4gaQiZ0ZjUkNtEG4 +ni5bIbDHP3kex+86kvqOniwd9s7r83TkvLkznUc5rKfnkmIMyticXxg1TCntLNkspnW yuphL54yPLt5a72RsqJ4+yjkmiayb3TgzgrXOVK8PmmE/x6dmLFI0UL8mXFQaOhbX+qf TuvGq1meYs/TvbRLTqLluzsVubk/pJntCBwMBqZODGG1mimdx3sS0P5cnH6/96XGBTeM p7tw== 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=CNF0geW1isIsqYNQsm/+dgQRQRH9U3Sna8UgDsQesNvMLvVmgBqBVS5NKQyJam9hnd Btna/A2LG/W/gWeIHX97VMvXCS+QdgxEhtph93pe9XM7VFU6wWN0R8ouy1pUIJIPm/ST stwfcR/A0KwlqGbsQZ/Bw9yhSKbz4vugLp/cXkkXQx22tgmuN5uXHu7Jfvj4taGc6QAc WrPBZJluKrqNJtisutVyUkbFhRKNmkDs+5vBplP0wNioM40Lh2tvUUsNQejrJmVMmY0i dHwR1Fb6d3MJs27jdMWqKFIGZD9vPyYbam9C1AnD4q5hstPhXinsaypY0JUtTW8yc/rk aoRg== X-Gm-Message-State: AOAM5334MST7OyHXmUtJZnt9PO1pOYLGto95J8rZFapZ4HgSTiAewqkt ia0ULoil5Bwx2VjXpPMfRGvXPrUjLG4XlM/6tvbXdIVPZdSFL0BVV2gbprjl4UxZL9R/JdjBZFP 9MpqMRuR+UjbIeR+VvgGCrOFmka3EUVVruUcwmnB5aBEAsiTPniGHMR/HjK8//9M= X-Google-Smtp-Source: ABdhPJy7g1PDvJITIoP3lvbz/BKxi35wjLbDf4DcIrU78GFXNPL5EBIa/qla7pR2SjKXhxji2yIlQaITEehTyQ== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:90a:8e85:b0:1bc:429b:513d with SMTP id f5-20020a17090a8e8500b001bc429b513dmr13203970pjo.11.1646439315143; Fri, 04 Mar 2022 16:15:15 -0800 (PST) Date: Fri, 4 Mar 2022 16:14:00 -0800 In-Reply-To: <20220305001401.20888-1-chooglen@google.com> Message-Id: <20220305001401.20888-13-chooglen@google.com> Mime-Version: 1.0 References: <20220303005727.69270-1-chooglen@google.com> <20220305001401.20888-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v4 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 Sat Mar 5 00:14:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12770130 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 19DB9C433EF for ; Sat, 5 Mar 2022 00:15:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230179AbiCEAQT (ORCPT ); Fri, 4 Mar 2022 19:16:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230157AbiCEAQO (ORCPT ); Fri, 4 Mar 2022 19:16:14 -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 A39C427D137 for ; Fri, 4 Mar 2022 16:15:17 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id 1-20020a630c41000000b00378d9d6bd91so5299269pgm.17 for ; Fri, 04 Mar 2022 16:15:17 -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=F4JAl+Ipreodqxw+nDXd53bBQklbd5hZYaFKouK7s9R4hBmG7g2tQPMWVr5w9/kDcl OiRDZUe2EPpw/7cIg4CcFtaE7gjAg9pmaM71Xi2dORBprmmqgWYVG4jedblWDS9jpVZq pzbgIFK3DnSm5vcXmFbJQKaXkbuwgKUHIHFDJthYtD3QTBGNFY1mB25Ym0IgKJhLb0Wd TZnWuAf9n2GiYtRvoXXzxw37UlFTTKA+Kf1qHoA+ZmlCLAjgttE7pl865MnWDXW8DKLG xf3peD0dy5zpvOUwYKCbUfvTcPlf3YDka23G6bV7isoz3JxZpCksnDLdvuY2jTE72Axc C4hQ== 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=grLmZpZifPPr7rXNQKndujw6b2bcCOiF4hf9UzZRFgcYk8Iig2vzmIVlB8PYDB3EPz bV/Y4bTjJXajAlsQvxf7MjBcYgj/KKUr/UM2LvAGZOI76fNhUQJou4pT112oCk7B1qO7 oPO62mU+LniptIwBexPmqFcV0YNNNY8Xm9sokkgHEi/KljRsMGE2tQsAPa9jDPUmNJ+b uh45muOOldBplt9vjY0NGbXHx4IffGQ5127pnpB4xrwcNkYJ+MFclxxkzmZsecV8imII 6ni8MZ+YwtTrY8x6pFnoTV7+yeyrvqeT/XksU5Z2ymTyoy7m0CKqMPt0sg4s/8sNqZsB dBmQ== X-Gm-Message-State: AOAM530htWZTA392b/2hcJyDxEJSdZv0Nv2IZstLXy5hKYenAPjN3snl sXc6yiMNRlrGZcLuM6jn3Su3uFpwXj5lqbNTfA5Nk7L56bcOlS2v2HpIkC1OIVwNRSMe/ESV7UP HewoY13QBnmP6IP08BfGBg3dMIgkPCeUyHtwYiVmFvz08lsGEtJGQnJeUjdCw+7c= X-Google-Smtp-Source: ABdhPJzr013PoHMisUr4VavLCDzu8ItqM5+ApDxEsliPhDHtqc6m/NN1I+p3kKDtKeVWo7koOZiKCf90VmCyXQ== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:aa7:90d5:0:b0:4e1:307c:d94a with SMTP id k21-20020aa790d5000000b004e1307cd94amr1097622pfk.38.1646439317046; Fri, 04 Mar 2022 16:15:17 -0800 (PST) Date: Fri, 4 Mar 2022 16:14:01 -0800 In-Reply-To: <20220305001401.20888-1-chooglen@google.com> Message-Id: <20220305001401.20888-14-chooglen@google.com> Mime-Version: 1.0 References: <20220303005727.69270-1-chooglen@google.com> <20220305001401.20888-1-chooglen@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog Subject: [PATCH v4 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} \