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

Re: [PATCH v5 2/4] introduce submodule.superprojectGitDir record

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 5, 2021, 07:50 UTC
Message-ID
<xmqqo86zxcqp.fsf@gitster.g>
In-Reply-To
<20211104234942.3473650-3-emilyshaffer@google.com>
Emily Shaffer <emilyshaffer@google.com> writes:
Show 5 quoted lines
> 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. And by using the path from gitdir to gitdir, we can
> move the submodule within the superproject's tree structure without
> breaking the submodule's cache, too.

All of the above explains what the design choice is, and what benefit the chosen design brings us. But this last one ...

> Finally, by pointing at "get_git_common_dir()" instead of
> "get_git_dir()", we ensure the link will refer to the parent repo,
> not to a specific worktree.

... only says that we choose to point at the common one, not a specific worktree (i.e. what behaviour was chosen by the design), but it is left unclear what benefit it is trying to bring us.

Thinking aloud, imagine that there are two worktrees for the superproject. For simplicity, let's further imagine that these worktrees have a clean check-out of the same commit, hence, these two worktrees have the same commit from the same submodule checked out at the same location relative to the project root.

The subdirectory in each of these two superproject worktrees that checks out the submodule has .git file (as we "absorb" the gitdir in the modern submodule layout) pointing at somewhere. It probably is OK if they point at the same place, but it might be more natural if these two submodule checkouts are two worktrees for a single submodule repository (this part I am not very clear, and that is why I labeled the discussion "thinking aloud").

It seems to me that both design choices would have equally valid arguments for them. If both of these submodule worktrees point at the "common" dir of the superproject, because the "common" one is part of the primary worktree, which is harder to lose than secondary worktrees, of the superproject, it is presumably harder to go stale when "worktree rm" is done at superproject, which may be a plus. But then from the "cached" pointer, each of these submodule worktrees cannot tell which worktree of the superproject they are checked out as a part of. Of course we can go to the root level of the submodule worktree and do the usual repository discovery to learn where the root level of the superproject worktree it belongs to, but it somehow feels that it defeats half the point of having this "cache" information.

If we instead point at the git-dir, from there, it is just one level of indirection to find out where the common dir of the superproject is.

Show 5 quoted lines
> If the new config is present, we can do some optional value-added
> behavior, like letting "git status" print additional info about the
> submodule's status in relation to its superproject, or like letting the
> superproject and submodule share an additional config file separate from
> either one's local config.

And one value-add that I would think of off the top of my head is to show "we have commit X checked out, which is 4 commits on top of what the superproject's index records for this submodule" when "git status" is run in the submodule's worktree. I do not know that is an operation to specifically optimize for, but by choosing to "cache" the common dir, not the one specific to the worktree of the superporject our submodule checkout is a part of, the chosen design seems to make it harder to implement?

Thanks.
Previous: Emily ShafferNext: Emily Shaffer
Message 16 of 31 in “cache parent project's gitdir in submodules”
  1. 0/4 cache parent project's gitdir in submodulesEmily Shaffer, Oct 14, 2021
  2. 1/4 t7400-submodule-basic: modernize inspect() helperEmily Shaffer, Oct 14, 2021
  3. 2/4 introduce submodule.superprojectGitDir recordEmily Shaffer, Oct 14, 2021
  4. 3/4 submodule: record superproject gitdir during absorbgitdirsEmily Shaffer, Oct 14, 2021
  5. Jonathan TanOct 18, 2021
  6. Derrick StoleeOct 25, 2021
  7. Emily ShafferNov 4, 2021
  8. Derrick StoleeNov 8, 2021
  9. Emily ShafferNov 4, 2021
  10. 4/4 submodule: record superproject gitdir during 'update'Emily Shaffer, Oct 14, 2021
  11. Derrick StoleeOct 25, 2021
  12. Derrick StoleeOct 25, 2021
  13. 0/4 cache parent project's gitdir in submodulesEmily Shaffer, Nov 4, 2021
  14. 1/4 t7400-submodule-basic: modernize inspect() helperEmily Shaffer, Nov 4, 2021
  15. 2/4 introduce submodule.superprojectGitDir recordEmily Shaffer, Nov 4, 2021
  16. Junio C HamanoNov 5, 2021
  17. Emily ShafferNov 8, 2021
  18. 3/4 submodule: record superproject gitdir during absorbgitdirsEmily Shaffer, Nov 4, 2021
  19. 4/4 submodule: record superproject gitdir during 'update'Emily Shaffer, Nov 4, 2021
  20. Junio C HamanoNov 5, 2021
  21. Ævar Arnfjörð BjarmasonNov 5, 2021
  22. Emily ShafferNov 8, 2021
  23. Ævar Arnfjörð BjarmasonNov 9, 2021
  24. Emily ShafferNov 9, 2021
  25. Emily ShafferNov 9, 2021
  26. Ævar Arnfjörð BjarmasonNov 5, 2021
  27. Emily ShafferNov 8, 2021
  28. Ævar Arnfjörð BjarmasonNov 9, 2021
  29. Derrick StoleeNov 8, 2021
  30. Emily ShafferNov 8, 2021
  31. Derrick StoleeNov 9, 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.