git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH 0/4] cache parent project's gitdir in submodules

From
Emily Shaffer <emilyshaffer@google.com>
Date
Jun 11, 2021, 22:54 UTC
Message-ID
<20210611225428.1208973-1-emilyshaffer@google.com>

It's necessary for a superproject to know which submodules it contains. However, historically submodules do not know they are anything but a normal single-repo Git project (or a superproject, in nested-submodules cases). This decision does help prevent us from having to support divergent behaviors in submodule projects vs. superprojects, which makes sure Git is (somewhat) less confusing for the reader, and helps simplify our code.

One could imagine, though, some conveniences we could gain from submodules learning added behavior (though not necessarily *different* behavior) to provide more context about the state of the project as a whole, and to make large submodule-based projects easier to work with. One example is a series[1] I sent some time ago, adding a config to be shared between the superproject and all its submodules. The RFC[2] I sent around the same time mentions a few other examples, such as "git status" run in the submodule noticing whether the superproject has a commit referencing the submodule's current HEAD.

It's expensive and non-definitive to try and guess whether or not the current repo is a submodule. submodule.c:get_superproject_working_tree() does so by essentially running 'git -C .. ls-files -- <own-path>', invoking an additional process. get_superproject_working_tree() is not called often, so that's mostly fine. However, [1] attempted to include an additional config located in the superproject's gitdir by running 'git -C .. rev-parse --git-dir' during startup - a little expensive in the best case, because it's an extra process, but extremely expensive in the case when the current repo is *not* a submodule, because we hunt all the way up the filesystem looking for a '.git'. Adding that cost to every startup is infeasible.

To that end, in this series I propose caching a path to the superproject's gitdir - by having the superproject write that relative path to the submodule's config on creation or update. The goal here is *not* to say "If I am a submodule, I must have submodule.superprojectGitDir set" - but instead to say "If I have submodule.superprojectGitDir set, then I must be a submodule." That is, I expect we will find edge cases where a submodule was introduced in some interesting way that bypassed any of the patches below, and therefore doesn't have the superproject's gitdir cached.

The combination of these two rules:
 - Anything relying on submodule.superprojectGitDir must be nice to
   have, but not essential, because
 - It's possible for a submodule to be valid without having
   submodule.superprojectGitDir set
makes me feel more comfortable with the idea of submodules learning
additional behavior based on this config. I feel pretty unconfident in
our ability to ensure that *every* submodule has this config set.
The series covers a few paths for introducing that config, which I'm
hoping covers most cases.
 - "git submodule update" (which seems to be part of the "git submodule
   init" flow)
 - "git submodule absorbgitdir" to convert a "git init"'d repo into a
   submodule

Notably, we can only really set this config when 'the_repository' is the superproject - that appears to be the only time when we know the gitdirs of both the superproject and the submodule.

I'm expecting folks may have a lot to say about this, so I look forward to discussion :)

 - Emily

1: https://lore.kernel.org/git/20210423001539.4059524-1-emilyshaffer@google.com 2: https://lore.kernel.org/git/YHofmWcIAidkvJiD@google.com

Emily Shaffer (4):
  t7400-submodule-basic: modernize inspect() helper
  introduce submodule.superprojectGitDir cache
  submodule: cache superproject gitdir during absorbgitdirs
  submodule: cache superproject gitdir during 'update'
 builtin/submodule--helper.c        |  4 +++
 git-submodule.sh                   |  9 ++++++
 submodule.c                        | 10 ++++++
 t/t7400-submodule-basic.sh         | 49 ++++++++++++++----------------
 t/t7406-submodule-update.sh        | 10 ++++++
 t/t7412-submodule-absorbgitdirs.sh |  1 +
 6 files changed, 57 insertions(+), 26 deletions(-)
-- 
2.32.0.272.g935e593368-goog
Next: Emily Shaffer
Message 1 of 51 in “cache parent project's gitdir in submodules”
  1. 0/4 cache parent project's gitdir in submodulesEmily Shaffer, Jun 11, 2021
  2. 1/4 t7400-submodule-basic: modernize inspect() helperEmily Shaffer, Jun 11, 2021
  3. Junio C HamanoJun 14, 2021
  4. 2/4 introduce submodule.superprojectGitDir cacheEmily Shaffer, Jun 11, 2021
  5. Junio C HamanoJun 14, 2021
  6. Emily ShafferJun 15, 2021
  7. 3/4 submodule: cache superproject gitdir during absorbgitdirsEmily Shaffer, Jun 11, 2021
  8. Junio C HamanoJun 14, 2021
  9. 4/4 submodule: cache superproject gitdir during 'update'Emily Shaffer, Jun 11, 2021
  10. Junio C HamanoJun 14, 2021
  11. Emily ShafferJun 15, 2021
  12. Jacob KellerJun 12, 2021
  13. Junio C HamanoJun 14, 2021
  14. Emily ShafferJun 15, 2021
  15. 0/4 cache parent project's gitdir in submodulesEmily Shaffer, Jun 16, 2021
  16. 1/4 t7400-submodule-basic: modernize inspect() helperEmily Shaffer, Jun 16, 2021
  17. Jonathan TanJul 27, 2021
  18. Emily ShafferAug 19, 2021
  19. 2/4 introduce submodule.superprojectGitDir cacheEmily Shaffer, Jun 16, 2021
  20. Junio C HamanoJun 16, 2021
  21. Junio C HamanoJun 16, 2021
  22. Emily ShafferJun 18, 2021
  23. Emily ShafferJun 18, 2021
  24. Jonathan TanJul 27, 2021
  25. Emily ShafferAug 19, 2021
  26. Ævar Arnfjörð BjarmasonOct 14, 2021
  27. 3/4 submodule: cache superproject gitdir during absorbgitdirsEmily Shaffer, Jun 16, 2021
  28. 4/4 submodule: cache superproject gitdir during 'update'Emily Shaffer, Jun 16, 2021
  29. Jonathan TanJul 27, 2021
  30. Emily ShafferAug 19, 2021
  31. 0/4 cache parent project's gitdir in submodulesEmily Shaffer, Aug 19, 2021
  32. 1/4 t7400-submodule-basic: modernize inspect() helperEmily Shaffer, Aug 19, 2021
  33. 2/4 introduce submodule.superprojectGitDir recordEmily Shaffer, Aug 19, 2021
  34. Derrick StoleeAug 20, 2021
  35. Emily ShafferOct 13, 2021
  36. Matheus TavaresSep 4, 2021
  37. Emily ShafferOct 13, 2021
  38. 3/4 submodule: record superproject gitdir during absorbgitdirsEmily Shaffer, Aug 19, 2021
  39. Derrick StoleeAug 20, 2021
  40. Emily ShafferOct 13, 2021
  41. Matheus TavaresSep 4, 2021
  42. Emily ShafferOct 14, 2021
  43. 4/4 submodule: record superproject gitdir during 'update'Emily Shaffer, Aug 19, 2021
  44. Derrick StoleeAug 20, 2021
  45. Emily ShafferOct 14, 2021
  46. Junio C HamanoAug 19, 2021
  47. Derrick StoleeAug 20, 2021
  48. Emily ShafferOct 13, 2021
  49. Derrick StoleeOct 14, 2021
  50. Emily ShafferOct 14, 2021
  51. Matheus Tavares BernardinoSep 4, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.