Message ID | 20210616004508.87186-5-emilyshaffer@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | cache parent project's gitdir in submodules | expand |
> A cached path to the superproject's gitdir might be added during 'git [snip] > + # Cache a pointer to the superproject's gitdir. This may have Patches 3 and 4 look good to me except that for me, a cache is something that lets us avoid an expensive computation. But as far as I know, we're not planning to perform the expensive computation in the absence of a cache. Maybe the word "record" would fit better. This is nit-picky, though, and if others think that the word "cache" fits here, that's fine by me too.
On Tue, Jul 27, 2021 at 10:51:51AM -0700, Jonathan Tan wrote: > > > A cached path to the superproject's gitdir might be added during 'git > > [snip] > > > + # Cache a pointer to the superproject's gitdir. This may have > > Patches 3 and 4 look good to me except that for me, a cache is something > that lets us avoid an expensive computation. But as far as I know, we're > not planning to perform the expensive computation in the absence of a > cache. Maybe the word "record" would fit better. > > This is nit-picky, though, and if others think that the word "cache" > fits here, that's fine by me too. Thanks. I switched the commit messages around to use 'record' and 'hint' when appropriate instead. I'll send a reroll with those nits as soon as it passes CI. - Emily
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
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 <emilyshaffer@google.com> --- git-submodule.sh | 10 ++++++++++ t/t7406-submodule-update.sh | 10 ++++++++++ 2 files changed, 20 insertions(+)