From patchwork Tue Feb 8 08:39:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12738326 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 9C07AC433EF for ; Tue, 8 Feb 2022 08:40:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350328AbiBHIkC (ORCPT ); Tue, 8 Feb 2022 03:40:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350389AbiBHIkA (ORCPT ); Tue, 8 Feb 2022 03:40:00 -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 1AE73C03FEC1 for ; Tue, 8 Feb 2022 00:40:00 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id g14-20020a17090a7d0e00b001b8ef9f9545so950451pjl.0 for ; Tue, 08 Feb 2022 00:40: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=CB41Hx9KQblKQQyGOHxaQcsrTVonFagZUhdzStudoQs=; b=LoKWd9UeBIG6ybqdhu+FwnVvmx1YqC5rzo1GQdieT4K4KI9Ti2fb2pclzST98NY0UO bXAexBjce4VgNRC01DHpj7Mt995jYECU8lhzoL6nNhok5x4iO+njMnpeeLobADfjXXQz 0hdjMWukJr+D/uVXN36vYf1k0iBn1uzuLddt9oQ+ycYu4M0V7GhSfcBTRP954aaFd3pb E3tzXUyvLe5RDZ4ooSWkPKM2bTEAZcW5+xFrgRVlVzYfeVzNdy2eHnpYriu06dlcOtAv xuUPq/uv9AwN8lnGgP2mpGyp+K0b+1WH6hOIfDAmNDiGQgqtc/UHYEkbBH/oCish1K5k Nv8Q== 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=CB41Hx9KQblKQQyGOHxaQcsrTVonFagZUhdzStudoQs=; b=TWWcqZwxGnd5oktKfNZYXDnlCWKo2rxLy9JIb7AZkRU+4XbYc3DaCeTUeGX4NWF5/Q SlJ9Ex51Cfm/Yb+vd4q198szCM+BU1Tr6iEzQnAgMgU9sDofLv3Wan4xjR3gqP9fbaWO 3LIFi9StcmIPAdzj/EvFPxCxUTOhXF54TV9WL+ufcARUC+d7eHzqJvMCrx1ztMuJ5k0X Y25xPs5mRwDhSg8VxGKr9s0Cm5UpWfwUh1Jo8RTF1w1/c9la0P0ZlkqTAOjV2vaoczkf IHo3ByxZJsXR6kr37/Yhc96JyFYzQA301uTFuwEoNZccc5ttPL+SJzkLXi/FVs1e2nbi wuOQ== X-Gm-Message-State: AOAM533w2DfEfj5or3Tin2acB+JDgpuynHVRkl9XBtu7Uki6PS2dXSDB QAQvqwUHgljP42RdVLLTug1/pfZ7LeOFvIM0oB4uLVTXTLjl8dWWffp4LNyo+xdlMucN89em06z KstlVVqa/Io96yZsUpMX/wKWqdZndMATAqrgPkuFbPRvo9fc21+mClEiws9mbMgw= X-Google-Smtp-Source: ABdhPJyZre48T1SWsBzdU/E3XXiCzVx/ssremMdAx7LPAXEd9V3osRtOfD41pxCL8i3Pj7nd9ozYNYtOCqT+aw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a05:6a00:1914:: with SMTP id y20mr3489339pfi.39.1644309599322; Tue, 08 Feb 2022 00:39:59 -0800 (PST) Date: Tue, 8 Feb 2022 16:39:37 +0800 In-Reply-To: <20220208083952.35036-1-chooglen@google.com> Message-Id: <20220208083952.35036-2-chooglen@google.com> Mime-Version: 1.0 References: <20220208083952.35036-1-chooglen@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v6 01/16] submodule--helper: get remote names from any repository From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Christian Couder , Emily Shaffer , Jonathan Nieder , Kaartic Sivaraam , pc44800@gmail.com, Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Atharva Raykar `get_default_remote()` retrieves the name of a remote by resolving the refs from of the current repository's ref store. Thus in order to use it for retrieving the remote name of a submodule, we have to start a new subprocess which runs from the submodule directory. Let's instead introduce a function called `repo_get_default_remote()` which takes any repository object and retrieves the remote accordingly. `get_default_remote()` is then defined as a call to `repo_get_default_remote()` with 'the_repository' passed to it. Now that we have `repo_get_default_remote()`, we no longer have to start a subprocess that called `submodule--helper get-default-remote` from within the submodule directory. So let's make a function called `get_default_remote_submodule()` which takes a submodule path, and returns the default remote for that submodule, all within the same process. We can now use this function to save an unnecessary subprocess spawn in `sync_submodule()`, and also in the next patch, which will require this functionality. Mentored-by: Christian Couder Mentored-by: Shourya Shukla Helped-by: Glen Choo Signed-off-by: Atharva Raykar Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- builtin/submodule--helper.c | 39 +++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index c5d3fc3817..4c7c1e1432 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -29,11 +29,14 @@ typedef void (*each_submodule_fn)(const struct cache_entry *list_item, void *cb_data); -static char *get_default_remote(void) +static char *repo_get_default_remote(struct repository *repo) { char *dest = NULL, *ret; struct strbuf sb = STRBUF_INIT; - const char *refname = resolve_ref_unsafe("HEAD", 0, NULL, NULL); + struct ref_store *store = get_main_ref_store(repo); + int ignore_errno; + const char *refname = refs_resolve_ref_unsafe(store, "HEAD", 0, NULL, + NULL, &ignore_errno); if (!refname) die(_("No such ref: %s"), "HEAD"); @@ -46,7 +49,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; @@ -55,6 +58,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; @@ -1341,9 +1357,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)) @@ -1382,21 +1397,15 @@ static void sync_submodule(const char *path, const char *prefix, if (!is_submodule_populated_gently(path, NULL)) goto cleanup; - prepare_submodule_repo_env(&cp.env_array); - cp.git_cmd = 1; - cp.dir = path; - strvec_pushl(&cp.args, "submodule--helper", - "print-default-remote", NULL); - strbuf_reset(&sb); - if (capture_command(&cp, &sb, 0)) + default_remote = get_default_remote_submodule(path); + if (!default_remote) die(_("failed to get the default remote for submodule '%s'"), path); - strbuf_strip_suffix(&sb, "\n"); - remote_key = xstrfmt("remote.%s.url", sb.buf); + remote_key = xstrfmt("remote.%s.url", default_remote); + free(default_remote); - strbuf_reset(&sb); submodule_to_gitdir(&sb, path); strbuf_addstr(&sb, "/config"); From patchwork Tue Feb 8 08:39:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12738327 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 E43B1C433F5 for ; Tue, 8 Feb 2022 08:40:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350666AbiBHIkN (ORCPT ); Tue, 8 Feb 2022 03:40:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348463AbiBHIkD (ORCPT ); Tue, 8 Feb 2022 03:40:03 -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 ACE9EC03FEC0 for ; Tue, 8 Feb 2022 00:40:02 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id z20-20020aa791d4000000b004bd024eaf19so9247487pfa.16 for ; Tue, 08 Feb 2022 00:40: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=sPmqUnovKFAKLuQYhu1Sg3pAOs7Z4qVb4uilqbLBvJ8=; b=VoFoCBBKW7qgLZWsFGwsQoeVckorp1iB1bXPJe1ntKq08gUisEM05M3rP64h1ndCqo pXXk5Xs+7WWy2FWorQqitQUFwuGEQ7//QqJJBRlLdSRLOwAUBzRa6uSLCl3QaOSscUAo cuFu4dGvAyU0EftvOpzIhHnPB27MmvQM4pvBd9BI5QzwENNQHeRyGRMrCcUJr2IEVKdY 7qyIOOsm6Pglep8JLfvBDS87HLDQbD4vsureD1QYFpoZVXjblt6RPa73NoQKQUrxCvKo QlulrF3BGN1i3HBl9dpflcT0WT7zBL2xCiKHMUZN/Zg/nfFXJIGRi/Zfd+oOzWOdiEKm MX/w== 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=sPmqUnovKFAKLuQYhu1Sg3pAOs7Z4qVb4uilqbLBvJ8=; b=o8dGF7SNfMnmazEGavVnFvpa60agR1mvhB1HX0kNnWIiIPM6t4j3DerifXmJWvgQNY 1V5oldtRLjTk6oyZaRLCQYHwtYMNlgGIMZVD8taesG+1PKrLcr3vQQVxa9k35dHE6PKD HEJA6toic9YKb4oaRV23c22tyP88W4oFPB9bB7yugSyC1NwIuXrdNExqHF7cCrNIU6q+ sWQRdRrC40WMtKtJm+9S026RK6dek2I/whHvdbBnxUl1OWwl8GJDGVvLI3AhtzTw9kGP +3yfum7CA2zbZ1z4lo/cbc1fV702t2rf8Sgm55o4fSTrbhcRpFA3v5q/zrjjGAkiP8kw XUyg== X-Gm-Message-State: AOAM532w55QgitYKK3gU0RpE28Olr9/0iy8/wr+Yj1fQx37Z2az5VUaz hTfaZtq87oEuY9q1EOc5NrnNylJ1EPs7hcSRqJCJ9nYr5xR5Ltelthoy3EUZ7v2lNXTRzVtLhgj yfoY/yC3Dr+5MwkxcPBYF0jwlpJJcPmh0kt3J2b9Fmk6Lzx3v5FF48tQTKzKosu8= X-Google-Smtp-Source: ABdhPJxLCbDdEPwuYxFWjlLCBjl5Bcdui3n4Y+pof/lp2+iaXcS3WfNIhlnxnhX16LM1yyz6pU0HN0fP045rfQ== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:c192:: with SMTP id d18mr3334281pld.149.1644309601988; Tue, 08 Feb 2022 00:40:01 -0800 (PST) Date: Tue, 8 Feb 2022 16:39:38 +0800 In-Reply-To: <20220208083952.35036-1-chooglen@google.com> Message-Id: <20220208083952.35036-3-chooglen@google.com> Mime-Version: 1.0 References: <20220208083952.35036-1-chooglen@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v6 02/16] submodule--helper: refactor get_submodule_displaypath() From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Christian Couder , Emily Shaffer , Jonathan Nieder , Kaartic Sivaraam , pc44800@gmail.com, Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Atharva Raykar We create a function called `do_get_submodule_displaypath()` that generates the display path required by several submodule functions, and takes a custom superprefix parameter, instead of reading it from the environment. We then redefine the existing `get_submodule_displaypath()` function as a call to this new function, where the superprefix is obtained from the environment. Mentored-by: Christian Couder Mentored-by: Shourya Shukla Signed-off-by: Atharva Raykar Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- builtin/submodule--helper.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 4c7c1e1432..5efceb9d46 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -261,11 +261,8 @@ static int resolve_relative_url_test(int argc, const char **argv, const char *pr return 0; } -/* the result should be freed by the caller. */ -static char *get_submodule_displaypath(const char *path, const char *prefix) +static char *do_get_submodule_displaypath(const char *path, const char *prefix, const char *super_prefix) { - const char *super_prefix = get_super_prefix(); - if (prefix && super_prefix) { BUG("cannot have prefix '%s' and superprefix '%s'", prefix, super_prefix); @@ -281,6 +278,13 @@ static char *get_submodule_displaypath(const char *path, const char *prefix) } } +/* the result should be freed by the caller. */ +static char *get_submodule_displaypath(const char *path, const char *prefix) +{ + const char *super_prefix = get_super_prefix(); + return do_get_submodule_displaypath(path, prefix, super_prefix); +} + static char *compute_rev_name(const char *sub_path, const char* object_id) { struct strbuf sb = STRBUF_INIT; From patchwork Tue Feb 8 08:39:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12738329 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 A76CEC433EF for ; Tue, 8 Feb 2022 08:40:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350668AbiBHIkV (ORCPT ); Tue, 8 Feb 2022 03:40:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350480AbiBHIkM (ORCPT ); Tue, 8 Feb 2022 03:40:12 -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 DF397C03FECA for ; Tue, 8 Feb 2022 00:40:04 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id d5-20020a623605000000b004e01ccd08abso735088pfa.10 for ; Tue, 08 Feb 2022 00:40: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=d5OdSxOJpSIJ8Imz8Plwa6pJa7oLeJV7xRwU926Etao=; b=JzCr4ouGq2rmGB3cJ8DTjSEBlfkxOHmgbZ/kLv5OU5d0aeZAfZ7FVYqWtEuPdIOO1W UIgyAHpYJcRZGiP9PkdwkJXFAo8/ewZYMa7cKwFbRriF/ITswswFp+g0SibfjKM6MvB6 LMRFaxSrG/S+5BGDTGdqxXW0gXl96oT6SaqjSXKa4adEPdLJ4esf9IW0AiwZhloefovD wlFB0yQCb23GpAypih7PRtpi2GWZFO76SPzw3buwGkYdTBI2TATIw9bPv8X8eIuLirz4 5XcnZn4jGCdG3nFvCVdF6Hprz5VHPhSsFan5DLgRWd5MkPcmyvVeHs0Jd7Jd2yUnO4R3 ID+w== 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=d5OdSxOJpSIJ8Imz8Plwa6pJa7oLeJV7xRwU926Etao=; b=1uKbI3/BmKe/lJ3sZN5Rq4gKWZ86XP+7wkDz4d1dQ9PVAqM/uhVNEFKxDmmuhoN+SO OF0wnq83SqU3UuYrWAwskkB5VWW9ygTx5wRsUwNTLh3Y5iWVKjdu7B/wJk1hqpCj6Fz7 mtcMa3JJVYHkkzVs7EsiwBndkT7cAPdP7xX9796cj+D4zMduMq+qEqAR4/GyRidzgpBQ 5NN60hiEwUZGwdP5mMcQfgDCiIJwtBuyF++oA9DyOZcy4i2+nydRq2/Jt13fZ1apWGOU 6Y1Yy+I/YlQDo3+wo3U875MfEGJxFt2PE8HCM7AI/tb4cSWhN9jf0OSKK91ydxdO3/du L8Gg== X-Gm-Message-State: AOAM532+ZY8n64sBntDwBEXdIFyu4d2DAlYCHo61Pu+A08mGwmjmLV6k uCKOcE8kCxKF8a48rRp0Ws2UNYKYsN6D6SqxD4tNAyKF4PKtg6iOhP8O3lA92oaXu0I/75Ad7nY hIzB4UDrZ/Ki4oj8eBcCWAqneHXeGCa2c8J1Txs/aSrutV8zFNYvhPsDNXNOotrU= X-Google-Smtp-Source: ABdhPJzSpfvrXHj+tmEqGfJxrEzbQkwek8Xb/HkJu4UQP2MltN12VgGzpWuaeC8mbln98puMYbhl3yqSiXymRA== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a63:4717:: with SMTP id u23mr2729402pga.74.1644309604179; Tue, 08 Feb 2022 00:40:04 -0800 (PST) Date: Tue, 8 Feb 2022 16:39:39 +0800 In-Reply-To: <20220208083952.35036-1-chooglen@google.com> Message-Id: <20220208083952.35036-4-chooglen@google.com> Mime-Version: 1.0 References: <20220208083952.35036-1-chooglen@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v6 03/16] submodule--helper: allow setting superprefix for init_submodule() From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Christian Couder , Emily Shaffer , Jonathan Nieder , Kaartic Sivaraam , pc44800@gmail.com, Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " 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 5efceb9d46..09cda67c1e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -606,18 +606,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); @@ -691,7 +695,7 @@ static void init_submodule(const char *path, const char *prefix, static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data) { struct init_cb *info = cb_data; - init_submodule(list_item->name, info->prefix, info->flags); + init_submodule(list_item->name, info->prefix, info->superprefix, info->flags); } static int module_init(int argc, const char **argv, const char *prefix) From patchwork Tue Feb 8 08:39:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12738328 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 942D2C433EF for ; Tue, 8 Feb 2022 08:40:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350563AbiBHIkQ (ORCPT ); Tue, 8 Feb 2022 03:40:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350595AbiBHIkM (ORCPT ); Tue, 8 Feb 2022 03:40: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 2A6A3C03FED2 for ; Tue, 8 Feb 2022 00:40:07 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id iy10-20020a17090b16ca00b001b8a7ed5b2cso1113652pjb.7 for ; Tue, 08 Feb 2022 00:40: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:content-transfer-encoding; bh=1q5oLNtDReJ7p0+YX28Bu8psSH2hz+Z8tqtHbnD/3Rs=; b=N0L+4fZaQzxGZJFFUXkJe/7QcJ0ZwkeltEyAuEDBoA2YeLLA3l6j0eTqVA2FpAGvQK 3m3c3WLYVA32A2cFe+TIiO8Al2WWT3SKxVSWWgOiTHiaB8KP/5UnOsHxPIjtdW/6aGXQ nRoDLtJxALolApmlYDKOGFpnMwDxftU3gL3Nd4ACXtBmq5oidcvcT8IsToUXUwwKdmbK 4II6CLUCFOS7TKVveF4wAF63p3T9kSwuyADCGSABODc8z7GZ/yNACiPq3Y6l3N185X+v 7750PghCae6C5zPvyfRtW/zBuB8PX+uwDWWqQ6NPLFvN41BFIKP7qFZfiLJUnGsfNxrd NtUA== 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=1q5oLNtDReJ7p0+YX28Bu8psSH2hz+Z8tqtHbnD/3Rs=; b=0FkGjqSIQd7n8EGBsmbu9lueZ4ILlreVfmujPi/9opd6AB/Ff2u9Ts0h995fI8Y/oA 5hF1SHHgobbZeBsNCOqV8RyrG5thRaq2pko6eKmPy0L+lXfWYH2RhMZ3y+1QffssN7eu 0Pc3+mVDDn4HIp6AZx/8HkH3cTwOAik7Zmlf1QfeIsOP40JrWJkwxMkK0bqg++4IGxtC bHW9BB9Fg3d9dg9O1s2t75mlMvgOOPxd+LCdzE8lzACEvDvVdFpArszmAVJApmrf1BQT IHY4vqLQomrov/zQmL2yaSgCXWe+MNlmP/Cr+lyLfoxF/bm66p/J7gXZMlc/TcZCmJfB 3bvA== X-Gm-Message-State: AOAM530K9Y1wn5jh+ToMtHEGzfIWIpt29RJEoRCVfn+WBC+nktYUPqz+ h4u2Iu2xWFVDRqV2HEWQLsuh24/W9eHEZVx+FcrYwBP4OXjIqanQ6bUpVrFSKEYbJxziYfAK8SJ wMMmjv+osaw2rfL4j7zdPdaTUcp1AO2aOht0Ax0K1Otb80CSSdhA73tLqq5tUZV0= X-Google-Smtp-Source: ABdhPJy+2b2IXxcqMQn0AO/QPlMioH3xeS5W62GspCykCEn+GUdkE6d02H+V4NxXUXG1/5fiHNnyGddPn68QPA== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:7e0a:: with SMTP id b10mr3349567plm.17.1644309606470; Tue, 08 Feb 2022 00:40:06 -0800 (PST) Date: Tue, 8 Feb 2022 16:39:40 +0800 In-Reply-To: <20220208083952.35036-1-chooglen@google.com> Message-Id: <20220208083952.35036-5-chooglen@google.com> Mime-Version: 1.0 References: <20220208083952.35036-1-chooglen@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v6 04/16] submodule--helper: run update using child process struct From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Christian Couder , Emily Shaffer , Jonathan Nieder , Kaartic Sivaraam , pc44800@gmail.com, Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Atharva Raykar We switch to using the run-command API function that takes a 'struct child process', since we are using a lot of the options. This will also make it simple to switch over to using 'capture_command()' when we start handling the output of the command completely in C. 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 | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 09cda67c1e..db71e6f4ec 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2344,47 +2344,45 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, str static int run_update_command(struct update_data *ud, int subforce) { - struct strvec args = STRVEC_INIT; - struct strvec child_env = STRVEC_INIT; + struct child_process cp = CHILD_PROCESS_INIT; char *oid = oid_to_hex(&ud->oid); int must_die_on_failure = 0; - int git_cmd; switch (ud->update_strategy.type) { case SM_UPDATE_CHECKOUT: - git_cmd = 1; - strvec_pushl(&args, "checkout", "-q", NULL); + cp.git_cmd = 1; + strvec_pushl(&cp.args, "checkout", "-q", NULL); if (subforce) - strvec_push(&args, "-f"); + strvec_push(&cp.args, "-f"); break; case SM_UPDATE_REBASE: - git_cmd = 1; - strvec_push(&args, "rebase"); + cp.git_cmd = 1; + strvec_push(&cp.args, "rebase"); if (ud->quiet) - strvec_push(&args, "--quiet"); + strvec_push(&cp.args, "--quiet"); must_die_on_failure = 1; break; case SM_UPDATE_MERGE: - git_cmd = 1; - strvec_push(&args, "merge"); + cp.git_cmd = 1; + strvec_push(&cp.args, "merge"); if (ud->quiet) - strvec_push(&args, "--quiet"); + strvec_push(&cp.args, "--quiet"); must_die_on_failure = 1; break; case SM_UPDATE_COMMAND: - git_cmd = 0; - strvec_push(&args, ud->update_strategy.command); + cp.use_shell = 1; + strvec_push(&cp.args, ud->update_strategy.command); must_die_on_failure = 1; break; default: BUG("unexpected update strategy type: %s", submodule_strategy_to_string(&ud->update_strategy)); } - strvec_push(&args, oid); + strvec_push(&cp.args, oid); - prepare_submodule_repo_env(&child_env); - if (run_command_v_opt_cd_env(args.v, git_cmd ? RUN_GIT_CMD : RUN_USING_SHELL, - ud->sm_path, child_env.v)) { + cp.dir = xstrdup(ud->sm_path); + prepare_submodule_repo_env(&cp.env_array); + if (run_command(&cp)) { switch (ud->update_strategy.type) { case SM_UPDATE_CHECKOUT: printf(_("Unable to checkout '%s' in submodule path '%s'"), From patchwork Tue Feb 8 08:39:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12738330 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 C444DC433F5 for ; Tue, 8 Feb 2022 08:40:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350688AbiBHIkX (ORCPT ); Tue, 8 Feb 2022 03:40:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350652AbiBHIkN (ORCPT ); Tue, 8 Feb 2022 03:40:13 -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 93772C03FEDB for ; Tue, 8 Feb 2022 00:40:09 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id z3-20020a170903408300b0014d891103aaso1941585plc.0 for ; Tue, 08 Feb 2022 00:40: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:content-transfer-encoding; bh=EN32OlSdIPLW/h0ox/yybskI+VjrxA2w7zI+99muzsA=; b=a6DouT54OftLNNSO0Av49QOEDTtPxqSo03HAbbjWT33oSOWBOyCnfEommhcim5mAXG 6EMLH6308rbPrJFMjV1drgcL/JWffcPXrTAR1GU/6ipkuOKE6iAJKnmdA12+t0ap1usX 3z+Kww+UzRfxGMlTWgd7tRwL1hp8ZU3vIJrQT3kq660pYHF7aZeZmPpYXeefBBfTYu/n XLq8+XXaZZIsLVDrjBvfoRMWzRRHD9dHyhNX7lmwpjViUjR4DLnpY8h+0ZgfSh0umFVg w7rXY8db5hIp+Oye6SMIkOPcifgyXKUUrwIQVTqARVjwdPA7dej3GVRZFAX4ALpUCNGW RN5g== 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=EN32OlSdIPLW/h0ox/yybskI+VjrxA2w7zI+99muzsA=; b=FNczJalXIOa3VqVYtRef/FC1hGF06iBBvLT6siIXwfTJeMaCIQy6OW0Iyu26LkAkfC 2JKquqLLRjsBsJqDoivnO3v3WcoQeNd4LwL05iH0s7pUPppHnAX3i9OmywT8Nea2Mwzd RPYkhHwfaPNFuXeNZFoRfLsVPY/KiIpexAOviGyYIAF+z453BS2bnBPfXVI59XM7anq2 KoDwRmueEtlvns/JGlbCA7iMSr0Cb+zyUfuENtJ0vPk337y3MMjAZxhfY5Zs8I8ZZk2n SEhBHi00mOjaIQdueCRNngCd4yHasO2iSxnr8JD9nwzXIu+zOXIMSHoARYGL5oI4p+52 Gj6w== X-Gm-Message-State: AOAM532RHAXs0/jEH2wJJTl8LVFEJEpr/5/5LQoNUt9Z22kW0xOFcx3N 9YJJJQma/OWYmPWcD1AJeHwtHeHGc6AuNt+vQxMexYUDZTcUDhoi81oEVRqz+8udsLCIOeWYqrr 9uXeQQbt238n6LLeAFddL18k3x3Wv0BJLAbc3bOnz8u6Uu5aKyOriCAnzLZCbarc= X-Google-Smtp-Source: ABdhPJxau1HTrGeZq5Wj9Ui9dVtRCFalVxgUpnMkLIyRw/Ym5uBfIawBZYss4Th/Vu8KqV29hiiwFttbputkDw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a05:6a00:10c1:: with SMTP id d1mr3392382pfu.84.1644309608880; Tue, 08 Feb 2022 00:40:08 -0800 (PST) Date: Tue, 8 Feb 2022 16:39:41 +0800 In-Reply-To: <20220208083952.35036-1-chooglen@google.com> Message-Id: <20220208083952.35036-6-chooglen@google.com> Mime-Version: 1.0 References: <20220208083952.35036-1-chooglen@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v6 05/16] builtin/submodule--helper.c: reformat designated initializers From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Christian Couder , Emily Shaffer , Jonathan Nieder , Kaartic Sivaraam , pc44800@gmail.com, Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Atharva Raykar The second hunk here will make a subsequent commit's diff smaller, and let's do the first and third hunks while we're at it so that we consistently format all of these. Signed-off-by: Atharva Raykar Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- builtin/submodule--helper.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index db71e6f4ec..9f79bdf4d5 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1654,7 +1654,10 @@ struct module_clone_data { unsigned int require_init: 1; int single_branch; }; -#define MODULE_CLONE_DATA_INIT { .reference = STRING_LIST_INIT_NODUP, .single_branch = -1 } +#define MODULE_CLONE_DATA_INIT { \ + .reference = STRING_LIST_INIT_NODUP, \ + .single_branch = -1, \ +} struct submodule_alternate_setup { const char *submodule_name; @@ -2047,7 +2050,9 @@ struct update_data { unsigned int nofetch: 1; unsigned int just_cloned: 1; }; -#define UPDATE_DATA_INIT { .update_strategy = SUBMODULE_UPDATE_STRATEGY_INIT } +#define UPDATE_DATA_INIT { \ + .update_strategy = SUBMODULE_UPDATE_STRATEGY_INIT, \ +} static void next_submodule_warn_missing(struct submodule_update_clone *suc, struct strbuf *out, const char *displaypath) @@ -3013,7 +3018,9 @@ struct add_data { unsigned int progress: 1; unsigned int dissociate: 1; }; -#define ADD_DATA_INIT { .depth = -1 } +#define ADD_DATA_INIT { \ + .depth = -1, \ +} static void append_fetch_remotes(struct strbuf *msg, const char *git_dir_path) { From patchwork Tue Feb 8 08:39:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12738334 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 166A9C433F5 for ; Tue, 8 Feb 2022 08:40:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348670AbiBHIkb (ORCPT ); Tue, 8 Feb 2022 03:40:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350665AbiBHIkN (ORCPT ); Tue, 8 Feb 2022 03:40:13 -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 D85A5C03FEDF for ; Tue, 8 Feb 2022 00:40:11 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id q4-20020a170902f78400b0014d57696618so3277303pln.20 for ; Tue, 08 Feb 2022 00:40:11 -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=KtVdYHgHYdpKDN+uE8Vjf4NJtM9JXHAqmyaEt4fA0kc=; b=h+Q35Z0AvavTBY9Ml66zidVjfKs2zonSqbp4dXgKwHMjNWlz90g08AMiiQwYJ6+llT LDt62siP+7dKnUYQ8KZvFcyrr7ffNR43WvCoHZ8z0DQHrRj1F3BzZxUs//iXYp60RaDK 4vn4kUq3xfkY4szTHjYY3pJwes5b7PCFxgkW8/5kYuFvhwGLy6Ze8aTUgtemKOQOTkqQ xDyMjAcm0kBtAeEvGK+gRUXLHysDydNUeq7uSqx9WvHlFqx3RFxouuMMC86VkhB6cQci tI4EDaacTYEYuPVizoLI/GRjWrWFKNSGmX5CznfHuHV04xgIBJzf3yDcYqsHS355/lcm q+lw== 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=KtVdYHgHYdpKDN+uE8Vjf4NJtM9JXHAqmyaEt4fA0kc=; b=2iJH8fYiahx1J+y/CQplFOrkGIyfD/XSGz6Zj5A2MMPF1FcIS+/ezq4cMGhsF5vdnk MAAaRX71r0hgFqTaMZerOAzjmPWxsG6CnqlUY1dINKZqy1zQhKRXl6YnJcJ56+wZrLWR Wrf8J8TDLgBPisW55BzPr/gmiLJgWqW8zlZLRCE1imIhb2OgswVqW6Zz44O2PSCiKkmm 11sMVsfymIENvDz7TfWR6Qh4he40SXtj9KCeldo7y4CB13Vnmr+5JQEdLoWk7OLkJvzC cONlIVo/AQqWBjWSwq2O5rPSwA9nMK5ZSmrBC92/8vG1Klaty/X4zYk7S2xccErDBiXa 5ohg== X-Gm-Message-State: AOAM532KMvO4VRRf2GoaResp5OdBLkmmFjWKyR3/jPDQF0TTwQI6iIuX tYahxfEkEposRx2DSdMjwR2lzUf13keYH5hjok1cYYva4eHfsn2p3YPsytqzDOJ/d/wJPtXoiYu JUtjKeWx5pDQU89IT14UfbULaPxSjFZ1AZLIV0Ot5Fc4k+T4phBl/XKCMPmHOfvA= X-Google-Smtp-Source: ABdhPJweeAAxgDhemkl6CN7GeJHUQeSBatP4bemcHT93akyYrxrhPMZXcf2Tl1QERotVFaka35Cy718P6HYlgQ== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:ec83:: with SMTP id x3mr3609219plg.153.1644309611275; Tue, 08 Feb 2022 00:40:11 -0800 (PST) Date: Tue, 8 Feb 2022 16:39:42 +0800 In-Reply-To: <20220208083952.35036-1-chooglen@google.com> Message-Id: <20220208083952.35036-7-chooglen@google.com> Mime-Version: 1.0 References: <20220208083952.35036-1-chooglen@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v6 06/16] builtin/submodule--helper.c: rename option variables to "opt" From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Christian Couder , Emily Shaffer , Jonathan Nieder , Kaartic Sivaraam , pc44800@gmail.com, Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ævar Arnfjörð Bjarmason Rename the "suc" variable in update_clone() to "opt", and do the same for the "update_data" variable in run_update_procedure(). The only reason for this change is to make the subsequent commit's diff smaller, by doing this rename we can "anchor" the diff better, as it "borrow" most of the options declared here as-is as far as the diff rename detection is concerned. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- builtin/submodule--helper.c | 74 ++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 9f79bdf4d5..c2d4fd0347 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2517,36 +2517,36 @@ static int update_clone(int argc, const char **argv, const char *prefix) { const char *update = NULL; struct pathspec pathspec; - struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT; + struct submodule_update_clone opt = SUBMODULE_UPDATE_CLONE_INIT; struct option module_update_clone_options[] = { OPT_STRING(0, "prefix", &prefix, N_("path"), N_("path into the working tree")), - OPT_STRING(0, "recursive-prefix", &suc.recursive_prefix, + OPT_STRING(0, "recursive-prefix", &opt.recursive_prefix, N_("path"), N_("path into the working tree, across nested " "submodule boundaries")), OPT_STRING(0, "update", &update, N_("string"), N_("rebase, merge, checkout or none")), - OPT_STRING_LIST(0, "reference", &suc.references, N_("repo"), + OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"), N_("reference repository")), - OPT_BOOL(0, "dissociate", &suc.dissociate, + OPT_BOOL(0, "dissociate", &opt.dissociate, N_("use --reference only while cloning")), - OPT_STRING(0, "depth", &suc.depth, "", + OPT_STRING(0, "depth", &opt.depth, "", N_("create a shallow clone truncated to the " "specified number of revisions")), - OPT_INTEGER('j', "jobs", &suc.max_jobs, + OPT_INTEGER('j', "jobs", &opt.max_jobs, N_("parallel jobs")), - OPT_BOOL(0, "recommend-shallow", &suc.recommend_shallow, + OPT_BOOL(0, "recommend-shallow", &opt.recommend_shallow, N_("whether the initial clone should follow the shallow recommendation")), - OPT__QUIET(&suc.quiet, N_("don't print cloning progress")), - OPT_BOOL(0, "progress", &suc.progress, + OPT__QUIET(&opt.quiet, N_("don't print cloning progress")), + OPT_BOOL(0, "progress", &opt.progress, N_("force cloning progress")), - OPT_BOOL(0, "require-init", &suc.require_init, + OPT_BOOL(0, "require-init", &opt.require_init, N_("disallow cloning into non-empty directory")), - OPT_BOOL(0, "single-branch", &suc.single_branch, + OPT_BOOL(0, "single-branch", &opt.single_branch, N_("clone only one branch, HEAD or --branch")), OPT_END() }; @@ -2555,32 +2555,32 @@ static int update_clone(int argc, const char **argv, const char *prefix) N_("git submodule--helper update-clone [--prefix=] [...]"), NULL }; - suc.prefix = prefix; + opt.prefix = prefix; - update_clone_config_from_gitmodules(&suc.max_jobs); - git_config(git_update_clone_config, &suc.max_jobs); + update_clone_config_from_gitmodules(&opt.max_jobs); + git_config(git_update_clone_config, &opt.max_jobs); argc = parse_options(argc, argv, prefix, module_update_clone_options, git_submodule_helper_usage, 0); if (update) - if (parse_submodule_update_strategy(update, &suc.update) < 0) + if (parse_submodule_update_strategy(update, &opt.update) < 0) die(_("bad value for update parameter")); - if (module_list_compute(argc, argv, prefix, &pathspec, &suc.list) < 0) + if (module_list_compute(argc, argv, prefix, &pathspec, &opt.list) < 0) return 1; if (pathspec.nr) - suc.warn_if_uninitialized = 1; + opt.warn_if_uninitialized = 1; - return update_submodules(&suc); + return update_submodules(&opt); } 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 update_data opt = UPDATE_DATA_INIT; struct option options[] = { OPT__QUIET(&quiet, N_("suppress output for update by rebase or merge")), @@ -2589,20 +2589,20 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix) N_("don't fetch new objects from the remote site")), OPT_BOOL(0, "just-cloned", &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_INTEGER(0, "depth", &opt.depth, N_("depth for shallow fetch")), OPT_STRING(0, "prefix", &prefix, N_("path"), N_("path into the working tree")), OPT_STRING(0, "update", &update, N_("string"), N_("rebase, merge, checkout or none")), - OPT_STRING(0, "recursive-prefix", &update_data.recursive_prefix, N_("path"), + OPT_STRING(0, "recursive-prefix", &opt.recursive_prefix, N_("path"), N_("path into the working tree, across nested " "submodule boundaries")), - OPT_CALLBACK_F(0, "oid", &update_data.oid, N_("sha1"), + OPT_CALLBACK_F(0, "oid", &opt.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"), + OPT_CALLBACK_F(0, "suboid", &opt.suboid, N_("subsha1"), N_("SHA1 of submodule's HEAD"), PARSE_OPT_NONEG, parse_opt_object_id), OPT_END() @@ -2618,27 +2618,27 @@ 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]; + opt.force = !!force; + opt.quiet = !!quiet; + opt.nofetch = !!nofetch; + opt.just_cloned = !!just_cloned; + opt.sm_path = argv[0]; - if (update_data.recursive_prefix) - prefixed_path = xstrfmt("%s%s", update_data.recursive_prefix, update_data.sm_path); + if (opt.recursive_prefix) + prefixed_path = xstrfmt("%s%s", opt.recursive_prefix, opt.sm_path); else - prefixed_path = xstrdup(update_data.sm_path); + prefixed_path = xstrdup(opt.sm_path); - update_data.displaypath = get_submodule_displaypath(prefixed_path, prefix); + opt.displaypath = get_submodule_displaypath(prefixed_path, prefix); - determine_submodule_update_strategy(the_repository, update_data.just_cloned, - update_data.sm_path, update, - &update_data.update_strategy); + determine_submodule_update_strategy(the_repository, opt.just_cloned, + opt.sm_path, update, + &opt.update_strategy); free(prefixed_path); - if (!oideq(&update_data.oid, &update_data.suboid) || update_data.force) - return do_run_update_procedure(&update_data); + if (!oideq(&opt.oid, &opt.suboid) || opt.force) + return do_run_update_procedure(&opt); return 3; } From patchwork Tue Feb 8 08:39:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12738331 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 C0C2EC433EF for ; Tue, 8 Feb 2022 08:40:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350470AbiBHIkY (ORCPT ); Tue, 8 Feb 2022 03:40:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350499AbiBHIkP (ORCPT ); Tue, 8 Feb 2022 03:40:15 -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 BA63FC03FEC1 for ; Tue, 8 Feb 2022 00:40:14 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id n4-20020a17090ade8400b001b8bb511c3bso4417576pjv.7 for ; Tue, 08 Feb 2022 00:40:14 -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=puu5AcCYsaaMCyP0Miw6o/BQAKwD83xVxXobDV0qE4M=; b=rAkicTeYXxRkr1ZY4gqppCfDT18V7xofK13eEHPKHLe8/ObuT3tNs+FeGvaEEkm52d 42pfdRsRkohkhRDf2ULxLDEhLx0J51RA17OOyie+6BKHyUgxNbGjSuLbEaSNRZNaqjhl 5Ymb7WbLFQNtk6nNf3K/EGiWquQB3tBURy1jo7W9djTsi6Ye7Ecwr1TIiVLm5ZpORP2h XEd8uhZlV5hqNJuLFyRdzI2lr2YeUDrGEDeoW7gyJhPSZDyoOR/AsKXctcRlBqlWeKd7 b+im9iBPXxsSaKJwxwa14Y4YjchoEnO1zVpqgsova2qZpwCFV1hs7mTo5TXM1uNRcJa7 jCTA== 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=puu5AcCYsaaMCyP0Miw6o/BQAKwD83xVxXobDV0qE4M=; b=EH8mx7JcViUpF9x9e3aEwCpxQ8i5RicYPJqvr3rXeM78BrpVgtZlZ8udVRF3DafgO9 1cgGOA/BbdyBzciHviShbTZUTgczzSmBXLqN8Mpb5x6wMu7ncqJ3rte22QdnFLmYFmUM ldXgiS8sT9ulIIsYA2r1pVGdkgADu3sPd0ULmArV3Kpc7nUvAs1xvFY5LuMtS8VKctsQ kyHACOal7aVP1CXqdkcB5qUUwCngDcUuOC6Pk15wVQode57o7Q2lzUaqnyZS9jp9umio ELnERx/NXvZFpiJeNg9iwEfgDe3sMjj+t3P+EfdazVc5ZQqKrTZ0nL/8yWRevWA59Xps fDMQ== X-Gm-Message-State: AOAM531LuPJNoUDikbgtdXXwpnpKI7/4qxbNMuTa0/RWXZ/Ovy/h7y9W 70YmHzwlSXu11Sr5piqVHoZP9ALHvUSRwqC71UEGxt3F+cerB2g6YSwzbtPCxaUf/9UcI9W8S9P XksoG968mGT192yGnd6DuQqZJCKXbrwV7xKtZs0EQ9iF8WAg42ByLlf+zEaX85WU= X-Google-Smtp-Source: ABdhPJzmYXol8wGBfasXrn8AcU5gJ4+8ne6tLLiWPavkwzxjkwkuffYx8yVJizSs254fMHqr0zNLdrIgZR4ymg== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a05:6a00:134b:: with SMTP id k11mr3480040pfu.33.1644309613702; Tue, 08 Feb 2022 00:40:13 -0800 (PST) Date: Tue, 8 Feb 2022 16:39:43 +0800 In-Reply-To: <20220208083952.35036-1-chooglen@google.com> Message-Id: <20220208083952.35036-8-chooglen@google.com> Mime-Version: 1.0 References: <20220208083952.35036-1-chooglen@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v6 07/16] 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 , Christian Couder , Emily Shaffer , Jonathan Nieder , Kaartic Sivaraam , pc44800@gmail.com, Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " 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. This will also make a subsequent large commit's diff smaller. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- 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 c2d4fd0347..4a0890954e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2045,10 +2045,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 opt = 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(&opt.quiet, + N_("suppress output for update by rebase or merge")), + OPT__FORCE(&opt.force, N_("force checkout updates"), + 0), + OPT_BOOL('N', "no-fetch", &opt.nofetch, N_("don't fetch new objects from the remote site")), - OPT_BOOL(0, "just-cloned", &just_cloned, + OPT_BOOL(0, "just-cloned", &opt.just_cloned, N_("overrides update mode in case the repository is a fresh clone")), OPT_INTEGER(0, "depth", &opt.depth, N_("depth for shallow fetch")), OPT_STRING(0, "prefix", &prefix, @@ -2618,10 +2619,6 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix) if (argc != 1) usage_with_options(usage, options); - opt.force = !!force; - opt.quiet = !!quiet; - opt.nofetch = !!nofetch; - opt.just_cloned = !!just_cloned; opt.sm_path = argv[0]; if (opt.recursive_prefix) From patchwork Tue Feb 8 08:39:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12738332 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 9DEE2C433EF for ; Tue, 8 Feb 2022 08:40:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231630AbiBHIkZ (ORCPT ); Tue, 8 Feb 2022 03:40:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350627AbiBHIkR (ORCPT ); Tue, 8 Feb 2022 03:40:17 -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 F03EBC03FEC8 for ; Tue, 8 Feb 2022 00:40:16 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id d16-20020a056a0010d000b004e0204c9753so555133pfu.7 for ; Tue, 08 Feb 2022 00:40:16 -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=PcDPigmq9mq3SJk3g82pK/HsmEj4Qxy6w2HHVzWfTMo=; b=MMkvtlBqf31YYdiSyeksNt4An+7U2EkuZR8RfQTzweFYZiHHtS6ActkyrqSY/ODCba CUnvmcLbAqJvwXXhy40LIAbOWmPEzetGZ7P2GDBQvG89drg5snvyDGK+3Myzqhura8+v iooy2TdQnn3ohWQ1IejyFfmIwn4TiCpGhRJDXmq7Aa51QvYkjHzHgq2ZxJzSSMGK5w2u rHpJjMwkIZzdCjd2DvaIp8MEh45F+0gfUbD4/siY3ncPYreRzi+gUHo1TmZazSxF2Y/x txpZafBw5biwI+1MGN4VUEJ43Dkyy8CBkaffn6FAV6tNwBPp1mdPRDlcEXBY6pSfy8Li dmUw== 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=PcDPigmq9mq3SJk3g82pK/HsmEj4Qxy6w2HHVzWfTMo=; b=tGJhjNEaSn3P/4pTmis+qeXKR8ZxJzi7i9ec7W62/JVFVMvPzcfY1XfmgQyQlv/l1r SqYw/xkDW7KyIEjJgpkJGzO1APVgR/0SBMzQJ0Ry15dsnS1k8iyegwTXqdQsaASsHU8m wYzQzEdCpIZ222TNyQYInVb2zENgZ/FHaSC1pHDWraASEwiK11Jbei6MyydZEqoSx3l9 G7cEy+uPGdweFYGPakD61axX0Cpm5h1FfpoOwnUQdDlScmzS6lPXcTOR/SqXgBZCXgsf zzfUt2NeKNMuXmXVBGyxiRXNUEHIWHohHrAyA4rUF7+fWPRgrgAPlgKSw09RGSIr7W1L COtQ== X-Gm-Message-State: AOAM5331CrYgSRv3iPLB0BS7GEGwmrBSPOilIpWRwyaAXnuY+f69huS6 mzdixrGN3hxGRp7oL91OCS8MNord+5I97R8T7sLQa6lzel9EQK+HfSiQEpf0a2hhdWS6TdJMty3 NnFGGk2TcWKzIjN7u1PN6q2287UJCf3CEKdbhdiEYfVUWWFX1vSoDCEeF6qUfqa0= X-Google-Smtp-Source: ABdhPJwkhvPg+iloxT6YvXPI42dExdbk+ARNXX4e5pY6bbSw63LoAGc6dTJ1STiINDsaCzgCl2kP6AAGaNld/g== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a05:6a00:16c1:: with SMTP id l1mr3311166pfc.52.1644309616383; Tue, 08 Feb 2022 00:40:16 -0800 (PST) Date: Tue, 8 Feb 2022 16:39:44 +0800 In-Reply-To: <20220208083952.35036-1-chooglen@google.com> Message-Id: <20220208083952.35036-9-chooglen@google.com> Mime-Version: 1.0 References: <20220208083952.35036-1-chooglen@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v6 08/16] 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 , Christian Couder , Emily Shaffer , Jonathan Nieder , Kaartic Sivaraam , pc44800@gmail.com, Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " 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 --- t/t7406-submodule-update.sh | 14 ++++++++++++-- t/t7408-submodule-reference.sh | 14 +++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index 11cccbb333..7764c1c3cb 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -205,8 +205,18 @@ test_expect_success 'submodule update should fail due to local changes' ' (cd submodule && compare_head ) && - test_must_fail git submodule update submodule - ) + test_must_fail git submodule update submodule 2>../actual.raw + ) && + sed "s/^> //" >expect <<-\EOF && + > error: Your local changes to the following files would be overwritten by checkout: + > file + > Please commit your changes or stash them before you switch branches. + > Aborting + > fatal: Unable to checkout OID in submodule path '\''submodule'\'' + EOF + sed -e "s/checkout $SQ[^$SQ]*$SQ/checkout OID/" actual && + test_cmp expect actual + ' test_expect_success 'submodule update should throw away changes with --force ' ' (cd super && diff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh index a3892f494b..c3a4545510 100755 --- a/t/t7408-submodule-reference.sh +++ b/t/t7408-submodule-reference.sh @@ -193,7 +193,19 @@ test_expect_success 'missing nested submodule alternate fails clone and submodul cd supersuper-clone && check_that_two_of_three_alternates_are_used && # update of the submodule fails - test_must_fail git submodule update --init --recursive + cat >expect <<-\EOF && + fatal: submodule '\''sub'\'' cannot add alternate: path ... does not exist + Failed to clone '\''sub'\''. Retry scheduled + fatal: submodule '\''sub-dissociate'\'' cannot add alternate: path ... does not exist + Failed to clone '\''sub-dissociate'\''. Retry scheduled + fatal: submodule '\''sub'\'' cannot add alternate: path ... does not exist + Failed to clone '\''sub'\'' a second time, aborting + fatal: Failed to recurse into submodule path ... + EOF + test_must_fail git submodule update --init --recursive 2>err && + grep -e fatal: -e ^Failed err >actual.raw && + sed -e "s/path $SQ[^$SQ]*$SQ/path .../" actual && + test_cmp expect actual ) ' From patchwork Tue Feb 8 08:39:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12738333 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 E32F7C433EF for ; Tue, 8 Feb 2022 08:40:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350627AbiBHIk1 (ORCPT ); Tue, 8 Feb 2022 03:40:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350670AbiBHIkW (ORCPT ); Tue, 8 Feb 2022 03:40:22 -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 75C8DC03FECC for ; Tue, 8 Feb 2022 00:40:19 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id f2-20020a17090a4a8200b001b7dac53bd6so11404428pjh.4 for ; Tue, 08 Feb 2022 00:40:19 -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=aOKoxMtNyA0xhNibVJgaFQ9E2qSM8PrWwJbEr/7dtj0=; b=EhYJBWAzyDky9IAL6bKqEhfO2bdgcFuPJjTUXMAvL9Um4WxEobNZ+uz05gO0HnO+FW WprhKfXmbnK7YYJO3VldEUn94hL7Nm2IinaXeh9wU30Bf2I0+7GPq+Bxzjo0Vm3W5erJ 3dCY9UvNIO7maGf3XfimXQCMfB+nWhj0NpEYwcbuPLo3SQWOnZxqsrdc/tQ6um8cUuzX 6MLx88JzSlLmMFi/1pBLU7fB1RXjGplnTnU+fDGDnPam6OZOas12peuO7NQ1xaMxEgSZ trT7DEvf1Rs+w4n8uG224F91H8umaVS8oobN1GU6n8pbJY1xOWEa2OWidBfb+Yi8wOyJ 6kSQ== 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=aOKoxMtNyA0xhNibVJgaFQ9E2qSM8PrWwJbEr/7dtj0=; b=a8g2j8szoycwrVG7s6c4g+9sn040+OGDzESs0wEtE5PBy2NR1K+wl7r9lr6rLRT+SC VgtsEfzacCK1kMHDo2DR9AnVz5Jwfm4xbu0G17zy9rUmtfAVrDbT7ecL+tVp91blh9Ux +Qxi91ih3NmODXlRk/52DtPVa+7G733m2Zav+EXmsa9Z+dUO0WWAl/VsygYomUQZ7toT aRPXgLUT08II4m+t0kKE54VBXzaLFCgP4n8hPUqh4AOtp7lb3EUDhmwdDB69Sgg6Cc/5 3ySOExJOMijbEv8GNkEJyURLvm9LAldVTaCg9Y45GpieFUHv8KOYer0raqJL0UOoZ1as KV4A== X-Gm-Message-State: AOAM533G5J6jYQdro2XGUv2M8axipnlODCcRG8JR2H4x8regRxHAwxbO TBRFNYS+KnDn/+E1b29O/Km0jSIIjKwjD1jAeFy5HcyVgn2pZhilArk3cWoX076TJxjbRsCj49z Vq8DKEYPW5C2Y6o01gyAOjkePZxFWIPjDA11oohBkQ0RbLnVR3haVQcr+D+RdmO0= X-Google-Smtp-Source: ABdhPJwEno20MHcwgHB/yRuzCgJnhLLbZd034ubY0e2ZCqbbj3ieFWu/34skyFobcaKTuXtENRBDGU5f5iXJSA== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:903:300d:: with SMTP id o13mr3501263pla.27.1644309618743; Tue, 08 Feb 2022 00:40:18 -0800 (PST) Date: Tue, 8 Feb 2022 16:39:45 +0800 In-Reply-To: <20220208083952.35036-1-chooglen@google.com> Message-Id: <20220208083952.35036-10-chooglen@google.com> Mime-Version: 1.0 References: <20220208083952.35036-1-chooglen@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v6 09/16] submodule--helper: remove update-module-mode From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Christian Couder , Emily Shaffer , Jonathan Nieder , Kaartic Sivaraam , pc44800@gmail.com, Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " 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 4a0890954e..e0cc1c1b79 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1965,29 +1965,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; @@ -3388,7 +3365,6 @@ static struct cmd_struct commands[] = { {"name", module_name, 0}, {"clone", module_clone, 0}, {"add", module_add, SUPPORT_SUPER_PREFIX}, - {"update-module-mode", module_update_module_mode, 0}, {"update-clone", update_clone, 0}, {"run-update-procedure", run_update_procedure, 0}, {"ensure-core-worktree", ensure_core_worktree, 0}, From patchwork Tue Feb 8 08:39:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12738335 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 9BD84C433F5 for ; Tue, 8 Feb 2022 08:40:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350546AbiBHIke (ORCPT ); Tue, 8 Feb 2022 03:40:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350684AbiBHIkW (ORCPT ); Tue, 8 Feb 2022 03:40:22 -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 00BEEC03FED0 for ; Tue, 8 Feb 2022 00:40:21 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id b11-20020aa7950b000000b004df185959c4so7015016pfp.8 for ; Tue, 08 Feb 2022 00:40:21 -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=9tSCNhbr0674my1WC8Aj0WZhf1LgKShpcEo/fODt+ps=; b=WZiXn7lsc5MQshFKwIPo8/tsOD/vfoVKF0yGk65XapIh0t8S4BiuKfYoAKNCF49AhW Ydj4aMDAWc4hq4CouiE76D6YlTm28j8i8NdnrSR5ULmcdKzx88fyk3OI7y8o8lN4UndB pJjJ5+kKhUSjMhFd9yJELE0Lr9wTgvgfRNDjIRhwVYjfd7urAwzNTJ9nu5t+lNChXw1t ICPsYdZOdxlzVSVIpdbjo3Tye877wbQ4QgxURBH9sQ8xbxkI0+UOz6H03BlBhCkBW0KY NdIPOdszG6mCdZMoidmZjwGH+CgDTbLCsXM5BmLsh5nJSytmfjKUxGgwkMPW1uZsdmW+ uGJg== 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=9tSCNhbr0674my1WC8Aj0WZhf1LgKShpcEo/fODt+ps=; b=U6upOpNGtge7ABLKeymjVRSu+a0m3Dnd8ipRbw5/5OufjwKfjW++HYNHf3q95hdF7h FEaOuKOcfXuyz6KNI8S/hqyXDuM+nQjImy35IcHL6V96TnirVLra44Ny+GomBmQcgIjK A78h6SuV8cCiX3BmBDh9fq+5gRcsrtoDkVh1wbeavgAYi9lvV40eCCoZ8gAPHWV0E3+U 3vmYvwRLFnKwbWV3hM7XsHHJarDb/rbfeEtC0jBCoDPWYKCGs5BCyjHjjuyv4UoXlU81 1GmHpohmnDOUzXhctzP75Qy6xKBt1Vsn5HcUzR7TLODR/wCmj2iW2YWLs+vPHa7J8RN3 oqtg== X-Gm-Message-State: AOAM530BEyzxJ1hOHPLJWiFl9pGxpoAJ4CXhKh4K6MlqoaqBIn2njL0b UUryWEOQF0sNUFW9MBPk+ligKiQmKkHkZ5bMdgsb70cksD9TE67yehPwfira1CseA0N6SHQ9Zpw GnLKksSYtsgVdsqCvAil+lGq77ts9HG+RvwHZAo3Q1X0GHxmF0l5DRRzTQlrYqEg= X-Google-Smtp-Source: ABdhPJyU6MdB8KCr1P06xuyfP/ngjxLY+XzXnIKIK6IxEtNfeBYQgsaY/eSCqdRusO35xdDVwpKBfDt3RXs3Nw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a05:6a00:cc8:: with SMTP id b8mr3439831pfv.5.1644309621047; Tue, 08 Feb 2022 00:40:21 -0800 (PST) Date: Tue, 8 Feb 2022 16:39:46 +0800 In-Reply-To: <20220208083952.35036-1-chooglen@google.com> Message-Id: <20220208083952.35036-11-chooglen@google.com> Mime-Version: 1.0 References: <20220208083952.35036-1-chooglen@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v6 10/16] 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 , Christian Couder , Emily Shaffer , Jonathan Nieder , Kaartic Sivaraam , pc44800@gmail.com, Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Introduce a function, update_submodule2(), that performs an update for one submodule. This function will implement the functionality of run-update-procedure and its surrounding shell code in submodule.sh. Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index e0cc1c1b79..0b5120734a 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2553,6 +2553,11 @@ static int update_clone(int argc, const char **argv, const char *prefix) return update_submodules(&opt); } +/* + * NEEDSWORK: Use a forward declaration to avoid moving + * run_update_procedure() (which will be removed soon). + */ +static int update_submodule2(struct update_data *update_data); static int run_update_procedure(int argc, const char **argv, const char *prefix) { char *prefixed_path, *update = NULL; @@ -2610,11 +2615,7 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix) &opt.update_strategy); free(prefixed_path); - - if (!oideq(&opt.oid, &opt.suboid) || opt.force) - return do_run_update_procedure(&opt); - - return 3; + return update_submodule2(&opt); } static int resolve_relative_path(int argc, const char **argv, const char *prefix) @@ -2978,6 +2979,15 @@ static int module_set_branch(int argc, const char **argv, const char *prefix) return !!ret; } +/* NEEDSWORK: this is a temporary name until we delete update_submodule() */ +static int update_submodule2(struct update_data *update_data) +{ + if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) + return do_run_update_procedure(update_data); + + return 3; +} + struct add_data { const char *prefix; const char *branch; From patchwork Tue Feb 8 08:39:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12738338 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 E34F8C433EF for ; Tue, 8 Feb 2022 08:41:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350694AbiBHIkk (ORCPT ); Tue, 8 Feb 2022 03:40:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350569AbiBHIkY (ORCPT ); Tue, 8 Feb 2022 03:40:24 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DD72C0401F6 for ; Tue, 8 Feb 2022 00:40:24 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id y13-20020a170902d64d00b0014cea2afd46so7018458plh.12 for ; Tue, 08 Feb 2022 00:40:24 -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=C4m91dacx6CAhzX4YyT26sMDoIhe7B1orAVRP6TgaLI=; b=QLreUN9hmK5PgX3vC385obTqFl4V44RXC49qLNvS97oCO50az2Ee/N+N+HBoeGF5ru nZweSmeARYf45Bv+orJnYLRAVxT42Q8zV3PQu3Dx9LbDvt+cTgJuDRXIXMHYX/f1dqee wVcAnCmZj/UrJBn62JIUnRBclRymMABfWXOpUl+y+3X3ZyApw1/i4kuLwXYx1bTkENH9 QYBVDBXTXhrxTURiqhP8RS3i+GxfCfo6G5w1D53oXLnPhRFtX/ThUGonAUAJHZ6ZHXWh 5AX6nTOfs4d7pg9+R4jWg0JUBBGcMB6TG6P3+JpDU9QMCENOrPQDKdkiOhI6mS63LIQe U5eQ== 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=C4m91dacx6CAhzX4YyT26sMDoIhe7B1orAVRP6TgaLI=; b=YcJ3QgYlKSUEUVM87Z+s5yTGVqeDSDaXpE3PufkAo9egGPW/yxuWBZcEg/rHOFJSMC WmB6Wt/Bfa9es9tDWUonezTmoDn7c3Y8gX9hUMv4Wc+UL+4dSpGh5qdVF/rd+9hwROQP ONVGt32/liYFkbo+T8OPalPDI/qqw9s2YhUMZApnOM6EBGsueCgzZBat7fjAxNsoNuGx P4RlBl6Mksb0jezcGqQ3B3zIYpQQdlw9sOKaEEAvTDDMVLTuWA3UzxVouSWeFC5ZGUh1 y553kidA31/M0Za+71FNLiYAs6VlWRHoRgJpT8J9pmFXJF45dInb4dn68Dw1wz483Syg H0mA== X-Gm-Message-State: AOAM532K3r1c0vzf8Z8LW2MwNX75o8dSYQmXgF39IBuCHY6eizQc1qSZ MR0kC4CQRRVSoQ3jYznole5VVi7as/9hR2cXOpUMCBRVsYPKGLKx10h7FpPsVlnm8YFXxytQIzI 7TeXZf1Ea7wDvWJ8kzF6rNwxfut2vX4ChPDnWDP/CQ8YnPBhPCzY5Aljevnc99H4= X-Google-Smtp-Source: ABdhPJzMPDwc9ml7SOLikhSBpQaBUs1gY60PrJlltSGFwvdaw/Aliw4FArmxkawtagJNPvfP8v9IshAbZq3FoA== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:90a:6448:: with SMTP id y8mr182596pjm.20.1644309623659; Tue, 08 Feb 2022 00:40:23 -0800 (PST) Date: Tue, 8 Feb 2022 16:39:47 +0800 In-Reply-To: <20220208083952.35036-1-chooglen@google.com> Message-Id: <20220208083952.35036-12-chooglen@google.com> Mime-Version: 1.0 References: <20220208083952.35036-1-chooglen@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v6 11/16] submodule--helper run-update-procedure: remove --suboid From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Christian Couder , Emily Shaffer , Jonathan Nieder , Kaartic Sivaraam , pc44800@gmail.com, Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " 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 | 12 +++++++++--- git-submodule.sh | 8 +------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 0b5120734a..a26477ce04 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2585,9 +2585,6 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix) OPT_CALLBACK_F(0, "oid", &opt.oid, N_("sha1"), N_("SHA1 expected by superproject"), PARSE_OPT_NONEG, parse_opt_object_id), - OPT_CALLBACK_F(0, "suboid", &opt.suboid, N_("subsha1"), - N_("SHA1 of submodule's HEAD"), PARSE_OPT_NONEG, - parse_opt_object_id), OPT_END() }; @@ -2982,6 +2979,15 @@ static int module_set_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) { + /* NEEDSWORK: fix the style issues e.g. braces */ + 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 652861aa66..d48c314f01 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -391,14 +391,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" @@ -426,7 +421,6 @@ cmd_update() ${update:+--update "$update"} \ ${prefix:+--recursive-prefix "$prefix"} \ ${sha1:+--oid "$sha1"} \ - ${subsha1:+--suboid "$subsha1"} \ "--" \ "$sm_path") From patchwork Tue Feb 8 08:39:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12738336 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 20121C433FE for ; Tue, 8 Feb 2022 08:40:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350674AbiBHIkg (ORCPT ); Tue, 8 Feb 2022 03:40:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350652AbiBHIk2 (ORCPT ); Tue, 8 Feb 2022 03:40:28 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6909C03FEC5 for ; Tue, 8 Feb 2022 00:40:26 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id q4-20020a170902f78400b0014d57696618so3277675pln.20 for ; Tue, 08 Feb 2022 00:40:26 -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=AIDjye1DDOnT7iBsdjGhA08VwNJHQSPMOfgmMBSCDP8=; b=r206j5nQ3jCGMrSBvI+WV/hFuN6uccY2UPq8f1ldeck7dWc4mO0WmeC2vR2iw5KL/k ekJJlGnmaLi7hIXyHQF3jqnbfbYR0Lc8EccOiN3DBlePhWh/1EqTQJyChJNRlbpKlXpD r2+4DLfMKYhFdeoBsiiJqJ7+PxLQOXKSFAAZXmn2LTsf+3pokapPKzuUCDq5pcbRbeHp bhNpOJzkzcGeXReLgq0S7n36aZhfGFEX9kmPK900n3t4B7JcjSVgk4LdfeK1OsjtRyL6 eWhUETatAYj4fT72rqp2bkrJaeW4m+yEzH2Ks+6uhA2crboYcIs8FlBTmbO51+KY+ooN E9HQ== 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=AIDjye1DDOnT7iBsdjGhA08VwNJHQSPMOfgmMBSCDP8=; b=AvEJO/WbNiC7Q/1N7kiUXFGfHh6KC4lqCeY0ACyG53829LMZG/aA9Gc8COHa2427kr rZh3um8McyUMiKG/GoAabBBIk5n2MYaQrOTE/cvt0WzV5CsToihURpxbL4NLLjTkBqEX Ux7IuRvFkBRB/sZLnx+q/S3JUMTqIV4JQSC906YtSeWYniMEJIbqCk4PH/7N0uHmN8GK 14ni5bXyayRp+sqnhedhVJ2mf892gQqTnb1JiMTTqunctJh+yKopSVmj7rOpWEtpjUXw CVLDlrxB/m3v+4+TSDkdPQZnGvGOrMV5K6BYqnfuaTVetkFA2y9SZBEpx9/i/SRjYHSc QYCg== X-Gm-Message-State: AOAM532eh71hq6OPu1Pmb0ejwA2mpudIbUhifYZqGlnuB7PirGwpCa51 35gy61vNtrVRxGQPp1FJ5hCOVsC43ZX5DAblg0EPPzmTFcVnugiRPu2XHjdUxbqlvQ4nQD9adRg elj02QiIbcKkyokNCu+APrF2iWOewEzYzBJHvSWJ1O8fVxqaUwt5aFfyEWs8xoxE= X-Google-Smtp-Source: ABdhPJxhgB2jPjQSM1GmET0p0QUETSGp+KHlbHrZcurIRtW+ceVL1HN8s771m2M+O2L8IC/91iDG2ZMIhpyDJw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:90a:e40f:: with SMTP id hv15mr199463pjb.1.1644309625914; Tue, 08 Feb 2022 00:40:25 -0800 (PST) Date: Tue, 8 Feb 2022 16:39:48 +0800 In-Reply-To: <20220208083952.35036-1-chooglen@google.com> Message-Id: <20220208083952.35036-13-chooglen@google.com> Mime-Version: 1.0 References: <20220208083952.35036-1-chooglen@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v6 12/16] submodule--helper run-update-procedure: learn --remote From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Christian Couder , Emily Shaffer , Jonathan Nieder , Kaartic Sivaraam , pc44800@gmail.com, Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Teach run-update-procedure to handle --remote instead of parsing --remote in git-submodule.sh. As a result, "git submodule--helper print-default-remote" has no more callers, so remove it. Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 39 ++++++++++++++++++++++--------------- git-submodule.sh | 30 +--------------------------- 2 files changed, 24 insertions(+), 45 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index a26477ce04..15ae986692 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -71,21 +71,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]); @@ -2026,6 +2011,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, \ @@ -2585,6 +2571,8 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix) OPT_CALLBACK_F(0, "oid", &opt.oid, N_("sha1"), N_("SHA1 expected by superproject"), PARSE_OPT_NONEG, parse_opt_object_id), + OPT_BOOL(0, "remote", &opt.remote, + N_("use SHA-1 of submodule's remote tracking branch")), OPT_END() }; @@ -2988,6 +2976,25 @@ static int update_submodule2(struct update_data *update_data) 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); @@ -3389,10 +3396,10 @@ static struct cmd_struct commands[] = { {"foreach", module_foreach, SUPPORT_SUPER_PREFIX}, {"init", module_init, SUPPORT_SUPER_PREFIX}, {"status", module_status, SUPPORT_SUPER_PREFIX}, - {"print-default-remote", print_default_remote, 0}, {"sync", module_sync, SUPPORT_SUPER_PREFIX}, {"deinit", module_deinit, 0}, {"summary", module_summary, SUPPORT_SUPER_PREFIX}, + /* NEEDSWORK: remote-branch is also obsolete */ {"remote-branch", resolve_remote_submodule_branch, 0}, {"push-check", push_check, 0}, {"absorb-git-dirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX}, diff --git a/git-submodule.sh b/git-submodule.sh index d48c314f01..29fd69250d 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -246,20 +246,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 # @@ -396,21 +382,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} \ @@ -421,6 +392,7 @@ cmd_update() ${update:+--update "$update"} \ ${prefix:+--recursive-prefix "$prefix"} \ ${sha1:+--oid "$sha1"} \ + ${remote:+--remote} \ "--" \ "$sm_path") From patchwork Tue Feb 8 08:39:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12738337 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 00698C433F5 for ; Tue, 8 Feb 2022 08:41:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351003AbiBHIkm (ORCPT ); Tue, 8 Feb 2022 03:40:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350645AbiBHIka (ORCPT ); Tue, 8 Feb 2022 03:40:30 -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 24753C0401F6 for ; Tue, 8 Feb 2022 00:40:30 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id n4-20020a17090ade8400b001b8bb511c3bso4418014pjv.7 for ; Tue, 08 Feb 2022 00:40:30 -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=IQ/TmO04ivwY6jOcn7+5hzTvbedJJB/armLAxZ1CAiA=; b=WfuWMgyVsHynIQZUQpPGtoYqshWoA21B0C7YuqzxZ9gBl+PVr1xBQSWPoorOgeJDV2 0ozoNRR6VfDPagTgeQbH30fjbKD5TsmSlHanp82McqtWrSZbd2HGu58BwC7sG7g3osCO rWsZBtbSSjwlFVPeL6yMx/n7Uo6Lh1VloyJ0ZU11RTVW7/cx/4rGXQBFQM/LEtM6eOGR YN6QRUQH6vKDPY6prDfeTTyxLkTDhAWRjqSbxKAB0Iiz1SR1QFGe4aCq1EHOKxPL67Lr 9JZaGIa5gxYfUm7PFcekI1OTJ31/yx0bHHDmiq4PJUyBz3mF1SrAvrUBSbHB5fxJgw3X v9WQ== 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=IQ/TmO04ivwY6jOcn7+5hzTvbedJJB/armLAxZ1CAiA=; b=orVLITRk/mW3WxJphygtjy4dBio+gLlrlf6O35vk6ZIU5ZiIFJNXZChc3TgPb1uD85 YpxfEXq7iEa4i1Vr7rl7YmIEs3ioSGKCWVEJ05YXAbijo/DYmZjWtjkkpHaRR8Gp4rQU 0i1XwT4pa9bJ0S8QyZIq9lR99u0MTLnxU6S/Ih9h38ZtIWnVZPn6NUwd2PAwywDFZy3p 1PxJ9aHfMLUpHTfyUzp30/lkz+c6UvsWFNRh5JRZ9vgwdz7d/JljDeYEXgtWar9bn10u tU+I8nQb577IqTta0MENx5s5hnl4swTGSdEEjLuk9jjK9AXvUzLlR2G3vXgiQ62LXV8L Wz7g== X-Gm-Message-State: AOAM530UM92GqEyd0EzMcQhpkUvdofHsCmuR+eeLqw+S9q4/zGxV4Rct PMi4a7mxzuQAYilWUQELAn3ZzpES7UeDV9WKkGVUiV6/qrCcNy6SHySD8nx8uyZna5R3tR1q/ZT gZEqwGhq/Sd/ZkLNdBuSN+MXa5qj+BP5krCJw9yLvnFTungS98QnlPp+lFEij4cQ= X-Google-Smtp-Source: ABdhPJxBdmTfpwZEZeLh3nBI4cRHCUtPpoUb/Q0qgwIT1NAaMynJ1vNNOnZej3qgzYFdFMouwB9PZc5H5s/YbQ== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:da85:: with SMTP id j5mr3345905plx.81.1644309629248; Tue, 08 Feb 2022 00:40:29 -0800 (PST) Date: Tue, 8 Feb 2022 16:39:49 +0800 In-Reply-To: <20220208083952.35036-1-chooglen@google.com> Message-Id: <20220208083952.35036-14-chooglen@google.com> Mime-Version: 1.0 References: <20220208083952.35036-1-chooglen@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v6 13/16] submodule--helper: remove ensure-core-worktree From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Christian Couder , Emily Shaffer , Jonathan Nieder , Kaartic Sivaraam , pc44800@gmail.com, Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " 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 | 13 +++---------- git-submodule.sh | 2 -- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 15ae986692..a05aea5cd6 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2746,17 +2746,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); @@ -2776,8 +2770,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) @@ -2967,6 +2959,8 @@ static int module_set_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); + /* NEEDSWORK: fix the style issues e.g. braces */ if (update_data->just_cloned) { oidcpy(&update_data->suboid, null_oid()); @@ -3390,7 +3384,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 29fd69250d..aa9c898e1c 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -373,8 +373,6 @@ cmd_update() do die_if_unmatched "$quickabort" "$sha1" - git submodule--helper ensure-core-worktree "$sm_path" || exit 1 - displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix") if test $just_cloned -eq 0 From patchwork Tue Feb 8 08:39: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: 12738339 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 CB73DC433EF for ; Tue, 8 Feb 2022 08:41:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350702AbiBHIlF (ORCPT ); Tue, 8 Feb 2022 03:41:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238745AbiBHIkd (ORCPT ); Tue, 8 Feb 2022 03:40:33 -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 974EBC0401F6 for ; Tue, 8 Feb 2022 00:40:32 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id y10-20020a17090a134a00b001b8b7e5983bso4586891pjf.6 for ; Tue, 08 Feb 2022 00:40:32 -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=eDE9N2lSSvdsSpnLVK+ske7kG+FpFoWcwLzUChjaM1g=; b=hlN4Y1n/qfZlFF3G56c3tZhFh47wk/iXl0Yu/SaxsO1zMES1thiXv28z4T3qXHHdkr HlmA4ZoaATsf+LpIhYbVKtypqXIXHuaz3VvQRqZ5ELfI8ww/NE+bxlCBjsi5D+0yRr2B qUMi+rGEBQGxjjASqM6P0r+RxfflXoP24IlJM8s5pa6KUAIlDmY8EA6JKTyDx5Mg5pSY 7p6krfpTw/muVU59yGd0U8Wn8MngHdElHncuHaPRkxl5S08A6aFbXaHGC8siIP3H6KSa fIHPT4GtD0P7m5tR5FYMchk9dL+UGX7tiRnn7abs3+oI2g/fiYLLymdcxc1rB8KXWjzh r8mw== 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=eDE9N2lSSvdsSpnLVK+ske7kG+FpFoWcwLzUChjaM1g=; b=BbN0ZmX0R50+t/kBxHLxSfxuJ+rUTGI0q3K5rlSt5YQ70X9r82b1CR0GEG3epyo78A ID7nqcpDHzcbd9gt3QwgKkGVplctJkj2YRXkq/QFfc8i6FObWNHpbSKzBrZhal2L1b48 6kGqIycw0FQ6hIxwiap1mzYjsfaNDTx7d5YDxbq30xX7Eax07p4r7C6df1+f2KcvHmGQ Y4gSLpranrwOzkZr3YRoe0AzbGQgd2Q22dgnSNZGYbSiIerOxAQPdN7c0UUwzPPVirnE o3nHhFsyw5qXFlGPdFCrs4nn16nOdPwmVvE2PiR/hywfcGKdagNlAN3AFP+8NrfGJ6tZ 36oQ== X-Gm-Message-State: AOAM531FsvTCXET7DAdcKcqeSDiJqphn6XxJ80xAAvYSW7R5aLmp4HDT ztP2A8+afv83W9Skwn2PcHeXolUKdUYXKK4nigKcNAQ/S/+D7GvJQq4UzsKs/Pm8atqGhd7w2w5 ckiqDTboRJj/H6l+lqPTE+RqWKdv1gAF4c2xfZO50ceE3zuVuNVaNEQnLgcj7PJA= X-Google-Smtp-Source: ABdhPJwy5mTjS9o9Fnaj2/KgRu292FklKNisFCq4OzCtIBvaw1ZO+q9dsRnWIYiCu42Xp0AmqBIC1Pr5Jp+yxw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:90a:4544:: with SMTP id r4mr163174pjm.186.1644309632029; Tue, 08 Feb 2022 00:40:32 -0800 (PST) Date: Tue, 8 Feb 2022 16:39:50 +0800 In-Reply-To: <20220208083952.35036-1-chooglen@google.com> Message-Id: <20220208083952.35036-15-chooglen@google.com> Mime-Version: 1.0 References: <20220208083952.35036-1-chooglen@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v6 14/16] submodule--helper update-clone: learn --init From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Christian Couder , Emily Shaffer , Jonathan Nieder , Kaartic Sivaraam , pc44800@gmail.com, Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " 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 a05aea5cd6..5635f0c48b 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1989,6 +1989,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, \ @@ -2483,6 +2484,8 @@ static int update_clone(int argc, const char **argv, const char *prefix) struct submodule_update_clone opt = SUBMODULE_UPDATE_CLONE_INIT; struct option module_update_clone_options[] = { + OPT_BOOL(0, "init", &opt.init, + N_("initialize uninitialized submodules before update")), OPT_STRING(0, "prefix", &prefix, N_("path"), N_("path into the working tree")), @@ -2536,6 +2539,29 @@ static int update_clone(int argc, const char **argv, const char *prefix) if (pathspec.nr) opt.warn_if_uninitialized = 1; + if (opt.init) { + struct module_list list = MODULE_LIST_INIT; + struct init_cb info = INIT_CB_INIT; + + if (module_list_compute(argc, argv, opt.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 = opt.prefix; + info.superprefix = opt.recursive_prefix; + if (opt.quiet) + info.flags |= OPT_QUIET; + + for_each_listed_submodule(&list, init_submodule_cb, &info); + } + return update_submodules(&opt); } diff --git a/git-submodule.sh b/git-submodule.sh index aa9c898e1c..3ccf2388bf 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -347,14 +347,11 @@ cmd_update() shift done - if test -n "$init" - then - cmd_init "--" "$@" || return - fi - { - git submodule--helper update-clone ${GIT_QUIET:+--quiet} \ + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update-clone \ + ${GIT_QUIET:+--quiet} \ ${progress:+"--progress"} \ + ${init:+--init} \ ${wt_prefix:+--prefix "$wt_prefix"} \ ${prefix:+--recursive-prefix "$prefix"} \ ${update:+--update "$update"} \ From patchwork Tue Feb 8 08:39: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: 12738340 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 702ABC4332F for ; Tue, 8 Feb 2022 08:41:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350760AbiBHIlH (ORCPT ); Tue, 8 Feb 2022 03:41:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350670AbiBHIkf (ORCPT ); Tue, 8 Feb 2022 03:40:35 -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 D71DCC03FEC5 for ; Tue, 8 Feb 2022 00:40:34 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id u80-20020a627953000000b004c82105f20dso9282410pfc.11 for ; Tue, 08 Feb 2022 00:40:34 -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=PwVv5DANedhFe1iffJX8jChxJU4YFztjSW+fYl5zs1g=; b=h3NuYBWUD8kzun4/amXdUhdCcBwGlA918sxxqZjCaGkx1r8zSR7m0gwpFuZDimai5H +OcJYLZ05qGSUiNPtfpqYYndagfuXK+uS4E/f8JiAhD39CAZX/9/2xrQLCh9fVJVKOki BuqwHDbhU0XXmm70bA9RHwtvYPWD/Ni47+gHfdm7YB1kiR7rpW0+kQmXEFXvmb+tTGzq VlWsy/FwJ0g/WGCWTBrUgArVKw129tLmVP8elCKewfNLbSUiCNXRPaLeMmfhGZRiIvjs ZaZN5a6Q3IX4gtTZeZOrdaF5aUtPuw/huezXYn2DMNoYSwJ5sfl6umVo/B4jt+LMrzQL tb+Q== 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=PwVv5DANedhFe1iffJX8jChxJU4YFztjSW+fYl5zs1g=; b=LaZoxin3mUR6CowA7Vd1hQqEakZ7anHdfYw7QBYQw57nZBUacQgNG7vWYkybTae49e Y+DVIcHiyYaPeQx5i0ZpcrC5/q3g4ZuuCsbzKjx6dgAJseeIKY5TjTGsQC8+I4NTfuKE 2KQmJAwzGBYKBObYM6S/sWVxk5lrkhi7yjjfSL3vU0YIeQmgPlIsNi4NSW1mYDDjy/ji gtBNpCCmyW2N9rp9dxtrBX4QqBmW4/6CsgzQDPX4ySZA4nB5zRK1jgKRDlJlgeTPaS1H UyCA2fXvFRWYk8Y9bzFj/jVkWVk+xyGCxaXz5uupGiLpFFSeKYjEhcRBHFZSi6tUJPPI YQEA== X-Gm-Message-State: AOAM533+4UHloRQ14t8rXgEWgwECPCxlu5By14OXSV/sGg+VMArN1Hpy PqIK+C5+xHtKFvI2c9DxRy5jMQ5t1q3SxFngyA3FnPY/KiQr9H2R0b7uRwSr2dzEk1vjjaFP4iz p+TKOpZKGkhYNy35Xy2mnimwTfNR/DO6PtpXBHSEv67wSGHMTXsEzX06HlBeest4= X-Google-Smtp-Source: ABdhPJx7c4FBYyNndXPLLQcngr6aghOFL8EcFMj23DsnOC371/bgTpS0+wpNnJteHD8KU2BQzpgD2TxwHCMO3w== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a63:5a64:: with SMTP id k36mr2616955pgm.408.1644309634237; Tue, 08 Feb 2022 00:40:34 -0800 (PST) Date: Tue, 8 Feb 2022 16:39:51 +0800 In-Reply-To: <20220208083952.35036-1-chooglen@google.com> Message-Id: <20220208083952.35036-16-chooglen@google.com> Mime-Version: 1.0 References: <20220208083952.35036-1-chooglen@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v6 15/16] submodule--helper: move functions around From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Christian Couder , Emily Shaffer , Jonathan Nieder , Kaartic Sivaraam , pc44800@gmail.com, Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The next commit will change the internals of several functions and arrange them in a more logical manner. Move these functions to their final positions so that the diff is smaller. Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 228 ++++++++++++++++++------------------ 1 file changed, 114 insertions(+), 114 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 5635f0c48b..0ab8f9d49f 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2451,120 +2451,6 @@ static void update_submodule(struct update_clone_data *ucd) ucd->sub->path); } -static int update_submodules(struct submodule_update_clone *suc) -{ - int i; - - run_processes_parallel_tr2(suc->max_jobs, update_clone_get_next_task, - update_clone_start_failure, - update_clone_task_finished, suc, "submodule", - "parallel/update"); - - /* - * We saved the output and put it out all at once now. - * That means: - * - the listener does not have to interleave their (checkout) - * work with our fetching. The writes involved in a - * checkout involve more straightforward sequential I/O. - * - the listener can avoid doing any work if fetching failed. - */ - if (suc->quickstop) - return 1; - - for (i = 0; i < suc->update_clone_nr; i++) - update_submodule(&suc->update_clone[i]); - - return 0; -} - -static int update_clone(int argc, const char **argv, const char *prefix) -{ - const char *update = NULL; - struct pathspec pathspec; - struct submodule_update_clone opt = SUBMODULE_UPDATE_CLONE_INIT; - - struct option module_update_clone_options[] = { - OPT_BOOL(0, "init", &opt.init, - N_("initialize uninitialized submodules before update")), - OPT_STRING(0, "prefix", &prefix, - N_("path"), - N_("path into the working tree")), - OPT_STRING(0, "recursive-prefix", &opt.recursive_prefix, - N_("path"), - N_("path into the working tree, across nested " - "submodule boundaries")), - OPT_STRING(0, "update", &update, - N_("string"), - N_("rebase, merge, checkout or none")), - OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"), - N_("reference repository")), - OPT_BOOL(0, "dissociate", &opt.dissociate, - N_("use --reference only while cloning")), - OPT_STRING(0, "depth", &opt.depth, "", - N_("create a shallow clone truncated to the " - "specified number of revisions")), - OPT_INTEGER('j', "jobs", &opt.max_jobs, - N_("parallel jobs")), - OPT_BOOL(0, "recommend-shallow", &opt.recommend_shallow, - N_("whether the initial clone should follow the shallow recommendation")), - OPT__QUIET(&opt.quiet, N_("don't print cloning progress")), - OPT_BOOL(0, "progress", &opt.progress, - N_("force cloning progress")), - OPT_BOOL(0, "require-init", &opt.require_init, - N_("disallow cloning into non-empty directory")), - OPT_BOOL(0, "single-branch", &opt.single_branch, - N_("clone only one branch, HEAD or --branch")), - OPT_END() - }; - - const char *const git_submodule_helper_usage[] = { - N_("git submodule--helper update-clone [--prefix=] [...]"), - NULL - }; - opt.prefix = prefix; - - update_clone_config_from_gitmodules(&opt.max_jobs); - git_config(git_update_clone_config, &opt.max_jobs); - - argc = parse_options(argc, argv, prefix, module_update_clone_options, - git_submodule_helper_usage, 0); - - if (update) - if (parse_submodule_update_strategy(update, &opt.update) < 0) - die(_("bad value for update parameter")); - - if (module_list_compute(argc, argv, prefix, &pathspec, &opt.list) < 0) - return 1; - - if (pathspec.nr) - opt.warn_if_uninitialized = 1; - - if (opt.init) { - struct module_list list = MODULE_LIST_INIT; - struct init_cb info = INIT_CB_INIT; - - if (module_list_compute(argc, argv, opt.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 = opt.prefix; - info.superprefix = opt.recursive_prefix; - if (opt.quiet) - info.flags |= OPT_QUIET; - - for_each_listed_submodule(&list, init_submodule_cb, &info); - } - - return update_submodules(&opt); -} - /* * NEEDSWORK: Use a forward declaration to avoid moving * run_update_procedure() (which will be removed soon). @@ -3021,6 +2907,120 @@ static int update_submodule2(struct update_data *update_data) return 3; } +static int update_submodules(struct submodule_update_clone *suc) +{ + int i; + + run_processes_parallel_tr2(suc->max_jobs, update_clone_get_next_task, + update_clone_start_failure, + update_clone_task_finished, suc, "submodule", + "parallel/update"); + + /* + * We saved the output and put it out all at once now. + * That means: + * - the listener does not have to interleave their (checkout) + * work with our fetching. The writes involved in a + * checkout involve more straightforward sequential I/O. + * - the listener can avoid doing any work if fetching failed. + */ + if (suc->quickstop) + return 1; + + for (i = 0; i < suc->update_clone_nr; i++) + update_submodule(&suc->update_clone[i]); + + return 0; +} + +static int update_clone(int argc, const char **argv, const char *prefix) +{ + const char *update = NULL; + struct pathspec pathspec; + struct submodule_update_clone opt = SUBMODULE_UPDATE_CLONE_INIT; + + struct option module_update_clone_options[] = { + OPT_BOOL(0, "init", &opt.init, + N_("initialize uninitialized submodules before update")), + OPT_STRING(0, "prefix", &prefix, + N_("path"), + N_("path into the working tree")), + OPT_STRING(0, "recursive-prefix", &opt.recursive_prefix, + N_("path"), + N_("path into the working tree, across nested " + "submodule boundaries")), + OPT_STRING(0, "update", &update, + N_("string"), + N_("rebase, merge, checkout or none")), + OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"), + N_("reference repository")), + OPT_BOOL(0, "dissociate", &opt.dissociate, + N_("use --reference only while cloning")), + OPT_STRING(0, "depth", &opt.depth, "", + N_("create a shallow clone truncated to the " + "specified number of revisions")), + OPT_INTEGER('j', "jobs", &opt.max_jobs, + N_("parallel jobs")), + OPT_BOOL(0, "recommend-shallow", &opt.recommend_shallow, + N_("whether the initial clone should follow the shallow recommendation")), + OPT__QUIET(&opt.quiet, N_("don't print cloning progress")), + OPT_BOOL(0, "progress", &opt.progress, + N_("force cloning progress")), + OPT_BOOL(0, "require-init", &opt.require_init, + N_("disallow cloning into non-empty directory")), + OPT_BOOL(0, "single-branch", &opt.single_branch, + N_("clone only one branch, HEAD or --branch")), + OPT_END() + }; + + const char *const git_submodule_helper_usage[] = { + N_("git submodule--helper update-clone [--prefix=] [...]"), + NULL + }; + opt.prefix = prefix; + + update_clone_config_from_gitmodules(&opt.max_jobs); + git_config(git_update_clone_config, &opt.max_jobs); + + argc = parse_options(argc, argv, prefix, module_update_clone_options, + git_submodule_helper_usage, 0); + + if (update) + if (parse_submodule_update_strategy(update, &opt.update) < 0) + die(_("bad value for update parameter")); + + if (module_list_compute(argc, argv, prefix, &pathspec, &opt.list) < 0) + return 1; + + if (pathspec.nr) + opt.warn_if_uninitialized = 1; + + if (opt.init) { + struct module_list list = MODULE_LIST_INIT; + struct init_cb info = INIT_CB_INIT; + + if (module_list_compute(argc, argv, opt.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 = opt.prefix; + info.superprefix = opt.recursive_prefix; + if (opt.quiet) + info.flags |= OPT_QUIET; + + for_each_listed_submodule(&list, init_submodule_cb, &info); + } + + return update_submodules(&opt); +} + struct add_data { const char *prefix; const char *branch; From patchwork Tue Feb 8 08:39:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12738341 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 D03C7C433FE for ; Tue, 8 Feb 2022 08:41:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350933AbiBHIlJ (ORCPT ); Tue, 8 Feb 2022 03:41:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350807AbiBHIkm (ORCPT ); Tue, 8 Feb 2022 03:40:42 -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 3DD71C03FED3 for ; Tue, 8 Feb 2022 00:40:37 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id p16-20020a170902a41000b0014992c5d56bso7057798plq.19 for ; Tue, 08 Feb 2022 00:40:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=S1Qr+GtSpYazLEW45ksWTcj9eCLvgX9jDR2tEB1H8BY=; b=NFqI0NXQpP59JZ4zMT+vKk2j+8DXpBwdLGP7o5x0xDnbyExvoRazno5ak/kguT5u7y 7v3OPR7UrNEGU/xC8q03Y/Nz0TP69hIlrkL7a+cHyAewsBs3zy4ObdDQK7wPzGBdj6Gs pHKyYopmmT86psKSMNzRFkmcytEN6Sex6TvT1d3WYjqjwyL9ow2cMnQaj40zUEt1P6Pp Z0G04b9AlZhRFAyp4EE3csR68yb4zpyPTdDg8bryW9LvqWCJHkMWlQaDVXtjDbfc/qv3 LpQzRDUulsNYtpBTY/rGDuBOdIxWFAOklZPvJQ89i68+pX2nGdngxHubW7za8yTFzsHu 87Dw== 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=S1Qr+GtSpYazLEW45ksWTcj9eCLvgX9jDR2tEB1H8BY=; b=FhxLfbBmpiVyIEW79xFCmZhe+zIz6v03VLYn3InRRkrCgNLRl3cFLsJC/52IMUIiLJ i0pjfaZ7K6i3RSyW3b3tvSOjPaPxcxaEnVD/r+CVGAzSboC6476u2fEp6h8doisCPGes +dDV2YKKKCzSpRGdkdRUqKk2mZirDb2WHa/R3lrg2DiartqIqBuqbhGsEq1mXAmPZxo9 Pr4E22vl1PmPPj+nxC1tLCzONXm3R6Xala5c8ygSAgET+zTyIUaiYXhjTmjq29HiPWRw 8yFbH0kJP4bda8hXWAVib5HQuWCklFYqojiQNQ5ldZZQaFjulSR3sasQVCtIbiIpTuWq yiIg== X-Gm-Message-State: AOAM533jCnjK/jzv7aNbx/QMT60vOCF8+ixxz9l3Ca0GblfQIyqbDt15 D06N7421SFcC4ELRurJVo1W4//evQ4sKNrCov8SwpQUOrrZfvRi/OSAGEw7aZYKdAPsPRabaR4g f99TGPl9wzBTVgb5Y28PPN0ipULQDarhogGd55Kf0u/j5NhHGsgl7EFE9fTFSeLQ= X-Google-Smtp-Source: ABdhPJyy9XpZ66lh3lDYA+szDyYwraBv5p1wvroFUo+jvj2X+3eYqDNaZ8m1QJXDZETwXE77SjTDQ0m1ocL4RQ== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a05:6a00:1513:: with SMTP id q19mr3363249pfu.12.1644309636594; Tue, 08 Feb 2022 00:40:36 -0800 (PST) Date: Tue, 8 Feb 2022 16:39:52 +0800 In-Reply-To: <20220208083952.35036-1-chooglen@google.com> Message-Id: <20220208083952.35036-17-chooglen@google.com> Mime-Version: 1.0 References: <20220208083952.35036-1-chooglen@google.com> X-Mailer: git-send-email 2.35.0.263.gb82422642f-goog Subject: [PATCH v6 16/16] submodule: move core cmd_update() logic to C From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Junio C Hamano , Atharva Raykar , Christian Couder , Emily Shaffer , Jonathan Nieder , Kaartic Sivaraam , pc44800@gmail.com, Shourya Shukla , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= " Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Atharva Raykar This patch completes the conversion past the flag parsing of `submodule update` by introducing a helper subcommand called `submodule--helper update`. The behaviour of `submodule update` should remain the same after this patch. We add more fields to the `struct update_data` that are required by `struct submodule_update_clone` to be able to perform a clone, when that is needed to be done. Recursing on a submodule is done by calling a subprocess that launches `submodule--helper update`, with a modified `--recursive-prefix` and `--prefix` parameter. 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 Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 360 ++++++++++++++++++++++-------------- git-submodule.sh | 102 +--------- 2 files changed, 227 insertions(+), 235 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 0ab8f9d49f..5085b28a2d 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1977,7 +1977,6 @@ struct submodule_update_clone { const char *prefix; int single_branch; - /* to be consumed by git-submodule.sh */ struct update_clone_data *update_clone; int update_clone_nr; int update_clone_alloc; @@ -1989,7 +1988,6 @@ 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, \ @@ -2001,6 +1999,7 @@ struct submodule_update_clone { } struct update_data { + const char *prefix; const char *recursive_prefix; const char *sm_path; const char *displaypath; @@ -2008,14 +2007,54 @@ struct update_data { struct object_id suboid; struct submodule_update_strategy update_strategy; int depth; + int recommend_shallow; + int single_branch; + int max_jobs; + unsigned int init; unsigned int force; unsigned int quiet; unsigned int nofetch; unsigned int just_cloned; unsigned int remote; + unsigned int recursive; + unsigned int progress; + unsigned int dissociate; + unsigned int require_init; + unsigned warn_if_uninitialized ; + struct string_list references; + struct module_list list; }; #define UPDATE_DATA_INIT { \ + .list = MODULE_LIST_INIT, \ .update_strategy = SUBMODULE_UPDATE_STRATEGY_INIT, \ + .recommend_shallow = -1, \ + .references = STRING_LIST_INIT_DUP, \ + .single_branch = -1, \ + .max_jobs = 1, \ +} + +static void update_clone_from_update_data(struct submodule_update_clone *suc, + struct update_data *update_data) +{ + suc->prefix = update_data->prefix; + suc->recursive_prefix = update_data->recursive_prefix; + suc->max_jobs = update_data->max_jobs; + suc->progress = update_data->progress; + suc->quiet = update_data->quiet; + suc->dissociate = update_data->dissociate; + suc->require_init = update_data->require_init; + suc->single_branch = update_data->single_branch; + suc->warn_if_uninitialized = update_data->warn_if_uninitialized; + suc->list = update_data->list; + suc->update = update_data->update_strategy; + suc->recommend_shallow = update_data->recommend_shallow; + if (update_data->depth) + suc->depth = xstrfmt("--depth=%d", update_data->depth); + if (update_data->references.nr) { + struct string_list_item *item; + for_each_string_list_item(item, &update_data->references) + string_list_append(&suc->references, item->string); + } } static void next_submodule_warn_missing(struct submodule_update_clone *suc, @@ -2316,8 +2355,15 @@ static int run_update_command(struct update_data *ud, int subforce) struct child_process cp = CHILD_PROCESS_INIT; char *oid = oid_to_hex(&ud->oid); int must_die_on_failure = 0; + struct submodule_update_strategy strategy = SUBMODULE_UPDATE_STRATEGY_INIT; + + if (ud->update_strategy.type == SM_UPDATE_UNSPECIFIED || ud->just_cloned) + determine_submodule_update_strategy(the_repository, ud->just_cloned, + ud->sm_path, NULL, &strategy); + else + strategy = ud->update_strategy; - switch (ud->update_strategy.type) { + switch (strategy.type) { case SM_UPDATE_CHECKOUT: cp.git_cmd = 1; strvec_pushl(&cp.args, "checkout", "-q", NULL); @@ -2340,55 +2386,54 @@ static int run_update_command(struct update_data *ud, int subforce) break; case SM_UPDATE_COMMAND: cp.use_shell = 1; - strvec_push(&cp.args, ud->update_strategy.command); + strvec_push(&cp.args, strategy.command); must_die_on_failure = 1; break; default: BUG("unexpected update strategy type: %s", - submodule_strategy_to_string(&ud->update_strategy)); + submodule_strategy_to_string(&strategy)); } strvec_push(&cp.args, oid); cp.dir = xstrdup(ud->sm_path); prepare_submodule_repo_env(&cp.env_array); if (run_command(&cp)) { - switch (ud->update_strategy.type) { + switch (strategy.type) { case SM_UPDATE_CHECKOUT: - printf(_("Unable to checkout '%s' in submodule path '%s'"), - oid, ud->displaypath); + die_message(_("Unable to checkout '%s' in submodule path '%s'"), + oid, ud->displaypath); break; case SM_UPDATE_REBASE: - printf(_("Unable to rebase '%s' in submodule path '%s'"), - oid, ud->displaypath); + if (!must_die_on_failure) + break; + die(_("Unable to rebase '%s' in submodule path '%s'"), + oid, ud->displaypath); break; case SM_UPDATE_MERGE: - printf(_("Unable to merge '%s' in submodule path '%s'"), - oid, ud->displaypath); + if (!must_die_on_failure) + break; + die(_("Unable to merge '%s' in submodule path '%s'"), + oid, ud->displaypath); break; case SM_UPDATE_COMMAND: - printf(_("Execution of '%s %s' failed in submodule path '%s'"), - ud->update_strategy.command, oid, ud->displaypath); + if (!must_die_on_failure) + break; + die(_("Execution of '%s %s' failed in submodule path '%s'"), + strategy.command, oid, ud->displaypath); break; default: BUG("unexpected update strategy type: %s", - submodule_strategy_to_string(&ud->update_strategy)); + submodule_strategy_to_string(&strategy)); } - /* - * NEEDSWORK: We are currently printing to stdout with error - * return so that the shell caller handles the error output - * properly. Once we start handling the error messages within - * C, we should use die() instead. - */ - if (must_die_on_failure) - return 2; - /* - * This signifies to the caller in shell that the command - * failed without dying - */ + + /* the command failed, but update must continue */ return 1; } - switch (ud->update_strategy.type) { + if (ud->quiet) + return 0; + + switch (strategy.type) { case SM_UPDATE_CHECKOUT: printf(_("Submodule path '%s': checked out '%s'\n"), ud->displaypath, oid); @@ -2403,17 +2448,17 @@ static int run_update_command(struct update_data *ud, int subforce) break; case SM_UPDATE_COMMAND: printf(_("Submodule path '%s': '%s %s'\n"), - ud->displaypath, ud->update_strategy.command, oid); + ud->displaypath, strategy.command, oid); break; default: BUG("unexpected update strategy type: %s", - submodule_strategy_to_string(&ud->update_strategy)); + submodule_strategy_to_string(&strategy)); } return 0; } -static int do_run_update_procedure(struct update_data *ud) +static int run_update_procedure(struct update_data *ud) { int subforce = is_null_oid(&ud->suboid) || ud->force; @@ -2443,89 +2488,6 @@ static int do_run_update_procedure(struct update_data *ud) return run_update_command(ud, subforce); } -static void update_submodule(struct update_clone_data *ucd) -{ - fprintf(stdout, "dummy %s %d\t%s\n", - oid_to_hex(&ucd->oid), - ucd->just_cloned, - ucd->sub->path); -} - -/* - * NEEDSWORK: Use a forward declaration to avoid moving - * run_update_procedure() (which will be removed soon). - */ -static int update_submodule2(struct update_data *update_data); -static int run_update_procedure(int argc, const char **argv, const char *prefix) -{ - char *prefixed_path, *update = NULL; - struct update_data opt = UPDATE_DATA_INIT; - - struct option options[] = { - OPT__QUIET(&opt.quiet, - N_("suppress output for update by rebase or merge")), - OPT__FORCE(&opt.force, N_("force checkout updates"), - 0), - OPT_BOOL('N', "no-fetch", &opt.nofetch, - N_("don't fetch new objects from the remote site")), - OPT_BOOL(0, "just-cloned", &opt.just_cloned, - N_("overrides update mode in case the repository is a fresh clone")), - OPT_INTEGER(0, "depth", &opt.depth, N_("depth for shallow fetch")), - OPT_STRING(0, "prefix", &prefix, - N_("path"), - N_("path into the working tree")), - OPT_STRING(0, "update", &update, - N_("string"), - N_("rebase, merge, checkout or none")), - OPT_STRING(0, "recursive-prefix", &opt.recursive_prefix, N_("path"), - N_("path into the working tree, across nested " - "submodule boundaries")), - OPT_CALLBACK_F(0, "oid", &opt.oid, N_("sha1"), - N_("SHA1 expected by superproject"), PARSE_OPT_NONEG, - parse_opt_object_id), - OPT_BOOL(0, "remote", &opt.remote, - N_("use SHA-1 of submodule's remote tracking branch")), - OPT_END() - }; - - const char *const usage[] = { - N_("git submodule--helper run-update-procedure [] "), - NULL - }; - - argc = parse_options(argc, argv, prefix, options, usage, 0); - - if (argc != 1) - usage_with_options(usage, options); - - opt.sm_path = argv[0]; - - if (opt.recursive_prefix) - prefixed_path = xstrfmt("%s%s", opt.recursive_prefix, opt.sm_path); - else - prefixed_path = xstrdup(opt.sm_path); - - opt.displaypath = get_submodule_displaypath(prefixed_path, prefix); - - determine_submodule_update_strategy(the_repository, opt.just_cloned, - opt.sm_path, update, - &opt.update_strategy); - - free(prefixed_path); - return update_submodule2(&opt); -} - -static int resolve_relative_path(int argc, const char **argv, const char *prefix) -{ - struct strbuf sb = STRBUF_INIT; - if (argc != 3) - die("submodule--helper relative-path takes exactly 2 arguments, got %d", argc); - - printf("%s", relative_path(argv[1], argv[2], &sb)); - strbuf_release(&sb); - return 0; -} - static const char *remote_submodule_branch(const char *path) { const struct submodule *sub; @@ -2868,11 +2830,66 @@ static int module_set_branch(int argc, const char **argv, const char *prefix) return !!ret; } -/* NEEDSWORK: this is a temporary name until we delete update_submodule() */ -static int update_submodule2(struct update_data *update_data) +static void update_data_to_args(struct update_data *update_data, struct strvec *args) +{ + const char *update = submodule_strategy_to_string(&update_data->update_strategy); + + strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL); + strvec_pushf(args, "--jobs=%d", update_data->max_jobs); + if (update_data->prefix) + strvec_pushl(args, "--prefix", update_data->prefix, NULL); + if (update_data->recursive_prefix) + strvec_pushl(args, "--recursive-prefix", + update_data->recursive_prefix, NULL); + if (update_data->quiet) + strvec_push(args, "--quiet"); + if (update_data->force) + strvec_push(args, "--force"); + if (update_data->init) + strvec_push(args, "--init"); + if (update_data->remote) + strvec_push(args, "--remote"); + if (update_data->nofetch) + strvec_push(args, "--no-fetch"); + if (update_data->dissociate) + strvec_push(args, "--dissociate"); + if (update_data->progress) + strvec_push(args, "--progress"); + if (update_data->require_init) + strvec_push(args, "--require-init"); + if (update_data->depth) + strvec_pushf(args, "--depth=%d", update_data->depth); + if (update) + strvec_pushl(args, "--update", update, NULL); + if (update_data->references.nr) { + struct string_list_item *item; + for_each_string_list_item(item, &update_data->references) + strvec_pushl(args, "--reference", item->string, NULL); + } + if (update_data->recommend_shallow == 0) + strvec_push(args, "--no-recommend-shallow"); + else if (update_data->recommend_shallow == 1) + strvec_push(args, "--recommend-shallow"); + if (update_data->single_branch >= 0) + strvec_push(args, "--single-branch"); +} + +static int update_submodule(struct update_data *update_data) { + char *prefixed_path; + ensure_core_worktree(update_data->sm_path); + if (update_data->recursive_prefix) + prefixed_path = xstrfmt("%s%s", update_data->recursive_prefix, + update_data->sm_path); + else + prefixed_path = xstrdup(update_data->sm_path); + + update_data->displaypath = get_submodule_displaypath(prefixed_path, + update_data->prefix); + free(prefixed_path); + /* NEEDSWORK: fix the style issues e.g. braces */ if (update_data->just_cloned) { oidcpy(&update_data->suboid, null_oid()); @@ -2902,18 +2919,55 @@ 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); + if (run_update_procedure(update_data)) + return 1; - return 3; + if (update_data->recursive) { + struct child_process cp = CHILD_PROCESS_INIT; + struct update_data next = *update_data; + int res; + + if (update_data->recursive_prefix) + prefixed_path = xstrfmt("%s%s/", update_data->recursive_prefix, + update_data->sm_path); + else + prefixed_path = xstrfmt("%s/", update_data->sm_path); + + next.recursive_prefix = get_submodule_displaypath(prefixed_path, + update_data->prefix); + next.prefix = NULL; + oidcpy(&next.oid, null_oid()); + oidcpy(&next.suboid, null_oid()); + + cp.dir = update_data->sm_path; + cp.git_cmd = 1; + prepare_submodule_repo_env(&cp.env_array); + update_data_to_args(&next, &cp.args); + + /* die() if child process die()'d */ + res = run_command(&cp); + if (!res) + return 0; + die_message(_("Failed to recurse into submodule path '%s'"), + update_data->displaypath); + if (res == 128) + exit(res); + else if (res) + return 1; + } + + return 0; } -static int update_submodules(struct submodule_update_clone *suc) +static int update_submodules(struct update_data *update_data) { - int i; + int i, res = 0; + struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT; - run_processes_parallel_tr2(suc->max_jobs, update_clone_get_next_task, + update_clone_from_update_data(&suc, update_data); + run_processes_parallel_tr2(suc.max_jobs, update_clone_get_next_task, update_clone_start_failure, - update_clone_task_finished, suc, "submodule", + update_clone_task_finished, &suc, "submodule", "parallel/update"); /* @@ -2924,25 +2978,45 @@ static int update_submodules(struct submodule_update_clone *suc) * checkout involve more straightforward sequential I/O. * - the listener can avoid doing any work if fetching failed. */ - if (suc->quickstop) - return 1; + if (suc.quickstop) { + res = 1; + goto cleanup; + } - for (i = 0; i < suc->update_clone_nr; i++) - update_submodule(&suc->update_clone[i]); + for (i = 0; i < suc.update_clone_nr; i++) { + struct update_clone_data ucd = suc.update_clone[i]; - return 0; + oidcpy(&update_data->oid, &ucd.oid); + update_data->just_cloned = ucd.just_cloned; + update_data->sm_path = ucd.sub->path; + + if (update_submodule(update_data)) + res = 1; + } + +cleanup: + string_list_clear(&update_data->references, 0); + return res; } -static int update_clone(int argc, const char **argv, const char *prefix) +static int module_update(int argc, const char **argv, const char *prefix) { const char *update = NULL; struct pathspec pathspec; - struct submodule_update_clone opt = SUBMODULE_UPDATE_CLONE_INIT; + struct update_data opt = UPDATE_DATA_INIT; + /* NEEDSWORK: update names and strings */ struct option module_update_clone_options[] = { + OPT__FORCE(&opt.force, N_("force checkout updates"), 0), OPT_BOOL(0, "init", &opt.init, N_("initialize uninitialized submodules before update")), - OPT_STRING(0, "prefix", &prefix, + OPT_BOOL(0, "remote", &opt.remote, + N_("use SHA-1 of submodule's remote tracking branch")), + OPT_BOOL(0, "recursive", &opt.recursive, + N_("traverse submodules recursively")), + OPT_BOOL('N', "no-fetch", &opt.nofetch, + N_("don't fetch new objects from the remote site")), + OPT_STRING(0, "prefix", &opt.prefix, N_("path"), N_("path into the working tree")), OPT_STRING(0, "recursive-prefix", &opt.recursive_prefix, @@ -2953,21 +3027,21 @@ static int update_clone(int argc, const char **argv, const char *prefix) N_("string"), N_("rebase, merge, checkout or none")), OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"), - N_("reference repository")), + N_("reference repository")), OPT_BOOL(0, "dissociate", &opt.dissociate, - N_("use --reference only while cloning")), - OPT_STRING(0, "depth", &opt.depth, "", - N_("create a shallow clone truncated to the " - "specified number of revisions")), + N_("use --reference only while cloning")), + OPT_INTEGER(0, "depth", &opt.depth, + N_("create a shallow clone truncated to the " + "specified number of revisions")), OPT_INTEGER('j', "jobs", &opt.max_jobs, N_("parallel jobs")), OPT_BOOL(0, "recommend-shallow", &opt.recommend_shallow, - N_("whether the initial clone should follow the shallow recommendation")), + N_("whether the initial clone should follow the shallow recommendation")), OPT__QUIET(&opt.quiet, N_("don't print cloning progress")), OPT_BOOL(0, "progress", &opt.progress, - N_("force cloning progress")), + N_("force cloning progress")), OPT_BOOL(0, "require-init", &opt.require_init, - N_("disallow cloning into non-empty directory")), + N_("disallow cloning into non-empty directory")), OPT_BOOL(0, "single-branch", &opt.single_branch, N_("clone only one branch, HEAD or --branch")), OPT_END() @@ -2977,16 +3051,18 @@ static int update_clone(int argc, const char **argv, const char *prefix) N_("git submodule--helper update-clone [--prefix=] [...]"), NULL }; - opt.prefix = prefix; update_clone_config_from_gitmodules(&opt.max_jobs); git_config(git_update_clone_config, &opt.max_jobs); argc = parse_options(argc, argv, prefix, module_update_clone_options, git_submodule_helper_usage, 0); + oidcpy(&opt.oid, null_oid()); + oidcpy(&opt.suboid, null_oid()); if (update) - if (parse_submodule_update_strategy(update, &opt.update) < 0) + if (parse_submodule_update_strategy(update, + &opt.update_strategy) < 0) die(_("bad value for update parameter")); if (module_list_compute(argc, argv, prefix, &pathspec, &opt.list) < 0) @@ -3408,9 +3484,7 @@ static struct cmd_struct commands[] = { {"name", module_name, 0}, {"clone", module_clone, 0}, {"add", module_add, SUPPORT_SUPER_PREFIX}, - {"update-clone", update_clone, 0}, - {"run-update-procedure", run_update_procedure, 0}, - {"relative-path", resolve_relative_path, 0}, + {"update", module_update, 0}, {"resolve-relative-url-test", resolve_relative_url_test, 0}, {"foreach", module_foreach, SUPPORT_SUPER_PREFIX}, {"init", module_init, SUPPORT_SUPER_PREFIX}, diff --git a/git-submodule.sh b/git-submodule.sh index 3ccf2388bf..bcd8b92aab 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -347,108 +347,26 @@ cmd_update() shift done - { - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update-clone \ + git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper update \ ${GIT_QUIET:+--quiet} \ - ${progress:+"--progress"} \ + ${force:+--force} \ + ${progress:+--progress} \ + ${dissociate:+--dissociate} \ + ${remote:+--remote} \ + ${recursive:+--recursive} \ ${init:+--init} \ + ${require_init:+--require-init} \ + ${nofetch:+--no-fetch} \ ${wt_prefix:+--prefix "$wt_prefix"} \ ${prefix:+--recursive-prefix "$prefix"} \ ${update:+--update "$update"} \ ${reference:+"$reference"} \ - ${dissociate:+"--dissociate"} \ - ${depth:+--depth "$depth"} \ - ${require_init:+--require-init} \ + ${depth:+"$depth"} \ $single_branch \ $recommend_shallow \ $jobs \ -- \ - "$@" || echo "#unmatched" $? - } | { - err= - while read -r quickabort sha1 just_cloned sm_path - do - die_if_unmatched "$quickabort" "$sha1" - - displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix") - - if test $just_cloned -eq 0 - then - just_cloned= - fi - - out=$(git submodule--helper run-update-procedure \ - ${wt_prefix:+--prefix "$wt_prefix"} \ - ${GIT_QUIET:+--quiet} \ - ${force:+--force} \ - ${just_cloned:+--just-cloned} \ - ${nofetch:+--no-fetch} \ - ${depth:+"$depth"} \ - ${update:+--update "$update"} \ - ${prefix:+--recursive-prefix "$prefix"} \ - ${sha1:+--oid "$sha1"} \ - ${remote:+--remote} \ - "--" \ - "$sm_path") - - # exit codes for run-update-procedure: - # 0: update was successful, say command output - # 1: update procedure failed, but should not die - # 2 or 128: subcommand died during execution - # 3: no update procedure was run - res="$?" - case $res in - 0) - say "$out" - ;; - 1) - err="${err};fatal: $out" - continue - ;; - 2|128) - die_with_status $res "fatal: $out" - ;; - esac - - if test -n "$recursive" - then - ( - prefix=$(git submodule--helper relative-path "$prefix$sm_path/" "$wt_prefix") - wt_prefix= - sanitize_submodule_env - cd "$sm_path" && - eval cmd_update - ) - res=$? - if test $res -gt 0 - then - die_msg="fatal: $(eval_gettext "Failed to recurse into submodule path '\$displaypath'")" - if test $res -ne 2 - then - err="${err};$die_msg" - continue - else - die_with_status $res "$die_msg" - fi - fi - fi - done - - if test -n "$err" - then - OIFS=$IFS - IFS=';' - for e in $err - do - if test -n "$e" - then - echo >&2 "$e" - fi - done - IFS=$OIFS - exit 1 - fi - } + "$@" } #