From patchwork Fri Jul 1 02:11:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12902542 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 081B5C43334 for ; Fri, 1 Jul 2022 02:12:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232632AbiGACMM (ORCPT ); Thu, 30 Jun 2022 22:12:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232319AbiGACML (ORCPT ); Thu, 30 Jun 2022 22:12:11 -0400 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 ADABE5927B for ; Thu, 30 Jun 2022 19:12:10 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id z5-20020aa785c5000000b00527d84dfb49so254107pfn.21 for ; Thu, 30 Jun 2022 19:12:10 -0700 (PDT) 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=1W8J32CwXeXzfRle6UA+Blg4bciYwwQD89cvBI0xtp8=; b=oWgUI3r6uUpjkpidLKG9K+FNUffRMEPGDFBatoXBBBgy66rp5dqRap9Xd+pM0BDbRJ REAQtdFCElG6wZSl6vrzPbmyoQ7RMfH9dft3NDBl7K1DzpC/sSNtogduOujNmnyj5oZX p2eJOpQPtk5qVg1kUdC1IieTsDgVz5CR+qtye9Wrp0JpV5Wiu2WbVISC0vJRkDVOsjTz 36hHYx9asApNzwV3tZSWaqyle4/1oqt1zCb/Zqcsal9CYAFl8EYGYNla8Piz5q9vNzXf P4z/CVthB30JO9BaZnKRIX3Wt36k7DwCYFRbGPRxJz000qrCUXxswfv+N4IQ0T4YtkhE gQ8g== 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=1W8J32CwXeXzfRle6UA+Blg4bciYwwQD89cvBI0xtp8=; b=TNs/ZhaZf5fI49AA6L0N6Wx9npFT5cpJnUbWVmfLENEBPVJjYtA4clbOMXRnEvjFQy cS6AwHNmSmjFkaCpWWxOpLuYFiAOYlEqCRxOND94vQboRDJ0vq9hahgC/jgujJqrDBW7 VfuCIOonRypsG/gBsDli7cwKultZhmbtH+Ho/LoyRQA48BNly0EvibJnf3KvAag1qYgA T43SKTfjmpg/qdDmXRftI5hO3nW0+5BfHXE1jQMpdwUegyfKlT4nSf44z3RSNq36Nty6 fuz41BTkR1id8W1tcGyxxWPMixDlRUHPHqimMWCO0HIFtp/RnDzO6qxwaCNJRDoU38o0 azbA== X-Gm-Message-State: AJIora/kjm5kocqi3+vRcKeAZRPBrvOApJ1iRPFpXW0TI1SzMuO+CmTy m3QFhIGbC6RI07J2P40HkFINq2Z7LVKyhRqGRD5NWt7+oOoUcStCEDuEd1RXJII5CEd3BbEz0oX itABjcVdScp7vj/ZGaK5vfFULBQZrdVgew9a5z50nFhj1EOFvG1ZX3gW9b4sQW2M= X-Google-Smtp-Source: AGRyM1vIy92Dz/5PI7CjiJDrqaHgyTdpQ3EL/5X+XpH0hIedoeRqOHS3Ez2ezzsJfNON4jdRUGTSlI88RaKnug== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a62:b514:0:b0:525:1ccd:4506 with SMTP id y20-20020a62b514000000b005251ccd4506mr17472757pfe.8.1656641530136; Thu, 30 Jun 2022 19:12:10 -0700 (PDT) Date: Thu, 30 Jun 2022 19:11:51 -0700 In-Reply-To: <20220701021157.88858-1-chooglen@google.com> Message-Id: <20220701021157.88858-2-chooglen@google.com> Mime-Version: 1.0 References: <20220630221147.45689-1-chooglen@google.com> <20220701021157.88858-1-chooglen@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v4 1/7] submodule--helper tests: add missing "display path" coverage From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Atharva Raykar , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= " , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There are two locations in prepare_to_clone_next_submodule() that manually calculate the submodule display path. As discussed in the next commit the "Skipping" output isn't exactly what we want, but let's test how we behave now, before changing the existing behavior. Signed-off-by: Glen Choo Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t7406-submodule-update.sh | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index 06d804e213..9a076e025f 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -1116,4 +1116,66 @@ 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, starting with bottom + test_commit -C bottom upstream_commit && + # Create middle commit + git -C middle/bottom fetch && + git -C middle/bottom checkout -f FETCH_HEAD && + git -C middle add bottom && + git -C middle commit -m "upstream_commit" && + # Create top commit + git -C top/middle fetch && + git -C top/middle checkout -f FETCH_HEAD && + git -C top add middle && + git -C top commit -m "upstream_commit" && + + # Create a downstream conflict + test_commit -C top-cloned/middle/bottom downstream_commit && + git -C top-cloned/middle add bottom && + git -C top-cloned/middle commit -m "downstream_commit" && + git -C top-cloned/middle fetch --recurse-submodules origin && + test_must_fail git -C top-cloned/middle 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 && + cat >expect.err <<-\EOF && + Skipping unmerged submodule middle//bottom + EOF + test_cmp expect.err 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 && + cat >expect.err <<-\EOF && + Skipping submodule '\''../middle/'\'' + EOF + test_cmp expect.err actual.err +' + test_done From patchwork Fri Jul 1 02:11:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12902543 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 EEF3BC43334 for ; Fri, 1 Jul 2022 02:12:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232851AbiGACMQ (ORCPT ); Thu, 30 Jun 2022 22:12:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231777AbiGACMO (ORCPT ); Thu, 30 Jun 2022 22:12:14 -0400 Received: from mail-ot1-x34a.google.com (mail-ot1-x34a.google.com [IPv6:2607:f8b0:4864:20::34a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9F0B5C9D5 for ; Thu, 30 Jun 2022 19:12:12 -0700 (PDT) Received: by mail-ot1-x34a.google.com with SMTP id z35-20020a9d24a6000000b006169679be60so523782ota.4 for ; Thu, 30 Jun 2022 19:12:12 -0700 (PDT) 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=5rKBXAkepuPmAcAwO6HKgUAqFe1oVJv4K7pGXgqHBx8=; b=OcR51Ey3Xd9S3pMqFpoRRfBaZqnBzr/VqwXUP1wHa2Nty/f8IwAGgRXueqh1nR73g5 7zvoNx1+gkz5I1Bp+4ruTT7kD+cqjEvxBbypZqndvYDIegNO4997zdTxiviZEoYrNuJL Cb9GOIIui040iOzs0kSSZk8jL3O5lMFYqdomBnRY89G7LD3I5JBK0z403yEoDKiZovmA WLu7PP18vS47DYhmCXdLNiNDF9XeIUgx9hvA+HXlxP2z6snFVOYCmvf1fIE+cuqpi5od vk6YYu97jnow568HcvMpdSQwEGFm3R9Ft9RKI3Mhx2FKPS2W20mTzqkBpy1GsNF2tsF/ kqPA== 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=5rKBXAkepuPmAcAwO6HKgUAqFe1oVJv4K7pGXgqHBx8=; b=Dnr8PihHFlDmW6yREkC9vwL55Ekmoa3JR5WQ+rcIg95Dd+D34eTbQBPDFMKkQh/mR9 C0dMutLsVNyoDw1/kJZ3txIipFApBMqruGAvBVEpMzothgB8w4AFJKBpLgv66Qbfc9ea CWmE1Zzbx1V2JKOcHonsorEAnqpE/qCv6HCUJdbT4MPQwFgeqKrT4HGNc50y51EiO6H5 Np0WwuRSSS2noY78/mtFeyepmlRfFqKqo/q1rqTOoh3pJ9vySOBIw6N2KfaymfSKWB/u 0Mh25S4foxcAJwp5gqQg2enrVc0SB7zjhE1xk6gceHrpC0fTu471FEWXwbla7Gzbnb5g qPGQ== X-Gm-Message-State: AJIora9yO4NYXTN7sm9gECCU0VBLqlcojem22Tfzc9u+MAm1J1BK5YWI fd7b8lIOcJ9fYHNkwWCDSDTG2fibMtPbpB14WwK6Blz+zfLdxr2jo3A9ToQTI6Uk25ZfMwKqYVL M3mt5Z+g3kwzYjX1MFlNDsjkHPD95GB+NM27y5tWsTTGg5MGSFeFGR4QkdIj5bPw= X-Google-Smtp-Source: AGRyM1t30R6HbfdviTWODJJhxZiSx4UvmQYfXBKxX3OKW4mLFxzJLwJg4CmQGegSvzFYki0nXBFQZe5eDoqJfw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a05:6870:1e8c:b0:106:a0ac:9f73 with SMTP id pb12-20020a0568701e8c00b00106a0ac9f73mr7046050oab.163.1656641532122; Thu, 30 Jun 2022 19:12:12 -0700 (PDT) Date: Thu, 30 Jun 2022 19:11:52 -0700 In-Reply-To: <20220701021157.88858-1-chooglen@google.com> Message-Id: <20220701021157.88858-3-chooglen@google.com> Mime-Version: 1.0 References: <20220630221147.45689-1-chooglen@google.com> <20220701021157.88858-1-chooglen@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v4 2/7] submodule--helper update: use display path helper From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Atharva Raykar , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= " , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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. Until the preceding commit this code had never been tested, with our newly added tests we can see 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". [1] I verified this by applying the tests to 48308681b0. Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 19 +++++-------------- t/t7406-submodule-update.sh | 4 ++-- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 389b900602..9381127d56 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1947,30 +1947,21 @@ 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 update_data *ud = suc->update_data; + char *displaypath = do_get_submodule_displaypath(ce->name, ud->prefix, + ud->recursive_prefix); struct strbuf sb = STRBUF_INIT; - const char *displaypath = NULL; int needs_cloning = 0; int need_free_url = 0; 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_addf(out, _("Skipping unmerged submodule %s"), displaypath); strbuf_addch(out, '\n'); 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; @@ -2060,7 +2051,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 9a076e025f..6cc07460dd 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -1160,7 +1160,7 @@ test_expect_success 'submodule update should skip unmerged submodules' ' test_config -C top-cloned submodule.middle.update !true && git -C top-cloned submodule update --recursive 2>actual.err && cat >expect.err <<-\EOF && - Skipping unmerged submodule middle//bottom + Skipping unmerged submodule middle/bottom EOF test_cmp expect.err actual.err ' @@ -1173,7 +1173,7 @@ test_expect_success 'submodule update --recursive skip submodules with strategy= git -C top-cloned/middle config submodule.bottom.update none && git -C top-cloned submodule update --recursive 2>actual.err && cat >expect.err <<-\EOF && - Skipping submodule '\''../middle/'\'' + Skipping submodule '\''middle/bottom'\'' EOF test_cmp expect.err actual.err ' From patchwork Fri Jul 1 02:11:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12902544 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 4FDD3C43334 for ; Fri, 1 Jul 2022 02:12:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232852AbiGACMV (ORCPT ); Thu, 30 Jun 2022 22:12:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232845AbiGACMQ (ORCPT ); Thu, 30 Jun 2022 22:12:16 -0400 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 F0ECD5C9E4 for ; Thu, 30 Jun 2022 19:12:14 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id nl1-20020a17090b384100b001ef0930ec9fso607172pjb.7 for ; Thu, 30 Jun 2022 19:12:14 -0700 (PDT) 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=hk44uy+nIhh4BP3afglzKX71919gUBL9sVJTuv4iSn0=; b=sTRFKYzpPPuDPv++q+z0T5970yz4kIv/Txq+s0EwBpDQZwnIEt9tI5QygHQjWEfdKd TgCslKLoBhlKv8jjmUdFAUfP0wRyUVMe7ICqs8y+BLPgWKLkcU4ynlGXOf96Atnk2iCe +gTfjjGA5RKmugXMa3WeC4I9lH+HwPHrsEcnUGxLTtOVLubr18HKZgtLj2o63UCpCYmV fLKDwMy2RHKEEmW1lgG32xrY/cayqeCFCtndhIAiiv17NPLHz1YY/a+UiGBJdAS0l8jw twMBVMQOOquKT8Vy8SeKkLGypMtoOxT6xttzdDppoxYRFzpYPpVu/WZ4ydSkAjuoxgSc MWjw== 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=hk44uy+nIhh4BP3afglzKX71919gUBL9sVJTuv4iSn0=; b=0cOSm+C2R4uIuLM5hQC2jsCeyftKthGPHqQ7VIqREDOoNBfwBvU9OEzuuYkzJdHiuC GSjBhbzCkuQAWZnECKQayLgxDauS/glQFeSmgaOZX9baPUCsdK1KhroVp69wx8/duLDM 7gPsrIFSUw0HTFp8q0p/gltVz5P78puXuPYlehPFum8FleBCBZBnDHflB0QfDeJXscNf bZ/kBSDeugnFd1OfF73lUTQc1yCqs+2TbuiGwodiF6Ok0M2tzWM4pG+0bJ+IIk2YV0oi feo5HM5l0690Bihi2ajxU322HrNMobH2F6xBfnYS/VJEny8TS0/NifrpCqS89wznSQ+k lt9Q== X-Gm-Message-State: AJIora8ZBU5nvHfp9btk5ifzae1DX1TbfteYvLSWHFF5FvFkmcZJt7pg S8b3PyuKDckqyFA1gIqH0H4vJl+gHlyXdFTJ5rDV/Pxio/iFBqnd5QsH00RqRnIeYXR2qUhXtRQ h97JWSFKuCROscZ5Scd7dmli1E98ERe2yOmU55Ff0KFIA+IJMPWexAuzGjY8uDZg= X-Google-Smtp-Source: AGRyM1vZJ7MYs37Et2lzgbJUuW39rco1Bzy3kz/YFF8goxB0GfQBQFrmGALLLeq4dVJT5NaXiC/vWsj3wz5ifA== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:903:1c3:b0:16b:a8f8:882c with SMTP id e3-20020a17090301c300b0016ba8f8882cmr8100640plh.158.1656641534134; Thu, 30 Jun 2022 19:12:14 -0700 (PDT) Date: Thu, 30 Jun 2022 19:11:53 -0700 In-Reply-To: <20220701021157.88858-1-chooglen@google.com> Message-Id: <20220701021157.88858-4-chooglen@google.com> Mime-Version: 1.0 References: <20220630221147.45689-1-chooglen@google.com> <20220701021157.88858-1-chooglen@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v4 3/7] submodule--helper: don't recreate recursive prefix From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Atharva Raykar , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= " , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 9381127d56..4a0eb05ba2 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2416,9 +2416,10 @@ 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_push(args, "--recursive-prefix"); + strvec_pushf(args, "%s/", update_data->displaypath); + } if (update_data->quiet) strvec_push(args, "--quiet"); if (update_data->force) @@ -2514,14 +2515,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 Fri Jul 1 02:11:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12902545 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 F399DC43334 for ; Fri, 1 Jul 2022 02:12:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232740AbiGACMd (ORCPT ); Thu, 30 Jun 2022 22:12:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232173AbiGACMR (ORCPT ); Thu, 30 Jun 2022 22:12:17 -0400 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 C9BF25C9E4 for ; Thu, 30 Jun 2022 19:12:16 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id u6-20020a17090a1d4600b001ec8200fe70so670310pju.1 for ; Thu, 30 Jun 2022 19:12:16 -0700 (PDT) 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=OhxB8Ha20RvzutIxfZ24TgLwnYOTpOhJl8faME5W5zg=; b=BMPxlux/Pjj0IlgFgr8RrzQvLGuyHYk1RHG4Z7D2aJR2Shi1rmFtlEXD4d1LUy3JZ6 Qi2seyvp5KqXY3FQFgTgfLr7qjqshK337Le2h66hrg3gOsLkdUWhQ0wmZqUn/nnnZw10 cqcPn5jEMGgnFsMFnTZZipMWLMPsFH9NzaRel/++y88FiQSI1+2ghONDSG4gLS8OghoJ tPbZI63CvaAEZfIt7w85WDU75KLnKGjI491bK5ghRoBmB7j84OwI0KWImvUe8msKogqV IzlKlpACYGUUYC57G+aE4TbkD1GYwzRhFijXeFmjGzfglM17xnnbTXtUw3cltbsFDROB LSeQ== 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=OhxB8Ha20RvzutIxfZ24TgLwnYOTpOhJl8faME5W5zg=; b=iGuoLERNGQiKmvuxiHSTJ/ahmDgwjf7vP2rIgWaGmLRYK0cucd8wdC4zBJmZNItSgw YHB58mzoss2x5idOublVMPRwYD3SFq3AYZtENa/CioceJtf5huckmIfTqvGhK72XRdH+ VxjlrMz6KFra8sBsopH6feu+DkA/U9WDmPcjC9yE0wGkpfqKinBo5/qhPfLdjGy3pKg6 32SztpBuZBy2DATEn0xMMR6MfvnAkJJ3QlxKe5AzEIqIlWljOZ23zba9CczLkSJ1ZrHw Tl4oVpSdoKjc6uszvHoiTA7N4dHZkZn88SVgX0yM/T8xlFx5N1nPikiJYbcnvNm5uhcG en/g== X-Gm-Message-State: AJIora8ocq8hxTqCeXtFG9Qae/9qpK3HIxW6nnB4t3lb8HMzTK79y6Qn 3iExccRVmLlyJ4rxROdPHeMsLcIwn2L+GM6k8UQswzBTdM+si5shg5f9xHjNbBKSsT6H4lzzjak lVZpQ97Lzc8yoOmGuak23VmFjOl3YA6xIuZvyzlBgQz6KW4IrlI1jXwGobmPCV2c= X-Google-Smtp-Source: AGRyM1saIhBHscNTHyVNpap22Op4M5Si8ypOrofUGH9MC+Tgf/vpTA5eJojAwC4rR0+exmfrcOJtZzs2dYV79w== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:d50b:b0:16a:2cb3:750d with SMTP id b11-20020a170902d50b00b0016a2cb3750dmr18897762plg.17.1656641536279; Thu, 30 Jun 2022 19:12:16 -0700 (PDT) Date: Thu, 30 Jun 2022 19:11:54 -0700 In-Reply-To: <20220701021157.88858-1-chooglen@google.com> Message-Id: <20220701021157.88858-5-chooglen@google.com> Mime-Version: 1.0 References: <20220630221147.45689-1-chooglen@google.com> <20220701021157.88858-1-chooglen@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v4 4/7] submodule--helper: use correct display path helper From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Atharva Raykar , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= " , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 4a0eb05ba2..65350bde4b 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2463,19 +2463,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 Fri Jul 1 02:11:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12902547 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 E6C14C43334 for ; Fri, 1 Jul 2022 02:12:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232923AbiGACMj (ORCPT ); Thu, 30 Jun 2022 22:12:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232931AbiGACMY (ORCPT ); Thu, 30 Jun 2022 22:12:24 -0400 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 BA0435C9F5 for ; Thu, 30 Jun 2022 19:12:18 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id jg5-20020a17090326c500b0016a020648bcso591548plb.19 for ; Thu, 30 Jun 2022 19:12:18 -0700 (PDT) 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=JZx8jZJDz2rNmvvwjsJHtZPhT7Qj+ZSMSQlTgAKxanw=; b=Ix8yHpl11hocEdVwKGVr/kVHwfxViXVOlqFtm1hv3OEPFXvCI5M9e7Tm5+J+b2GDT0 ZEr8FgHSN2om056NlsEg/Qv6KCkilk/Cl5vgxBUMYYnULF+SAhq5a7TrZ3KNstoa45Ar Zge8jyylrK85fyvXVUygbt78KtARhMmUZMfZBfrleTRTK1uSwvUJuzWJh79OQQJrwQsg +DKbxtQ8FhUYqgP6txMAXp38k9xhWi6or+PvvMvKVC8HXZMifZZcyo3u2dBXvCkadAB/ bR0+s5LjxYSkGhzxhw3x6m+dmwGgWwlcFEjL6JIZp9kK3ieBAWxYvRk5lzN2/MSIud6u kx+g== 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=JZx8jZJDz2rNmvvwjsJHtZPhT7Qj+ZSMSQlTgAKxanw=; b=k/N7vZdEqvVQrLcd3AGdBmM2QLKkVGw4qdmmtd3BYdwviX/i8Wez01cijlOdJhLK81 wkkWsmP2b4zPubw4TBp59TjAI7fRZvt0y8qfYAXd+5U/K3zomIayoTy4VqZf1IUMIVuo juRidKJY3eJVA2Bb8IpJfNnE/BCHNWBJoVBbUxU3XQHvhJQhdgYOvM/1oXbBmScBVyah +SjT4DZ33+Fzn2Q2K37mGvBRFSiLuIdM+cD2TB0JH6x6kA9w+f9hu7ezoZHdEIxDVvh5 mAdDqeSYRCMr8RWbszumLAriRbFh2y131gVDE1WZx/7Do6u/6+usUpq199Ep5i74wh1C e/kA== X-Gm-Message-State: AJIora9IMP8umNkdylkTz15+9wdz21ABxM7BhhkqTLSHUrdtYLF9aGaO E13XqXy3o26WBMzsCgzOjpB9zthxpgIbFH93lhrg2kZMq7BQFwzPxYDZIDWBUCtKyJhBcfCBXE8 Ol18lB19xjQvsOH0CaxtGF8+4N1CkZN4Pc0V9LAmUMtblY8HafjfE1utR45JieN4= X-Google-Smtp-Source: AGRyM1uo9Nz5EHbzl7YUO9VQAkufK4vPhtdLn+qc6NR4mXzUnMF3NBBVg/CVopNn9RiD7fsB5fSBvj3Uleaa5A== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a05:6a00:1908:b0:525:5dad:cb1c with SMTP id y8-20020a056a00190800b005255dadcb1cmr18544493pfi.47.1656641538070; Thu, 30 Jun 2022 19:12:18 -0700 (PDT) Date: Thu, 30 Jun 2022 19:11:55 -0700 In-Reply-To: <20220701021157.88858-1-chooglen@google.com> Message-Id: <20220701021157.88858-6-chooglen@google.com> Mime-Version: 1.0 References: <20220630221147.45689-1-chooglen@google.com> <20220701021157.88858-1-chooglen@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v4 5/7] submodule--helper: remove unused SUPPORT_SUPER_PREFIX flags From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Atharva Raykar , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= " , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ævar Arnfjörð Bjarmason Remove the SUPPORT_SUPER_PREFIX flag from "add", "init" and "summary". For the "add" command it hasn't been used since [1], likewise for "init" and "summary" since [2] and [3], respectively. As implemented in 74866d75793 (git: make super-prefix option, 2016-10-07) the SUPPORT_SUPER_PREFIX flag in git.c applies for the entire command, but as implemented in 89c86265576 (submodule helper: support super prefix, 2016-12-08) we assert here in cmd_submodule__helper() that we're not getting the flag unexpectedly. 1. 8c8195e9c3e (submodule--helper: introduce add-clone subcommand, 2021-07-10) 2. 6e7c14e65c8 (submodule update --init: display correct path from submodule, 2017-01-06) 3. 1cf823d8f00 (submodule: remove unnecessary `prefix` based option logic, 2021-06-22) Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Glen Choo --- builtin/submodule--helper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 65350bde4b..a7b40482b8 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -3378,15 +3378,15 @@ static struct cmd_struct commands[] = { {"list", module_list, 0}, {"name", module_name, 0}, {"clone", module_clone, 0}, - {"add", module_add, SUPPORT_SUPER_PREFIX}, + {"add", module_add, 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}, + {"init", module_init, 0}, {"status", module_status, SUPPORT_SUPER_PREFIX}, {"sync", module_sync, SUPPORT_SUPER_PREFIX}, {"deinit", module_deinit, 0}, - {"summary", module_summary, SUPPORT_SUPER_PREFIX}, + {"summary", module_summary, 0}, {"push-check", push_check, 0}, {"absorbgitdirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX}, {"is-active", is_active, 0}, From patchwork Fri Jul 1 02:11:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12902546 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 A5736C433EF for ; Fri, 1 Jul 2022 02:12:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232884AbiGACMh (ORCPT ); Thu, 30 Jun 2022 22:12:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233017AbiGACMZ (ORCPT ); Thu, 30 Jun 2022 22:12:25 -0400 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 1E94A5C9FF for ; Thu, 30 Jun 2022 19:12:21 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id g23-20020a056a00079700b00525285ae44eso258404pfu.13 for ; Thu, 30 Jun 2022 19:12:21 -0700 (PDT) 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=eUCtPsfSctwRCZhpKBSi8lmY7LmQyiCzsCMGjA6+Kgk=; b=YcXdyTnQUcpnbsPh32cmw2VT9zOzFaDmGlwiL4bp8moiIuH5FtbV/gViaxEaTWye6S cZ9/jCnhfj2QmO5SZcqRV/q4ybH2+jPwsbDLEUX48ysuXTl8CVxlX+xCkBbGJKUe/tir jIdu2JF8mBlV7YP7Au9tI5H/krPK57yerRqkKh74MtO7UkoTte390QhyuSWqKFCuL/Yn 3sHjNxk3A98VWb/lGEDxhY6vwtOmlRdlbvWUr2W2pQxzpbDaPfVdD6d6klLY4EZVYBUK 8QT9gimiokIbk6cjkKXkhLg7dKxQScCoUNYC9Rc+QCQQxk8qPV/8dc9MtEHubKQOkL6i HwBQ== 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=eUCtPsfSctwRCZhpKBSi8lmY7LmQyiCzsCMGjA6+Kgk=; b=Nsw3hHBp7HvM9exR7WhExlubSdD0vFgHERrSpRyi9EMOdR1zwjkYD7Svereayz/Umx /IJKGiB5sHFxE9a60fUKgQr0R/s6bmBSYHnuB9Sj3Wx09ORZEEuiy1eFrPbKRJV9JS+B 5yBlvQKKnsFUnS3KLe5QV22X2BOZXe6lvv8Thln3HLa6aaJbBlGLNyIB43x+ep2YPU/e U8zwonCJnT9OrlC1+tM0xuHOd81+he1lFoFfqBgz0k+2zksQdS2em5KcTR8ujBZP54ww am9LdfbjEf1uzNH2wwiMXwDmm7V92+voyQyQRI3a/m6/qTGa+j/7dK/2p1/tI2r0dVCE fDsQ== X-Gm-Message-State: AJIora8+zmWfdS+lMK44zMZzCi5SX842O0e5OfAhfocI8Rn1TVmfeV79 ztkEF1HswWUEIeP5/XsfYEzcqUyEk9MUlUrV4OLs+nDOXFdJx+ChrRVp7eV9tLNTLBn784JNbtg sqGneqdDYquHqkX7DEboZylS8ESv5VnPmA2JKSL2NwPikCnfW5srz1jUxl27LX48= X-Google-Smtp-Source: AGRyM1sSP0Un1B6unL/3FzbIdy6cFGu0rCF2Lf9q5xpbhNoD9LlwJM5TMmKX5AcpCxeQICArntrOLPtxZ+b0uw== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:90a:249:b0:1e0:a8a3:3c6c with SMTP id t9-20020a17090a024900b001e0a8a33c6cmr344126pje.0.1656641540075; Thu, 30 Jun 2022 19:12:20 -0700 (PDT) Date: Thu, 30 Jun 2022 19:11:56 -0700 In-Reply-To: <20220701021157.88858-1-chooglen@google.com> Message-Id: <20220701021157.88858-7-chooglen@google.com> Mime-Version: 1.0 References: <20220630221147.45689-1-chooglen@google.com> <20220701021157.88858-1-chooglen@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v4 6/7] submodule--helper update: use --super-prefix From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Atharva Raykar , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= " , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 a7b40482b8..eb84e3a98b 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) @@ -1878,7 +1874,6 @@ struct submodule_update_clone { struct update_data { const char *prefix; - const char *recursive_prefix; const char *displaypath; enum submodule_update_type update_default; struct object_id suboid; @@ -1949,7 +1944,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, char *key; struct update_data *ud = suc->update_data; char *displaypath = do_get_submodule_displaypath(ce->name, ud->prefix, - ud->recursive_prefix); + get_super_prefix()); struct strbuf sb = STRBUF_INIT; int needs_cloning = 0; int need_free_url = 0; @@ -2414,12 +2409,12 @@ static void update_data_to_args(struct update_data *update_data, struct strvec * { enum submodule_update_type update_type = update_data->update_default; - strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL); - strvec_pushf(args, "--jobs=%d", update_data->max_jobs); if (update_data->displaypath) { - strvec_push(args, "--recursive-prefix"); + strvec_push(args, "--super-prefix"); strvec_pushf(args, "%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) @@ -2467,7 +2462,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, @@ -2591,10 +2586,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_SET_INT(0, "checkout", &opt.update_default, N_("use the 'checkout' update strategy (default)"), SM_UPDATE_CHECKOUT), @@ -2680,7 +2671,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; @@ -3377,9 +3367,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, 0}, - {"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, 0}, From patchwork Fri Jul 1 02:11:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glen Choo X-Patchwork-Id: 12902548 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 9C422C43334 for ; Fri, 1 Jul 2022 02:12:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232963AbiGACMk (ORCPT ); Thu, 30 Jun 2022 22:12:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233034AbiGACM0 (ORCPT ); Thu, 30 Jun 2022 22:12:26 -0400 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 7293060508 for ; Thu, 30 Jun 2022 19:12:22 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id jg5-20020a17090326c500b0016a020648bcso591653plb.19 for ; Thu, 30 Jun 2022 19:12:22 -0700 (PDT) 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=l4pUsrUEx/+7EPda9I7NMpbfcYywsaWP95UMb/3whBI=; b=mYlTmUM00VNHT8MACWMlQaWtPx0SgZBfWW7O7S5YpgWHqFxAdAIj9lxDfXj+3hFKVU 5mV5a7zSUdPYQ2fQ/ZczyG7ajRacOCK4/WxVJ0XMpg7OzWJw4Wx+w9XewjGeF07HY267 ulzugWxPQ0eWIC9gtRHve7Y91di7FCED5VYN/boVCD30tGj7egoXqnD55Zk3WiYUTujF gDm6y2HuXVIuXTSTawA6Po09dobHPggVQ6ke60Q4uy1bv8Yqm5nEbDQ8TXFFW2AeJBgq n+VeDZZeh+2mKkbzbr1jFY7WySpOBr+BMwv9Qji4+OKYek9xW5S9fFgiaBGxS532NG0i xpcQ== 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=l4pUsrUEx/+7EPda9I7NMpbfcYywsaWP95UMb/3whBI=; b=xNYn9n7frkSEBhra1nHlbvdTzKkpDvU2leOK8a9IQ9WwsVmleRt1e/M31+qjukAip6 9ITC4cvXu7eeKhqfdz5NcY4t9LFCysdTmsEZe8swWsNwBTZXxHUOhYJtEwPIAX5DKSFe zI/gTt1lFx9AdbtJWIFsIW3HlwWqezzVxBkALyUNQT9R5CesDsFwHIE8cPeMhKGyEGkC ZEOjebd6L7syKG2rM85ai5EUUEl31xxTPo5e7VEV33Wd927IAWRVLA4ONhaFV2HUnT74 PurYqDAqpLBe/zOHYCCQN5wUAHFkeQxSTtMS+xyjFuP5aV1Tz7WNVX9N51cGGMaFB5Sy KJyQ== X-Gm-Message-State: AJIora+GRcSUucpFUFLlkTp4Rr8jhe+CnFqFPJeMmOyJ99Q8wAlVuPkS u50EFdPr/5aOYcN74vYFFgS6sYzzwCMunfDDiIEfSif7uZ91uzQgYrPwLvNkhagcVu7mGILqBlE OiPy5arR8geR7O4hTcXPS6rPWRhGyswb4CbXVqJ4NT3xF2qsKxp/H3whs9HADGfQ= X-Google-Smtp-Source: AGRyM1sFgg/qQqkhkoOrKQMPANUkaNongP0D8CmEa2I/VKUTuVu+ihG8nR35/DR/Lomu3LPfhZohl7AATBWAtg== X-Received: from chooglen.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:26d9]) (user=chooglen job=sendgmr) by 2002:a17:902:c948:b0:16a:58f4:c142 with SMTP id i8-20020a170902c94800b0016a58f4c142mr17859292pla.103.1656641542137; Thu, 30 Jun 2022 19:12:22 -0700 (PDT) Date: Thu, 30 Jun 2022 19:11:57 -0700 In-Reply-To: <20220701021157.88858-1-chooglen@google.com> Message-Id: <20220701021157.88858-8-chooglen@google.com> Mime-Version: 1.0 References: <20220630221147.45689-1-chooglen@google.com> <20220701021157.88858-1-chooglen@google.com> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog Subject: [PATCH v4 7/7] submodule--helper: remove display path helper From: Glen Choo To: git@vger.kernel.org Cc: Glen Choo , Atharva Raykar , " =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= " , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index eb84e3a98b..405a4224c5 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); @@ -1943,8 +1937,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, enum submodule_update_type update_type; char *key; struct update_data *ud = suc->update_data; - char *displaypath = do_get_submodule_displaypath(ce->name, ud->prefix, - get_super_prefix()); + char *displaypath = get_submodule_displaypath(ce->name, ud->prefix); struct strbuf sb = STRBUF_INIT; int needs_cloning = 0; int need_free_url = 0; @@ -2460,9 +2453,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,