From patchwork Wed Jun 16 00:45:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12323497 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92E0FC48BE5 for ; Wed, 16 Jun 2021 00:45:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7310761153 for ; Wed, 16 Jun 2021 00:45:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231765AbhFPArZ (ORCPT ); Tue, 15 Jun 2021 20:47:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230265AbhFPArZ (ORCPT ); Tue, 15 Jun 2021 20:47:25 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4DB7C061574 for ; Tue, 15 Jun 2021 17:45:18 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id d7-20020ac811870000b02901e65f85117bso438520qtj.18 for ; Tue, 15 Jun 2021 17:45:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=TV0prvvrsCIJBrwi27jPzB+dng21Wkg3mr1uXlMe5I4=; b=e0loB2AVoPJiYJdqxLRrila9iKsHiKpHGh0kqb0FsnSs7TcVtTwJ3ix837flVyIx+8 x7xI31oipYrD7o8pbEce9qqmhs+0ADBJe/HWXYCUAShfOaCOn4EPE9RuoIUsHyt7nuyu YP7E7oRQWn37H2EAIX0hL5MSlKJv2E4bIF+1C8O40SbXzNukhzMHX6RhutiqE2vm9jsu cOB18Xbi951FyKHY6ElA9WHpicTOUXt0KaY407N8y8h5lt+/el9QyhDbun/u7knBYLeL NOils4hu7dj6DwatJmUgY33exntngO87V6qHoGm7p16A0yVV56odMdnzcHzF/4kNP/Wf 8kqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=TV0prvvrsCIJBrwi27jPzB+dng21Wkg3mr1uXlMe5I4=; b=Tq/TU3CzpAKVFJw+RuEp9nE6IXZ2sHtyFfCxDu8MTyV5/O9MrCXoiDVjgFdq2nE37e ThgxM+V8K8XRYK/PkNMCnXKsuPFdzEtPVP5+1QzTiW6kggpp8gWnz1EbQRqbZRaaR7Tj K2SJjEGqHM75QrHwlfyO9RKIOYU+hO1nvQ/GfNHGetWESKyeJhy1YrqRRV8W2ahR1iMp l25EeyTxtGg4H+5SNC4JE/ld8rVpxVDygFm3Ap7x/CtQbC7RjnPYB/dG6K0/H8wQVL1N 4pCJDuSxCdQ4b3AI6ZEzS5b14Yp/mo53JDDUx2z+7rytdLBrYjVLT0Dxp1NaacDytDzQ XNLw== X-Gm-Message-State: AOAM531kbDnVp3FUbWC4x8UJpXmfTUl0ibvLY4rmd+DoS1x6G7HxKWwO EStYtJGoq7jVsAtt93ee5ysPuKyjtYvQJquPPI1UWaooVHjAA0h0jUTg1VTu77Kbp7iBNZfWV2/ ObSUiqlGuX0dJfk/QrDzRNjIT+fTuH+MJ1tpWjq7fD8wKCqv9hVndsbnctwV/kXodcp2Y0wqLFQ == X-Google-Smtp-Source: ABdhPJzB6ks1ekIopA2xFquN1h4ouXrt/vSXINcxIbczvMtgOcn/oPpba/P0D2wM1wvXPqpiVDDP4GTeLXymiHh6CUY= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:d4cc:f4a9:b043:ff6e]) (user=emilyshaffer job=sendgmr) by 2002:a0c:f684:: with SMTP id p4mr8248601qvn.16.1623804317919; Tue, 15 Jun 2021 17:45:17 -0700 (PDT) Date: Tue, 15 Jun 2021 17:45:05 -0700 In-Reply-To: <20210616004508.87186-1-emilyshaffer@google.com> Message-Id: <20210616004508.87186-2-emilyshaffer@google.com> Mime-Version: 1.0 References: <20210616004508.87186-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog Subject: [PATCH v2 1/4] t7400-submodule-basic: modernize inspect() helper From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Since the inspect() helper in the submodule-basic test suite was written, 'git -C ' was added. By using -C, we no longer need a reference to the base directory for the test. This simplifies callsites, and will make the addition of other arguments in later patches more readable. Signed-off-by: Emily Shaffer --- t/t7400-submodule-basic.sh | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index a924fdb7a6..f5dc051a6e 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -107,25 +107,18 @@ test_expect_success 'setup - repository to add submodules to' ' # generates, which will expand symbolic links. submodurl=$(pwd -P) -listbranches() { - git for-each-ref --format='%(refname)' 'refs/heads/*' -} - inspect() { dir=$1 && - dotdot="${2:-..}" && - ( - cd "$dir" && - listbranches >"$dotdot/heads" && - { git symbolic-ref HEAD || :; } >"$dotdot/head" && - git rev-parse HEAD >"$dotdot/head-sha1" && - git update-index --refresh && - git diff-files --exit-code && - git clean -n -d -x >"$dotdot/untracked" - ) + git -C "$dir" for-each-ref --format='%(refname)' 'refs/heads/*' >heads && + { git -C "$dir" symbolic-ref HEAD || :; } >head && + git -C "$dir" rev-parse HEAD >head-sha1 && + git -C "$dir" update-index --refresh && + git -C "$dir" diff-files --exit-code && + git -C "$dir" clean -n -d -x >untracked } + test_expect_success 'submodule add' ' echo "refs/heads/main" >expect && @@ -146,7 +139,7 @@ test_expect_success 'submodule add' ' ) && rm -f heads head untracked && - inspect addtest/submod ../.. && + inspect addtest/submod && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -237,7 +230,7 @@ test_expect_success 'submodule add --branch' ' ) && rm -f heads head untracked && - inspect addtest/submod-branch ../.. && + inspect addtest/submod-branch && test_cmp expect-heads heads && test_cmp expect-head head && test_must_be_empty untracked @@ -253,7 +246,7 @@ test_expect_success 'submodule add with ./ in path' ' ) && rm -f heads head untracked && - inspect addtest/dotsubmod/frotz ../../.. && + inspect addtest/dotsubmod/frotz && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -269,7 +262,7 @@ test_expect_success 'submodule add with /././ in path' ' ) && rm -f heads head untracked && - inspect addtest/dotslashdotsubmod/frotz ../../.. && + inspect addtest/dotslashdotsubmod/frotz && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -285,7 +278,7 @@ test_expect_success 'submodule add with // in path' ' ) && rm -f heads head untracked && - inspect addtest/slashslashsubmod/frotz ../../.. && + inspect addtest/slashslashsubmod/frotz && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -301,7 +294,7 @@ test_expect_success 'submodule add with /.. in path' ' ) && rm -f heads head untracked && - inspect addtest/realsubmod ../.. && + inspect addtest/realsubmod && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -317,7 +310,7 @@ test_expect_success 'submodule add with ./, /.. and // in path' ' ) && rm -f heads head untracked && - inspect addtest/realsubmod2 ../.. && + inspect addtest/realsubmod2 && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -348,7 +341,7 @@ test_expect_success 'submodule add in subdirectory' ' ) && rm -f heads head untracked && - inspect addtest/realsubmod3 ../.. && + inspect addtest/realsubmod3 && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked From patchwork Wed Jun 16 00:45:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12323499 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26ED3C49361 for ; Wed, 16 Jun 2021 00:45:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0C58161369 for ; Wed, 16 Jun 2021 00:45:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231761AbhFPAr0 (ORCPT ); Tue, 15 Jun 2021 20:47:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231749AbhFPArZ (ORCPT ); Tue, 15 Jun 2021 20:47:25 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BBA4C061574 for ; Tue, 15 Jun 2021 17:45:20 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id g9-20020a25ae490000b029052f9e5b7d3fso570593ybe.4 for ; Tue, 15 Jun 2021 17:45:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=i6zQVxJDwkeyVQCay7H3LISlaFW4Ee0RtDXk4aJYJ/o=; b=qiCx599tVkV2C/hwzcKhraD5EnPlxd4XsB/z1Z6jLzsMKwXb1qwFPmv2kDm/aUALn4 JdiobQ1AfXhdTA6tqC6xsIYB8zDHl6oUCNSpe/BjdTWcxAibbFsINMAAnpBRk2TPZYXl AAMYIY/lYJx5EgYA23dvVo5FowkBZAlifWFiv2NzlK3J0XCW3D3gd/nmJOSzlEVRMJmG zSZ02DtWzHVchXFfLxf4NutjAqQbfp7MCDA1cj0+HlX+4GkRfWolWUo7bPSqU7I2kqBC wdI2cyg5lwVyNjc/l3vg0egnN/rG7QVnenUvhXRF0IdW+ma1y5/fkbOAb+RXbW2YPs8W 5Cow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=i6zQVxJDwkeyVQCay7H3LISlaFW4Ee0RtDXk4aJYJ/o=; b=CYx7Cgr5+7fgF0BQxFhNV2uCpJzqKsfg4bKPvM5gFmBRtwPJT+2IV7qufETrrIM+kP PydpVDgHPuDP9VwGnUq/ZW/n2HoTAYd4y54aVSv3sIEWZW2EMSzauxg0U71W1MhOIVNw PHPUCVBTYjC+3VrAEd0HSdiBnLGMjCYlZeNzCxELveKO9IDcWHJ9txxq/LVJGOGc2ece 7XC0ivykvmIGexDAlINCgidxNF0/jrDtaYRqvB2B3nY+m5CW4AcaikBni5xd+T5fDuzf aFgqhZGhJiwCOwwiCtURgYdjuonL7KAbuvI9R9u2FPsyya8Q5WR0EegjKoY+I24NujW3 RfIQ== X-Gm-Message-State: AOAM530wEcHoCum8wFLw27ZdBvVzxKlGwCXvpRIzK/Uetb2QHtofDHiQ R/OIhLaijzaAliFiABLbrEfojNwVOxLdpteDpwnYZfD3vtpRgjbiZC8tuM5PtZrSHIi1Nb99Q0T JNf2JolB/sriTKtZNxAN8pg1uYx2mfQA+GFhtwvPB15UwjjicgSKjJdftdcAMejP+YrU7YhA1Jw == X-Google-Smtp-Source: ABdhPJxezdHT3T+dPbjELlPJWGsoXcaOhVKLeU5ufqAGdfoZhRiqZLynuAZgRhabM7mEX35qx9IDadL72QwSzDX5lY8= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:d4cc:f4a9:b043:ff6e]) (user=emilyshaffer job=sendgmr) by 2002:a25:db93:: with SMTP id g141mr2824972ybf.141.1623804319784; Tue, 15 Jun 2021 17:45:19 -0700 (PDT) Date: Tue, 15 Jun 2021 17:45:06 -0700 In-Reply-To: <20210616004508.87186-1-emilyshaffer@google.com> Message-Id: <20210616004508.87186-3-emilyshaffer@google.com> Mime-Version: 1.0 References: <20210616004508.87186-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog Subject: [PATCH v2 2/4] introduce submodule.superprojectGitDir cache From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Teach submodules a reference to their superproject's gitdir. This allows us to A) know that we're running from a submodule, and B) have a shortcut to the superproject's vitals, for example, configs. By using a relative path instead of an absolute path, we can move the superproject directory around on the filesystem without breaking the submodule's cache. Since this cached value is only introduced during new submodule creation via `git submodule add`, though, there is more work to do to allow the cache to be created at other times. Signed-off-by: Emily Shaffer --- Documentation/config/submodule.txt | 12 +++++++++ builtin/submodule--helper.c | 4 +++ t/t7400-submodule-basic.sh | 40 ++++++++++++++++-------------- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/Documentation/config/submodule.txt b/Documentation/config/submodule.txt index d7a63c8c12..7c459cc19e 100644 --- a/Documentation/config/submodule.txt +++ b/Documentation/config/submodule.txt @@ -90,3 +90,15 @@ submodule.alternateErrorStrategy:: `ignore`, `info`, `die`. Default is `die`. Note that if set to `ignore` or `info`, and if there is an error with the computed alternate, the clone proceeds as if no alternate was specified. + +submodule.superprojectGitDir:: + The relative path from the submodule's worktree to the superproject's + gitdir. This config should only be present in projects which are + submodules, but is not guaranteed to be present in every submodule. It + is set automatically during submodule creation. ++ + In situations where more than one superproject references the same + submodule worktree, the value of this config and the behavior of + operations which use it are undefined. To reference a single project + from multiple superprojects, it is better to create a worktree of the + submodule for each superproject. diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index d55f6262e9..d60fcd2c7d 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1910,6 +1910,10 @@ static int module_clone(int argc, const char **argv, const char *prefix) git_config_set_in_file(p, "submodule.alternateErrorStrategy", error_strategy); + git_config_set_in_file(p, "submodule.superprojectGitdir", + relative_path(absolute_path(get_git_dir()), + path, &sb)); + free(sm_alternate); free(error_strategy); diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index f5dc051a6e..e45f42588f 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -108,14 +108,18 @@ test_expect_success 'setup - repository to add submodules to' ' submodurl=$(pwd -P) inspect() { - dir=$1 && - - git -C "$dir" for-each-ref --format='%(refname)' 'refs/heads/*' >heads && - { git -C "$dir" symbolic-ref HEAD || :; } >head && - git -C "$dir" rev-parse HEAD >head-sha1 && - git -C "$dir" update-index --refresh && - git -C "$dir" diff-files --exit-code && - git -C "$dir" clean -n -d -x >untracked + sub_dir=$1 && + super_dir=$2 && + + git -C "$sub_dir" for-each-ref --format='%(refname)' 'refs/heads/*' >heads && + { git -C "$sub_dir" symbolic-ref HEAD || :; } >head && + git -C "$sub_dir" rev-parse HEAD >head-sha1 && + git -C "$sub_dir" update-index --refresh && + git -C "$sub_dir" diff-files --exit-code && + cached_super_dir="$(git -C "$sub_dir" config --get submodule.superprojectGitDir)" && + [ "$(git -C "$super_dir" rev-parse --absolute-git-dir)" \ + -ef "$sub_dir/$cached_super_dir" ] && + git -C "$sub_dir" clean -n -d -x >untracked } @@ -139,7 +143,7 @@ test_expect_success 'submodule add' ' ) && rm -f heads head untracked && - inspect addtest/submod && + inspect addtest/submod addtest && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -230,7 +234,7 @@ test_expect_success 'submodule add --branch' ' ) && rm -f heads head untracked && - inspect addtest/submod-branch && + inspect addtest/submod-branch addtest && test_cmp expect-heads heads && test_cmp expect-head head && test_must_be_empty untracked @@ -246,7 +250,7 @@ test_expect_success 'submodule add with ./ in path' ' ) && rm -f heads head untracked && - inspect addtest/dotsubmod/frotz && + inspect addtest/dotsubmod/frotz addtest && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -262,7 +266,7 @@ test_expect_success 'submodule add with /././ in path' ' ) && rm -f heads head untracked && - inspect addtest/dotslashdotsubmod/frotz && + inspect addtest/dotslashdotsubmod/frotz addtest && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -278,7 +282,7 @@ test_expect_success 'submodule add with // in path' ' ) && rm -f heads head untracked && - inspect addtest/slashslashsubmod/frotz && + inspect addtest/slashslashsubmod/frotz addtest && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -294,7 +298,7 @@ test_expect_success 'submodule add with /.. in path' ' ) && rm -f heads head untracked && - inspect addtest/realsubmod && + inspect addtest/realsubmod addtest && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -310,7 +314,7 @@ test_expect_success 'submodule add with ./, /.. and // in path' ' ) && rm -f heads head untracked && - inspect addtest/realsubmod2 && + inspect addtest/realsubmod2 addtest && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -341,7 +345,7 @@ test_expect_success 'submodule add in subdirectory' ' ) && rm -f heads head untracked && - inspect addtest/realsubmod3 && + inspect addtest/realsubmod3 addtest && test_cmp expect heads && test_cmp expect head && test_must_be_empty untracked @@ -482,7 +486,7 @@ test_expect_success 'update should work when path is an empty dir' ' git submodule update -q >update.out && test_must_be_empty update.out && - inspect init && + inspect init . && test_cmp expect head-sha1 ' @@ -541,7 +545,7 @@ test_expect_success 'update should checkout rev1' ' echo "$rev1" >expect && git submodule update init && - inspect init && + inspect init . && test_cmp expect head-sha1 ' From patchwork Wed Jun 16 00:45:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12323501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F645C48BDF for ; Wed, 16 Jun 2021 00:45:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3955B61153 for ; Wed, 16 Jun 2021 00:45:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231766AbhFPAr3 (ORCPT ); Tue, 15 Jun 2021 20:47:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231749AbhFPAr1 (ORCPT ); Tue, 15 Jun 2021 20:47:27 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69DBEC061574 for ; Tue, 15 Jun 2021 17:45:22 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id eb2-20020ad44e420000b029025a58adfc6bso832880qvb.9 for ; Tue, 15 Jun 2021 17:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=UHH7lt3Mp23ZWUnF+lHu8bmsruUoRPJCsYStn0pWHOo=; b=NwmdsDDowA3o28EzNyTp/F0yGtvHTQQvIuwxmfikd9RQgRj4mzs0qk1mt8neC7geH1 tplmMvqabFluE/7F2lkh6cyRfRTOI9BwqiDYX5wvxyR7lPRgwUBloz4W1vUO16wjWPtt gfyaWtRs3dugX5RHrO+2eSkt54UWL4rDfVeh2v2JC9BTvfVKG/hgzAX2qTA4Y5ddIPxk 30AtJkgTqlHPcJsu1HBe2habQ6jmzx3lmceuBy59tUjk2xOJaJzBegoiNyZkyxG1bg1R lORPwpftnTvnpJWdfLhq83rbjiKp/gkNrthf3T8II6mLdFck6Y0dEqZkX+8xXJKuLbcX 4ixA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=UHH7lt3Mp23ZWUnF+lHu8bmsruUoRPJCsYStn0pWHOo=; b=dRVXQmPSufvsrqBb7mepldS7n+ghHwU1fCsmt+cqhznnYuD1lNN4ISc8UpCW5mP1UF 1/ry09q/yt/rkKi9nMCtEULpV74jjqHsToWDmdvuu+VmDmeIKh5LXLdxCFDerS+Cai23 AyrzISEu/dYNnP52ngXknkP7QxAYHELh9tDo6v6CGlxQgfF8VymexJaP7Hxx9dZm7oIZ f2lBnVFCBAd/IZXk1XkxUwCfhSoip92MZx31I5ZysFcUnSl4XtaZp+lq8DumX6Hk7id2 bfhw2BJ0GbhrqrGz2OREegVMB/VyNY6MpngfmpPKltrQULi470OM/YIlUJhqA+FYZ2KH 2sAw== X-Gm-Message-State: AOAM530U5qruKirX1+Uh7x0GIfnvw5wMEZkPilmXTbBDbpW3KgTLBxrj ea0C2CjirUxj75W1YoVfbXKt/umGIVc2PjZ02Dyi78YE2TH4boxExu5CUVrx3x4F1qHejS3SgwR 5b0zyADETjZSUuxPxpZU7nl4RF6ZTPYBP4WPNiQ5SSQ1FYpVVqZtchSzG88MuoMOWf4UBLw8VqQ == X-Google-Smtp-Source: ABdhPJwpZI2AwhRC/PEQvQoqX62QiyG3JovcJNzgsIVjn8xMevgEpTJPfo5dHhBi+kcvgLp6kMlMUDQIvWyTOs84O50= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:d4cc:f4a9:b043:ff6e]) (user=emilyshaffer job=sendgmr) by 2002:a0c:c3d1:: with SMTP id p17mr8044970qvi.44.1623804321541; Tue, 15 Jun 2021 17:45:21 -0700 (PDT) Date: Tue, 15 Jun 2021 17:45:07 -0700 In-Reply-To: <20210616004508.87186-1-emilyshaffer@google.com> Message-Id: <20210616004508.87186-4-emilyshaffer@google.com> Mime-Version: 1.0 References: <20210616004508.87186-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog Subject: [PATCH v2 3/4] submodule: cache superproject gitdir during absorbgitdirs From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Already during 'git submodule add' we cache a pointer to the superproject's gitdir. However, this doesn't help brand-new submodules created with 'git init' and later absorbed with 'git submodule absorbgitdir'. Let's start adding that pointer during 'git submodule absorbgitdir' too. Signed-off-by: Emily Shaffer --- submodule.c | 10 ++++++++++ t/t7412-submodule-absorbgitdirs.sh | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/submodule.c b/submodule.c index 0b1d9c1dde..4b314bf09c 100644 --- a/submodule.c +++ b/submodule.c @@ -2065,6 +2065,7 @@ static void relocate_single_git_dir_into_superproject(const char *path) char *old_git_dir = NULL, *real_old_git_dir = NULL, *real_new_git_dir = NULL; char *new_git_dir; const struct submodule *sub; + struct strbuf config_path = STRBUF_INIT, sb = STRBUF_INIT; if (submodule_uses_worktrees(path)) die(_("relocate_gitdir for submodule '%s' with " @@ -2096,6 +2097,15 @@ static void relocate_single_git_dir_into_superproject(const char *path) relocate_gitdir(path, real_old_git_dir, real_new_git_dir); + /* cache pointer to superproject's gitdir */ + /* NEEDSWORK: this may differ if experimental.worktreeConfig is enabled */ + strbuf_addf(&config_path, "%s/config", real_new_git_dir); + git_config_set_in_file(config_path.buf, "submodule.superprojectGitdir", + relative_path(get_super_prefix_or_empty(), + path, &sb)); + + strbuf_release(&config_path); + strbuf_release(&sb); free(old_git_dir); free(real_old_git_dir); free(real_new_git_dir); diff --git a/t/t7412-submodule-absorbgitdirs.sh b/t/t7412-submodule-absorbgitdirs.sh index 1cfa150768..e2d78e01df 100755 --- a/t/t7412-submodule-absorbgitdirs.sh +++ b/t/t7412-submodule-absorbgitdirs.sh @@ -30,7 +30,14 @@ test_expect_success 'absorb the git dir' ' git status >actual.1 && git -C sub1 rev-parse HEAD >actual.2 && test_cmp expect.1 actual.1 && - test_cmp expect.2 actual.2 + test_cmp expect.2 actual.2 && + + # make sure the submodule cached the superproject gitdir correctly + test-tool path-utils real_path . >expect && + test-tool path-utils real_path \ + "$(git -C sub1 config submodule.superprojectGitDir)" >actual && + + test_cmp expect actual ' test_expect_success 'absorbing does not fail for deinitialized submodules' ' From patchwork Wed Jun 16 00:45:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12323503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2FA9C48BE5 for ; Wed, 16 Jun 2021 00:45:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9A70C61241 for ; Wed, 16 Jun 2021 00:45:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231777AbhFPArc (ORCPT ); Tue, 15 Jun 2021 20:47:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231775AbhFPAra (ORCPT ); Tue, 15 Jun 2021 20:47:30 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53D40C061574 for ; Tue, 15 Jun 2021 17:45:24 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id i3-20020a259d030000b029054c59edf217so573204ybp.3 for ; Tue, 15 Jun 2021 17:45:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=+4gINbzM6jbipQ/SlVuYxWfW/gZphO4a+ijKs8CI7/U=; b=R3SfMs3TZneQyu4ii3evq1lRgIQYBZC9TWbgzIktqHFXmbUzG4T45ajIvO1ab7uIZZ fHkwL8VYIZIdLQoApjbHGc75tans4nIWfKOD38zF+hBxMFvGqABvoX2k2Y1HAxb6pMPL 1n9a3sLG/r6m2OMkDgOolgtxOdRvRdfZzTQ/Xz+Irqgy19FhLTQh9JfdtG49A8HMu+vL 6z2yQDmU9tW5LqXEXyJRnDjHgrk8Edj+HJU6Tg4Jv0i5JbMMg/YK60WLjDCnudxG9Y8z H72N2aQxwWrjOSkgDn3zQV7plQl8cLhHqRM8JeX2dMXl63Plq2pNbpdJkTy7/ciGgtdS D87A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=+4gINbzM6jbipQ/SlVuYxWfW/gZphO4a+ijKs8CI7/U=; b=h3GH5mNhfJOgqODJo0EYAQllMHXh47kA9spooLmdzUoJ6J64fXydDaMD7nu8Yn2M64 omeXo+e2a5DTYrQIDbiyfCpsNF+2sfc579+/4EKUBalbi9qhYZ9NtFWHZk0u+/8vUbc7 XcWMIgODeFSI+VgNn6StzYia6s4XJw0Z9Yq2VuO1xtzNiaiPJtvBAYqPtYijE026y23k mhjEFbPTZj92Uoz69w6BSYvghfsv75awHwyxQdtP/zPgTdk4qrkBFxIeQsqDJiDJqF+4 YMT9g6Jy2Qd97iN9+bgAR/RlRuk19DlE5SOz/GPZWIaaRgNlGgUmdJmvDHF36CnDMIkI 0Y/w== X-Gm-Message-State: AOAM530Dm++CzVr/KZES9n2UbVRfmuKNzTUJcHIvWcYN3sqwaSKPM3oB 5fDoc5Pi1vjb2jPLgoqTvwt2CBlW9jeeNmtm3P8ZcUmMC3f+mJB7l308U7go1LnrWekHsYvysNR gN2oomTxn0PHfrGRtFLQvi8VPpgvSk2w3PsKFs4Hl+Sc6jPoXmz3vtGzJCb2PfY/XvSxd/cjuAw == X-Google-Smtp-Source: ABdhPJxX7k3e/9if4G3hiA7dYH11AdzFmcLDd+/OF6ftSX4PYDWazuIwhyd4aB8We0yoAsvfE+GC2vhI8uooyB9MHgM= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:d4cc:f4a9:b043:ff6e]) (user=emilyshaffer job=sendgmr) by 2002:a25:bcd1:: with SMTP id l17mr2326365ybm.33.1623804323514; Tue, 15 Jun 2021 17:45:23 -0700 (PDT) Date: Tue, 15 Jun 2021 17:45:08 -0700 In-Reply-To: <20210616004508.87186-1-emilyshaffer@google.com> Message-Id: <20210616004508.87186-5-emilyshaffer@google.com> Mime-Version: 1.0 References: <20210616004508.87186-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog Subject: [PATCH v2 4/4] submodule: cache superproject gitdir during 'update' From: Emily Shaffer To: git@vger.kernel.org Cc: Emily Shaffer Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org A cached path to the superproject's gitdir might be added during 'git submodule add', but in some cases - like submodules which were created before 'git submodule add' learned to cache that info - it might be useful to update the cache. Let's do it during 'git submodule update', when we already have a handle to the superproject while calling operations on the submodules. Signed-off-by: Emily Shaffer --- git-submodule.sh | 10 ++++++++++ t/t7406-submodule-update.sh | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/git-submodule.sh b/git-submodule.sh index 4678378424..f98dcc16ae 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -648,6 +648,16 @@ cmd_update() fi fi + # Cache a pointer to the superproject's gitdir. This may have + # changed, so rewrite it unconditionally. Writes it to worktree + # if applicable, otherwise to local. + relative_gitdir="$(git rev-parse --path-format=relative \ + --prefix "${sm_path}" \ + --git-dir)" + + git -C "$sm_path" config --worktree \ + submodule.superprojectgitdir "$relative_gitdir" + if test -n "$recursive" then ( diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index f4f61fe554..c39821ba8e 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -1061,4 +1061,14 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s ) ' +test_expect_success 'submodule update adds superproject gitdir to older repos' ' + (cd super && + git -C submodule config --unset submodule.superprojectGitdir && + git submodule update && + echo "../.git" >expect && + git -C submodule config submodule.superprojectGitdir >actual && + test_cmp expect actual + ) +' + test_done