From patchwork Mon Jun 27 23:20:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12897284 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 67153C433EF for ; Mon, 27 Jun 2022 23:20:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241829AbiF0XUX (ORCPT ); Mon, 27 Jun 2022 19:20:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241117AbiF0XUW (ORCPT ); Mon, 27 Jun 2022 19:20:22 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72CCF2408F for ; Mon, 27 Jun 2022 16:20:21 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id o4so11166096wrh.3 for ; Mon, 27 Jun 2022 16:20:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=7O0JW1YeyGLYQ/boC6Lsk5ZRa1VVtTah6mpLiweSmBI=; b=mEFgNures3Iei5KKEZPzs2yhQyWensYreoB7bBk75BTC+0+NkdqtF8ajjQ9zcZYVaO 3ItwrzwZdxx7bry5MLZuappYlnH7u5pvV3YzqIGIYmE2huSwSHief6TgZQ2jgWqV4Cyl LdJh9FGuu5CN9aRSl5yQa4ILnhn6HYr98deulFj4cZ7GfEbJXu75tDrV1EFtwoonHAD3 o/aBvzSeyBEaeBr25TBFDS9zkOiN57HigGMdNUf3BzdB5//bWTjuTZdrovW1p1qwQGaV pmEzJYklwXD8SN8wwvMDIDvofufMiA1zBKgypmIHSvrfwWRQ6g9DVCH1qZSZGokzEVus RrpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=7O0JW1YeyGLYQ/boC6Lsk5ZRa1VVtTah6mpLiweSmBI=; b=rx5tbTM9Ta3rj5QbhuN5x84UnHXPr7hnm29Hct4UliAQreq79x4brbY/veF4Xtm/kL gvfjWv8DVM0qdgwcHG2qig/vZJyp60KOSvSBdSn9PClCJSFGD+x5SFYF+C2ffLKsCTF2 rmJ1iEEyyUkYCZibCW3fh6MZcSxO2YqCx/o86ofcbTL5FouNZRJYNWW0MrcaCUMNa84g oc20hSxJ4zSRtKKljICVEf478YR3+NitnvIXFE89SoKpD4t7INP7Uv5dMsi4rMTx2Lp6 kJzQggAH0GOdqgn6umrwo5bwwy3wXx54XIaCjNLRDQyBZ6nXtaGRyw1dMsdY7LvTU23r +iBQ== X-Gm-Message-State: AJIora+YOoZZT3fW2zwYy6cx5HqMxZNPi87BKlleuYh8so5onfb2ay5u ZQiRS49g468TvsQsLK3yBuzyTHWjMa7N/A== X-Google-Smtp-Source: AGRyM1t/z7ogHRj0nDSAzFATf1NzGMTa6pfKzSAxqiQxiOiHF6RXJdvTvPj9uZ7regXcbpRwZeXFQw== X-Received: by 2002:a5d:6812:0:b0:21b:8a2f:f732 with SMTP id w18-20020a5d6812000000b0021b8a2ff732mr14184659wru.202.1656372019706; Mon, 27 Jun 2022 16:20:19 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z5-20020adfe545000000b0021b81855c1csm14264937wrm.27.2022.06.27.16.20.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 16:20:19 -0700 (PDT) Message-Id: <473548f2fa473b9b94fcc099a81613c622a32022.1656372017.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 27 Jun 2022 23:20:13 +0000 Subject: [PATCH 1/5] submodule--helper update: use display path helper Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Atharva Raykar , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Johannes Schindelin , Glen Choo , Glen Choo Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Glen Choo From: Glen Choo There are two locations in prepare_to_clone_next_submodule() that manually calculate the submodule display path, but should just use do_get_submodule_displaypath() for consistency. Do this replacement and reorder the code slightly to avoid computing the display path twice. This code was never tested, and adding tests shows that both these sites have been computing the display path incorrectly ever since they were introduced in 48308681b0 (git submodule update: have a dedicated helper for cloning, 2016-02-29) [1]: - The first hunk puts a "/" between recursive_prefix and ce->name, but recursive_prefix already ends with "/". - The second hunk calls relative_path() on recursive_prefix and ce->name, but relative_path() only makes sense when both paths share the same base directory. This is never the case here: - recursive_prefix is the path from the topmost superproject to the current submodule - ce->name is the path from the root of the current submodule to its submodule. so, e.g. recursive_prefix="super" and ce->name="submodule" produces displayname="../super" instead of "super/submodule". While we're fixing the display names, also fix inconsistent quoting of the submodule name. [1] I verified this by applying the tests to 48308681b0. Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 22 +++++--------- t/t7406-submodule-update.sh | 59 +++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 15 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index c597df7528e..63c661b26a6 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1949,30 +1949,22 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, const char *update_string; enum submodule_update_type update_type; char *key; - struct strbuf displaypath_sb = STRBUF_INIT; struct strbuf sb = STRBUF_INIT; - const char *displaypath = NULL; + char *displaypath = NULL; int needs_cloning = 0; int need_free_url = 0; + displaypath = do_get_submodule_displaypath(ce->name, + suc->update_data->prefix, + suc->update_data->recursive_prefix); + if (ce_stage(ce)) { - if (suc->update_data->recursive_prefix) - strbuf_addf(&sb, "%s/%s", suc->update_data->recursive_prefix, ce->name); - else - strbuf_addstr(&sb, ce->name); - strbuf_addf(out, _("Skipping unmerged submodule %s"), sb.buf); - strbuf_addch(out, '\n'); + strbuf_addf(out, _("Skipping unmerged submodule '%s'\n"), displaypath); goto cleanup; } sub = submodule_from_path(the_repository, null_oid(), ce->name); - if (suc->update_data->recursive_prefix) - displaypath = relative_path(suc->update_data->recursive_prefix, - ce->name, &displaypath_sb); - else - displaypath = ce->name; - if (!sub) { next_submodule_warn_missing(suc, out, displaypath); goto cleanup; @@ -2062,7 +2054,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, "--no-single-branch"); cleanup: - strbuf_release(&displaypath_sb); + free(displaypath); strbuf_release(&sb); if (need_free_url) free((void*)url); diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index 43f779d751c..e1dc3b1041b 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -1116,4 +1116,63 @@ test_expect_success 'submodule update --filter sets partial clone settings' ' test_cmp_config -C super-filter/submodule blob:none remote.origin.partialclonefilter ' +# NEEDSWORK: Clean up the tests so that we can reuse the test setup. +# Don't reuse the existing repos because the earlier tests have +# intentionally disruptive configurations. +test_expect_success 'setup clean recursive superproject' ' + git init bottom && + test_commit -C bottom "bottom" && + git init middle && + git -C middle submodule add ../bottom bottom && + git -C middle commit -m "middle" && + git init top && + git -C top submodule add ../middle middle && + git -C top commit -m "top" && + git clone --recurse-submodules top top-clean +' + +test_expect_success 'submodule update should skip unmerged submodules' ' + test_when_finished "rm -fr top-cloned" && + cp -r top-clean top-cloned && + + # Create an upstream commit in each repo + test_commit -C bottom upstream_commit && + (cd middle && + git -C bottom fetch && + git -C bottom checkout -f FETCH_HEAD && + git add bottom && + git commit -m "upstream_commit" + ) && + (cd top && + git -C middle fetch && + git -C middle checkout -f FETCH_HEAD && + git add middle && + git commit -m "upstream_commit" + ) && + + # Create a downstream conflict + (cd top-cloned/middle && + test_commit -C bottom downstream_commit && + git add bottom && + git commit -m "downstream_commit" && + git fetch --recurse-submodules origin && + test_must_fail git merge origin/main + ) && + # Make the update of "middle" a no-op, otherwise we error out + # because of its unmerged state + test_config -C top-cloned submodule.middle.update !true && + git -C top-cloned submodule update --recursive 2>actual.err && + grep "Skipping unmerged submodule .middle/bottom." actual.err +' + +test_expect_success 'submodule update --recursive skip submodules with strategy=none' ' + test_when_finished "rm -fr top-cloned" && + cp -r top-clean top-cloned && + + test_commit -C top-cloned/middle/bottom downstream_commit && + git -C top-cloned/middle config submodule.bottom.update none && + git -C top-cloned submodule update --recursive 2>actual.err && + grep "Skipping submodule .middle/bottom." actual.err +' + test_done From patchwork Mon Jun 27 23:20:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12897283 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 AD230C43334 for ; Mon, 27 Jun 2022 23:20:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241981AbiF0XUY (ORCPT ); Mon, 27 Jun 2022 19:20:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241766AbiF0XUX (ORCPT ); Mon, 27 Jun 2022 19:20:23 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5598A24091 for ; Mon, 27 Jun 2022 16:20:22 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id e28so9951770wra.0 for ; Mon, 27 Jun 2022 16:20:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=BxY3LF83wgNGjpK2zPazu4z9IGR7cWNHVrVfQfTF7Ek=; b=f3lDwZkQ/n7ogYzMY0iXAlHl3+dBVF/CZhIgAuUJ74PNxede1B8DM4N12N07qjXVwe tvuOUbUrxM/PPW6v/BHMSe45iGf67CuweSkgnkzWLAjxxs5Ow+4ZIyhqTnO5xjYuzPvN xd+HnMw+Wwuupc0irWWV+qSsSXN1G8sFMeNb+CZB2/4BdAJ2KwO6cDRYnDo5SOFYtKLf L3RfOwZJwUftqcsPVArBQJrAiIraPn410EMFo8qzH4lA4ZrpkfYVt3n2+J9LWPLFXBP6 Sd9JMx3L4Tp/NK+5nJVJHyCiCIAkZvdGSfIZb/zfTTGpi/B2Vzgd6MExHGnIAeYzrJ41 prSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=BxY3LF83wgNGjpK2zPazu4z9IGR7cWNHVrVfQfTF7Ek=; b=CTVulnTg038UWmA1iZyxtsYMqw/xgdwBsBadPajY+xybejwTz2DIzZp+kZtpFXRqeX QZ0/QWbhHv50Nj8FlrOv+o70FvHM1T6YuU+RT53RgzTutxb8zwGX0S7+3EFbsseus2LO FQhtZ+/rq4yGN6FKjIg8d9HHs23su+ZO6pEE1azJAQDlYPbaLkegaDY3h/x9gCLeEOJd IHwBAyu0Oj1x8t2N6yX+S9k0aWVXbR+62/w/BDiSyZfHxOgar7eg/RW7ZQgy9b8eN7r3 jot9zVPrfYmn2w9rrrbR5r/OXi6pj7XUERWl9DzDDJisLbzFDt8qKKdjpAjkAJe1eWEi pYMw== X-Gm-Message-State: AJIora8rWpdKJh8ftSCjajbPjLghu9NyQJkt+iv7rMnq+8HslEakYJf2 Xi0vgaDvGp9U2tQZRjOzsrs0WHxzMVFztw== X-Google-Smtp-Source: AGRyM1uLHJ0ql4ckorqIKWpRiGcyo2XYZuGrqqKBBRUdGT43m2srFIihE0kwcWrLnzm7RLMqAJZqSA== X-Received: by 2002:a5d:52cb:0:b0:21a:3cc5:f5f4 with SMTP id r11-20020a5d52cb000000b0021a3cc5f5f4mr14728682wrv.367.1656372020660; Mon, 27 Jun 2022 16:20:20 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id bs30-20020a056000071e00b0021bb9071374sm10242991wrb.53.2022.06.27.16.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 16:20:20 -0700 (PDT) Message-Id: <618053730e1f0732fa5a56ffbaa123129eaa17ca.1656372017.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 27 Jun 2022 23:20:14 +0000 Subject: [PATCH 2/5] submodule--helper: don't recreate recursive prefix Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Atharva Raykar , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Johannes Schindelin , Glen Choo , Glen Choo Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Glen Choo From: Glen Choo update_submodule() uses duplicated code to compute update_data->displaypath and next.recursive_prefix. The latter is just the former with "/" appended to it, and since update_data->displaypath not changed outside of this statement, we can just reuse the already computed result. We can go one step further and remove the reference to next.recursive_prefix altogether. Since it is only used in update_data_to_args() (to compute the "--recursive-prefix" flag for the recursive update child process) we can just use the already computed .displaypath value of there. Delete the duplicated code, and remove the unnecessary reference to next.recursive_prefix. As a bonus, this fixes a memory leak where prefixed_path was never freed (this leak was first reported in [1]). [1] https://lore.kernel.org/git/877a45867ae368bf9e053caedcb6cf421e02344d.1655336146.git.gitgitgadget@gmail.com Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 63c661b26a6..7a963a967b8 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2401,9 +2401,9 @@ static void update_data_to_args(struct update_data *update_data, struct strvec * { strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL); strvec_pushf(args, "--jobs=%d", update_data->max_jobs); - if (update_data->recursive_prefix) - strvec_pushl(args, "--recursive-prefix", - update_data->recursive_prefix, NULL); + if (update_data->displaypath) + strvec_pushf(args, "--recursive-prefix=%s/", + update_data->displaypath); if (update_data->quiet) strvec_push(args, "--quiet"); if (update_data->force) @@ -2497,14 +2497,6 @@ static int update_submodule(struct update_data *update_data) 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()); From patchwork Mon Jun 27 23:20:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12897285 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 5DA9EC433EF for ; Mon, 27 Jun 2022 23:20:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241722AbiF0XU2 (ORCPT ); Mon, 27 Jun 2022 19:20:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241117AbiF0XUY (ORCPT ); Mon, 27 Jun 2022 19:20:24 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 401A52408F for ; Mon, 27 Jun 2022 16:20:23 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id c130-20020a1c3588000000b0039c6fd897b4so8374201wma.4 for ; Mon, 27 Jun 2022 16:20:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=qBDa1j6tjIudbPwVuTOWST5afbkWAt1ljAD8RMfo12Y=; b=n8p9+ItEQfcIfsXs6sy4cCSpZj9QfRos6/fIrQ6i/jH1LCc2voPcID4+w/BUSVOsEH 0vaDlbO8XCTo+R26XR61lTABSN6x9wwTcpO46iSfbh9ADZSmJhHkg5ivIjVdHnVQeM46 7FCq4CbVMmBlILEY+g+c162yw0wwKDVzCbJWf4FcCLYwXEJTdVHFTUk+Y1d0UKtjDAj2 t7KXngVyOwtaE0KRYyekbQg6uNVNd+xlWnDjm7JkZr/Z1bf9PhjV0Us9jysyu/SFBem4 gcQTwdU0H6uOPpTSKeQjYXXJfKiBQWk3DYebyTmHtJFUdUa/vTsI68GjyerA5Lvenbyk 89vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=qBDa1j6tjIudbPwVuTOWST5afbkWAt1ljAD8RMfo12Y=; b=xyjQq3i7eorJpJYst2zB3shO1I+x0lvsM1ZlDejYu3zq/zqdUVRw/ZZtTeA9uq1bJy fzFuVS4um+hJkSAoaWduRXwEs5d9xNvRkIn0ekSjzM9BnQQHDJ5Y1OV7w3dphpD9Bclu xsynBMJxaVn8pm/3rQj8Z/G8B1pKvh3XPAYTeDF5qd9qEi+w4VenvOTATXmN21GM18/0 074ABewNTQfdvR8SSaKcSEg+Y13AunWkEZtpQ4ha7YMyQmTaZkxDq65GyXuKCXvnc8cm ZErGb4ha3lBz+p89Tl4jet3VbuINPZOug6X6gHZZWHollJacy+g72zhKH7GnGV5tv27+ OgUw== X-Gm-Message-State: AJIora/Q6jHfGCktznJCi5nsT9iFFQhHqriKWPI34O03QT2KcekCPd6r 0oaaYPf6twZrU5Ixj79A2IEd0Bu7L1f/vg== X-Google-Smtp-Source: AGRyM1uerk6POzvchSNIjiX9f8DA43g9X+iipFq9cEWebq5VXbiNnvelHQgagicFFyG6e5f5NqEgGw== X-Received: by 2002:a1c:cc1a:0:b0:3a0:39b1:3408 with SMTP id h26-20020a1ccc1a000000b003a039b13408mr17847356wmb.157.1656372021561; Mon, 27 Jun 2022 16:20:21 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k31-20020a05600c1c9f00b0039c5642e430sm15327274wms.20.2022.06.27.16.20.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 16:20:21 -0700 (PDT) Message-Id: <7cd1c46f350bf26216814dcf9dd4b8002a91467a.1656372017.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 27 Jun 2022 23:20:15 +0000 Subject: [PATCH 3/5] submodule--helper: use correct display path helper Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Atharva Raykar , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Johannes Schindelin , Glen Choo , Glen Choo Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Glen Choo From: Glen Choo Replace a chunk of code in update_submodule() with an equivalent do_get_submodule_displaypath() invocation. This is already tested by t/t7406-submodule-update.sh:'submodule update --init --recursive from subdirectory', so no tests are added. The two are equivalent because: - Exactly one of recursive_prefix|prefix is non-NULL at a time; prefix is set at the superproject level, and recursive_prefix is set when recursing into submodules. There is also a BUG() statement in get_submodule_displaypath() that asserts that both cannot be non-NULL. - In get_submodule_displaypath(), get_super_prefix() always returns NULL because "--super-prefix" is never passed. Thus calling it is equivalent to calling do_get_submodule_displaypath() with super_prefix = NULL. Therefore: - When recursive_prefix is non-NULL, prefix is NULL, and thus get_submodule_displaypath() just returns prefixed_path. This is identical to calling do_get_submodule_displaypath() with super_prefix = recursive_prefix because the return value is still the concatenation of recursive_prefix + update_data->sm_path. - When prefix is non-NULL, prefixed_path = update_data->sm_path. Thus calling get_submodule_displaypath() with prefixed_path is equivalent to calling do_get_submodule_displaypath() with update_data->sm_path Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 7a963a967b8..fa8256526e9 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2445,19 +2445,11 @@ static void update_data_to_args(struct update_data *update_data, struct strvec * 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); + update_data->displaypath = do_get_submodule_displaypath(update_data->sm_path, + update_data->prefix, + update_data->recursive_prefix); determine_submodule_update_strategy(the_repository, update_data->just_cloned, update_data->sm_path, update_data->update_default, From patchwork Mon Jun 27 23:20:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12897286 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 6F6A1C433EF for ; Mon, 27 Jun 2022 23:20:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242241AbiF0XUd (ORCPT ); Mon, 27 Jun 2022 19:20:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241934AbiF0XUY (ORCPT ); Mon, 27 Jun 2022 19:20:24 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53E3A24096 for ; Mon, 27 Jun 2022 16:20:23 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id o4so11166096wrh.3 for ; Mon, 27 Jun 2022 16:20:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=5JutwRJpD/70ZgoFS+vtRHakI4NctN9EOqcsuj5G/J0=; b=ONh1Kb0Jggc9UoRvP+wJxJBCtxF+mQuw0Ye/EenRzM1khfhCr9WNfgUB3qjVMPQnNZ yTguxsTAav8BO5MR5Y4ZXekMS39kZ3vdxZzpvUSQS2RN4ixShPj5ZJAe3W4+pDBrNBai GVpST6rkl8KnIOClu0htVemFLGk7qRAyqHknsBStJvaJRiVXO+l91Ihx9FGL6mrw6fL0 aiVwLOKh9n1U27wa0bafTaMWdsuDaoSkWpLUwyd7iy6yZoiX7XZtRQFIxJ/Mi9jDdBLk P8BEhK+/BKUX2gBA9LZWr0CxlRkEzYkcr2ttqLKYQ9FS70XJdqHK1jAHFSWx5qlGKXzI 9j7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=5JutwRJpD/70ZgoFS+vtRHakI4NctN9EOqcsuj5G/J0=; b=Uw0U6mU4sVAC8bsx7vMIpsNmvcevLj49dRoSCyhSlk3V0IrwLUGwb2f75eMB8CRoHa S/36DkzWEAF19+dEJuYCxPcg/wbNTHoT6+gt2pwVOB9DQoUZK3mNfW2nEo8NiM7Low7J rAWtg5syX6VRC1cLkettVImZaTtxjLDCgF+ghIxs2TXdqkrBnrcJyp46KdNc1VZgi+NC 0kfwlBPqFrIn6t4IJFj940IprcqL2Ep6BInAAZQpz+O9IFaFiJfHw1GbsHUVq45/a2yL XeQdqOw5SRiuWEgLXB04+pFMElNKvT8swkJ0vQClrLVvsl1G6k+MduNTTSUAfUuhWY77 HOcg== X-Gm-Message-State: AJIora+cFSFSB5g7chXNsu17csxVaIzSIcWf/HoAXmuFTC6VsfQmHIW3 yw7sReFb1rxAht4kQhS9ssNvNQ7a3B3BAg== X-Google-Smtp-Source: AGRyM1tCjy+usQ8btJoPlXOOSFOQXWwkxJCnU6s1Jp5vciJ5wNKkAfEqcN4GJjfWmFKPBK3Z7Y1Ayw== X-Received: by 2002:adf:dece:0:b0:21b:a4b0:f7e3 with SMTP id i14-20020adfdece000000b0021ba4b0f7e3mr14891981wrn.197.1656372022493; Mon, 27 Jun 2022 16:20:22 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p2-20020adfcc82000000b0021b9662a0c7sm11653389wrj.78.2022.06.27.16.20.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 16:20:22 -0700 (PDT) Message-Id: <57988287fc01a8baf5c4fd7326772c80bc015f3c.1656372017.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 27 Jun 2022 23:20:16 +0000 Subject: [PATCH 4/5] submodule--helper update: use --super-prefix Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Atharva Raykar , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Johannes Schindelin , Glen Choo , Glen Choo Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Glen Choo From: Glen Choo Unlike the other subcommands, "git submodule--helper update" uses the "--recursive-prefix" flag instead of "--super-prefix". The two flags are otherwise identical (they only serve to compute the 'display path' of a submodule), except that there is a dedicated helper function to get the value of "--super-prefix". This inconsistency exists because "git submodule update" used to pass "--recursive-prefix" between shell and C (introduced in [1]) before "--super-prefix" was introduced (in [2]), and for simplicity, we kept this name when "git submodule--helper update" was created. Remove "--recursive-prefix" and its associated code from "git submodule--helper update", replacing it with "--super-prefix". To use "--super-prefix", module_update is marked with SUPPORT_SUPER_PREFIX. Note that module_clone must also be marked with SUPPORT_SUPER_PREFIX, otherwise the "git submodule--helper clone" subprocess will fail check because "--super-prefix" is propagated via the environment. [1] 48308681b0 (git submodule update: have a dedicated helper for cloning, 2016-02-29) [2] 74866d7579 (git: make super-prefix option, 2016-10-07) Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index fa8256526e9..81ea4669aab 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -477,22 +477,18 @@ static int starts_with_dot_dot_slash(const char *const path) 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, - const char *superprefix, unsigned int flags) + unsigned int flags) { const struct submodule *sub; struct strbuf sb = STRBUF_INIT; char *upd = NULL, *url = NULL, *displaypath; - /* 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); + displaypath = do_get_submodule_displaypath(path, prefix, get_super_prefix()); sub = submodule_from_path(the_repository, null_oid(), path); @@ -566,7 +562,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->superprefix, info->flags); + init_submodule(list_item->name, info->prefix, info->flags); } static int module_init(int argc, const char **argv, const char *prefix) @@ -1880,7 +1876,6 @@ struct submodule_update_clone { struct update_data { const char *prefix; - const char *recursive_prefix; const char *displaypath; const char *update_default; struct object_id suboid; @@ -1956,7 +1951,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, displaypath = do_get_submodule_displaypath(ce->name, suc->update_data->prefix, - suc->update_data->recursive_prefix); + get_super_prefix()); if (ce_stage(ce)) { strbuf_addf(out, _("Skipping unmerged submodule '%s'\n"), displaypath); @@ -2399,11 +2394,11 @@ static void ensure_core_worktree(const char *path) static void update_data_to_args(struct update_data *update_data, struct strvec *args) { - strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL); - strvec_pushf(args, "--jobs=%d", update_data->max_jobs); if (update_data->displaypath) - strvec_pushf(args, "--recursive-prefix=%s/", + strvec_pushf(args, "--super-prefix=%s/", update_data->displaypath); + strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL); + strvec_pushf(args, "--jobs=%d", update_data->max_jobs); if (update_data->quiet) strvec_push(args, "--quiet"); if (update_data->force) @@ -2449,7 +2444,7 @@ static int update_submodule(struct update_data *update_data) update_data->displaypath = do_get_submodule_displaypath(update_data->sm_path, update_data->prefix, - update_data->recursive_prefix); + get_super_prefix()); determine_submodule_update_strategy(the_repository, update_data->just_cloned, update_data->sm_path, update_data->update_default, @@ -2573,10 +2568,6 @@ static int module_update(int argc, const char **argv, const char *prefix) OPT_STRING(0, "prefix", &opt.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", &opt.update_default, N_("string"), N_("rebase, merge, checkout or none")), @@ -2655,7 +2646,6 @@ static int module_update(int argc, const char **argv, const char *prefix) module_list_active(&list); info.prefix = opt.prefix; - info.superprefix = opt.recursive_prefix; if (opt.quiet) info.flags |= OPT_QUIET; @@ -3352,9 +3342,9 @@ struct cmd_struct { static struct cmd_struct commands[] = { {"list", module_list, 0}, {"name", module_name, 0}, - {"clone", module_clone, 0}, + {"clone", module_clone, SUPPORT_SUPER_PREFIX}, {"add", module_add, SUPPORT_SUPER_PREFIX}, - {"update", module_update, 0}, + {"update", module_update, SUPPORT_SUPER_PREFIX}, {"resolve-relative-url-test", resolve_relative_url_test, 0}, {"foreach", module_foreach, SUPPORT_SUPER_PREFIX}, {"init", module_init, SUPPORT_SUPER_PREFIX}, From patchwork Mon Jun 27 23:20:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12897287 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 063EFC43334 for ; Mon, 27 Jun 2022 23:20:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242119AbiF0XUo (ORCPT ); Mon, 27 Jun 2022 19:20:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242014AbiF0XU1 (ORCPT ); Mon, 27 Jun 2022 19:20:27 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3512124093 for ; Mon, 27 Jun 2022 16:20:25 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id n1so15090980wrg.12 for ; Mon, 27 Jun 2022 16:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Zo91zgT3j+dK4VHiPk16G+LAMPUeaUatKo//jodID5g=; b=F+eRzJGMo4+ErF3giCwqKJgdSWXiy0NkOUsyKOOdHh9MmruCpZwSUHeukwZ+HGIQUT niqt1ciARnLOoj800Qh86qkLjVMAZ+Krlh3elc6X5dAziNB6GV0a6aIWRmMJpiSqAOrB rgpELM6Z6ov/Nloe+cvrHHbEF6WkvE3evVnVeiKIIGFbLnGvgtbyt6I1mH0wPrXtpawC p0dBHwVpeSc3QjFG2BhkkQJh+h/1aGuCBMlOv8VHjh8t7GfEsnW4a8O6i5S8KNdqjCqk 2vUCsZ5JQr3YdUkKsJO8iABgFeF/w7JL9JdWH3scQGVUXUNf73NMDF0lizu7xqCa280d d74w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Zo91zgT3j+dK4VHiPk16G+LAMPUeaUatKo//jodID5g=; b=tShVbSnULKVTMUvZU/HhCnjrTnweZfbdS8RAC0OSCqo2NsVaP6AMIi1auE7eyoyBue 1KpAxV2KCI3isAMeJn7ljoqalA7w8I/7n3GMi0mWhRq+0ljgZAACgg5MCsAE3LMdyrWm BU+fN+viEZvPZvs7WL20lTnUD+XuDsYfg2lQmgY7T1Z01T9UqQMMAVypDEXpyEm/HvBb uyR2xKN2Zm/xLL6t3zR0cr7Kzs6VhXIII/F7glPbpkmxs2xyOm3riIv08MK3CLmdQ91k 1KWu0mFOmfWKGl8JUAWtBjcj+THhERQVarDnumrpHBitsJBDE/IZen+7NnIUnPsaKBnz URTQ== X-Gm-Message-State: AJIora8Xn/ZRVcb6T1IQEtNvE+av9BGYu/vga1OkL1NScKzGoqv32Hrq cFYVT7GAmC4Y1z0hocqMeEK6H3CvAMjy8A== X-Google-Smtp-Source: AGRyM1ukTvIbjP62eb2OkknbasE812NYjnBbJpHLWzQX8uzNk3l6o2XxWP9/cTtZ3EljxWPResrNhA== X-Received: by 2002:adf:ef11:0:b0:21b:a557:b06d with SMTP id e17-20020adfef11000000b0021ba557b06dmr14839789wro.434.1656372023522; Mon, 27 Jun 2022 16:20:23 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n12-20020a5d420c000000b0021b8d1b0568sm12012604wrq.52.2022.06.27.16.20.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 16:20:22 -0700 (PDT) Message-Id: <9fa13380b02174a4ff9cbe153166689561d23535.1656372017.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 27 Jun 2022 23:20:17 +0000 Subject: [PATCH 5/5] submodule--helper: remove display path helper Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Atharva Raykar , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Johannes Schindelin , Glen Choo , Glen Choo Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Glen Choo From: Glen Choo All invocations of do_get_submodule_displaypath() pass get_super_prefix() as the super_prefix arg, which is exactly the same as get_submodule_displaypath(). Replace all calls to do_get_submodule_displaypath() with get_submodule_displaypath(), and since it has no more callers, remove it. Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 81ea4669aab..73b36f47600 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -118,10 +118,11 @@ static int resolve_relative_url_test(int argc, const char **argv, const char *pr return 0; } -static char *do_get_submodule_displaypath(const char *path, - const char *prefix, - const char *super_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(); + if (prefix && super_prefix) { BUG("cannot have prefix '%s' and superprefix '%s'", prefix, super_prefix); @@ -137,13 +138,6 @@ static char *do_get_submodule_displaypath(const char *path, } } -/* 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; @@ -488,7 +482,7 @@ static void init_submodule(const char *path, const char *prefix, struct strbuf sb = STRBUF_INIT; char *upd = NULL, *url = NULL, *displaypath; - displaypath = do_get_submodule_displaypath(path, prefix, get_super_prefix()); + displaypath = get_submodule_displaypath(path, prefix); sub = submodule_from_path(the_repository, null_oid(), path); @@ -1949,9 +1943,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, int needs_cloning = 0; int need_free_url = 0; - displaypath = do_get_submodule_displaypath(ce->name, - suc->update_data->prefix, - get_super_prefix()); + displaypath = + get_submodule_displaypath(ce->name, suc->update_data->prefix); if (ce_stage(ce)) { strbuf_addf(out, _("Skipping unmerged submodule '%s'\n"), displaypath); @@ -2442,9 +2435,8 @@ static int update_submodule(struct update_data *update_data) { ensure_core_worktree(update_data->sm_path); - update_data->displaypath = do_get_submodule_displaypath(update_data->sm_path, - update_data->prefix, - get_super_prefix()); + update_data->displaypath = get_submodule_displaypath( + update_data->sm_path, update_data->prefix); determine_submodule_update_strategy(the_repository, update_data->just_cloned, update_data->sm_path, update_data->update_default,