From patchwork Fri Jun 11 22:54:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12316609 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, 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 A5BEDC48BE5 for ; Fri, 11 Jun 2021 22:54:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8061161374 for ; Fri, 11 Jun 2021 22:54:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230267AbhFKW4q (ORCPT ); Fri, 11 Jun 2021 18:56:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229951AbhFKW4p (ORCPT ); Fri, 11 Jun 2021 18:56:45 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7E60C0617AF for ; Fri, 11 Jun 2021 15:54:37 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id d7-20020ac811870000b02901e65f85117bso2788449qtj.18 for ; Fri, 11 Jun 2021 15:54:37 -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=ms1y5aUv5UszjIuhfDeEcE0ayRaxqRyY77qDKHkkoEKafMUhhfks0xUSrSQbXq+nmR /Rz3QxVKVAT/brwzmB2BIfGZsjU4BQy39CdBM4znCpqgPGcDhUgoAPlOl1yNgkBRWu5E KGZQerRUiOt6p6atuXvG5N+PYTk79CfRGjTz5c4oJvgJdkJCLvHtsH13UmXsVJqOREdW vWn3D8Zpx2ehuPNMiBvkbg/LLXUCOBA6RlNznkjp1JPXCUKzfgeiOJILTNYSs30A8O9v z/FMyIJYIEn6pHjaQG34wXLppwBXg3yxqmGNe2oVa/tsSy7r4aDgilgLNrFZYbrQd4Wx Dy5A== 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=U83EHpXHol3DpPUh+WNKkM3IYxcEjjAir1ei9RYETqeBtz4x1q3CZi2IsUCM656N05 DnLmGaqSXu/WlQHVk54QaINKL+poMvD1c5Jl5C4jqZxDnmi4Bflyfo5kdkZGdIMMUy1U uvj/8g+g/FdXJWSA6IXgKbse0v9AxHXmwME19QrW+3IHUOrd4ls8zOg2M81mdfRELxG/ Pd3iBrWqhox1oedDS3dBLuBHM0BLRKFnQqpXSZqmlZJQv7qOAmEWqmuWfRM6xsSJQ+FN LXsHzo+OrBRTJ/vLPs2iFEaNhIBMRnsornmABOOSdEgrcOkO8RuYLYC4Tlmwws9sV4rw ctwA== X-Gm-Message-State: AOAM530M71p9OVqG1T7qiceiTFu3EmxPp9GDel4TpaAkNpjdoKR5kE+h DxUUwiy9cbncuIDlcfKo04deagpfeHyvqaK+XbrhdniuZEWFxbOjrGuoaDVzaK079oN3zjIB+MH WEjbpeWuuA0jXcfPt1im/YIB5dkoyGN35CbeyUhRtnzaun4kReK9TFhqi6HTh8NpSNwXav0YPGQ == X-Google-Smtp-Source: ABdhPJxKNTotb5mZZ8J/V8URC6uNMqz60TiPw28iw4IVLmP2u2s9+qBrUKJJjK6h8zXgGrMONsHsQb9RAgTs768ydqI= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:c894:862c:2364:ff78]) (user=emilyshaffer job=sendgmr) by 2002:ad4:4502:: with SMTP id k2mr7099034qvu.43.1623452076890; Fri, 11 Jun 2021 15:54:36 -0700 (PDT) Date: Fri, 11 Jun 2021 15:54:25 -0700 In-Reply-To: <20210611225428.1208973-1-emilyshaffer@google.com> Message-Id: <20210611225428.1208973-2-emilyshaffer@google.com> Mime-Version: 1.0 References: <20210611225428.1208973-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog Subject: [RFC PATCH 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 Fri Jun 11 22:54:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12316611 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, 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 ABFC7C48BD1 for ; Fri, 11 Jun 2021 22:54:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7EEC0613DF for ; Fri, 11 Jun 2021 22:54:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230297AbhFKW4u (ORCPT ); Fri, 11 Jun 2021 18:56:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229951AbhFKW4t (ORCPT ); Fri, 11 Jun 2021 18:56:49 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C737C0613A2 for ; Fri, 11 Jun 2021 15:54:40 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id j190-20020a253cc70000b029054c72781aa2so5014700yba.9 for ; Fri, 11 Jun 2021 15:54:40 -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=3IxDtWA6ByJxnRZ+gtO9fxE4iYaPRZEZ1uXikqz+6rE=; b=wTC/IaplmPMxRhK3PYgxrTQcInlr048mnaJQ95vSia0RprwoMKnlXD2G3whP23gz4O 8I+WJcANd4x169Pjv72MSzIzSvWGFgGjKs1eChJmsC50qt6enEWXBSVIj9jXjSspYw3V p9EYxFH4/+hmkAUXhIciNte3mS2UjECWwleiqpevIGcv3VhynYh/Lg4I5DwgT68LZX+I fZGL+QAOhUGD+YKSHZCRyg0rXHFVJJO3cQaqQ98oleD3u6uWAuvY4xAUk+MWcEUQwOy4 mc+oPv77UvlH7reQc7vYZGFknP1gYsMFBOzyVbwqte4cocZpmBbGY9HKsvnrU2de5Z2i PlBA== 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=3IxDtWA6ByJxnRZ+gtO9fxE4iYaPRZEZ1uXikqz+6rE=; b=OrrjQlgSkUZMrR6Zabxhn2EijcSUVno/BFd0PoYlUP/u7PXhF61gmB4/VYC3wA8Sow AiIDUnwpBqbAFhWrRfgC07ctYVzvNTi1YYZUAo/KGIUapE+sO2f54CNijhyYmVK/vKR2 8cdC+n9uxa5vUw6ZaGALANd/GpK5iq9N5xVxBhrQ/+SQkF2B4FvhyrYfb+vi+cofpk6B CAg49geKY/bALIhyg1xBatW0MfThbIWlHTJKEhGn/uhtVs4WC4P0mkO1dhkR+DC6oo/D dFlRwety2V7AP55ooreg34Ije8fpSUSjiInxTAzN9QHj0QdtkPgr9g+jxI61nQYO9ld5 U1YA== X-Gm-Message-State: AOAM531ePC0yyfW22NjcaLzXjfwaup3PUiGNbueRdohTebNlLUFumQxY prX78ex/8NNm1O6QaQBYZ/M8jAK3LD1EC7qdFIUpVlIT7DPVDvhzH3tMXGAqL3IndV3sFbsDvW6 g56UzgaD0brGSPSRq7irTQfKrr/3uw2rzuKLwoLtR3elculFCUkIzrjMB/BEfynhknum8vtANnQ == X-Google-Smtp-Source: ABdhPJzHXC9yKVldY45hg05kwGnpEco68bcRe2DN0X7G0d5DKJTTYna2FFgIk7eXhpEKgYjzK/DAZXxgTo2Ea9PegKg= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:c894:862c:2364:ff78]) (user=emilyshaffer job=sendgmr) by 2002:a25:31c3:: with SMTP id x186mr8036327ybx.382.1623452079246; Fri, 11 Jun 2021 15:54:39 -0700 (PDT) Date: Fri, 11 Jun 2021 15:54:26 -0700 In-Reply-To: <20210611225428.1208973-1-emilyshaffer@google.com> Message-Id: <20210611225428.1208973-3-emilyshaffer@google.com> Mime-Version: 1.0 References: <20210611225428.1208973-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog Subject: [RFC PATCH 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 --- builtin/submodule--helper.c | 4 ++++ t/t7400-submodule-basic.sh | 40 ++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 9d505a6329..3d6fd54c9b 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1909,6 +1909,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 Fri Jun 11 22:54:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12316613 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, 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 6C692C48BD1 for ; Fri, 11 Jun 2021 22:55:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 45EDF61374 for ; Fri, 11 Jun 2021 22:55:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230302AbhFKW54 (ORCPT ); Fri, 11 Jun 2021 18:57:56 -0400 Received: from mail-qk1-f202.google.com ([209.85.222.202]:36660 "EHLO mail-qk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229814AbhFKW5y (ORCPT ); Fri, 11 Jun 2021 18:57:54 -0400 Received: by mail-qk1-f202.google.com with SMTP id c3-20020a37b3030000b02903ad0001a2e8so739459qkf.3 for ; Fri, 11 Jun 2021 15:55:41 -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=LOPYuWoJG1GmLXx5cVSAjfxC6H+fFWbsSGMiDMrsKN0=; b=Zp+dNTFP+gTBLsL4e8+e4U49W02ASOVzN4U9Xku2K+ywWNqzDxPf0HnRKY6GT7xaWZ P6ZcA3hjy6HGyoM9ajbBwDEfCFPg8G0AAgnegvGCsDyeFOqjuoAqMHiq7GznszPwgEHL 5CKWXuOqJQnv8B5g4WWUCGyrJ5/m1aAo0unXm+SrldaKNFosQElMvuCmmL2WLPPb4H3b GVYeq3WdVe/kp1dfZq+4ibaC1Y9auCWHIdNa+5O2f9tEv8IwVahfaFyIu1QxnIukNl5+ SdhTWH7zacfTtNxUzSM/zbKqNKQ+fuKtNaDyjWHDKc8BJj6EUih6erDLwvP6k3h2ARyn PXDQ== 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=LOPYuWoJG1GmLXx5cVSAjfxC6H+fFWbsSGMiDMrsKN0=; b=mn0UvkFlMCrR5HmKls3fD099ByFVm8mW5HBC2jUCbbfqNKkm0wHgYZ/6/t3uKRGtme VZftSLVgPI7VVPzvyG/yGv96BgMah9dR4WBpiD3nvhQaf2Nuf9aLSQr6QWLuJq928Psb PEJZcg6MB4SHEbYxev3qzL4FSubXW5OIhPjr/5s0K9YW6FjUjK8mnZ8ysFI05nd3mJ/G RNG9cgyDo4Z0r+WyAqqnglKlTnl4VVQ0NnDOeKZ7f7ppo5a1zlxV4u9BWiPv1i5cmKMR vamdzgnSt8FnhIAcudKbyJ6dZHgY9X4Di3pVA1C4wnim9DCf98Rafvbeh0wA9FFeoXUH 6ehw== X-Gm-Message-State: AOAM532LYCR0cBqBhrAKJ11OlskSLHDKGkleUgEpQUJgKqog/DNqCpvt IaQvS2huL/9WelQGXi7fSrZFL4ojZuyng0oCeT22fn39dw6NfyvbmtdNFCItOuc0RbnRyySUO2y OQgfrvACObL7uc31ngmMkjeRyZ1jfzSH/ndyUwCjY8QOYgzgq4D8rGyhvgwHP1o4Mtf3K2OA/zA == X-Google-Smtp-Source: ABdhPJxuWpB83nxS4qi5af2VwBCDum+boKycm3wnNoBVeQgKGx0Kr4kVOodsvCWKPea+oh/MOzJ5aPmSjGMU98Jvj1Q= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:c894:862c:2364:ff78]) (user=emilyshaffer job=sendgmr) by 2002:ad4:4241:: with SMTP id l1mr7326118qvq.2.1623452081474; Fri, 11 Jun 2021 15:54:41 -0700 (PDT) Date: Fri, 11 Jun 2021 15:54:27 -0700 In-Reply-To: <20210611225428.1208973-1-emilyshaffer@google.com> Message-Id: <20210611225428.1208973-4-emilyshaffer@google.com> Mime-Version: 1.0 References: <20210611225428.1208973-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog Subject: [RFC PATCH 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 | 1 + 2 files changed, 11 insertions(+) diff --git a/submodule.c b/submodule.c index 9767ba9893..09dfc4ee38 100644 --- a/submodule.c +++ b/submodule.c @@ -2064,6 +2064,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 " @@ -2095,6 +2096,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..70fc282937 100755 --- a/t/t7412-submodule-absorbgitdirs.sh +++ b/t/t7412-submodule-absorbgitdirs.sh @@ -29,6 +29,7 @@ test_expect_success 'absorb the git dir' ' test -d .git/modules/sub1 && git status >actual.1 && git -C sub1 rev-parse HEAD >actual.2 && + test . -ef "$(git -C sub1 config submodule.superprojectGitDir)" && test_cmp expect.1 actual.1 && test_cmp expect.2 actual.2 ' From patchwork Fri Jun 11 22:54:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emily Shaffer X-Patchwork-Id: 12316615 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, 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 CC6DBC48BE5 for ; Fri, 11 Jun 2021 22:55:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AD92C61374 for ; Fri, 11 Jun 2021 22:55:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230305AbhFKW54 (ORCPT ); Fri, 11 Jun 2021 18:57:56 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:39618 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229951AbhFKW5y (ORCPT ); Fri, 11 Jun 2021 18:57:54 -0400 Received: by mail-qk1-f201.google.com with SMTP id v16-20020ae9e3100000b02903aafadba721so7948157qkf.6 for ; Fri, 11 Jun 2021 15:55:43 -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=C4Ecs1VoZMSdLkgCKV06ArCy7TfqUq6TKSoKEmyI068=; b=asEayoDm68oJHd6DRQSVu7778wXoKeuz+rN2zcv9oR+jx9XtVQyev/Xoc9/3O0ml2A /LH+Lh0yksu54QRHm98T7Z417cbu8dzUGvwjN8hMlWXjzM9ekt+c6FHkLLpxoy8ySXVD k/G+PEcDA+8ViI9XUcXJJaQ7joDxg54vT46mE+i3Up1+qROLNRHFlUy34DFbQ2bZ9bEQ 9cNoALuX2czE06sRHAQus+5OyqicZXm2PGVF2c4nt/a1XrAJ2Ds6TNm3U7uDtEuEprvA dDH8I2jjTtoZReMfBdqe+QBnVLhT03zS0jsX2ow9lo41NGzJ2pchI8neLVVnJoTB0Pc0 qUXQ== 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=C4Ecs1VoZMSdLkgCKV06ArCy7TfqUq6TKSoKEmyI068=; b=cZcji4ziHpp9Uut4ywCQJZd86yqJWvCN4r0FvVTpop1JY/4xmoWQThXdGrTgMdcckS ykOCwzSOFLyz2gIYtj5UcsF/ox/dQNMUTFUQmcOQvwOgECDFb4/NCJk2uTMrO0upmi02 Bx20QRMqfwNvFczlcEZAuSMH/83xNeV2jClNuULqKHYb2nZY+hbL5Ggr8nYctXBJ5AvJ I5vXGC5W82wM9BM4uwEm/HWLJJzbYt2jk071tSdiFiBo92+GWeN6o1BWs+POBsDitILd 0hxJI0NymEl6uHABoY+GQEuQ+3pmTNRIJYL4+532DO0FN4hwpuPIfNHYJ1dnpjDosSsU N/5Q== X-Gm-Message-State: AOAM532IU5StmIzb5awfisPzrB8++7on/+ZXnp/1vwvayh1M18tLjdUO sWTJxoCOv+hDZPSUCVUUuhDTdhV8CWyVZBZR/Q3RoGdFcors2S6oq82E+vIXXaSkak2g+X2ciH0 XXe+rvJl0n+bMRPua2b7/NXZiJModRh7/ilgNR5Ol98vOppAAw3pzQZpA4CErO63v2x0Fc1mwVg == X-Google-Smtp-Source: ABdhPJwQx6/RWMwzJFsBEHA7mTRknDVpnGeZkvKPpmzDaBpQY2t1NKFuoyV3S3mE3OZ4dE6R+JLr9x/mFUIkpw6j8RI= X-Received: from podkayne.svl.corp.google.com ([2620:15c:2ce:0:c894:862c:2364:ff78]) (user=emilyshaffer job=sendgmr) by 2002:a05:6214:20e3:: with SMTP id 3mr7231493qvk.48.1623452083496; Fri, 11 Jun 2021 15:54:43 -0700 (PDT) Date: Fri, 11 Jun 2021 15:54:28 -0700 In-Reply-To: <20210611225428.1208973-1-emilyshaffer@google.com> Message-Id: <20210611225428.1208973-5-emilyshaffer@google.com> Mime-Version: 1.0 References: <20210611225428.1208973-1-emilyshaffer@google.com> X-Mailer: git-send-email 2.32.0.272.g935e593368-goog Subject: [RFC PATCH 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 | 9 +++++++++ t/t7406-submodule-update.sh | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/git-submodule.sh b/git-submodule.sh index eb90f18229..ddda751cfa 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -648,6 +648,15 @@ 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. + + sp_gitdir="$(git rev-parse --absolute-git-dir)" + relative_gitdir="$(realpath --relative-to "$sm_path" "$sp_gitdir")" + 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 ff3ba5422e..96023cbb6a 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -1037,4 +1037,14 @@ test_expect_success 'submodule update --quiet passes quietness to merge/rebase' ) ' +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