git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v6 0/5] teach submodules to know they're submodules
@ 2021-11-17  0:56 Emily Shaffer
  2021-11-17  0:56 ` [PATCH v6 1/5] t7400-submodule-basic: modernize inspect() helper Emily Shaffer
                   ` (7 more replies)
  0 siblings, 8 replies; 64+ messages in thread
From: Emily Shaffer @ 2021-11-17  0:56 UTC (permalink / raw)
  To: git
  Cc: Emily Shaffer, Albert Cui, Phillip Wood, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason, Junio C Hamano,
	Matheus Tavares Bernardino, Jonathan Nieder, Jacob Keller,
	Atharva Raykar, Derrick Stolee, Jonathan Tan

For the original cover letter, see
https://lore.kernel.org/git/20210611225428.1208973-1-emilyshaffer%40google.com.

CI run: https://github.com/nasamuffin/git/actions/runs/1469463328

Since v5:

A couple things. Firstly, a semantics change *back* to the semantics of
v3 - we map from gitdir to gitdir, *not* from common dir to common dir,
so that theoretically a submodule with multiple worktrees in multiple
superproject worktrees will be able to figure out which worktree of the
superproject it's in. (Realistically, that's not really possible right
now, but I'd like to change that soon.)

Secondly, a rewording of comments and commit messages to indicate that
this isn't a cache of some expensive operation, but rather intended to
be the source of truth for all submodules. I also added a fifth commit
rewriting `git rev-parse --show-superproject-working-tree` to
demonstrate what that means in practice - but from a practical
standpoint, I'm a little worried about that fifth patch. More details in
the patch 5 description.

I did discuss Ævar's idea of relying on in-process filesystem digging to
find the superproject's gitdir with the rest of the Google team, but in
the end decided that there are some worries about filesystem digging in
this way (namely, some ugly interactions with network drives that are
actually already an issue for Googler Linux machines). Plus, the allure
of being able to definitively know that we're a submodule is pretty
strong. ;) But overall, this is the direction I'd prefer to keep going
in, rather than trying to guess from the filesystem going forward.

Since v4:

The only real change here is a slight semantics change to map from
<submodule gitdir> to <superproject common git dir>. In every case
*except* for when the superproject has a worktree, this changes nothing.
For the case when the superproject has a worktree, this means that now
submodules will refer to the general superproject common dir (e.g. no
worktree-specific refs or configs or whatnot).

I *think* that because a submodule should exist in the context of the
common dir, not the worktree gitdir, that is ok. However, it does mean
it would be difficult to do something like sharing a config specific to
the worktree (the initial goal of this series).

$ROOT/.git
$ROOT/.git/config.superproject <- shared by $ROOT/.git/modules/sub
$ROOT/.git/modules/sub <- points to $ROOT/.git
$ROOT/.git/worktrees/wt
$ROOT/.git/worktrees/wt/config.superproject <- contains a certain config-based pre-commit hook

If the submodule only knows about the common dir, that is tough, because
the submodule would basically have to guess which worktree it's in from
its own path. There would be no way for '$WT/sub' to inherit
'$ROOT/.git/worktrees/wt/config.superproject'.

That said... right now, we don't support submodules in worktrees very
well at all. A submodule in a worktree will get a brand new gitdir in
$ROOT/.git/worktrees/modules/ (and that brand new gitdir would point to
the super's common dir). So I think we can punt on this entire question
until we teach submodules and worktrees to play more gracefully together
(it's on my long list...), and at that time we can probably introduce a
pointer from $ROOT/.git/modules/sub/worktrees/wt/ to
$ROOT/.git/worktrees/wt/....

Or, to summarize the long ramble above: "this is still kind of weird
with worktrees, but let's fix it later when we fix worktrees more
thoroughly".

(More rambling about worktree weirdness here:
https://lore.kernel.org/git/YYRaII8YWVxlBqsF%40google.com )


Since v3, a pretty major change: the semantics of
submodule.superprojectGitDir has changed, to point from the submodule's
gitdir to the superproject's gitdir (in v3 and earlier, we kept a path
from the submodule's *worktree* to the superproject's gitdir instead).
This cleans up some of the confusions about the behavior when a
submodule worktree moves around in the superproject's tree, or in a
future when we support submodules having multiple worktrees.

I also tried to simplify the tests to use 'test-tool path-utils
relative_path' everywhere - I think that makes them much more clear for
a test reader, but if you're reviewing and it isn't obvious what we're
testing for, please speak up.

I think this is pretty mature and there was a lot of general agreement
that the gitdir->gitdir association was the way to go, so please be
brutal and look for nits, leaks, etc. this round ;)
[/v4 cover letter]

Emily Shaffer (5):
  t7400-submodule-basic: modernize inspect() helper
  introduce submodule.superprojectGitDir record
  submodule: record superproject gitdir during absorbgitdirs
  submodule: record superproject gitdir during 'update'
  submodule: use config to find superproject worktree

 Documentation/config/submodule.txt |  12 ++++
 builtin/submodule--helper.c        |  11 +++
 git-submodule.sh                   |  15 ++++
 submodule.c                        | 108 ++++++++++++++++++++++++++++-
 t/t1500-rev-parse.sh               |   9 +++
 t/t7400-submodule-basic.sh         |  54 ++++++++-------
 t/t7406-submodule-update.sh        |  27 ++++++++
 t/t7412-submodule-absorbgitdirs.sh |  82 +++++++++++++++++++++-
 8 files changed, 290 insertions(+), 28 deletions(-)

Range-diff against v5:
1:  6ff10beaf2 = 1:  f1b08a7057 t7400-submodule-basic: modernize inspect() helper
2:  d4f4627585 ! 2:  d46c8439ab introduce submodule.superprojectGitDir record
    @@ Commit message
     
         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
    +    submodule's pointer. 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. 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.
    +    breaking the submodule's pointer, too. Finally, by pointing at the
    +    superproject's worktree gitdir (if it exists), we ensure that we can
    +    tell which worktree contains our submodule.
     
         Since this hint value is only introduced during new submodule creation
         via `git submodule add`, though, there is more work to do to allow the
         record to be created at other times.
     
    -    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.
    +    Once this new config is reliably in place, we can use it to know
    +    definitively that we are working in a submodule, and to know which
    +    superproject we are a submodule of. This allows us to do some
    +    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.
     
         Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
         Helped-by: Junio C Hamano <gitster@pobox.com>
    @@ Documentation/config/submodule.txt: submodule.alternateErrorStrategy::
     +
     +submodule.superprojectGitDir::
     +	The relative path from the submodule's gitdir to its superproject's
    -+	common dir. When Git is run in a repository, it usually makes no
    ++	gitdir. When Git is run in a repository, it usually makes no
     +	difference whether this repository is standalone or a submodule, but if
     +	this configuration variable is present, additional behavior may be
     +	possible, such as "git status" printing additional information about
    @@ builtin/submodule--helper.c: static int clone_submodule(struct module_clone_data
      		git_config_set_in_file(p, "submodule.alternateErrorStrategy",
      				       error_strategy);
      
    -+	git_config_set_in_file(p, "submodule.superprojectGitdir",
    -+			       relative_path(absolute_path(get_git_common_dir()),
    ++	/*
    ++	 * Set the path from submodule's new gitdir to superproject's gitdir.
    ++	 * The latter may be a worktree gitdir. However, it is not possible for
    ++	 * the submodule to have a worktree-specific gitdir or config at clone
    ++	 * time, because "extensions.worktreeConfig" is only valid when set in
    ++	 * the local gitconfig, which the brand new submodule does not have yet.
    ++	 */
    ++	git_config_set_in_file(p, "submodule.superprojectGitDir",
    ++			       relative_path(absolute_path(get_git_dir()),
     +					     sm_gitdir, &sb));
     +
      	free(sm_alternate);
    @@ t/t7400-submodule-basic.sh: submodurl=$(pwd -P)
     +	# Ensure that submodule.superprojectGitDir contains the path from the
     +	# submodule's gitdir to the superproject's gitdir.
     +
    -+	super_abs_gitdir=$(git -C "$super_dir" rev-parse --path-format=absolute --git-common-dir) &&
    -+	sub_abs_gitdir=$(git -C "$sub_dir" rev-parse --path-format=absolute --git-common-dir) &&
    ++	super_abs_gitdir=$(git -C "$super_dir" rev-parse --absolute-git-dir) &&
    ++	sub_abs_gitdir=$(git -C "$sub_dir" rev-parse --absolute-git-dir) &&
     +
     +	[ "$(git -C "$sub_dir" config --get submodule.superprojectGitDir)" = \
     +	  "$(test-tool path-utils relative_path "$super_abs_gitdir" \
3:  2dae297943 ! 3:  63ddaf5608 submodule: record superproject gitdir during absorbgitdirs
    @@ submodule.c: static void relocate_single_git_dir_into_superproject(const char *p
      	char *old_git_dir = NULL, *real_old_git_dir = NULL, *real_new_git_dir = NULL;
      	struct strbuf new_gitdir = STRBUF_INIT;
      	const struct submodule *sub;
    ++	struct config_set sub_cs;
     +	struct strbuf config_path = STRBUF_INIT, sb = STRBUF_INIT;
    ++	int tmp;
      
      	if (submodule_uses_worktrees(path))
      		die(_("relocate_gitdir for submodule '%s' with "
    @@ submodule.c: static void relocate_single_git_dir_into_superproject(const char *p
      
      	relocate_gitdir(path, real_old_git_dir, real_new_git_dir);
      
    -+	/* cache pointer to superproject's gitdir */
    ++	/*
    ++	 * Note location of superproject's gitdir. Because the submodule already
    ++	 * has a gitdir and local config, we can store this pointer from
    ++	 * worktree config to worktree config, if the submodule has
    ++	 * extensions.worktreeConfig set.
    ++	 */
     +	strbuf_addf(&config_path, "%s/config", real_new_git_dir);
    ++	git_configset_init(&sub_cs);
    ++	git_configset_add_file(&sub_cs, config_path.buf);
    ++	/* return 0 indicates config was found - we have a worktree config */
    ++	if (!git_configset_get_bool(&sub_cs, "extensions.worktreeConfig", &tmp))
    ++		strbuf_addstr(&config_path, ".worktree");
    ++
     +	git_config_set_in_file(config_path.buf, "submodule.superprojectGitdir",
    -+			       relative_path(absolute_path(get_git_common_dir()),
    ++			       relative_path(absolute_path(get_git_dir()),
     +					     real_new_git_dir, &sb));
     +
    ++	git_configset_clear(&sub_cs);
     +	strbuf_release(&config_path);
     +	strbuf_release(&sb);
      	free(old_git_dir);
    @@ t/t7412-submodule-absorbgitdirs.sh: test_expect_success 'absorbing fails for a s
     +	# absorb the git dir
     +	git submodule absorbgitdirs sub4 &&
     +
    -+	# make sure the submodule cached the superproject gitdir correctly
    -+	submodule_gitdir="$(git -C sub4 rev-parse --path-format=absolute --git-common-dir)" &&
    -+	superproject_gitdir="$(git rev-parse --path-format=absolute --git-common-dir)" &&
    ++	# make sure the submodule noted the superproject gitdir correctly
    ++	submodule_gitdir="$(git -C sub4 rev-parse --absolute-git-dir)" &&
    ++	superproject_gitdir="$(git rev-parse --absolute-git-dir)" &&
     +
     +	test-tool path-utils relative_path "$superproject_gitdir" \
     +		"$submodule_gitdir" >expect &&
    @@ t/t7412-submodule-absorbgitdirs.sh: test_expect_success 'absorbing fails for a s
     +	test_cmp expect actual
     +	)
     +'
    ++
    ++test_expect_success 'absorbgitdirs works with a submodule with worktree config' '
    ++	# reuse the worktree of the superproject
    ++	(
    ++	cd wt &&
    ++
    ++	# create a new unembedded git dir
    ++	git init sub5 &&
    ++	test_commit -C sub5 first &&
    ++	git submodule add ./sub5 &&
    ++	test_tick &&
    ++
    ++	# turn on worktree configs for submodule
    ++	git -C sub5 config extensions.worktreeConfig true &&
    ++
    ++	# absorb the git dir
    ++	git submodule absorbgitdirs sub5 &&
    ++
    ++	# make sure the submodule noted the superproject gitdir correctly
    ++	submodule_gitdir="$(git -C sub5 rev-parse --absolute-git-dir)" &&
    ++	superproject_gitdir="$(git rev-parse --absolute-git-dir)" &&
    ++
    ++	test-tool path-utils relative_path "$superproject_gitdir" \
    ++		"$submodule_gitdir" >expect &&
    ++	git -C sub5 config submodule.superprojectGitDir >actual &&
    ++
    ++	test_cmp expect actual &&
    ++
    ++	# make sure the config went into the submodule config.worktree
    ++	test_file_not_empty "$submodule_gitdir/config.worktree"
    ++	)
    ++'
     +
      test_done
4:  f0412d6d34 ! 4:  33a582ef13 submodule: record superproject gitdir during 'update'
    @@ Metadata
      ## Commit message ##
         submodule: record superproject gitdir during 'update'
     
    -    A recorded hint path to the superproject's gitdir might be added during
    +    A recorded 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 record that info - it might
         be useful to update the hint. Let's do it during 'git submodule
    @@ git-submodule.sh: cmd_update()
      			;;
      		esac
      
    -+		# Cache a pointer to the superproject's common dir. This may have
    -+		# changed, unless it's a fresh clone. Writes it to worktree
    -+		# if applicable, otherwise to local.
    ++		# Store a poitner to the superproject's gitdir. This may have
    ++		# changed, unless it's a fresh clone. Write to worktree if
    ++		# applicable, and point to superproject's worktree gitdir if
    ++		# applicable.
     +		if test -z "$just_cloned"
     +		then
     +			sm_gitdir="$(git -C "$sm_path" rev-parse --absolute-git-dir)"
     +			relative_gitdir="$(git rev-parse --path-format=relative \
     +							 --prefix "${sm_gitdir}" \
    -+							 --git-common-dir)"
    ++							 --git-dir)"
     +
     +			git -C "$sm_path" config --worktree \
     +				submodule.superprojectgitdir "$relative_gitdir"
    @@ t/t7406-submodule-update.sh: test_expect_success 'submodule update --quiet passe
     +	 git -C submodule config --unset submodule.superprojectGitdir &&
     +	 git submodule update &&
     +	 test-tool path-utils relative_path \
    -+		"$(git rev-parse --path-format=absolute --git-common-dir)" \
    -+		"$(git -C submodule rev-parse --path-format=absolute --git-common-dir)" >expect &&
    ++		"$(git rev-parse --absolute-git-dir)" \
    ++		"$(git -C submodule rev-parse --absolute-git-dir)" >expect &&
     +	 git -C submodule config submodule.superprojectGitdir >actual &&
     +	 test_cmp expect actual
     +	)
     +'
    ++
    ++test_expect_success 'submodule update uses config.worktree if applicable' '
    ++	(cd super &&
    ++	 git -C submodule config --unset submodule.superprojectGitDir &&
    ++	 git -C submodule config extensions.worktreeConfig true &&
    ++	 git submodule update &&
    ++	 test-tool path-utils relative_path \
    ++		"$(git rev-parse --absolute-git-dir)" \
    ++		"$(git -C submodule rev-parse --absolute-git-dir)" >expect &&
    ++	 git -C submodule config submodule.superprojectGitdir >actual &&
    ++	 test_cmp expect actual &&
    ++
    ++	 test_file_not_empty "$(git -C submodule rev-parse --absolute-git-dir)/config.worktree"
    ++	)
    ++'
     +
      test_done
-:  ---------- > 5:  a8b5d40a77 submodule: use config to find superproject worktree
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v6 1/5] t7400-submodule-basic: modernize inspect() helper
  2021-11-17  0:56 [PATCH v6 0/5] teach submodules to know they're submodules Emily Shaffer
@ 2021-11-17  0:56 ` Emily Shaffer
  2021-11-17  0:56 ` [PATCH v6 2/5] introduce submodule.superprojectGitDir record Emily Shaffer
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 64+ messages in thread
From: Emily Shaffer @ 2021-11-17  0:56 UTC (permalink / raw)
  To: git; +Cc: Emily Shaffer

Since the inspect() helper in the submodule-basic test suite was
written, 'git -C <dir>' 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 <emilyshaffer@google.com>
---
 t/t7400-submodule-basic.sh | 40 +++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 24 deletions(-)

diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index cb1b8e35db..d69a5c0032 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -107,23 +107,15 @@ 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"
-	)
+	sub_dir=$1 &&
+
+	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 &&
+	git -C "$sub_dir" clean -n -d -x >untracked
 }
 
 test_expect_success 'submodule add' '
@@ -146,7 +138,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
@@ -248,7 +240,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
@@ -264,7 +256,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
@@ -280,7 +272,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
@@ -296,7 +288,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
@@ -312,7 +304,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
@@ -328,7 +320,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
@@ -359,7 +351,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
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH v6 2/5] introduce submodule.superprojectGitDir record
  2021-11-17  0:56 [PATCH v6 0/5] teach submodules to know they're submodules Emily Shaffer
  2021-11-17  0:56 ` [PATCH v6 1/5] t7400-submodule-basic: modernize inspect() helper Emily Shaffer
@ 2021-11-17  0:56 ` Emily Shaffer
  2021-11-17 23:43   ` Jonathan Tan
  2021-11-17  0:56 ` [PATCH v6 3/5] submodule: record superproject gitdir during absorbgitdirs Emily Shaffer
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 64+ messages in thread
From: Emily Shaffer @ 2021-11-17  0:56 UTC (permalink / raw)
  To: git; +Cc: Emily Shaffer, Junio C Hamano

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 pointer. 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 pointer, too. Finally, by pointing at the
superproject's worktree gitdir (if it exists), we ensure that we can
tell which worktree contains our submodule.

Since this hint value is only introduced during new submodule creation
via `git submodule add`, though, there is more work to do to allow the
record to be created at other times.

Once this new config is reliably in place, we can use it to know
definitively that we are working in a submodule, and to know which
superproject we are a submodule of. This allows us to do some
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.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/config/submodule.txt | 12 +++++++++++
 builtin/submodule--helper.c        | 11 ++++++++++
 t/t7400-submodule-basic.sh         | 32 ++++++++++++++++++++----------
 3 files changed, 45 insertions(+), 10 deletions(-)

diff --git a/Documentation/config/submodule.txt b/Documentation/config/submodule.txt
index ee454f8126..61d975745e 100644
--- a/Documentation/config/submodule.txt
+++ b/Documentation/config/submodule.txt
@@ -91,3 +91,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 gitdir to its superproject's
+	gitdir. When Git is run in a repository, it usually makes no
+	difference whether this repository is standalone or a submodule, but if
+	this configuration variable is present, additional behavior may be
+	possible, such as "git status" printing additional information about
+	this submodule's status with respect to its superproject. This config
+	should only be present in projects which are submodules, but is not
+	guaranteed to be present in every submodule, so only optional
+	value-added behavior should be linked to it. It is set automatically
+	during submodule creation.
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index e630f0c730..24f0ef2a78 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1838,6 +1838,17 @@ static int clone_submodule(struct module_clone_data *clone_data)
 		git_config_set_in_file(p, "submodule.alternateErrorStrategy",
 				       error_strategy);
 
+	/*
+	 * Set the path from submodule's new gitdir to superproject's gitdir.
+	 * The latter may be a worktree gitdir. However, it is not possible for
+	 * the submodule to have a worktree-specific gitdir or config at clone
+	 * time, because "extensions.worktreeConfig" is only valid when set in
+	 * the local gitconfig, which the brand new submodule does not have yet.
+	 */
+	git_config_set_in_file(p, "submodule.superprojectGitDir",
+			       relative_path(absolute_path(get_git_dir()),
+					     sm_gitdir, &sb));
+
 	free(sm_alternate);
 	free(error_strategy);
 
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index d69a5c0032..3d146491df 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -109,12 +109,24 @@ submodurl=$(pwd -P)
 
 inspect() {
 	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 &&
+
+	# Ensure that submodule.superprojectGitDir contains the path from the
+	# submodule's gitdir to the superproject's gitdir.
+
+	super_abs_gitdir=$(git -C "$super_dir" rev-parse --absolute-git-dir) &&
+	sub_abs_gitdir=$(git -C "$sub_dir" rev-parse --absolute-git-dir) &&
+
+	[ "$(git -C "$sub_dir" config --get submodule.superprojectGitDir)" = \
+	  "$(test-tool path-utils relative_path "$super_abs_gitdir" \
+						"$sub_abs_gitdir")" ] &&
+
 	git -C "$sub_dir" clean -n -d -x >untracked
 }
 
@@ -138,7 +150,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
@@ -240,7 +252,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
@@ -256,7 +268,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
@@ -272,7 +284,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
@@ -288,7 +300,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
@@ -304,7 +316,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
@@ -320,7 +332,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
@@ -351,7 +363,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
@@ -492,7 +504,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
 '
 
@@ -551,7 +563,7 @@ test_expect_success 'update should checkout rev1' '
 	echo "$rev1" >expect &&
 
 	git submodule update init &&
-	inspect init &&
+	inspect init . &&
 
 	test_cmp expect head-sha1
 '
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH v6 3/5] submodule: record superproject gitdir during absorbgitdirs
  2021-11-17  0:56 [PATCH v6 0/5] teach submodules to know they're submodules Emily Shaffer
  2021-11-17  0:56 ` [PATCH v6 1/5] t7400-submodule-basic: modernize inspect() helper Emily Shaffer
  2021-11-17  0:56 ` [PATCH v6 2/5] introduce submodule.superprojectGitDir record Emily Shaffer
@ 2021-11-17  0:56 ` Emily Shaffer
  2021-11-17  0:57 ` [PATCH v6 4/5] submodule: record superproject gitdir during 'update' Emily Shaffer
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 64+ messages in thread
From: Emily Shaffer @ 2021-11-17  0:56 UTC (permalink / raw)
  To: git; +Cc: Emily Shaffer

Already during 'git submodule add' we record 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 absorbgitdirs'. Let's start adding that pointer during 'git
submodule absorbgitdirs' too.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
---
 submodule.c                        | 23 +++++++++
 t/t7412-submodule-absorbgitdirs.sh | 82 +++++++++++++++++++++++++++++-
 2 files changed, 103 insertions(+), 2 deletions(-)

diff --git a/submodule.c b/submodule.c
index c689070524..d7395c7551 100644
--- a/submodule.c
+++ b/submodule.c
@@ -2097,6 +2097,9 @@ 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;
 	struct strbuf new_gitdir = STRBUF_INIT;
 	const struct submodule *sub;
+	struct config_set sub_cs;
+	struct strbuf config_path = STRBUF_INIT, sb = STRBUF_INIT;
+	int tmp;
 
 	if (submodule_uses_worktrees(path))
 		die(_("relocate_gitdir for submodule '%s' with "
@@ -2127,6 +2130,26 @@ static void relocate_single_git_dir_into_superproject(const char *path)
 
 	relocate_gitdir(path, real_old_git_dir, real_new_git_dir);
 
+	/*
+	 * Note location of superproject's gitdir. Because the submodule already
+	 * has a gitdir and local config, we can store this pointer from
+	 * worktree config to worktree config, if the submodule has
+	 * extensions.worktreeConfig set.
+	 */
+	strbuf_addf(&config_path, "%s/config", real_new_git_dir);
+	git_configset_init(&sub_cs);
+	git_configset_add_file(&sub_cs, config_path.buf);
+	/* return 0 indicates config was found - we have a worktree config */
+	if (!git_configset_get_bool(&sub_cs, "extensions.worktreeConfig", &tmp))
+		strbuf_addstr(&config_path, ".worktree");
+
+	git_config_set_in_file(config_path.buf, "submodule.superprojectGitdir",
+			       relative_path(absolute_path(get_git_dir()),
+					     real_new_git_dir, &sb));
+
+	git_configset_clear(&sub_cs);
+	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..5753f90268 100755
--- a/t/t7412-submodule-absorbgitdirs.sh
+++ b/t/t7412-submodule-absorbgitdirs.sh
@@ -30,7 +30,17 @@ 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
+	submodule_gitdir="$(git -C sub1 rev-parse --path-format=absolute --git-common-dir)" &&
+	superproject_gitdir="$(git rev-parse --path-format=absolute --git-common-dir)" &&
+
+	test-tool path-utils relative_path "$superproject_gitdir" \
+		"$submodule_gitdir" >expect &&
+	git -C sub1 config submodule.superprojectGitDir >actual &&
+
+	test_cmp expect actual
 '
 
 test_expect_success 'absorbing does not fail for deinitialized submodules' '
@@ -61,7 +71,16 @@ test_expect_success 'absorb the git dir in a nested submodule' '
 	git status >actual.1 &&
 	git -C sub1/nested rev-parse HEAD >actual.2 &&
 	test_cmp expect.1 actual.1 &&
-	test_cmp expect.2 actual.2
+	test_cmp expect.2 actual.2 &&
+
+	sub1_gitdir="$(git -C sub1 rev-parse --path-format=absolute --git-common-dir)" &&
+	sub1_nested_gitdir="$(git -C sub1/nested rev-parse --path-format=absolute --git-common-dir)" &&
+
+	test-tool path-utils relative_path "$sub1_gitdir" "$sub1_nested_gitdir" \
+		>expect &&
+	git -C sub1/nested config submodule.superprojectGitDir >actual &&
+
+	test_cmp expect actual
 '
 
 test_expect_success 're-setup nested submodule' '
@@ -130,4 +149,63 @@ test_expect_success 'absorbing fails for a submodule with multiple worktrees' '
 	test_i18ngrep "not supported" error
 '
 
+test_expect_success 'absorbgitdirs works when called from a superproject worktree' '
+	# set up a worktree of the superproject
+	git worktree add wt &&
+	(
+	cd wt &&
+
+	# create a new unembedded git dir
+	git init sub4 &&
+	test_commit -C sub4 first &&
+	git submodule add ./sub4 &&
+	test_tick &&
+
+	# absorb the git dir
+	git submodule absorbgitdirs sub4 &&
+
+	# make sure the submodule noted the superproject gitdir correctly
+	submodule_gitdir="$(git -C sub4 rev-parse --absolute-git-dir)" &&
+	superproject_gitdir="$(git rev-parse --absolute-git-dir)" &&
+
+	test-tool path-utils relative_path "$superproject_gitdir" \
+		"$submodule_gitdir" >expect &&
+	git -C sub4 config submodule.superprojectGitDir >actual &&
+
+	test_cmp expect actual
+	)
+'
+
+test_expect_success 'absorbgitdirs works with a submodule with worktree config' '
+	# reuse the worktree of the superproject
+	(
+	cd wt &&
+
+	# create a new unembedded git dir
+	git init sub5 &&
+	test_commit -C sub5 first &&
+	git submodule add ./sub5 &&
+	test_tick &&
+
+	# turn on worktree configs for submodule
+	git -C sub5 config extensions.worktreeConfig true &&
+
+	# absorb the git dir
+	git submodule absorbgitdirs sub5 &&
+
+	# make sure the submodule noted the superproject gitdir correctly
+	submodule_gitdir="$(git -C sub5 rev-parse --absolute-git-dir)" &&
+	superproject_gitdir="$(git rev-parse --absolute-git-dir)" &&
+
+	test-tool path-utils relative_path "$superproject_gitdir" \
+		"$submodule_gitdir" >expect &&
+	git -C sub5 config submodule.superprojectGitDir >actual &&
+
+	test_cmp expect actual &&
+
+	# make sure the config went into the submodule config.worktree
+	test_file_not_empty "$submodule_gitdir/config.worktree"
+	)
+'
+
 test_done
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH v6 4/5] submodule: record superproject gitdir during 'update'
  2021-11-17  0:56 [PATCH v6 0/5] teach submodules to know they're submodules Emily Shaffer
                   ` (2 preceding siblings ...)
  2021-11-17  0:56 ` [PATCH v6 3/5] submodule: record superproject gitdir during absorbgitdirs Emily Shaffer
@ 2021-11-17  0:57 ` Emily Shaffer
  2021-11-17  0:57 ` [PATCH v6 5/5] submodule: use config to find superproject worktree Emily Shaffer
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 64+ messages in thread
From: Emily Shaffer @ 2021-11-17  0:57 UTC (permalink / raw)
  To: git; +Cc: Emily Shaffer

A recorded 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 record that info - it might
be useful to update the hint. 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            | 15 +++++++++++++++
 t/t7406-submodule-update.sh | 27 +++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/git-submodule.sh b/git-submodule.sh
index 652861aa66..7c247bee7f 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -449,6 +449,21 @@ cmd_update()
 			;;
 		esac
 
+		# Store a poitner to the superproject's gitdir. This may have
+		# changed, unless it's a fresh clone. Write to worktree if
+		# applicable, and point to superproject's worktree gitdir if
+		# applicable.
+		if test -z "$just_cloned"
+		then
+			sm_gitdir="$(git -C "$sm_path" rev-parse --absolute-git-dir)"
+			relative_gitdir="$(git rev-parse --path-format=relative \
+							 --prefix "${sm_gitdir}" \
+							 --git-dir)"
+
+			git -C "$sm_path" config --worktree \
+				submodule.superprojectgitdir "$relative_gitdir"
+		fi
+
 		if test -n "$recursive"
 		then
 			(
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 11cccbb333..b42a339982 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -1061,4 +1061,31 @@ 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 &&
+	 test-tool path-utils relative_path \
+		"$(git rev-parse --absolute-git-dir)" \
+		"$(git -C submodule rev-parse --absolute-git-dir)" >expect &&
+	 git -C submodule config submodule.superprojectGitdir >actual &&
+	 test_cmp expect actual
+	)
+'
+
+test_expect_success 'submodule update uses config.worktree if applicable' '
+	(cd super &&
+	 git -C submodule config --unset submodule.superprojectGitDir &&
+	 git -C submodule config extensions.worktreeConfig true &&
+	 git submodule update &&
+	 test-tool path-utils relative_path \
+		"$(git rev-parse --absolute-git-dir)" \
+		"$(git -C submodule rev-parse --absolute-git-dir)" >expect &&
+	 git -C submodule config submodule.superprojectGitdir >actual &&
+	 test_cmp expect actual &&
+
+	 test_file_not_empty "$(git -C submodule rev-parse --absolute-git-dir)/config.worktree"
+	)
+'
+
 test_done
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH v6 5/5] submodule: use config to find superproject worktree
  2021-11-17  0:56 [PATCH v6 0/5] teach submodules to know they're submodules Emily Shaffer
                   ` (3 preceding siblings ...)
  2021-11-17  0:57 ` [PATCH v6 4/5] submodule: record superproject gitdir during 'update' Emily Shaffer
@ 2021-11-17  0:57 ` Emily Shaffer
  2021-11-17 11:43 ` [RFC PATCH 0/2] submodule: test what happens if submodule.superprojectGitDir isn't around Ævar Arnfjörð Bjarmason
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 64+ messages in thread
From: Emily Shaffer @ 2021-11-17  0:57 UTC (permalink / raw)
  To: git; +Cc: Emily Shaffer

Now that submodule.superprojectGitDir is being treated as the point of
truth for whether a repo is a submodule or not, let's use it in `git
rev-parse --show-superproject-working-tree`.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>

---

This commit may be more of an RFC - to demonstrate what life looks like
if we use submodule.superprojectGitDir as the source of truth. But since
'git rev-parse --show-superproject-working-tree' is used in a lot of
scripts in the wild[1], I'm not so sure it's a great example.

To be honest, I'd prefer to die("Try running 'git submodule update'")
here, but I don't think that's very script-friendly. However, falling
back on the old implementation kind of undermines the idea of treating
submodule.superprojectGitDir as the point of truth. One thought I did
have was to put that error message in builtin/rev-parse.c instead, and
print it to stderr (per usual with user-visible messages) so it doesn't
interfere with scripts, but gives a hint for debugging.

Another thought - captured by the NEEDSWORK in the diff - was that we
could "heal" by adding that config after we know the worktree of the
superproject.

Or, it could be that it won't be a problem for a long time, as anybody
running 'git submodule update' will eventually have that config
specified - that's why I included the traces, so we could try and get an
understanding of how long repos remain in this state where they have
submodules but nobody ran 'git submodule update'. But that will only
give me visibility into submodule users at Google, who we expect to be
making a lot of workflow changes soon, anyway.

1: https://github.com/search?q=%22--show-superproject-working-tree%22&type=code
---
 submodule.c          | 85 +++++++++++++++++++++++++++++++++++++++++++-
 t/t1500-rev-parse.sh |  9 +++++
 2 files changed, 93 insertions(+), 1 deletion(-)

diff --git a/submodule.c b/submodule.c
index d7395c7551..ad95cdda07 100644
--- a/submodule.c
+++ b/submodule.c
@@ -2236,7 +2236,7 @@ void absorb_git_dir_into_superproject(const char *path,
 	}
 }
 
-int get_superproject_working_tree(struct strbuf *buf)
+static int get_superproject_working_tree_from_fs(struct strbuf *buf)
 {
 	struct child_process cp = CHILD_PROCESS_INIT;
 	struct strbuf sb = STRBUF_INIT;
@@ -2320,6 +2320,89 @@ int get_superproject_working_tree(struct strbuf *buf)
 	return ret;
 }
 
+int get_superproject_working_tree(struct strbuf *buf)
+{
+	char *super_gitdir = NULL;
+	const char *cwd = xgetcwd();
+	struct child_process cp = CHILD_PROCESS_INIT;
+	struct strbuf absolute_super_gitdir = STRBUF_INIT;
+	struct strbuf out = STRBUF_INIT;
+	struct string_list lines = STRING_LIST_INIT_NODUP;
+	struct string_list_item *it = NULL;
+	const char *wt_prefix = "worktree ";
+	int rc = 0;
+
+
+	/* Do we know we have a superproject? */
+	if (git_config_get_string("submodule.superprojectgitdir", &super_gitdir))
+		goto fallback;
+
+	strbuf_addf(&absolute_super_gitdir, "%s/%s", get_git_dir(), super_gitdir);
+
+	/*
+	 * NEEDSWORK: This is a child process call because worktree.c still
+	 * relies heavily on the_repository. If we can make worktree.c work with
+	 * a repository object - or, better yet, a gitdir path alone - then we
+	 * can drop the child process and ask worktree.c directly.
+	 *
+	 * Alternatively, if 'git worktree' learns a way to say 'the worktree
+	 * associated with this gitdir' instead of 'all worktrees', that would
+	 * be clearer because we could skip the foreach below.
+	 */
+
+	/* Get the output of `git worktree list` from that superproject */
+	prepare_other_repo_env(&cp.env_array, absolute_super_gitdir.buf);
+	strvec_pushl(&cp.args, "-C", absolute_super_gitdir.buf, "worktree", "list",
+		    "--porcelain", NULL);
+
+	cp.git_cmd = 1;
+	if (capture_command(&cp, &out, 0) ||
+	    !string_list_split_in_place(&lines, out.buf, '\n', -1))
+		die("submodule.superprojectGitDir is stale; run 'git submodule "
+		    "update' from the superproject.");
+
+	for_each_string_list_item(it, &lines) {
+		char *trimmed;
+		/*
+		 * Lines containing worktree dirs look like
+		 * 'worktree /some/path'
+		 */
+		if (strncmp(it->string, wt_prefix, strlen(wt_prefix)))
+			continue;
+		trimmed = it->string + strlen(wt_prefix);
+
+		/*
+		 * '/some/path/to/sub' is a prefix of '/some/path' - that's our
+		 * worktree
+		 */
+		if (!strncmp(cwd, trimmed, strlen(trimmed))) {
+			strbuf_addstr(buf, trimmed);
+			rc = 1;
+			goto cleanup;
+		}
+	}
+
+fallback:
+	/*
+	 * Because a submodule may have been created before
+	 * submodule.superprojectGitDir was introduced, fall back on checking
+	 * whether ../ is the superproject.
+	 */
+	trace2_data_intmax("submodule", the_repository,
+			   "get_superproject_wt/config_missing", rc);
+	rc = get_superproject_working_tree_from_fs(buf);
+
+	/*
+	 * NEEDSWORK: Is it possible to teach a submodule the path to its
+	 * superproject when this happens?
+	 */
+
+cleanup:
+	string_list_clear(&lines, 0);
+	strbuf_release(&out);
+	return rc;
+}
+
 /*
  * Put the gitdir for a submodule (given relative to the main
  * repository worktree) into `buf`, or return -1 on error.
diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh
index 1c2df08333..e569910289 100755
--- a/t/t1500-rev-parse.sh
+++ b/t/t1500-rev-parse.sh
@@ -247,6 +247,15 @@ test_expect_success 'showing the superproject correctly' '
 	test_cmp expect out
 '
 
+test_expect_success 'show the superproject correctly without superprojectGitDir' '
+	# repos created before submodule.superprojectGitDir was introduced which
+	# have not been `git submodule update`-ed lately must not break
+	git -C super/dir/sub config --unset submodule.superprojectGitDir &&
+	echo $(pwd)/super >expect &&
+	git -C super/dir/sub rev-parse --show-superproject-working-tree >out &&
+	test_cmp expect out
+'
+
 # at least one external project depends on this behavior:
 test_expect_success 'rev-parse --since= unsqueezed ordering' '
 	x1=--since=1970-01-01T00:00:01Z &&
-- 
2.34.0.rc1.387.gb447b232ab-goog


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [RFC PATCH 0/2] submodule: test what happens if submodule.superprojectGitDir isn't around
  2021-11-17  0:56 [PATCH v6 0/5] teach submodules to know they're submodules Emily Shaffer
                   ` (4 preceding siblings ...)
  2021-11-17  0:57 ` [PATCH v6 5/5] submodule: use config to find superproject worktree Emily Shaffer
@ 2021-11-17 11:43 ` Ævar Arnfjörð Bjarmason
  2021-11-17 11:43   ` [RFC PATCH 1/2] submodule tests: fix potentially broken "config .. --unset" Ævar Arnfjörð Bjarmason
                     ` (2 more replies)
  2021-11-17 23:28 ` [PATCH v6 0/5] teach submodules to know they're submodules Jonathan Tan
  2022-02-03 21:59 ` Emily Shaffer
  7 siblings, 3 replies; 64+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-11-17 11:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Emily Shaffer, Albert Cui, Phillip Wood,
	Johannes Schindelin, Matheus Tavares Bernardino, Jonathan Nieder,
	Jacob Keller, Atharva Raykar, Derrick Stolee, Jonathan Tan,
	Ævar Arnfjörð Bjarmason

On Tue, Nov 16 2021, Emily Shaffer wrote:

> [...]
> A couple things. Firstly, a semantics change *back* to the semantics of
> v3 - we map from gitdir to gitdir, *not* from common dir to common dir,
> so that theoretically a submodule with multiple worktrees in multiple
> superproject worktrees will be able to figure out which worktree of the
> superproject it's in. (Realistically, that's not really possible right
> now, but I'd like to change that soon.)
>
> Secondly, a rewording of comments and commit messages to indicate that
> this isn't a cache of some expensive operation, but rather intended to
> be the source of truth for all submodules. I also added a fifth commit
> rewriting `git rev-parse --show-superproject-working-tree` to
> demonstrate what that means in practice - but from a practical
> standpoint, I'm a little worried about that fifth patch. More details in
> the patch 5 description.
>
> I did discuss Ævar's idea of relying on in-process filesystem digging to
> find the superproject's gitdir with the rest of the Google team, but in
> the end decided that there are some worries about filesystem digging in
> this way (namely, some ugly interactions with network drives that are
> actually already an issue for Googler Linux machines). Plus, the allure
> of being able to definitively know that we're a submodule is pretty
> strong. ;) But overall, this is the direction I'd prefer to keep going                                                                                                                          
> in, rather than trying to guess from the filesystem going forward.

Did you try running the ad-hoc benchmark I included in [1] on that
Google NFS? I've dealt with some slow-ish network filesystems, but if
it's slower than AIX's local FS (where I couldn't see a difference) I'd
put money on it being a cross-Atlantic mount or something :)

Re your:

    "this isn't a cache of some expensive operation, but rather intended to                                                                                                                          be the source of truth for all submodules."

In your 5/5 it says, in seeming contradiction to this:

    This commit may be more of an RFC - to demonstrate what life looks like
    if we use submodule.superprojectGitDir as the source of truth. But since
    'git rev-parse --show-superproject-working-tree' is used in a lot of
    scripts in the wild[1], I'm not so sure it's a great example.

    To be honest, I'd prefer to die("Try running 'git submodule update'")
    here, but I don't think that's very script-friendly. However, falling
    back on the old implementation kind of undermines the idea of treating
    submodule.superprojectGitDir as the point of truth.

Most of what I've been suggesting in my [1] and related is that I'm
confused about if & how this is a pure caching mechanism.

Removing mentions of it being a cache but it seemingly still being a
cache at the tip of this series has just added to that confusion for
me :)

Anyway. While I do think this caching mechanism is probably
unnecessary in the short to medium term, i.e. it seems to the extent
that it was ever needed was due to some bridging of *.sh<->*.c that
we're *this* close to eliminating anyway.

But maybe I'm wrong. The benchmark I suggested above on that Google
NFS might be indicative. I don't really see how something that'll be
doing a bunch of FS ops anyway is going to be noticeably slower with
that approach, but maybe opening the index/tree of the superproject is
more expensive than I'm expecting.

In any case, all of that's not the hill I'm picking to die on. If
you'd like to go ahead with this cache-or-not-a-cache then sure, I
won't belabor that point.

I *do* strongly think if we're doing so though that we should have
something like this on top. I.e. let's test wha happens if we do and
don't have this "caching" variable, which is demonstrably easy to do.

Benchmarking the two gives me:

    $ git hyperfine -L rev HEAD~0 -L s true,false -s 'make -j8 all' '(cd t && GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR={s} ./t7412-submodule-absorbgitdirs.sh)'
    Benchmark 1: (cd t && GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR=true ./t7412-submodule-absorbgitdirs.sh)' in 'HEAD~0
      Time (mean ± σ):     545.9 ms ±   1.6 ms    [User: 490.3 ms, System: 114.0 ms]
      Range (min … max):   543.5 ms … 548.1 ms    10 runs
     
    Benchmark 2: (cd t && GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR=false ./t7412-submodule-absorbgitdirs.sh)' in 'HEAD~0
      Time (mean ± σ):     537.9 ms ±  11.4 ms    [User: 476.8 ms, System: 117.6 ms]
      Range (min … max):   532.7 ms … 570.1 ms    10 runs
     
    Summary
      '(cd t && GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR=false ./t7412-submodule-absorbgitdirs.sh)' in 'HEAD~0' ran
        1.01 ± 0.02 times faster than '(cd t && GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR=true ./t7412-submodule-absorbgitdirs.sh)' in 'HEAD~0'

I.e. not using the cache is either indistinguishable or a bit faster
(the "a bit faster" is definitely due to just running less test code
though).

I'm sending this before the CI run[2] finishes (which now tests both
modes), but both of these work for me locally on a full test suite
run.

1. https://lore.kernel.org/git/211109.86v912dtfw.gmgdl@evledraar.gmail.com/
2. https://github.com/avar/git/runs/4237446991?check_suite_focus=true

Ævar Arnfjörð Bjarmason (2):
  submodule tests: fix potentially broken "config .. --unset"
  submodule: add test mode for checking absence of "superProjectGitDir"

 ci/run-build-and-tests.sh          |  1 +
 git-submodule.sh                   |  2 +-
 submodule.c                        |  7 +++++++
 t/lib-submodule-superproject.sh    | 24 ++++++++++++++++++++++++
 t/t7406-submodule-update.sh        | 13 ++++++-------
 t/t7412-submodule-absorbgitdirs.sh | 19 ++++++-------------
 6 files changed, 45 insertions(+), 21 deletions(-)
 create mode 100644 t/lib-submodule-superproject.sh

-- 
2.34.0.796.g2c87ed6146a


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [RFC PATCH 1/2] submodule tests: fix potentially broken "config .. --unset"
  2021-11-17 11:43 ` [RFC PATCH 0/2] submodule: test what happens if submodule.superprojectGitDir isn't around Ævar Arnfjörð Bjarmason
@ 2021-11-17 11:43   ` Ævar Arnfjörð Bjarmason
  2021-11-17 11:43   ` [RFC PATCH 2/2] submodule: add test mode for checking absence of "superProjectGitDir" Ævar Arnfjörð Bjarmason
  2021-11-23 20:08   ` [RFC PATCH 0/2] submodule: test what happens if submodule.superprojectGitDir isn't around Emily Shaffer
  2 siblings, 0 replies; 64+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-11-17 11:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Emily Shaffer, Albert Cui, Phillip Wood,
	Johannes Schindelin, Matheus Tavares Bernardino, Jonathan Nieder,
	Jacob Keller, Atharva Raykar, Derrick Stolee, Jonathan Tan,
	Ævar Arnfjörð Bjarmason

These "config ... --unset" at the start must be guarded by something
like a test_might_fail, or we'll fail if a previous test didn't run,
e.g. due to the --run option.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t7406-submodule-update.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index b42a339982b..01e1acaf300 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -1063,7 +1063,7 @@ 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 &&
+	 test_might_fail git -C submodule config --unset submodule.superprojectGitdir &&
 	 git submodule update &&
 	 test-tool path-utils relative_path \
 		"$(git rev-parse --absolute-git-dir)" \
@@ -1075,7 +1075,7 @@ test_expect_success 'submodule update adds superproject gitdir to older repos' '
 
 test_expect_success 'submodule update uses config.worktree if applicable' '
 	(cd super &&
-	 git -C submodule config --unset submodule.superprojectGitDir &&
+	 test_might_fail git -C submodule config --unset submodule.superprojectGitDir &&
 	 git -C submodule config extensions.worktreeConfig true &&
 	 git submodule update &&
 	 test-tool path-utils relative_path \
-- 
2.34.0.796.g2c87ed6146a


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [RFC PATCH 2/2] submodule: add test mode for checking absence of "superProjectGitDir"
  2021-11-17 11:43 ` [RFC PATCH 0/2] submodule: test what happens if submodule.superprojectGitDir isn't around Ævar Arnfjörð Bjarmason
  2021-11-17 11:43   ` [RFC PATCH 1/2] submodule tests: fix potentially broken "config .. --unset" Ævar Arnfjörð Bjarmason
@ 2021-11-17 11:43   ` Ævar Arnfjörð Bjarmason
  2021-11-23 20:08   ` [RFC PATCH 0/2] submodule: test what happens if submodule.superprojectGitDir isn't around Emily Shaffer
  2 siblings, 0 replies; 64+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-11-17 11:43 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Emily Shaffer, Albert Cui, Phillip Wood,
	Johannes Schindelin, Matheus Tavares Bernardino, Jonathan Nieder,
	Jacob Keller, Atharva Raykar, Derrick Stolee, Jonathan Tan,
	Ævar Arnfjörð Bjarmason

Add a GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR=false test mode to
assert what happens if "submodule.superProjectGitDir" is absent or
missing, this checks if the "fallback" codepath in
get_superproject_working_tree() is equivalent to the config lookup.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 ci/run-build-and-tests.sh          |  1 +
 git-submodule.sh                   |  2 +-
 submodule.c                        |  7 +++++++
 t/lib-submodule-superproject.sh    | 24 ++++++++++++++++++++++++
 t/t7406-submodule-update.sh        |  9 ++++-----
 t/t7412-submodule-absorbgitdirs.sh | 19 ++++++-------------
 6 files changed, 43 insertions(+), 19 deletions(-)
 create mode 100644 t/lib-submodule-superproject.sh

diff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh
index cc62616d806..5132a210057 100755
--- a/ci/run-build-and-tests.sh
+++ b/ci/run-build-and-tests.sh
@@ -33,6 +33,7 @@ linux-gcc)
 	export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
 	export GIT_TEST_WRITE_REV_INDEX=1
 	export GIT_TEST_CHECKOUT_WORKERS=2
+	export GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR=false
 	make test
 	;;
 linux-clang)
diff --git a/git-submodule.sh b/git-submodule.sh
index 7c247bee7f6..2b423ee05bc 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -453,7 +453,7 @@ cmd_update()
 		# changed, unless it's a fresh clone. Write to worktree if
 		# applicable, and point to superproject's worktree gitdir if
 		# applicable.
-		if test -z "$just_cloned"
+		if test -z "$just_cloned" && test "$GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR" != "false"
 		then
 			sm_gitdir="$(git -C "$sm_path" rev-parse --absolute-git-dir)"
 			relative_gitdir="$(git rev-parse --path-format=relative \
diff --git a/submodule.c b/submodule.c
index ad95cdda07d..f0411a320a8 100644
--- a/submodule.c
+++ b/submodule.c
@@ -2143,6 +2143,9 @@ static void relocate_single_git_dir_into_superproject(const char *path)
 	if (!git_configset_get_bool(&sub_cs, "extensions.worktreeConfig", &tmp))
 		strbuf_addstr(&config_path, ".worktree");
 
+	if (!git_env_bool("GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR", 1))
+		goto fallback;
+
 	git_config_set_in_file(config_path.buf, "submodule.superprojectGitdir",
 			       relative_path(absolute_path(get_git_dir()),
 					     real_new_git_dir, &sb));
@@ -2150,6 +2153,8 @@ static void relocate_single_git_dir_into_superproject(const char *path)
 	git_configset_clear(&sub_cs);
 	strbuf_release(&config_path);
 	strbuf_release(&sb);
+
+fallback:
 	free(old_git_dir);
 	free(real_old_git_dir);
 	free(real_new_git_dir);
@@ -2332,6 +2337,8 @@ int get_superproject_working_tree(struct strbuf *buf)
 	const char *wt_prefix = "worktree ";
 	int rc = 0;
 
+	if (!git_env_bool("GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR", 1))
+		goto fallback;
 
 	/* Do we know we have a superproject? */
 	if (git_config_get_string("submodule.superprojectgitdir", &super_gitdir))
diff --git a/t/lib-submodule-superproject.sh b/t/lib-submodule-superproject.sh
new file mode 100644
index 00000000000..4d49dd3782e
--- /dev/null
+++ b/t/lib-submodule-superproject.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+test_lazy_prereq SUBMODULE_CACHE_SUPERPROJECT_DIR '
+	test_bool_env GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR true
+'
+
+test_cmp_submodule_superprojectgitdir () {
+	if ! test_have_prereq SUBMODULE_CACHE_SUPERPROJECT_DIR
+	then
+		return 0
+	fi
+
+	git -C "$1" config submodule.superprojectGitDir >actual &&
+	test_cmp expect actual
+}
+
+test_file_not_empty_superprojectgitdir () {
+	if ! test_have_prereq SUBMODULE_CACHE_SUPERPROJECT_DIR
+	then
+		return 0
+	fi
+
+	test_file_not_empty "$(git -C $1 rev-parse --absolute-git-dir)/$2"
+}
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 01e1acaf300..f362f8d0ef0 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -13,6 +13,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
 . ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-submodule-superproject.sh
 
 
 compare_head()
@@ -1068,8 +1069,7 @@ test_expect_success 'submodule update adds superproject gitdir to older repos' '
 	 test-tool path-utils relative_path \
 		"$(git rev-parse --absolute-git-dir)" \
 		"$(git -C submodule rev-parse --absolute-git-dir)" >expect &&
-	 git -C submodule config submodule.superprojectGitdir >actual &&
-	 test_cmp expect actual
+	 test_cmp_submodule_superprojectgitdir submodule
 	)
 '
 
@@ -1081,10 +1081,9 @@ test_expect_success 'submodule update uses config.worktree if applicable' '
 	 test-tool path-utils relative_path \
 		"$(git rev-parse --absolute-git-dir)" \
 		"$(git -C submodule rev-parse --absolute-git-dir)" >expect &&
-	 git -C submodule config submodule.superprojectGitdir >actual &&
-	 test_cmp expect actual &&
+	 test_cmp_submodule_superprojectgitdir submodule &&
 
-	 test_file_not_empty "$(git -C submodule rev-parse --absolute-git-dir)/config.worktree"
+	 test_file_not_empty_superprojectgitdir submodule config.worktree
 	)
 '
 
diff --git a/t/t7412-submodule-absorbgitdirs.sh b/t/t7412-submodule-absorbgitdirs.sh
index 5753f902687..6faab7e56e9 100755
--- a/t/t7412-submodule-absorbgitdirs.sh
+++ b/t/t7412-submodule-absorbgitdirs.sh
@@ -7,6 +7,7 @@ directory into the superproject.
 '
 
 . ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-submodule-superproject.sh
 
 test_expect_success 'setup a real submodule' '
 	git init sub1 &&
@@ -38,9 +39,7 @@ test_expect_success 'absorb the git dir' '
 
 	test-tool path-utils relative_path "$superproject_gitdir" \
 		"$submodule_gitdir" >expect &&
-	git -C sub1 config submodule.superprojectGitDir >actual &&
-
-	test_cmp expect actual
+	test_cmp_submodule_superprojectgitdir sub1
 '
 
 test_expect_success 'absorbing does not fail for deinitialized submodules' '
@@ -78,9 +77,7 @@ test_expect_success 'absorb the git dir in a nested submodule' '
 
 	test-tool path-utils relative_path "$sub1_gitdir" "$sub1_nested_gitdir" \
 		>expect &&
-	git -C sub1/nested config submodule.superprojectGitDir >actual &&
-
-	test_cmp expect actual
+	test_cmp_submodule_superprojectgitdir sub1
 '
 
 test_expect_success 're-setup nested submodule' '
@@ -170,9 +167,7 @@ test_expect_success 'absorbgitdirs works when called from a superproject worktre
 
 	test-tool path-utils relative_path "$superproject_gitdir" \
 		"$submodule_gitdir" >expect &&
-	git -C sub4 config submodule.superprojectGitDir >actual &&
-
-	test_cmp expect actual
+	test_cmp_submodule_superprojectgitdir sub4
 	)
 '
 
@@ -199,12 +194,10 @@ test_expect_success 'absorbgitdirs works with a submodule with worktree config'
 
 	test-tool path-utils relative_path "$superproject_gitdir" \
 		"$submodule_gitdir" >expect &&
-	git -C sub5 config submodule.superprojectGitDir >actual &&
-
-	test_cmp expect actual &&
+	test_cmp_submodule_superprojectgitdir sub5 &&
 
 	# make sure the config went into the submodule config.worktree
-	test_file_not_empty "$submodule_gitdir/config.worktree"
+	test_file_not_empty_superprojectgitdir sub5 config.worktree
 	)
 '
 
-- 
2.34.0.796.g2c87ed6146a


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* Re: [PATCH v6 0/5] teach submodules to know they're submodules
  2021-11-17  0:56 [PATCH v6 0/5] teach submodules to know they're submodules Emily Shaffer
                   ` (5 preceding siblings ...)
  2021-11-17 11:43 ` [RFC PATCH 0/2] submodule: test what happens if submodule.superprojectGitDir isn't around Ævar Arnfjörð Bjarmason
@ 2021-11-17 23:28 ` Jonathan Tan
  2021-11-23 20:28   ` Emily Shaffer
  2022-02-03 21:59 ` Emily Shaffer
  7 siblings, 1 reply; 64+ messages in thread
From: Jonathan Tan @ 2021-11-17 23:28 UTC (permalink / raw)
  To: emilyshaffer
  Cc: git, albertcui, phillip.wood123, Johannes.Schindelin, avarab,
	gitster, matheus.bernardino, jrnieder, jacob.keller, raykar.ath,
	stolee, jonathantanmy

Emily Shaffer <emilyshaffer@google.com> writes:
> For the original cover letter, see
> https://lore.kernel.org/git/20210611225428.1208973-1-emilyshaffer%40google.com.

Also for reference, v4 and v5 (as a reply to v4) can be found here:
https://lore.kernel.org/git/20211014203416.2802639-1-emilyshaffer@google.com/

> Since v5:
> 
> A couple things. Firstly, a semantics change *back* to the semantics of
> v3 - we map from gitdir to gitdir, *not* from common dir to common dir,
> so that theoretically a submodule with multiple worktrees in multiple
> superproject worktrees will be able to figure out which worktree of the
> superproject it's in. (Realistically, that's not really possible right
> now, but I'd like to change that soon.)

Makes sense. Also, thanks for the tests covering what happens when this
is run from worktrees.

> Secondly, a rewording of comments and commit messages to indicate that
> this isn't a cache of some expensive operation, but rather intended to
> be the source of truth for all submodules. I also added a fifth commit
> rewriting `git rev-parse --show-superproject-working-tree` to
> demonstrate what that means in practice - but from a practical
> standpoint, I'm a little worried about that fifth patch. More details in
> the patch 5 description.

OK - this is not the "this variable being missing is OK" idea that I had
[1], but we want to be able to depend on it to some extent. (And it is
not a cache either - we are not planning to perform an operation to
obtain the superproject gitdir if the cache is missing, but we are just
going to assume that there is no superproject.)

To that end, the 5th patch is misleading - it is behaving exactly like a
cache. I think it's better to drop it.

What would make sense to me (and seems to be in the spirit of this patch
set) is to describe this as something that Git commands can rely on to
determine if the current repo is a submodule, for performance reasons.
So maybe Git commands/parameters that directly reference the submodule
concept like "--show-superproject-working-tree" will work hard to find
the superproject (by searching the filesystem), but those that do not
(e.g. "git status") can make assumptions.

Making this variable a source of truth wouldn't work, I think, because
the source of truth is whether this repo appears in a .gitmodules file
(and that hasn't changed).

To this end, I'll comment on the changes I'd like to see on the
individual patches too.

[1] https://lore.kernel.org/git/20210727174650.2462099-1-jonathantanmy@google.com/

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v6 2/5] introduce submodule.superprojectGitDir record
  2021-11-17  0:56 ` [PATCH v6 2/5] introduce submodule.superprojectGitDir record Emily Shaffer
@ 2021-11-17 23:43   ` Jonathan Tan
  0 siblings, 0 replies; 64+ messages in thread
From: Jonathan Tan @ 2021-11-17 23:43 UTC (permalink / raw)
  To: emilyshaffer; +Cc: git, gitster, Jonathan Tan

Emily Shaffer <emilyshaffer@google.com> writes:
> 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.

If we're going with my proposal [1], I think it's worth further
explaining the concept right at the beginning of the commit message:

  Teach submodules a config variable referencing their superproject's
  gitdir. Git commands may rely on this reference to determine if the
  current repo is a submodule to another repo: if this reference is
  absent, Git may assume that the current repo is not a submodule. In
  practice, commands and arguments that specifially reference the
  submodule relationship (like "rev-parse
  --show-superproject-working-tree") will still search the ancestor
  directory, but others (say, a "git status" that prints the submodule's
  status in relation to its superproject or a config option that lets
  the superproject and submodule share config) would not.

[1] https://lore.kernel.org/git/20211117232846.2596110-1-jonathantanmy@google.com/

> 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 pointer. 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 pointer, too. Finally, by pointing at the
> superproject's worktree gitdir (if it exists), we ensure that we can
> tell which worktree contains our submodule.

OK.

> Since this hint value is only introduced during new submodule creation
> via `git submodule add`, though, there is more work to do to allow the
> record to be created at other times.

This is not a hint anymore. I would reword as:

  This commit teaches "git submodule add" to add the aforementioned
  config variable. Subsequent commits will teach other commands to do
  so.

> Once this new config is reliably in place, we can use it to know
> definitively that we are working in a submodule, and to know which
> superproject we are a submodule of. This allows us to do some
> 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.

I folded this into the first paragraph above, so this would no longer
needed if you used my suggestion above.

> +submodule.superprojectGitDir::
> +	The relative path from the submodule's gitdir to its superproject's
> +	gitdir. When Git is run in a repository, it usually makes no
> +	difference whether this repository is standalone or a submodule, but if
> +	this configuration variable is present, additional behavior may be
> +	possible, such as "git status" printing additional information about
> +	this submodule's status with respect to its superproject. This config
> +	should only be present in projects which are submodules, but is not
> +	guaranteed to be present in every submodule, so only optional
> +	value-added behavior should be linked to it. It is set automatically
> +	during submodule creation.

If we're going to rely on the variable more, this needs to be updated.
Maybe:

  If this repository is a submodule, the relative path from this repo's
  gitdir to its superproject's gitdir. Git commands may rely on this
  reference to determine if the current repo is a submodule to another
  repo: if this reference is absent, Git may assume that the current
  repo is not a submodule (this does not make a difference to most Git
  commands). It is set automatically during ??

(and probably each subsequent patch will need to update the ??)

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [RFC PATCH 0/2] submodule: test what happens if submodule.superprojectGitDir isn't around
  2021-11-17 11:43 ` [RFC PATCH 0/2] submodule: test what happens if submodule.superprojectGitDir isn't around Ævar Arnfjörð Bjarmason
  2021-11-17 11:43   ` [RFC PATCH 1/2] submodule tests: fix potentially broken "config .. --unset" Ævar Arnfjörð Bjarmason
  2021-11-17 11:43   ` [RFC PATCH 2/2] submodule: add test mode for checking absence of "superProjectGitDir" Ævar Arnfjörð Bjarmason
@ 2021-11-23 20:08   ` Emily Shaffer
  2021-11-24  1:38     ` Ævar Arnfjörð Bjarmason
  2 siblings, 1 reply; 64+ messages in thread
From: Emily Shaffer @ 2021-11-23 20:08 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Albert Cui, Phillip Wood,
	Johannes Schindelin, Matheus Tavares Bernardino, Jonathan Nieder,
	Jacob Keller, Atharva Raykar, Derrick Stolee, Jonathan Tan

On Wed, Nov 17, 2021 at 12:43:38PM +0100, Ævar Arnfjörð Bjarmason wrote:
> 
> On Tue, Nov 16 2021, Emily Shaffer wrote:
> 
> > [...]
> > A couple things. Firstly, a semantics change *back* to the semantics of
> > v3 - we map from gitdir to gitdir, *not* from common dir to common dir,
> > so that theoretically a submodule with multiple worktrees in multiple
> > superproject worktrees will be able to figure out which worktree of the
> > superproject it's in. (Realistically, that's not really possible right
> > now, but I'd like to change that soon.)
> >
> > Secondly, a rewording of comments and commit messages to indicate that
> > this isn't a cache of some expensive operation, but rather intended to
> > be the source of truth for all submodules. I also added a fifth commit
> > rewriting `git rev-parse --show-superproject-working-tree` to
> > demonstrate what that means in practice - but from a practical
> > standpoint, I'm a little worried about that fifth patch. More details in
> > the patch 5 description.
> >
> > I did discuss Ævar's idea of relying on in-process filesystem digging to
> > find the superproject's gitdir with the rest of the Google team, but in
> > the end decided that there are some worries about filesystem digging in
> > this way (namely, some ugly interactions with network drives that are
> > actually already an issue for Googler Linux machines). Plus, the allure
> > of being able to definitively know that we're a submodule is pretty
> > strong. ;) But overall, this is the direction I'd prefer to keep going                                                                                                                          
> > in, rather than trying to guess from the filesystem going forward.
> 
> Did you try running the ad-hoc benchmark I included in [1] on that
> Google NFS? I've dealt with some slow-ish network filesystems, but if
> it's slower than AIX's local FS (where I couldn't see a difference) I'd
> put money on it being a cross-Atlantic mount or something :)
> 
> Re your:
> 
>     "this isn't a cache of some expensive operation, but rather intended to                                                                                                                          be the source of truth for all submodules."
> 
> In your 5/5 it says, in seeming contradiction to this:
> 
>     This commit may be more of an RFC - to demonstrate what life looks like
>     if we use submodule.superprojectGitDir as the source of truth. But since
>     'git rev-parse --show-superproject-working-tree' is used in a lot of
>     scripts in the wild[1], I'm not so sure it's a great example.
> 
>     To be honest, I'd prefer to die("Try running 'git submodule update'")
>     here, but I don't think that's very script-friendly. However, falling
>     back on the old implementation kind of undermines the idea of treating
>     submodule.superprojectGitDir as the point of truth.
> 
> Most of what I've been suggesting in my [1] and related is that I'm
> confused about if & how this is a pure caching mechanism.
> 
> Removing mentions of it being a cache but it seemingly still being a
> cache at the tip of this series has just added to that confusion for
> me :)

Yeah, I think this was a bad choice for me to include that patch. I was
really hopeful that I could show off "look, we don't need to ever hunt
in the FS above us", but for established repos, that's a bad idea
(because lots of people are already using this 'git rev-parse
--show-superproject-work-tree' thing in scripts, like I mentioned). So I
think it was a mistake to include it at all. Rather, I think it's
probably a better idea to treat that particular entry point as "legacy"
and implement other things using 'submodule.superprojectGitDir'
directly.

Because the patch 5 illustrates: "I'm saying that this new config isn't
a cache, but look, here's how I can treat it like a cache that might be
invalid and here's how I can fall back on a potentially expensive
operation anyways." I think I could have illustrated it a little better
with something like "here's a brand new 'git rev-parse
--show-superproject-gitdir'" which directly calls on the new config.

So, sorry about that.

> 
> Anyway. While I do think this caching mechanism is probably
> unnecessary in the short to medium term, i.e. it seems to the extent
> that it was ever needed was due to some bridging of *.sh<->*.c that
> we're *this* close to eliminating anyway.
> 
> But maybe I'm wrong. The benchmark I suggested above on that Google
> NFS might be indicative. I don't really see how something that'll be
> doing a bunch of FS ops anyway is going to be noticeably slower with
> that approach, but maybe opening the index/tree of the superproject is
> more expensive than I'm expecting.
> 
> In any case, all of that's not the hill I'm picking to die on. If
> you'd like to go ahead with this cache-or-not-a-cache then sure, I
> won't belabor that point.

Yeah, I think I would. I've heard some serious reservations from others
on my team about trying to use filesystem traversal here at all, so I
think that would be an uphill battle.

> 
> I *do* strongly think if we're doing so though that we should have
> something like this on top. I.e. let's test wha happens if we do and
> don't have this "caching" variable, which is demonstrably easy to do.
> 
> Benchmarking the two gives me:
> 
>     $ git hyperfine -L rev HEAD~0 -L s true,false -s 'make -j8 all' '(cd t && GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR={s} ./t7412-submodule-absorbgitdirs.sh)'
>     Benchmark 1: (cd t && GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR=true ./t7412-submodule-absorbgitdirs.sh)' in 'HEAD~0
>       Time (mean ± σ):     545.9 ms ±   1.6 ms    [User: 490.3 ms, System: 114.0 ms]
>       Range (min … max):   543.5 ms … 548.1 ms    10 runs
>      
>     Benchmark 2: (cd t && GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR=false ./t7412-submodule-absorbgitdirs.sh)' in 'HEAD~0
>       Time (mean ± σ):     537.9 ms ±  11.4 ms    [User: 476.8 ms, System: 117.6 ms]
>       Range (min … max):   532.7 ms … 570.1 ms    10 runs
>      
>     Summary
>       '(cd t && GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR=false ./t7412-submodule-absorbgitdirs.sh)' in 'HEAD~0' ran
>         1.01 ± 0.02 times faster than '(cd t && GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR=true ./t7412-submodule-absorbgitdirs.sh)' in 'HEAD~0'
> 
> I.e. not using the cache is either indistinguishable or a bit faster
> (the "a bit faster" is definitely due to just running less test code
> though).

Yeah, once again, I think it is better to treat "git rev-parse
--show-superproject-work-tree" as "legacy" and to rely solely on the
config for new options, meaning that "what happens without this
variable" is as simple as "we treat it like it's a standalone repository
with no superproject", rather than a performance difference at all.

 - Emily

> 
> I'm sending this before the CI run[2] finishes (which now tests both
> modes), but both of these work for me locally on a full test suite
> run.
> 
> 1. https://lore.kernel.org/git/211109.86v912dtfw.gmgdl@evledraar.gmail.com/
> 2. https://github.com/avar/git/runs/4237446991?check_suite_focus=true
> 
> Ævar Arnfjörð Bjarmason (2):
>   submodule tests: fix potentially broken "config .. --unset"
>   submodule: add test mode for checking absence of "superProjectGitDir"
> 
>  ci/run-build-and-tests.sh          |  1 +
>  git-submodule.sh                   |  2 +-
>  submodule.c                        |  7 +++++++
>  t/lib-submodule-superproject.sh    | 24 ++++++++++++++++++++++++
>  t/t7406-submodule-update.sh        | 13 ++++++-------
>  t/t7412-submodule-absorbgitdirs.sh | 19 ++++++-------------
>  6 files changed, 45 insertions(+), 21 deletions(-)
>  create mode 100644 t/lib-submodule-superproject.sh
> 
> -- 
> 2.34.0.796.g2c87ed6146a
> 

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v6 0/5] teach submodules to know they're submodules
  2021-11-17 23:28 ` [PATCH v6 0/5] teach submodules to know they're submodules Jonathan Tan
@ 2021-11-23 20:28   ` Emily Shaffer
  0 siblings, 0 replies; 64+ messages in thread
From: Emily Shaffer @ 2021-11-23 20:28 UTC (permalink / raw)
  To: Jonathan Tan
  Cc: git, albertcui, phillip.wood123, Johannes.Schindelin, avarab,
	gitster, matheus.bernardino, jrnieder, jacob.keller, raykar.ath,
	stolee

On Wed, Nov 17, 2021 at 03:28:46PM -0800, Jonathan Tan wrote:
> 
> Emily Shaffer <emilyshaffer@google.com> writes:
> > For the original cover letter, see
> > https://lore.kernel.org/git/20210611225428.1208973-1-emilyshaffer%40google.com.
> 
> Also for reference, v4 and v5 (as a reply to v4) can be found here:
> https://lore.kernel.org/git/20211014203416.2802639-1-emilyshaffer@google.com/
> 
> > Since v5:
> > 
> > A couple things. Firstly, a semantics change *back* to the semantics of
> > v3 - we map from gitdir to gitdir, *not* from common dir to common dir,
> > so that theoretically a submodule with multiple worktrees in multiple
> > superproject worktrees will be able to figure out which worktree of the
> > superproject it's in. (Realistically, that's not really possible right
> > now, but I'd like to change that soon.)
> 
> Makes sense. Also, thanks for the tests covering what happens when this
> is run from worktrees.
> 
> > Secondly, a rewording of comments and commit messages to indicate that
> > this isn't a cache of some expensive operation, but rather intended to
> > be the source of truth for all submodules. I also added a fifth commit
> > rewriting `git rev-parse --show-superproject-working-tree` to
> > demonstrate what that means in practice - but from a practical
> > standpoint, I'm a little worried about that fifth patch. More details in
> > the patch 5 description.
> 
> OK - this is not the "this variable being missing is OK" idea that I had
> [1], but we want to be able to depend on it to some extent. (And it is
> not a cache either - we are not planning to perform an operation to
> obtain the superproject gitdir if the cache is missing, but we are just
> going to assume that there is no superproject.)
> 
> To that end, the 5th patch is misleading - it is behaving exactly like a
> cache. I think it's better to drop it.

Yeah, I think you are right.

> 
> What would make sense to me (and seems to be in the spirit of this patch
> set) is to describe this as something that Git commands can rely on to
> determine if the current repo is a submodule, for performance reasons.
> So maybe Git commands/parameters that directly reference the submodule
> concept like "--show-superproject-working-tree" will work hard to find
> the superproject (by searching the filesystem), but those that do not
> (e.g. "git status") can make assumptions.

Oh interesting, I like the idea of that distinction. Thanks for the
suggestion.

I wonder, though, how best to delineate. I'd almost rather say like I
suggested to Ævar
(https://lore.kernel.org/git/YZ1KLNwsxx7IR1%2B5%40google.com), that we
can treat "--show-superproject-working-tree" as a "legacy" option people
are already using, and treat anything added from now on as "if it
doesn't think it is a submodule, you should 'git submodule update' in
the superproject". That relies on us being able to reliably keep the
value of submodule.superprojectGitDir correct, but I think the
gitdir->gitdir linking helps with that (as opposed to earlier
iterations).
> 
> Making this variable a source of truth wouldn't work, I think, because
> the source of truth is whether this repo appears in a .gitmodules file
> (and that hasn't changed).

Interestingly, '--show-superproject-working-tree' doesn't check the
.gitmodules file at all. It checks whether the project found in the
filesystem above it knows about an object named path/to/superproject/
which is a gitlink - that is, it asks the index, not .gitmodules, as far
as I understand it. So if the only existing alternative to
submodule.superprojectGitDir isn't treating .gitmodules as source of
truth, then what does that mean?

> 
> To this end, I'll comment on the changes I'd like to see on the
> individual patches too.
> 
> [1] https://lore.kernel.org/git/20210727174650.2462099-1-jonathantanmy@google.com/

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [RFC PATCH 0/2] submodule: test what happens if submodule.superprojectGitDir isn't around
  2021-11-23 20:08   ` [RFC PATCH 0/2] submodule: test what happens if submodule.superprojectGitDir isn't around Emily Shaffer
@ 2021-11-24  1:38     ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 64+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-11-24  1:38 UTC (permalink / raw)
  To: Emily Shaffer
  Cc: git, Junio C Hamano, Albert Cui, Phillip Wood,
	Johannes Schindelin, Matheus Tavares Bernardino, Jonathan Nieder,
	Jacob Keller, Atharva Raykar, Derrick Stolee, Jonathan Tan


On Tue, Nov 23 2021, Emily Shaffer wrote:

> On Wed, Nov 17, 2021 at 12:43:38PM +0100, Ævar Arnfjörð Bjarmason wrote:
>> 
>> On Tue, Nov 16 2021, Emily Shaffer wrote:
>> 
>> > [...]
>> > A couple things. Firstly, a semantics change *back* to the semantics of
>> > v3 - we map from gitdir to gitdir, *not* from common dir to common dir,
>> > so that theoretically a submodule with multiple worktrees in multiple
>> > superproject worktrees will be able to figure out which worktree of the
>> > superproject it's in. (Realistically, that's not really possible right
>> > now, but I'd like to change that soon.)
>> >
>> > Secondly, a rewording of comments and commit messages to indicate that
>> > this isn't a cache of some expensive operation, but rather intended to
>> > be the source of truth for all submodules. I also added a fifth commit
>> > rewriting `git rev-parse --show-superproject-working-tree` to
>> > demonstrate what that means in practice - but from a practical
>> > standpoint, I'm a little worried about that fifth patch. More details in
>> > the patch 5 description.
>> >
>> > I did discuss Ævar's idea of relying on in-process filesystem digging to
>> > find the superproject's gitdir with the rest of the Google team, but in
>> > the end decided that there are some worries about filesystem digging in
>> > this way (namely, some ugly interactions with network drives that are
>> > actually already an issue for Googler Linux machines). Plus, the allure
>> > of being able to definitively know that we're a submodule is pretty
>> > strong. ;) But overall, this is the direction I'd prefer to keep
>> > going
>> > in, rather than trying to guess from the filesystem going forward.
>> 
>> Did you try running the ad-hoc benchmark I included in [1] on that
>> Google NFS? I've dealt with some slow-ish network filesystems, but if
>> it's slower than AIX's local FS (where I couldn't see a difference) I'd
>> put money on it being a cross-Atlantic mount or something :)
>> 
>> Re your:
>> 
>>     "this isn't a cache of some expensive operation, but rather
>> intended to be the source of truth for all submodules."
>> 
>> In your 5/5 it says, in seeming contradiction to this:
>> 
>>     This commit may be more of an RFC - to demonstrate what life looks like
>>     if we use submodule.superprojectGitDir as the source of truth. But since
>>     'git rev-parse --show-superproject-working-tree' is used in a lot of
>>     scripts in the wild[1], I'm not so sure it's a great example.
>> 
>>     To be honest, I'd prefer to die("Try running 'git submodule update'")
>>     here, but I don't think that's very script-friendly. However, falling
>>     back on the old implementation kind of undermines the idea of treating
>>     submodule.superprojectGitDir as the point of truth.
>> 
>> Most of what I've been suggesting in my [1] and related is that I'm
>> confused about if & how this is a pure caching mechanism.
>> 
>> Removing mentions of it being a cache but it seemingly still being a
>> cache at the tip of this series has just added to that confusion for
>> me :)
>
> Yeah, I think this was a bad choice for me to include that patch. I was
> really hopeful that I could show off "look, we don't need to ever hunt
> in the FS above us", but for established repos, that's a bad idea
> (because lots of people are already using this 'git rev-parse
> --show-superproject-work-tree' thing in scripts, like I mentioned). So I
> think it was a mistake to include it at all. Rather, I think it's
> probably a better idea to treat that particular entry point as "legacy"
> and implement other things using 'submodule.superprojectGitDir'
> directly.
>
> Because the patch 5 illustrates: "I'm saying that this new config isn't
> a cache, but look, here's how I can treat it like a cache that might be
> invalid and here's how I can fall back on a potentially expensive
> operation anyways." I think I could have illustrated it a little better
> with something like "here's a brand new 'git rev-parse
> --show-superproject-gitdir'" which directly calls on the new config.
>
> So, sorry about that.

The RFC series here shows that the config & the on-the-fly discovery 1=1
map to each other (at least in terms of the tests your series adds).

Why wouldn't the same be the case with a --show-superproject-gitdir?
Unless the fallback implementation was intentionally removed.

>> 
>> Anyway. While I do think this caching mechanism is probably
>> unnecessary in the short to medium term, i.e. it seems to the extent
>> that it was ever needed was due to some bridging of *.sh<->*.c that
>> we're *this* close to eliminating anyway.
>> 
>> But maybe I'm wrong. The benchmark I suggested above on that Google
>> NFS might be indicative. I don't really see how something that'll be
>> doing a bunch of FS ops anyway is going to be noticeably slower with
>> that approach, but maybe opening the index/tree of the superproject is
>> more expensive than I'm expecting.
>> 
>> In any case, all of that's not the hill I'm picking to die on. If
>> you'd like to go ahead with this cache-or-not-a-cache then sure, I
>> won't belabor that point.
>
> Yeah, I think I would. I've heard some serious reservations from others
> on my team about trying to use filesystem traversal here at all, so I
> think that would be an uphill battle.

Do they have any benchmarks to share? :)

>> 
>> I *do* strongly think if we're doing so though that we should have
>> something like this on top. I.e. let's test wha happens if we do and
>> don't have this "caching" variable, which is demonstrably easy to do.
>> 
>> Benchmarking the two gives me:
>> 
>>     $ git hyperfine -L rev HEAD~0 -L s true,false -s 'make -j8 all' '(cd t && GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR={s} ./t7412-submodule-absorbgitdirs.sh)'
>>     Benchmark 1: (cd t && GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR=true ./t7412-submodule-absorbgitdirs.sh)' in 'HEAD~0
>>       Time (mean ± σ):     545.9 ms ±   1.6 ms    [User: 490.3 ms, System: 114.0 ms]
>>       Range (min … max):   543.5 ms … 548.1 ms    10 runs
>>      
>>     Benchmark 2: (cd t && GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR=false ./t7412-submodule-absorbgitdirs.sh)' in 'HEAD~0
>>       Time (mean ± σ):     537.9 ms ±  11.4 ms    [User: 476.8 ms, System: 117.6 ms]
>>       Range (min … max):   532.7 ms … 570.1 ms    10 runs
>>      
>>     Summary
>>       '(cd t && GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR=false ./t7412-submodule-absorbgitdirs.sh)' in 'HEAD~0' ran
>>         1.01 ± 0.02 times faster than '(cd t && GIT_TEST_SUBMODULE_CACHE_SUPERPROJECT_DIR=true ./t7412-submodule-absorbgitdirs.sh)' in 'HEAD~0'
>> 
>> I.e. not using the cache is either indistinguishable or a bit faster
>> (the "a bit faster" is definitely due to just running less test code
>> though).
>
> Yeah, once again, I think it is better to treat "git rev-parse
> --show-superproject-work-tree" as "legacy" and to rely solely on the
> config for new options, meaning that "what happens without this
> variable" is as simple as "we treat it like it's a standalone repository
> with no superproject", rather than a performance difference at all.

Why would it be better to have a hard reliance on the config for new
features or options? Your original CL says[1]:

    It's expensive and non-definitive to try and guess whether or not the
    current repo is a submodule.

Maybe that's the case somewhere, I haven't been able to dig up the
"expensive" part (aside from the fixable case of exec-ing rev-parse in a
loop).

Which leaves "non-definitive", that may be the case, but as the RFC
patches here show if there is such a case, it's not covered by any of
your existing tests in this series.

I'd think if those two things hold true (not expensive, and we can
unambiguously discover it on the fly) our bias should be towards not
introducing an indirection in the config, as such a thing needs to be
kept up-to-date, and which may become inaccurate for whatever
reason. Whereas the FS relationship between the won't ever be
out-of-date.

1. https://lore.kernel.org/git/20210611225428.1208973-1-emilyshaffer@google.com

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v6 0/5] teach submodules to know they're submodules
  2021-11-17  0:56 [PATCH v6 0/5] teach submodules to know they're submodules Emily Shaffer
                   ` (6 preceding siblings ...)
  2021-11-17 23:28 ` [PATCH v6 0/5] teach submodules to know they're submodules Jonathan Tan
@ 2022-02-03 21:59 ` Emily Shaffer
  2022-02-03 21:59   ` [PATCH v7 1/4] t7400-submodule-basic: modernize inspect() helper Emily Shaffer
                     ` (6 more replies)
  7 siblings, 7 replies; 64+ messages in thread
From: Emily Shaffer @ 2022-02-03 21:59 UTC (permalink / raw)
  To: git
  Cc: Emily Shaffer, Albert Cui, Phillip Wood, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason, Junio C Hamano,
	Matheus Tavares Bernardino, Jonathan Nieder, Jacob Keller,
	Atharva Raykar, Derrick Stolee, Jonathan Tan

For the original cover letter, see
https://lore.kernel.org/git/20210611225428.1208973-1-emilyshaffer%40google.com.

CI run: https://github.com/nasamuffin/git/actions/runs/1780282431

Since v6:

I've dropped the fifth commit to use this new config for `git rev-parse
--show-superproject-working-tree`. I think it did more harm than good -
that tool uses an odd way to determine whether the superproject is
actually the superproject, anyways.

I poked a little bit at trying to find some benchmark to demonstrate
that "submodule.superprojectGitDir" is actually faster - but I didn't
end up able to write one without writing a ton of new code to traverse
the filesystem. To be honest, I'm not all that interested in performance
- I want the config added for correctness, instead.

So, the only real changes between v6 and v7 are some documentation
changes suggested by Jonathan Tan
(https://lore.kernel.org/git/20211117234300.2598132-1-jonathantanmy%40google.com).

Since v5:

A couple things. Firstly, a semantics change *back* to the semantics of
v3 - we map from gitdir to gitdir, *not* from common dir to common dir,
so that theoretically a submodule with multiple worktrees in multiple
superproject worktrees will be able to figure out which worktree of the
superproject it's in. (Realistically, that's not really possible right
now, but I'd like to change that soon.)

Secondly, a rewording of comments and commit messages to indicate that
this isn't a cache of some expensive operation, but rather intended to
be the source of truth for all submodules. I also added a fifth commit
rewriting `git rev-parse --show-superproject-working-tree` to
demonstrate what that means in practice - but from a practical
standpoint, I'm a little worried about that fifth patch. More details in
the patch 5 description.

I did discuss Ævar's idea of relying on in-process filesystem digging to
find the superproject's gitdir with the rest of the Google team, but in
the end decided that there are some worries about filesystem digging in
this way (namely, some ugly interactions with network drives that are
actually already an issue for Googler Linux machines). Plus, the allure
of being able to definitively know that we're a submodule is pretty
strong. ;) But overall, this is the direction I'd prefer to keep going
in, rather than trying to guess from the filesystem going forward.

Since v4:

The only real change here is a slight semantics change to map from
<submodule gitdir> to <superproject common git dir>. In every case
*except* for when the superproject has a worktree, this changes nothing.
For the case when the superproject has a worktree, this means that now
submodules will refer to the general superproject common dir (e.g. no
worktree-specific refs or configs or whatnot).

I *think* that because a submodule should exist in the context of the
common dir, not the worktree gitdir, that is ok. However, it does mean
it would be difficult to do something like sharing a config specific to
the worktree (the initial goal of this series).

$ROOT/.git
$ROOT/.git/config.superproject <- shared by $ROOT/.git/modules/sub
$ROOT/.git/modules/sub <- points to $ROOT/.git
$ROOT/.git/worktrees/wt
$ROOT/.git/worktrees/wt/config.superproject <- contains a certain config-based pre-commit hook

If the submodule only knows about the common dir, that is tough, because
the submodule would basically have to guess which worktree it's in from
its own path. There would be no way for '$WT/sub' to inherit
'$ROOT/.git/worktrees/wt/config.superproject'.

That said... right now, we don't support submodules in worktrees very
well at all. A submodule in a worktree will get a brand new gitdir in
$ROOT/.git/worktrees/modules/ (and that brand new gitdir would point to
the super's common dir). So I think we can punt on this entire question
until we teach submodules and worktrees to play more gracefully together
(it's on my long list...), and at that time we can probably introduce a
pointer from $ROOT/.git/modules/sub/worktrees/wt/ to
$ROOT/.git/worktrees/wt/....

Or, to summarize the long ramble above: "this is still kind of weird
with worktrees, but let's fix it later when we fix worktrees more
thoroughly".

(More rambling about worktree weirdness here:
https://lore.kernel.org/git/YYRaII8YWVxlBqsF%40google.com )


Since v3, a pretty major change: the semantics of
submodule.superprojectGitDir has changed, to point from the submodule's
gitdir to the superproject's gitdir (in v3 and earlier, we kept a path
from the submodule's *worktree* to the superproject's gitdir instead).
This cleans up some of the confusions about the behavior when a
submodule worktree moves around in the superproject's tree, or in a
future when we support submodules having multiple worktrees.

I also tried to simplify the tests to use 'test-tool path-utils
relative_path' everywhere - I think that makes them much more clear for
a test reader, but if you're reviewing and it isn't obvious what we're
testing for, please speak up.

I think this is pretty mature and there was a lot of general agreement
that the gitdir->gitdir association was the way to go, so please be
brutal and look for nits, leaks, etc. this round ;)
[/v4 cover letter]


Emily Shaffer (4):
  t7400-submodule-basic: modernize inspect() helper
  introduce submodule.superprojectGitDir record
  submodule: record superproject gitdir during absorbgitdirs
  submodule: record superproject gitdir during 'update'

 Documentation/config/submodule.txt |  9 ++++
 builtin/submodule--helper.c        | 11 ++++
 git-submodule.sh                   | 15 ++++++
 submodule.c                        | 23 +++++++++
 t/t7400-submodule-basic.sh         | 54 +++++++++++---------
 t/t7406-submodule-update.sh        | 27 ++++++++++
 t/t7412-submodule-absorbgitdirs.sh | 82 +++++++++++++++++++++++++++++-
 7 files changed, 194 insertions(+), 27 deletions(-)

Range-diff against v6:
1:  f1b08a7057 = 1:  251510c687 t7400-submodule-basic: modernize inspect() helper
2:  d46c8439ab ! 2:  1a85deb1c5 introduce submodule.superprojectGitDir record
    @@ Metadata
      ## Commit message ##
         introduce submodule.superprojectGitDir record
     
    -    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.
    +    Teach submodules a config variable referencing to their superproject's
    +    gitdir. Git commands can rely on this reference to determine whether the
    +    current repo is a submodule to another repo. If this reference is
    +    absent, Git may assume the current repo is not a submodule.
    +
    +    In practice, some commands which specifically reference the submodule
    +    relationship, like 'git rev-parse --show-superproject-working-tree',
    +    will still search the parent directory. Other newly added or implicit
    +    behavior, such as "git status" showing the submodule's status in
    +    relation to the superproject, or a config which is shared between the
    +    superproject and the submodule, should not search the parent directory
    +    and instead rely on this "submodule.superprojectGitDir" config.
     
         By using a relative path instead of an absolute path, we can move the
         superproject directory around on the filesystem without breaking the
    @@ Commit message
         superproject's worktree gitdir (if it exists), we ensure that we can
         tell which worktree contains our submodule.
     
    -    Since this hint value is only introduced during new submodule creation
    -    via `git submodule add`, though, there is more work to do to allow the
    -    record to be created at other times.
    -
    -    Once this new config is reliably in place, we can use it to know
    -    definitively that we are working in a submodule, and to know which
    -    superproject we are a submodule of. This allows us to do some
    -    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.
    +    This commit teaches "git submodule add" to add the aformentioned config
    +    variable. Subsequent commits will teach other commands to do so.
     
         Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
         Helped-by: Junio C Hamano <gitster@pobox.com>
    @@ Documentation/config/submodule.txt: submodule.alternateErrorStrategy::
      	clone proceeds as if no alternate was specified.
     +
     +submodule.superprojectGitDir::
    -+	The relative path from the submodule's gitdir to its superproject's
    -+	gitdir. When Git is run in a repository, it usually makes no
    -+	difference whether this repository is standalone or a submodule, but if
    -+	this configuration variable is present, additional behavior may be
    -+	possible, such as "git status" printing additional information about
    -+	this submodule's status with respect to its superproject. This config
    -+	should only be present in projects which are submodules, but is not
    -+	guaranteed to be present in every submodule, so only optional
    -+	value-added behavior should be linked to it. It is set automatically
    -+	during submodule creation.
    ++	If this repository is a submodule, the relative path from this repo's
    ++	gitdir to its superproject's gitdir. Git commands may rely on this
    ++	reference to determine whether the current repo is a submodule to
    ++	another repo; if this reference is absent, Git will treat the current
    ++	repo as though it is not a submodule (this does not make a difference to
    ++	most Git commands). It is set automatically during submodule creation.
     
      ## builtin/submodule--helper.c ##
     @@ builtin/submodule--helper.c: static int clone_submodule(struct module_clone_data *clone_data)
3:  63ddaf5608 ! 3:  7a44b0edf9 submodule: record superproject gitdir during absorbgitdirs
    @@ Commit message
     
         Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
     
    + ## Documentation/config/submodule.txt ##
    +@@ Documentation/config/submodule.txt: submodule.superprojectGitDir::
    + 	reference to determine whether the current repo is a submodule to
    + 	another repo; if this reference is absent, Git will treat the current
    + 	repo as though it is not a submodule (this does not make a difference to
    +-	most Git commands). It is set automatically during submodule creation.
    ++	most Git commands). It is set automatically during submodule creation
    ++	and 'git submodule absorbgitdir'.
    +
      ## submodule.c ##
     @@ submodule.c: 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;
4:  33a582ef13 ! 4:  63e736e69d submodule: record superproject gitdir during 'update'
    @@ Commit message
     
         Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
     
    + ## Documentation/config/submodule.txt ##
    +@@ Documentation/config/submodule.txt: submodule.superprojectGitDir::
    + 	reference to determine whether the current repo is a submodule to
    + 	another repo; if this reference is absent, Git will treat the current
    + 	repo as though it is not a submodule (this does not make a difference to
    +-	most Git commands). It is set automatically during submodule creation
    +-	and 'git submodule absorbgitdir'.
    ++	most Git commands). It is set automatically during submodule creation,
    ++	update, and 'git submodule absorbgitdir'.
    +
      ## git-submodule.sh ##
     @@ git-submodule.sh: cmd_update()
      			;;
5:  a8b5d40a77 < -:  ---------- submodule: use config to find superproject worktree
-- 
2.35.0.263.gb82422642f-goog


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v7 1/4] t7400-submodule-basic: modernize inspect() helper
  2022-02-03 21:59 ` Emily Shaffer
@ 2022-02-03 21:59   ` Emily Shaffer
  2022-02-03 21:59   ` [PATCH v7 2/4] introduce submodule.superprojectGitDir record Emily Shaffer
                     ` (5 subsequent siblings)
  6 siblings, 0 replies; 64+ messages in thread
From: Emily Shaffer @ 2022-02-03 21:59 UTC (permalink / raw)
  To: git; +Cc: Emily Shaffer

Since the inspect() helper in the submodule-basic test suite was
written, 'git -C <dir>' 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 <emilyshaffer@google.com>
---
 t/t7400-submodule-basic.sh | 40 +++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 24 deletions(-)

diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index e7cec2e457..40cf8d89aa 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -107,23 +107,15 @@ 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"
-	)
+	sub_dir=$1 &&
+
+	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 &&
+	git -C "$sub_dir" clean -n -d -x >untracked
 }
 
 test_expect_success 'submodule add' '
@@ -146,7 +138,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
@@ -248,7 +240,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
@@ -264,7 +256,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
@@ -280,7 +272,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
@@ -296,7 +288,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
@@ -312,7 +304,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
@@ -328,7 +320,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
@@ -359,7 +351,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
-- 
2.35.0.263.gb82422642f-goog


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH v7 2/4] introduce submodule.superprojectGitDir record
  2022-02-03 21:59 ` Emily Shaffer
  2022-02-03 21:59   ` [PATCH v7 1/4] t7400-submodule-basic: modernize inspect() helper Emily Shaffer
@ 2022-02-03 21:59   ` Emily Shaffer
  2022-02-03 21:59   ` [PATCH v7 3/4] submodule: record superproject gitdir during absorbgitdirs Emily Shaffer
                     ` (4 subsequent siblings)
  6 siblings, 0 replies; 64+ messages in thread
From: Emily Shaffer @ 2022-02-03 21:59 UTC (permalink / raw)
  To: git; +Cc: Emily Shaffer, Junio C Hamano

Teach submodules a config variable referencing to their superproject's
gitdir. Git commands can rely on this reference to determine whether the
current repo is a submodule to another repo. If this reference is
absent, Git may assume the current repo is not a submodule.

In practice, some commands which specifically reference the submodule
relationship, like 'git rev-parse --show-superproject-working-tree',
will still search the parent directory. Other newly added or implicit
behavior, such as "git status" showing the submodule's status in
relation to the superproject, or a config which is shared between the
superproject and the submodule, should not search the parent directory
and instead rely on this "submodule.superprojectGitDir" config.

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 pointer. 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 pointer, too. Finally, by pointing at the
superproject's worktree gitdir (if it exists), we ensure that we can
tell which worktree contains our submodule.

This commit teaches "git submodule add" to add the aformentioned config
variable. Subsequent commits will teach other commands to do so.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/config/submodule.txt |  8 ++++++++
 builtin/submodule--helper.c        | 11 ++++++++++
 t/t7400-submodule-basic.sh         | 32 ++++++++++++++++++++----------
 3 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/Documentation/config/submodule.txt b/Documentation/config/submodule.txt
index ee454f8126..bebd25684e 100644
--- a/Documentation/config/submodule.txt
+++ b/Documentation/config/submodule.txt
@@ -91,3 +91,11 @@ 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::
+	If this repository is a submodule, the relative path from this repo's
+	gitdir to its superproject's gitdir. Git commands may rely on this
+	reference to determine whether the current repo is a submodule to
+	another repo; if this reference is absent, Git will treat the current
+	repo as though it is not a submodule (this does not make a difference to
+	most Git commands). It is set automatically during submodule creation.
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index c5d3fc3817..0485b384a1 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1839,6 +1839,17 @@ static int clone_submodule(struct module_clone_data *clone_data)
 		git_config_set_in_file(p, "submodule.alternateErrorStrategy",
 				       error_strategy);
 
+	/*
+	 * Set the path from submodule's new gitdir to superproject's gitdir.
+	 * The latter may be a worktree gitdir. However, it is not possible for
+	 * the submodule to have a worktree-specific gitdir or config at clone
+	 * time, because "extensions.worktreeConfig" is only valid when set in
+	 * the local gitconfig, which the brand new submodule does not have yet.
+	 */
+	git_config_set_in_file(p, "submodule.superprojectGitDir",
+			       relative_path(absolute_path(get_git_dir()),
+					     sm_gitdir, &sb));
+
 	free(sm_alternate);
 	free(error_strategy);
 
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 40cf8d89aa..7e4cc89bf5 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -109,12 +109,24 @@ submodurl=$(pwd -P)
 
 inspect() {
 	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 &&
+
+	# Ensure that submodule.superprojectGitDir contains the path from the
+	# submodule's gitdir to the superproject's gitdir.
+
+	super_abs_gitdir=$(git -C "$super_dir" rev-parse --absolute-git-dir) &&
+	sub_abs_gitdir=$(git -C "$sub_dir" rev-parse --absolute-git-dir) &&
+
+	[ "$(git -C "$sub_dir" config --get submodule.superprojectGitDir)" = \
+	  "$(test-tool path-utils relative_path "$super_abs_gitdir" \
+						"$sub_abs_gitdir")" ] &&
+
 	git -C "$sub_dir" clean -n -d -x >untracked
 }
 
@@ -138,7 +150,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
@@ -240,7 +252,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
@@ -256,7 +268,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
@@ -272,7 +284,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
@@ -288,7 +300,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
@@ -304,7 +316,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
@@ -320,7 +332,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
@@ -351,7 +363,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
@@ -492,7 +504,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
 '
 
@@ -551,7 +563,7 @@ test_expect_success 'update should checkout rev1' '
 	echo "$rev1" >expect &&
 
 	git submodule update init &&
-	inspect init &&
+	inspect init . &&
 
 	test_cmp expect head-sha1
 '
-- 
2.35.0.263.gb82422642f-goog


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH v7 3/4] submodule: record superproject gitdir during absorbgitdirs
  2022-02-03 21:59 ` Emily Shaffer
  2022-02-03 21:59   ` [PATCH v7 1/4] t7400-submodule-basic: modernize inspect() helper Emily Shaffer
  2022-02-03 21:59   ` [PATCH v7 2/4] introduce submodule.superprojectGitDir record Emily Shaffer
@ 2022-02-03 21:59   ` Emily Shaffer
  2022-02-03 21:59   ` [PATCH v7 4/4] submodule: record superproject gitdir during 'update' Emily Shaffer
                     ` (3 subsequent siblings)
  6 siblings, 0 replies; 64+ messages in thread
From: Emily Shaffer @ 2022-02-03 21:59 UTC (permalink / raw)
  To: git; +Cc: Emily Shaffer

Already during 'git submodule add' we record 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 absorbgitdirs'. Let's start adding that pointer during 'git
submodule absorbgitdirs' too.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
---
 Documentation/config/submodule.txt |  3 +-
 submodule.c                        | 23 +++++++++
 t/t7412-submodule-absorbgitdirs.sh | 82 +++++++++++++++++++++++++++++-
 3 files changed, 105 insertions(+), 3 deletions(-)

diff --git a/Documentation/config/submodule.txt b/Documentation/config/submodule.txt
index bebd25684e..f801f49ea1 100644
--- a/Documentation/config/submodule.txt
+++ b/Documentation/config/submodule.txt
@@ -98,4 +98,5 @@ submodule.superprojectGitDir::
 	reference to determine whether the current repo is a submodule to
 	another repo; if this reference is absent, Git will treat the current
 	repo as though it is not a submodule (this does not make a difference to
-	most Git commands). It is set automatically during submodule creation.
+	most Git commands). It is set automatically during submodule creation
+	and 'git submodule absorbgitdir'.
diff --git a/submodule.c b/submodule.c
index c689070524..d7395c7551 100644
--- a/submodule.c
+++ b/submodule.c
@@ -2097,6 +2097,9 @@ 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;
 	struct strbuf new_gitdir = STRBUF_INIT;
 	const struct submodule *sub;
+	struct config_set sub_cs;
+	struct strbuf config_path = STRBUF_INIT, sb = STRBUF_INIT;
+	int tmp;
 
 	if (submodule_uses_worktrees(path))
 		die(_("relocate_gitdir for submodule '%s' with "
@@ -2127,6 +2130,26 @@ static void relocate_single_git_dir_into_superproject(const char *path)
 
 	relocate_gitdir(path, real_old_git_dir, real_new_git_dir);
 
+	/*
+	 * Note location of superproject's gitdir. Because the submodule already
+	 * has a gitdir and local config, we can store this pointer from
+	 * worktree config to worktree config, if the submodule has
+	 * extensions.worktreeConfig set.
+	 */
+	strbuf_addf(&config_path, "%s/config", real_new_git_dir);
+	git_configset_init(&sub_cs);
+	git_configset_add_file(&sub_cs, config_path.buf);
+	/* return 0 indicates config was found - we have a worktree config */
+	if (!git_configset_get_bool(&sub_cs, "extensions.worktreeConfig", &tmp))
+		strbuf_addstr(&config_path, ".worktree");
+
+	git_config_set_in_file(config_path.buf, "submodule.superprojectGitdir",
+			       relative_path(absolute_path(get_git_dir()),
+					     real_new_git_dir, &sb));
+
+	git_configset_clear(&sub_cs);
+	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..5753f90268 100755
--- a/t/t7412-submodule-absorbgitdirs.sh
+++ b/t/t7412-submodule-absorbgitdirs.sh
@@ -30,7 +30,17 @@ 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
+	submodule_gitdir="$(git -C sub1 rev-parse --path-format=absolute --git-common-dir)" &&
+	superproject_gitdir="$(git rev-parse --path-format=absolute --git-common-dir)" &&
+
+	test-tool path-utils relative_path "$superproject_gitdir" \
+		"$submodule_gitdir" >expect &&
+	git -C sub1 config submodule.superprojectGitDir >actual &&
+
+	test_cmp expect actual
 '
 
 test_expect_success 'absorbing does not fail for deinitialized submodules' '
@@ -61,7 +71,16 @@ test_expect_success 'absorb the git dir in a nested submodule' '
 	git status >actual.1 &&
 	git -C sub1/nested rev-parse HEAD >actual.2 &&
 	test_cmp expect.1 actual.1 &&
-	test_cmp expect.2 actual.2
+	test_cmp expect.2 actual.2 &&
+
+	sub1_gitdir="$(git -C sub1 rev-parse --path-format=absolute --git-common-dir)" &&
+	sub1_nested_gitdir="$(git -C sub1/nested rev-parse --path-format=absolute --git-common-dir)" &&
+
+	test-tool path-utils relative_path "$sub1_gitdir" "$sub1_nested_gitdir" \
+		>expect &&
+	git -C sub1/nested config submodule.superprojectGitDir >actual &&
+
+	test_cmp expect actual
 '
 
 test_expect_success 're-setup nested submodule' '
@@ -130,4 +149,63 @@ test_expect_success 'absorbing fails for a submodule with multiple worktrees' '
 	test_i18ngrep "not supported" error
 '
 
+test_expect_success 'absorbgitdirs works when called from a superproject worktree' '
+	# set up a worktree of the superproject
+	git worktree add wt &&
+	(
+	cd wt &&
+
+	# create a new unembedded git dir
+	git init sub4 &&
+	test_commit -C sub4 first &&
+	git submodule add ./sub4 &&
+	test_tick &&
+
+	# absorb the git dir
+	git submodule absorbgitdirs sub4 &&
+
+	# make sure the submodule noted the superproject gitdir correctly
+	submodule_gitdir="$(git -C sub4 rev-parse --absolute-git-dir)" &&
+	superproject_gitdir="$(git rev-parse --absolute-git-dir)" &&
+
+	test-tool path-utils relative_path "$superproject_gitdir" \
+		"$submodule_gitdir" >expect &&
+	git -C sub4 config submodule.superprojectGitDir >actual &&
+
+	test_cmp expect actual
+	)
+'
+
+test_expect_success 'absorbgitdirs works with a submodule with worktree config' '
+	# reuse the worktree of the superproject
+	(
+	cd wt &&
+
+	# create a new unembedded git dir
+	git init sub5 &&
+	test_commit -C sub5 first &&
+	git submodule add ./sub5 &&
+	test_tick &&
+
+	# turn on worktree configs for submodule
+	git -C sub5 config extensions.worktreeConfig true &&
+
+	# absorb the git dir
+	git submodule absorbgitdirs sub5 &&
+
+	# make sure the submodule noted the superproject gitdir correctly
+	submodule_gitdir="$(git -C sub5 rev-parse --absolute-git-dir)" &&
+	superproject_gitdir="$(git rev-parse --absolute-git-dir)" &&
+
+	test-tool path-utils relative_path "$superproject_gitdir" \
+		"$submodule_gitdir" >expect &&
+	git -C sub5 config submodule.superprojectGitDir >actual &&
+
+	test_cmp expect actual &&
+
+	# make sure the config went into the submodule config.worktree
+	test_file_not_empty "$submodule_gitdir/config.worktree"
+	)
+'
+
 test_done
-- 
2.35.0.263.gb82422642f-goog


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH v7 4/4] submodule: record superproject gitdir during 'update'
  2022-02-03 21:59 ` Emily Shaffer
                     ` (2 preceding siblings ...)
  2022-02-03 21:59   ` [PATCH v7 3/4] submodule: record superproject gitdir during absorbgitdirs Emily Shaffer
@ 2022-02-03 21:59   ` Emily Shaffer
  2022-02-03 22:39   ` [PATCH v6 0/5] teach submodules to know they're submodules Junio C Hamano
                     ` (2 subsequent siblings)
  6 siblings, 0 replies; 64+ messages in thread
From: Emily Shaffer @ 2022-02-03 21:59 UTC (permalink / raw)
  To: git; +Cc: Emily Shaffer

A recorded 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 record that info - it might
be useful to update the pointer. 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>
---
 Documentation/config/submodule.txt |  4 ++--
 git-submodule.sh                   | 15 +++++++++++++++
 t/t7406-submodule-update.sh        | 27 +++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/Documentation/config/submodule.txt b/Documentation/config/submodule.txt
index f801f49ea1..ab37800954 100644
--- a/Documentation/config/submodule.txt
+++ b/Documentation/config/submodule.txt
@@ -98,5 +98,5 @@ submodule.superprojectGitDir::
 	reference to determine whether the current repo is a submodule to
 	another repo; if this reference is absent, Git will treat the current
 	repo as though it is not a submodule (this does not make a difference to
-	most Git commands). It is set automatically during submodule creation
-	and 'git submodule absorbgitdir'.
+	most Git commands). It is set automatically during submodule creation,
+	update, and 'git submodule absorbgitdir'.
diff --git a/git-submodule.sh b/git-submodule.sh
index 652861aa66..7c247bee7f 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -449,6 +449,21 @@ cmd_update()
 			;;
 		esac
 
+		# Store a poitner to the superproject's gitdir. This may have
+		# changed, unless it's a fresh clone. Write to worktree if
+		# applicable, and point to superproject's worktree gitdir if
+		# applicable.
+		if test -z "$just_cloned"
+		then
+			sm_gitdir="$(git -C "$sm_path" rev-parse --absolute-git-dir)"
+			relative_gitdir="$(git rev-parse --path-format=relative \
+							 --prefix "${sm_gitdir}" \
+							 --git-dir)"
+
+			git -C "$sm_path" config --worktree \
+				submodule.superprojectgitdir "$relative_gitdir"
+		fi
+
 		if test -n "$recursive"
 		then
 			(
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 11cccbb333..b42a339982 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -1061,4 +1061,31 @@ 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 &&
+	 test-tool path-utils relative_path \
+		"$(git rev-parse --absolute-git-dir)" \
+		"$(git -C submodule rev-parse --absolute-git-dir)" >expect &&
+	 git -C submodule config submodule.superprojectGitdir >actual &&
+	 test_cmp expect actual
+	)
+'
+
+test_expect_success 'submodule update uses config.worktree if applicable' '
+	(cd super &&
+	 git -C submodule config --unset submodule.superprojectGitDir &&
+	 git -C submodule config extensions.worktreeConfig true &&
+	 git submodule update &&
+	 test-tool path-utils relative_path \
+		"$(git rev-parse --absolute-git-dir)" \
+		"$(git -C submodule rev-parse --absolute-git-dir)" >expect &&
+	 git -C submodule config submodule.superprojectGitdir >actual &&
+	 test_cmp expect actual &&
+
+	 test_file_not_empty "$(git -C submodule rev-parse --absolute-git-dir)/config.worktree"
+	)
+'
+
 test_done
-- 
2.35.0.263.gb82422642f-goog


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* Re: [PATCH v6 0/5] teach submodules to know they're submodules
  2022-02-03 21:59 ` Emily Shaffer
                     ` (3 preceding siblings ...)
  2022-02-03 21:59   ` [PATCH v7 4/4] submodule: record superproject gitdir during 'update' Emily Shaffer
@ 2022-02-03 22:39   ` Junio C Hamano
  2022-02-04  1:15   ` Ævar Arnfjörð Bjarmason
  2022-03-01  0:26   ` [PATCH v8 0/3] " Emily Shaffer
  6 siblings, 0 replies; 64+ messages in thread
From: Junio C Hamano @ 2022-02-03 22:39 UTC (permalink / raw)
  To: Emily Shaffer
  Cc: git, Albert Cui, Phillip Wood, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason,
	Matheus Tavares Bernardino, Jonathan Nieder, Jacob Keller,
	Atharva Raykar, Derrick Stolee, Jonathan Tan

Emily Shaffer <emilyshaffer@google.com> writes:

> A couple things. Firstly, a semantics change *back* to the semantics of
> v3 - we map from gitdir to gitdir, *not* from common dir to common dir,
> so that theoretically a submodule with multiple worktrees in multiple
> superproject worktrees will be able to figure out which worktree of the
> superproject it's in. (Realistically, that's not really possible right
> now, but I'd like to change that soon.)

Sounds sensible.

> Secondly, a rewording of comments and commit messages to indicate that
> this isn't a cache of some expensive operation, but rather intended to
> be the source of truth for all submodules.

I'd expect that there is a way (e.g. "git fsck") that helps the
users notice when the actual filesystem layout contradicts with what
the gitdir-to-gitdir link says, and repair the repositories when
they go out of sync if possible.

It would be similar to "git worktree", where a link between the
".git" file that records "gitdir:" in a secondary worktree and the
repository's $GIT_DIR/worktrees/*/gitdir, and the "repair" command
can be used to bring them back in sync after moving the real
repository without telling the secondary worktree about the move.

> I did discuss Ævar's idea of relying on in-process filesystem digging to
> find the superproject's gitdir with the rest of the Google team, but in
> the end decided that there are some worries about filesystem digging in
> this way (namely, some ugly interactions with network drives that are
> actually already an issue for Googler Linux machines). Plus, the allure
> of being able to definitively know that we're a submodule is pretty
> strong.

The other side of the coin is that, even when a configuration
variable says that you are a submodule of the superproject at
location X, if such a submodule gets moved out of the superproject
(perhaps because the end-user wanted to concentrate on that
submodule project alone as an independent project) and the
superproject that used to be at location X got archived away,
trusting and relying on what the configuration variable says would
not help us access the now-gone superproject.  And that would not
change no matter how strongly we declare that it is the source of
truth.

Unless we have a very good way to detect inconsistency and stop
spreading the damage (e.g. the setting thought our superproject sits
at directory X, but that location is now occupied by a different
repository that is not related), I am still skeptical about the
"setting is the sole truth" design.

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v6 0/5] teach submodules to know they're submodules
  2022-02-03 21:59 ` Emily Shaffer
                     ` (4 preceding siblings ...)
  2022-02-03 22:39   ` [PATCH v6 0/5] teach submodules to know they're submodules Junio C Hamano
@ 2022-02-04  1:15   ` Ævar Arnfjörð Bjarmason
  2022-02-04 16:20     ` Junio C Hamano
  2022-02-07 19:56     ` Jonathan Nieder
  2022-03-01  0:26   ` [PATCH v8 0/3] " Emily Shaffer
  6 siblings, 2 replies; 64+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-04  1:15 UTC (permalink / raw)
  To: Emily Shaffer
  Cc: git, Albert Cui, Phillip Wood, Johannes Schindelin,
	Junio C Hamano, Matheus Tavares Bernardino, Jonathan Nieder,
	Jacob Keller, Atharva Raykar, Derrick Stolee, Jonathan Tan


On Thu, Feb 03 2022, Emily Shaffer wrote:

> Since v6:

Thanks for the re-roll!

> I've dropped the fifth commit to use this new config for `git rev-parse
> --show-superproject-working-tree`. I think it did more harm than good -
> that tool uses an odd way to determine whether the superproject is
> actually the superproject, anyways.
>
> I poked a little bit at trying to find some benchmark to demonstrate
> that "submodule.superprojectGitDir" is actually faster - but I didn't
> end up able to write one without writing a ton of new code to traverse
> the filesystem.

I'm assuming that's tested against some variant of the submodule-in-C[1]
conversion. I.e. at least when I tested it [2][3] it seemed easy to come
up with (probably overly artificial) benchmarks where it would matter
for the shell-out in this series.

The question performance-wise was rather whether we'd just be
introducing the config mechanism as a transitory performance workaround,
and the need for it would evaporate once that C migration happened (re
original CL quoted in [3]).

> To be honest, I'm not all that interested in performance
> - I want the config added for correctness, instead.

And I'm honestly still at the point of not even being against this whole
thing, although it probably sounds like that. I'm really not.

I just genuinely don't get where this is headed. I.e. for the last
iteration I did a demo patch on top that showed that there was no case
added by the series where the on-the-fly discovery wasn't equivalent to
the set-in-config value[4].

That change showed that after this series in a state where the config
*is* redundant to on the fly discovery (or maybe not, and we're just
missing test coverage).

But since you're citing correctness do you have some repo->sub
relationship in mind that would be ambiguous in a way where the
configuration would resolve the ambiguity?

I can imagine how such a thing might work, e.g. if we gave submodules
some git-worktree-like method of being completely detached from the
parent. I.e. being able to place a /usr/me/repo.git whose submodule
entry for a "test" dir lives in /opt/tests or something. So when you "cd
/opt/tests" you wouldn't be able to detect you're within a submodule.

(I'm assuming the case where the submodule has its own "in-tree" .git,
is that even supported anymore...?)

But I can't think of one where such an ambiguity would arise within our
current featureset.

What I really can't see is how if the need for such "config [...] for
correctness" would arise how that doesn't also invalidate the
assumptions you're making in 3/4 and 4/4.

I.e. surely if we need the config for correctness it's also true that we
can't after-the-fact add the config on the fly to (such) existing
submodules without user intervention. Or maybe the ambiguity would only
arise from the POV of the submodule, but not for commands executed
within the parent?

1. https://lore.kernel.org/git/cover-v5-0.9-00000000000-20220128T125206Z-avarab@gmail.com/
2. https://lore.kernel.org/git/RFC-cover-0.2-00000000000-20211117T113134Z-avarab@gmail.com/
3. https://lore.kernel.org/git/211124.86a6hue2wk.gmgdl@evledraar.gmail.com/
4. https://lore.kernel.org/git/RFC-patch-2.2-b49d4c8db7d-20211117T113134Z-avarab@gmail.com/

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v6 0/5] teach submodules to know they're submodules
  2022-02-04  1:15   ` Ævar Arnfjörð Bjarmason
@ 2022-02-04 16:20     ` Junio C Hamano
  2022-02-07 19:56     ` Jonathan Nieder
  1 sibling, 0 replies; 64+ messages in thread
From: Junio C Hamano @ 2022-02-04 16:20 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Emily Shaffer, git, Albert Cui, Phillip Wood, Johannes Schindelin,
	Matheus Tavares Bernardino, Jonathan Nieder, Jacob Keller,
	Atharva Raykar, Derrick Stolee, Jonathan Tan

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> I just genuinely don't get where this is headed. I.e. for the last
> iteration I did a demo patch on top that showed that there was no case
> added by the series where the on-the-fly discovery wasn't equivalent to
> the set-in-config value[4].
>
> That change showed that after this series in a state where the config
> *is* redundant to on the fly discovery (or maybe not, and we're just
> missing test coverage).
>
> But since you're citing correctness do you have some repo->sub
> relationship in mind that would be ambiguous in a way where the
> configuration would resolve the ambiguity?

This is an excellent question, which I wish I could have raised in
my earlier response.  A clear explanation why this setting is not
a redundant copy but adds real information on top of what we should
be able to learn from the filesystem structure would really help in
justifying the new thing.

Thanks.

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v6 0/5] teach submodules to know they're submodules
  2022-02-04  1:15   ` Ævar Arnfjörð Bjarmason
  2022-02-04 16:20     ` Junio C Hamano
@ 2022-02-07 19:56     ` Jonathan Nieder
  2022-02-07 23:21       ` Junio C Hamano
  2022-02-12 20:35       ` Ævar Arnfjörð Bjarmason
  1 sibling, 2 replies; 64+ messages in thread
From: Jonathan Nieder @ 2022-02-07 19:56 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Emily Shaffer, git, Albert Cui, Phillip Wood, Johannes Schindelin,
	Junio C Hamano, Matheus Tavares Bernardino, Jacob Keller,
	Atharva Raykar, Derrick Stolee, Jonathan Tan

Hi,

Ævar Arnfjörð Bjarmason wrote:
> On Thu, Feb 03 2022, Emily Shaffer wrote:

>> To be honest, I'm not all that interested in performance
>> - I want the config added for correctness, instead.
>
> And I'm honestly still at the point of not even being against this whole
> thing, although it probably sounds like that. I'm really not.
>
> I just genuinely don't get where this is headed. I.e. for the last
> iteration I did a demo patch on top that showed that there was no case
> added by the series where the on-the-fly discovery wasn't equivalent to
> the set-in-config value[4].

Here's a few examples:

1. Suppose I track my $HOME directory as a git repository.  Within my
   home directory, I have a src/git/ subdirectory with a clone of
   git.git, but I never intended to treat this as a submodule.

   If I run "git rev-parse --show-superproject-working-tree", then it
   will discover my home directory repository, run ls-files in there
   to see if it has GITLINK entries, and either see one for src/git if
   I had "git add"ed it by mistake or not see one.  In either case,
   it would it would view my src/git/ directory as being a submodule
   of my home directory even though I hadn't intended it to be so.

2. Suppose I have a copy of a repository such as
   https://gerrit.googlesource.com/gerrit/, with all its submodules.
   I am in the plugins/replication/ directory.

   If I run "git rev-parse --show-superproject-working-tree", then it
   will discover my gerrit repository, run ls-files in there to see if
   it has GITLINK entries, and use the result to decide whether the
   cwd is a submodule.  So for example, if I had run "git rm --cached
   plugins/replication" to _prepare to_ remove the plugins/replication
   submodule, then "git rev-parse --show-superproject-working-tree"
   will produce the wrong result.

3. Suppose I am not using submodules at all.  I have a clone of
   mawk.git and I am working there.

   If I run "git rev-parse --show-superproject-working-tree", then I'm
   presumably interested in doing something submodule-specific;
   nothing wrong with that.  But the series we're responding to is
   meant to support a wider variety of operations --- for example,
   suppose I am running a plain "git status" operation.

   If "git status" runs "git rev-parse
   --show-superproject-working-tree", then git would walk up the
   filesystem above my mawk/ directory, looking for another .git dir.
   We can reach an NFS automounter directory and just hang.  Even
   without an NFS automounter, we'd expect this to take a while
   because, unlike normal repository discovery, we have no reason to
   believe that the walk is going to quickly discover a .git directory
   and terminate.  So this would violate user expectations.

Thanks and hope that helps,
Jonathan

> 4. https://lore.kernel.org/git/RFC-patch-2.2-b49d4c8db7d-20211117T113134Z-avarab@gmail.com/

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v6 0/5] teach submodules to know they're submodules
  2022-02-07 19:56     ` Jonathan Nieder
@ 2022-02-07 23:21       ` Junio C Hamano
  2022-02-08  1:18         ` Jonathan Nieder
  2022-02-12 20:35       ` Ævar Arnfjörð Bjarmason
  1 sibling, 1 reply; 64+ messages in thread
From: Junio C Hamano @ 2022-02-07 23:21 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: Ævar Arnfjörð Bjarmason, Emily Shaffer, git,
	Albert Cui, Phillip Wood, Johannes Schindelin,
	Matheus Tavares Bernardino, Jacob Keller, Atharva Raykar,
	Derrick Stolee, Jonathan Tan

Jonathan Nieder <jrnieder@gmail.com> writes:

> Here's a few examples:
>
> 1. Suppose I track my $HOME directory as a git repository.  Within my
>    home directory, I have a src/git/ subdirectory with a clone of
>    git.git, but I never intended to treat this as a submodule.
>
>    If I run "git rev-parse --show-superproject-working-tree", then it
>    will discover my home directory repository, run ls-files in there
>    to see if it has GITLINK entries, and either see one for src/git if
>    I had "git add"ed it by mistake or not see one.  In either case,
>    it would it would view my src/git/ directory as being a submodule
>    of my home directory even though I hadn't intended it to be so.

I am not sure about this one.  If you added an unrelated one with
"git add" by mistake, you'd want to know about the mistake sooner
rather than later, no?

> 2. Suppose I have a copy of a repository such as
>    https://gerrit.googlesource.com/gerrit/, with all its submodules.
>    I am in the plugins/replication/ directory.
>
>    If I run "git rev-parse --show-superproject-working-tree", then it
>    will discover my gerrit repository, run ls-files in there to see if
>    it has GITLINK entries, and use the result to decide whether the
>    cwd is a submodule.  So for example, if I had run "git rm --cached
>    plugins/replication" to _prepare to_ remove the plugins/replication
>    submodule, then "git rev-parse --show-superproject-working-tree"
>    will produce the wrong result.

Yes, looking only at the index of the superproject will have that
problem, but don't other things in the superproject point at the
submodule, too, e.g. submodule.<name>.* configuration variables?

And then, after removing them to truly dissociate the submodule from
the superproject, "git rev-parse --show-superproject-working-tree"
may stop saying that it is a submodule, but this series wants to
make it irrelevant what the command says.  Until you unset the
configuration variable in the submodule, it will stay to be a
submodule of the superproject, but the superproject no longer thinks
it is responsible for the submodule.  You'll have to deal with an
inconsistent state during the transition either way, so I am not
sure it is the best solution to introduce an extra setting that can
easily go out of sync.

> 3. Suppose I am not using submodules at all.  I have a clone of
>    mawk.git and I am working there.
>
>    If I run "git rev-parse --show-superproject-working-tree", then I'm
>    presumably interested in doing something submodule-specific;
>    nothing wrong with that.  But the series we're responding to is
>    meant to support a wider variety of operations --- for example,
>    suppose I am running a plain "git status" operation.
>
>    If "git status" runs "git rev-parse
>    --show-superproject-working-tree", then git would walk up the
>    filesystem above my mawk/ directory, looking for another .git dir.
>    We can reach an NFS automounter directory and just hang.  Even
>    without an NFS automounter, we'd expect this to take a while
>    because, unlike normal repository discovery, we have no reason to
>    believe that the walk is going to quickly discover a .git directory
>    and terminate.  So this would violate user expectations.

It would be a problem, but I do not know if "this is a submodule of
that superproject" link is the only solution, let alone the most
effective one.  It seems to me that you are looking more for
something like GIT_CEILING_DIRECTORIES.

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v6 0/5] teach submodules to know they're submodules
  2022-02-07 23:21       ` Junio C Hamano
@ 2022-02-08  1:18         ` Jonathan Nieder
  2022-02-08 18:24           ` Junio C Hamano
  0 siblings, 1 reply; 64+ messages in thread
From: Jonathan Nieder @ 2022-02-08  1:18 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Ævar Arnfjörð Bjarmason, Emily Shaffer, git,
	Albert Cui, Phillip Wood, Johannes Schindelin,
	Matheus Tavares Bernardino, Jacob Keller, Atharva Raykar,
	Derrick Stolee, Jonathan Tan

Junio C Hamano wrote:
> Jonathan Nieder <jrnieder@gmail.com> writes:

>> Here's a few examples:
>>
>> 1. Suppose I track my $HOME directory as a git repository.  Within my
>>    home directory, I have a src/git/ subdirectory with a clone of
>>    git.git, but I never intended to treat this as a submodule.
>>
>>    If I run "git rev-parse --show-superproject-working-tree", then it
>>    will discover my home directory repository, run ls-files in there
>>    to see if it has GITLINK entries, and either see one for src/git if
>>    I had "git add"ed it by mistake or not see one.  In either case,
>>    it would it would view my src/git/ directory as being a submodule
>>    of my home directory even though I hadn't intended it to be so.
>
> I am not sure about this one.  If you added an unrelated one with
> "git add" by mistake, you'd want to know about the mistake sooner
> rather than later, no?

My point with this example is that it's useful to have a definition of
what is a submodule repository, to make it unambiguous whether this
repository is a submodule or whether it's just a repository that
happens to have been cloned inside of a git-managed worktree.

For the specific example of having run "git add", I don't have any
very strong opinions.

[...]
>> 2. Suppose I have a copy of a repository such as
>>    https://gerrit.googlesource.com/gerrit/, with all its submodules.
>>    I am in the plugins/replication/ directory.
[...]
>>                         So for example, if I had run "git rm --cached
>>    plugins/replication" to _prepare to_ remove the plugins/replication
>>    submodule, then "git rev-parse --show-superproject-working-tree"
>>    will produce the wrong result.
>
> Yes, looking only at the index of the superproject will have that
> problem, but don't other things in the superproject point at the
> submodule, too, e.g. submodule.<name>.* configuration variables?

What all of those suggested alternatives have in common is that they
are pointers from another repository to the submodule.

This would be the first time in git history that we are saying a
property of a repository depends on having to examine files outside of
it.  I guess the main question I'd have is, why _wouldn't_ I want a
submodule to be able to point to the superproject containing it?  I
can think of many advantages to having that linkage, and the main
disadvantage I can think of is that it is a change.

I don't think that submodule.<name>.* is an adequate substitute for
having this setting, because it requires
- finding the superproject
- mapping the <name> to a path, using .gitmodules
- comparing the path to the submodule location

which would be complex, slow, and error-prone.

The one thing that I think could approach being an adequate substitute
is examining the path to the current repository and stripping off path
components until we find modules/; then the parent is the containing
superproject.  That would only work for absorbed submodules, though,
and it would be less explicit than having a config item.

> And then, after removing them to truly dissociate the submodule from
> the superproject, "git rev-parse --show-superproject-working-tree"
> may stop saying that it is a submodule, but this series wants to
> make it irrelevant what the command says.  Until you unset the
> configuration variable in the submodule, it will stay to be a
> submodule of the superproject, but the superproject no longer thinks
> it is responsible for the submodule.  You'll have to deal with an
> inconsistent state during the transition either way, so I am not
> sure it is the best solution to introduce an extra setting that can
> easily go out of sync.

This hints at a reason why one wouldn't want the linkage back ---
dealing with the ambiguity of inconsistencies (what if a submodule
declares a superproject but the superproject does not declare the
submodule?).

I would not expect that ambiguity to be much of a problem,
because the typical way to use superproject linkage would be to
print output from commands like "git status": for example,

	This is a submodule of ../../gerrit; you can run

		git -C ../../gerrit status

	to get the status of the superproject.

An inconsistency could occur due to the user using "mv" (instead of
"git mv") to move a submodule to a path a different number of path
components from its superproject.  One way to handle that would be to
make submodules record a boolean setting reflecting whether they are a
submodule, instead of the path to the superproject.  (This would be
similar to settings like core.bare.)  Alternatively, if the path to
the superproject is recorded and if "git fsck" is able to notice such
an inconsistency, then the user should be able to have an okay
experience repairing it.

[...]
>>    If "git status" runs "git rev-parse
>>    --show-superproject-working-tree", then git would walk up the
>>    filesystem above my mawk/ directory, looking for another .git dir.
>>    We can reach an NFS automounter directory and just hang.  Even
>>    without an NFS automounter, we'd expect this to take a while
>>    because, unlike normal repository discovery, we have no reason to
>>    believe that the walk is going to quickly discover a .git directory
>>    and terminate.  So this would violate user expectations.
>
> It would be a problem, but I do not know if "this is a submodule of
> that superproject" link is the only solution, let alone the most
> effective one.  It seems to me that you are looking more for
> something like GIT_CEILING_DIRECTORIES.

Who is the "you" addressed here?  The end user can use
GIT_CEILING_DIRECTORIES if they are expecting to run git commands
within an NFS automounter directory and outside of any git repository,
but they'd be right to be surprised if that suddenly became required
when inside git repositories.  I don't think we should assume that
running an extra .git discovery walk is cost-free to users who are not
using submodules and an acceptable burden to impose on them for the
sake of submodule users.

Thanks and hope that helps,
Jonathan

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v6 0/5] teach submodules to know they're submodules
  2022-02-08  1:18         ` Jonathan Nieder
@ 2022-02-08 18:24           ` Junio C Hamano
  2022-02-10 22:12             ` Emily Shaffer
  0 siblings, 1 reply; 64+ messages in thread
From: Junio C Hamano @ 2022-02-08 18:24 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: Ævar Arnfjörð Bjarmason, Emily Shaffer, git,
	Albert Cui, Phillip Wood, Johannes Schindelin,
	Matheus Tavares Bernardino, Jacob Keller, Atharva Raykar,
	Derrick Stolee, Jonathan Tan

Jonathan Nieder <jrnieder@gmail.com> writes:

> My point with this example is that it's useful to have a definition of
> what is a submodule repository, to make it unambiguous whether this
> repository is a submodule or whether it's just a repository that
> happens to have been cloned inside of a git-managed worktree.

OK, together with the other "no need to let NFS automounter worry
about parent directories", it makes a very successful argument for a
single bit (i.e. this is a free-standing repository and is not a
submodule, so no need to auto-discover if it is one).  I think the
"Alternatively" you later mention to solve ambiguity with just a
single bit, without "this is a submodule of that superproject"
linkage, is essentially the same?

But I do not think it argues for the need to say "a config, not
filesystem layout, must be the single source of truth to say which
superproject this repository belongs as its submodule".

> This would be the first time in git history that we are saying a
> property of a repository depends on having to examine files outside of
> it.

Well, path-based configuration inclusion, with configuration driven
hooks, I do not think the distinction matters much anymore in these
days.

> I guess the main question I'd have is, why _wouldn't_ I want a
> submodule to be able to point to the superproject containing it?

Because with (the absense of) a single "this is freestanding" bit, 
by default the filesystem layout can already "point" at it?

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v6 0/5] teach submodules to know they're submodules
  2022-02-08 18:24           ` Junio C Hamano
@ 2022-02-10 22:12             ` Emily Shaffer
  2022-02-10 22:53               ` Jonathan Nieder
  0 siblings, 1 reply; 64+ messages in thread
From: Emily Shaffer @ 2022-02-10 22:12 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Jonathan Nieder, Ævar Arnfjörð Bjarmason, git,
	Albert Cui, Phillip Wood, Johannes Schindelin,
	Matheus Tavares Bernardino, Jacob Keller, Atharva Raykar,
	Derrick Stolee, Jonathan Tan

On Tue, Feb 08, 2022 at 10:24:49AM -0800, Junio C Hamano wrote:
> 
> Jonathan Nieder <jrnieder@gmail.com> writes:
> 
> > My point with this example is that it's useful to have a definition of
> > what is a submodule repository, to make it unambiguous whether this
> > repository is a submodule or whether it's just a repository that
> > happens to have been cloned inside of a git-managed worktree.
> 
> OK, together with the other "no need to let NFS automounter worry
> about parent directories", it makes a very successful argument for a
> single bit (i.e. this is a free-standing repository and is not a
> submodule, so no need to auto-discover if it is one).  I think the
> "Alternatively" you later mention to solve ambiguity with just a
> single bit, without "this is a submodule of that superproject"
> linkage, is essentially the same?

That resolution - "teach submodules to know they're submodules, but not
whose submodule they are" - would still count as a success to me. The
reason I proposed a path instead of a boolean here was simply because
storing a path is a boolean (by whether it's present or not) *and*
additional information (the path to the superproject), and it seemed
silly to me to opt for less information. Or, to put it another way - "am
I a submodule?" seems pretty vital, and "yes, and I belong to xyz" is an
optimization on top of that. So I don't terribly mind sending this as
just a boolean, if we feel that the effort to keep it up outweighs the
benefit of saving us a filesystem walk.

I'm not completely convinced that it does, though - would the addition
of a 'git fsck' check for this config be satisfactory? In other words,
is the problem that the execution of this series wasn't thorough enough
and it should be refined, or that the concept itself is beyond saving?

 - Emily

> 
> But I do not think it argues for the need to say "a config, not
> filesystem layout, must be the single source of truth to say which
> superproject this repository belongs as its submodule".
> 
> > This would be the first time in git history that we are saying a
> > property of a repository depends on having to examine files outside of
> > it.
> 
> Well, path-based configuration inclusion, with configuration driven
> hooks, I do not think the distinction matters much anymore in these
> days.
> 
> > I guess the main question I'd have is, why _wouldn't_ I want a
> > submodule to be able to point to the superproject containing it?
> 
> Because with (the absense of) a single "this is freestanding" bit, 
> by default the filesystem layout can already "point" at it?

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v6 0/5] teach submodules to know they're submodules
  2022-02-10 22:12             ` Emily Shaffer
@ 2022-02-10 22:53               ` Jonathan Nieder
  0 siblings, 0 replies; 64+ messages in thread
From: Jonathan Nieder @ 2022-02-10 22:53 UTC (permalink / raw)
  To: Emily Shaffer
  Cc: Junio C Hamano, Ævar Arnfjörð Bjarmason, git,
	Albert Cui, Phillip Wood, Johannes Schindelin,
	Matheus Tavares Bernardino, Jacob Keller, Atharva Raykar,
	Derrick Stolee, Jonathan Tan

Emily Shaffer wrote:
> On Tue, Feb 08, 2022 at 10:24:49AM -0800, Junio C Hamano wrote:
>> Jonathan Nieder <jrnieder@gmail.com> writes:

>>> My point with this example is that it's useful to have a definition of
>>> what is a submodule repository, to make it unambiguous whether this
>>> repository is a submodule or whether it's just a repository that
>>> happens to have been cloned inside of a git-managed worktree.
>>
>> OK, together with the other "no need to let NFS automounter worry
>> about parent directories", it makes a very successful argument for a
>> single bit (i.e. this is a free-standing repository and is not a
>> submodule, so no need to auto-discover if it is one).  I think the
>> "Alternatively" you later mention to solve ambiguity with just a
>> single bit, without "this is a submodule of that superproject"
>> linkage, is essentially the same?
>
> That resolution - "teach submodules to know they're submodules, but not
> whose submodule they are" - would still count as a success to me.

Thanks, both.  Sounds like a good path forward.

[...]
>                              So I don't terribly mind sending this as
> just a boolean, if we feel that the effort to keep it up outweighs the
> benefit of saving us a filesystem walk.
>
> I'm not completely convinced that it does, though

Personally, I'm convinced --- e.g., life gets painful enough when
core.worktree ends up pointing to the wrong path, so being able to
avoid that complexity seems like a nice outcome.

>                                                  - would the addition
> of a 'git fsck' check for this config be satisfactory? In other words,
> is the problem that the execution of this series wasn't thorough enough
> and it should be refined, or that the concept itself is beyond saving?

For the absorbed case, the path to the superproject should be pretty
stable, and in that case it's probably possible to make this robust
enough.  (That said, the path to the superproject gitdir would
typically just be "../..", at least as long as we have the other patch
to escape slashes in the submodule name.)  In the non-absorbed case,
it seems likely to get messy fast because a user can "mv" the
submodule around.

Another kind of case that gets interesting is when there are multiple
superproject worktrees and multiple submodule worktrees.  Does the
relative path become a per-worktree variable?  Using a boolean saves
us from having to think through it.

Thanks for the clear explanations,
Jonathan

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v6 0/5] teach submodules to know they're submodules
  2022-02-07 19:56     ` Jonathan Nieder
  2022-02-07 23:21       ` Junio C Hamano
@ 2022-02-12 20:35       ` Ævar Arnfjörð Bjarmason
  2022-02-13  6:25         ` Junio C Hamano
  1 sibling, 1 reply; 64+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-02-12 20:35 UTC (permalink / raw)
  To: Jonathan Nieder
  Cc: Emily Shaffer, git, Albert Cui, Phillip Wood, Johannes Schindelin,
	Junio C Hamano, Matheus Tavares Bernardino, Jacob Keller,
	Atharva Raykar, Derrick Stolee, Jonathan Tan


On Mon, Feb 07 2022, Jonathan Nieder wrote:

> Hi,
>
> Ævar Arnfjörð Bjarmason wrote:
>> On Thu, Feb 03 2022, Emily Shaffer wrote:
>
>>> To be honest, I'm not all that interested in performance
>>> - I want the config added for correctness, instead.
>>
>> And I'm honestly still at the point of not even being against this whole
>> thing, although it probably sounds like that. I'm really not.
>>
>> I just genuinely don't get where this is headed. I.e. for the last
>> iteration I did a demo patch on top that showed that there was no case
>> added by the series where the on-the-fly discovery wasn't equivalent to
>> the set-in-config value[4].
>
> Here's a few examples:

I've read the downthread, but it's probably best to reply to this...

> 1. Suppose I track my $HOME directory as a git repository.  Within my
>    home directory, I have a src/git/ subdirectory with a clone of
>    git.git, but I never intended to treat this as a submodule.
>
>    If I run "git rev-parse --show-superproject-working-tree", then it
>    will discover my home directory repository, run ls-files in there
>    to see if it has GITLINK entries, and either see one for src/git if
>    I had "git add"ed it by mistake or not see one.  In either case,
>    it would it would view my src/git/ directory as being a submodule
>    of my home directory even though I hadn't intended it to be so.
>
> 2. Suppose I have a copy of a repository such as
>    https://gerrit.googlesource.com/gerrit/, with all its submodules.
>    I am in the plugins/replication/ directory.
>
>    If I run "git rev-parse --show-superproject-working-tree", then it
>    will discover my gerrit repository, run ls-files in there to see if
>    it has GITLINK entries, and use the result to decide whether the
>    cwd is a submodule.  So for example, if I had run "git rm --cached
>    plugins/replication" to _prepare to_ remove the plugins/replication
>    submodule, then "git rev-parse --show-superproject-working-tree"
>    will produce the wrong result.

These both seem like valid edge cases, but they're still going to be the
same edge case on the "parent" side even with a proposed cache (whether
it's a boolean or a path).

I.e. the question here is really not one of caching, but of what it
means for Y to be a submodule of X.

I assumed that we'd prefer a 1=1 relationship between the parent
reporting that Y is a submodule of it, and Y reporting that it is a
submodule (of the parent at some <path>).

If that's the case we can walk up and ask parent .git's whether they
think the <path> is their submodule.

If it's not the case perhaps a config is needed, but then that surely
has wider implications. I.e. won't it be the case that we can't add the
config after-the-fact as this series proposes in those some ambiguous
cases?xo

> 3. Suppose I am not using submodules at all.  I have a clone of
>    mawk.git and I am working there.
>
>    If I run "git rev-parse --show-superproject-working-tree", then I'm
>    presumably interested in doing something submodule-specific;
>    nothing wrong with that.  But the series we're responding to is
>    meant to support a wider variety of operations --- for example,
>    suppose I am running a plain "git status" operation.
>
>    If "git status" runs "git rev-parse
>    --show-superproject-working-tree", then git would walk up the
>    filesystem above my mawk/ directory, looking for another .git dir.
>    We can reach an NFS automounter directory and just hang.  Even
>    without an NFS automounter, we'd expect this to take a while
>    because, unlike normal repository discovery, we have no reason to
>    believe that the walk is going to quickly discover a .git directory
>    and terminate.  So this would violate user expectations.

We have a /a/b/c/d.git mounted, but not a parent /a/b/, and walking
upwards causes it to be mounted?

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v6 0/5] teach submodules to know they're submodules
  2022-02-12 20:35       ` Ævar Arnfjörð Bjarmason
@ 2022-02-13  6:25         ` Junio C Hamano
  0 siblings, 0 replies; 64+ messages in thread
From: Junio C Hamano @ 2022-02-13  6:25 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Jonathan Nieder, Emily Shaffer, git, Albert Cui, Phillip Wood,
	Johannes Schindelin, Matheus Tavares Bernardino, Jacob Keller,
	Atharva Raykar, Derrick Stolee, Jonathan Tan

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> We have a /a/b/c/d.git mounted, but not a parent /a/b/, and walking
> upwards causes it to be mounted?

;-)

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v8 0/3] teach submodules to know they're submodules
  2022-02-03 21:59 ` Emily Shaffer
                     ` (5 preceding siblings ...)
  2022-02-04  1:15   ` Ævar Arnfjörð Bjarmason
@ 2022-03-01  0:26   ` Emily Shaffer
  2022-03-01  0:26     ` [PATCH v8 1/3] t7400-submodule-basic: modernize inspect() helper Emily Shaffer
                       ` (4 more replies)
  6 siblings, 5 replies; 64+ messages in thread
From: Emily Shaffer @ 2022-03-01  0:26 UTC (permalink / raw)
  To: git
  Cc: Emily Shaffer, Albert Cui, Phillip Wood, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason, Junio C Hamano,
	Matheus Tavares Bernardino, Jonathan Nieder, Jacob Keller,
	Atharva Raykar, Derrick Stolee, Jonathan Tan

For the original cover letter, see
https://lore.kernel.org/git/20210611225428.1208973-1-emilyshaffer%40google.com.

CI run: https://github.com/nasamuffin/git/actions/runs/1866957146

Since v7:

Actually a fairly large rework. Rather than keeping the path from gitdir
to gitdir, just keep a boolean under 'submodule.hasSuperproject'. The
idea is that from this boolean, we can decide whether to traverse the
filesystem looking for a superproject.

Because this simplifies the implementation, I compressed the three
middle commits into one. As proof-of-concept, I added a patch at the end
to check for this boolean when running `git rev-parse
--show-superproject-working-tree`.

One thing I'm not sure about: in the tests, I check whether the config
is set, but not what the boolean value of it is. Is there a better way
to do that? For example, I could imagine someone deciding to set
`submodule.hasSuperproject = false` and the tests would not function
correctly in that case. I think we don't really normalize the value on a
boolean config like that, so I didn't want to write a lot of comparison
to check if the value is 1 or true or True or TRUE or Yes or .... Am I
overthinking it?

The other thing I'm not sure about: since it's just a bool, we're not
restricted to setting this config only when we have both gitdir paths
available. That makes me want to set the config any time we are doing
something with submodules anyway, like any time 'git-submodule--helper'
is used. But that helper seems to be called in the context of the
superproject, not of the submodules, so adding this config for each
submodule we touch would be a second child process. Is there some other
common entry point for submodules that we can use?

 - Emily

Since v6:

I've dropped the fifth commit to use this new config for `git rev-parse
--show-superproject-working-tree`. I think it did more harm than good -
that tool uses an odd way to determine whether the superproject is
actually the superproject, anyways.

I poked a little bit at trying to find some benchmark to demonstrate
that "submodule.superprojectGitDir" is actually faster - but I didn't
end up able to write one without writing a ton of new code to traverse
the filesystem. To be honest, I'm not all that interested in performance
- I want the config added for correctness, instead.

So, the only real changes between v6 and v7 are some documentation
changes suggested by Jonathan Tan
(https://lore.kernel.org/git/20211117234300.2598132-1-jonathantanmy%40google.com).

Since v5:

A couple things. Firstly, a semantics change *back* to the semantics of
v3 - we map from gitdir to gitdir, *not* from common dir to common dir,
so that theoretically a submodule with multiple worktrees in multiple
superproject worktrees will be able to figure out which worktree of the
superproject it's in. (Realistically, that's not really possible right
now, but I'd like to change that soon.)

Secondly, a rewording of comments and commit messages to indicate that
this isn't a cache of some expensive operation, but rather intended to
be the source of truth for all submodules. I also added a fifth commit
rewriting `git rev-parse --show-superproject-working-tree` to
demonstrate what that means in practice - but from a practical
standpoint, I'm a little worried about that fifth patch. More details in
the patch 5 description.

I did discuss Ævar's idea of relying on in-process filesystem digging to
find the superproject's gitdir with the rest of the Google team, but in
the end decided that there are some worries about filesystem digging in
this way (namely, some ugly interactions with network drives that are
actually already an issue for Googler Linux machines). Plus, the allure
of being able to definitively know that we're a submodule is pretty
strong. ;) But overall, this is the direction I'd prefer to keep going
in, rather than trying to guess from the filesystem going forward.

Since v4:

The only real change here is a slight semantics change to map from
<submodule gitdir> to <superproject common git dir>. In every case
*except* for when the superproject has a worktree, this changes nothing.
For the case when the superproject has a worktree, this means that now
submodules will refer to the general superproject common dir (e.g. no
worktree-specific refs or configs or whatnot).

I *think* that because a submodule should exist in the context of the
common dir, not the worktree gitdir, that is ok. However, it does mean
it would be difficult to do something like sharing a config specific to
the worktree (the initial goal of this series).

$ROOT/.git
$ROOT/.git/config.superproject <- shared by $ROOT/.git/modules/sub
$ROOT/.git/modules/sub <- points to $ROOT/.git
$ROOT/.git/worktrees/wt
$ROOT/.git/worktrees/wt/config.superproject <- contains a certain config-based pre-commit hook

If the submodule only knows about the common dir, that is tough, because
the submodule would basically have to guess which worktree it's in from
its own path. There would be no way for '$WT/sub' to inherit
'$ROOT/.git/worktrees/wt/config.superproject'.

That said... right now, we don't support submodules in worktrees very
well at all. A submodule in a worktree will get a brand new gitdir in
$ROOT/.git/worktrees/modules/ (and that brand new gitdir would point to
the super's common dir). So I think we can punt on this entire question
until we teach submodules and worktrees to play more gracefully together
(it's on my long list...), and at that time we can probably introduce a
pointer from $ROOT/.git/modules/sub/worktrees/wt/ to
$ROOT/.git/worktrees/wt/....

Or, to summarize the long ramble above: "this is still kind of weird
with worktrees, but let's fix it later when we fix worktrees more
thoroughly".

(More rambling about worktree weirdness here:
https://lore.kernel.org/git/YYRaII8YWVxlBqsF%40google.com )


Since v3, a pretty major change: the semantics of
submodule.superprojectGitDir has changed, to point from the submodule's
gitdir to the superproject's gitdir (in v3 and earlier, we kept a path
from the submodule's *worktree* to the superproject's gitdir instead).
This cleans up some of the confusions about the behavior when a
submodule worktree moves around in the superproject's tree, or in a
future when we support submodules having multiple worktrees.

I also tried to simplify the tests to use 'test-tool path-utils
relative_path' everywhere - I think that makes them much more clear for
a test reader, but if you're reviewing and it isn't obvious what we're
testing for, please speak up.

I think this is pretty mature and there was a lot of general agreement
that the gitdir->gitdir association was the way to go, so please be
brutal and look for nits, leaks, etc. this round ;)
[/v4 cover letter]

Emily Shaffer (3):
  t7400-submodule-basic: modernize inspect() helper
  introduce submodule.hasSuperproject record
  rev-parse: short-circuit superproject worktree when config unset

 Documentation/config/submodule.txt |  6 ++++
 builtin/submodule--helper.c        |  5 +++
 git-submodule.sh                   |  3 ++
 submodule.c                        | 30 ++++++++++++++++++
 t/t7400-submodule-basic.sh         | 42 ++++++++++++-------------
 t/t7406-submodule-update.sh        |  8 +++++
 t/t7412-submodule-absorbgitdirs.sh | 50 ++++++++++++++++++++++++++++--
 7 files changed, 119 insertions(+), 25 deletions(-)

Range-diff against v7:
1:  1a85deb1c5 < -:  ---------- introduce submodule.superprojectGitDir record
-:  ---------- > 1:  251510c687 t7400-submodule-basic: modernize inspect() helper
2:  7a44b0edf9 ! 2:  34cbfd81ee submodule: record superproject gitdir during absorbgitdirs
    @@ Metadata
     Author: Emily Shaffer <emilyshaffer@google.com>
     
      ## Commit message ##
    -    submodule: record superproject gitdir during absorbgitdirs
    +    introduce submodule.hasSuperproject record
     
    -    Already during 'git submodule add' we record 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 absorbgitdirs'. Let's start adding that pointer during 'git
    -    submodule absorbgitdirs' too.
    +    Teach submodules a config variable indicating the fact that they are a
    +    submodule. If this config is set to false or unset, Git may assume the
    +    current repo is not a submodule.
    +
    +    Git commands can use this variable to decide whether to traverse the
    +    filesystem and look for a superproject at all. 'git rev-parse
    +    --show-superproject-working-tree' can learn to exit early if this config
    +    is unset or false. Other newly added or implicit behavior - like "git
    +    status" showing the submodule's status in relation to the superproject,
    +    or a config shared between the superproject and submodule - can use this
    +    config to decide whether to search the parent directory to find a
    +    superproject.
    +
    +    Introduce this config everywhere we add a new submodule, or touch one
    +    that already exists, so that we can proliferate it in repos which are
    +    already out in the world using submodules.
     
         Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
    +    Helped-by: Junio C Hamano <gitster@pobox.com>
     
      ## Documentation/config/submodule.txt ##
    -@@ Documentation/config/submodule.txt: submodule.superprojectGitDir::
    - 	reference to determine whether the current repo is a submodule to
    - 	another repo; if this reference is absent, Git will treat the current
    - 	repo as though it is not a submodule (this does not make a difference to
    --	most Git commands). It is set automatically during submodule creation.
    -+	most Git commands). It is set automatically during submodule creation
    -+	and 'git submodule absorbgitdir'.
    +@@ Documentation/config/submodule.txt: 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.hasSuperproject::
    ++	Indicates whether this repository is a submodule. If this config is set
    ++	to 'true', Git may traverse the filesystem above this submodule in order
    ++	to identify the superproject. It is set automatically during submodule
    ++	creation, update, and 'git submodule absorbgitdir'.
    +
    + ## builtin/submodule--helper.c ##
    +@@ builtin/submodule--helper.c: static int clone_submodule(struct module_clone_data *clone_data)
    + 		git_config_set_in_file(p, "submodule.alternateErrorStrategy",
    + 				       error_strategy);
    + 
    ++	/*
    ++	 * Teach the submodule that it's a submodule.
    ++	 */
    ++	git_config_set_in_file(p, "submodule.hasSuperproject", "true");
    ++
    + 	free(sm_alternate);
    + 	free(error_strategy);
    + 
    +
    + ## git-submodule.sh ##
    +@@ git-submodule.sh: cmd_update()
    + 			;;
    + 		esac
    + 
    ++		# Note that the submodule is a submodule.
    ++		git -C "$sm_path" config submodule.hasSuperproject "true"
    ++
    + 		if test -n "$recursive"
    + 		then
    + 			(
     
      ## submodule.c ##
     @@ submodule.c: static void relocate_single_git_dir_into_superproject(const char *path)
    @@ submodule.c: static void relocate_single_git_dir_into_superproject(const char *p
      	const struct submodule *sub;
     +	struct config_set sub_cs;
     +	struct strbuf config_path = STRBUF_INIT, sb = STRBUF_INIT;
    -+	int tmp;
      
      	if (submodule_uses_worktrees(path))
      		die(_("relocate_gitdir for submodule '%s' with "
    @@ submodule.c: static void relocate_single_git_dir_into_superproject(const char *p
     +	strbuf_addf(&config_path, "%s/config", real_new_git_dir);
     +	git_configset_init(&sub_cs);
     +	git_configset_add_file(&sub_cs, config_path.buf);
    -+	/* return 0 indicates config was found - we have a worktree config */
    -+	if (!git_configset_get_bool(&sub_cs, "extensions.worktreeConfig", &tmp))
    -+		strbuf_addstr(&config_path, ".worktree");
     +
    -+	git_config_set_in_file(config_path.buf, "submodule.superprojectGitdir",
    -+			       relative_path(absolute_path(get_git_dir()),
    -+					     real_new_git_dir, &sb));
    ++	git_config_set_in_file(config_path.buf, "submodule.hasSuperproject",
    ++			       "true");
     +
     +	git_configset_clear(&sub_cs);
     +	strbuf_release(&config_path);
    @@ submodule.c: static void relocate_single_git_dir_into_superproject(const char *p
      	free(real_old_git_dir);
      	free(real_new_git_dir);
     
    + ## t/t7400-submodule-basic.sh ##
    +@@ t/t7400-submodule-basic.sh: inspect() {
    + 	git -C "$sub_dir" rev-parse HEAD >head-sha1 &&
    + 	git -C "$sub_dir" update-index --refresh &&
    + 	git -C "$sub_dir" diff-files --exit-code &&
    ++
    ++	# Ensure that submodule.hasSuperproject is set.
    ++	git -C "$sub_dir" config "submodule.hasSuperproject"
    ++
    + 	git -C "$sub_dir" clean -n -d -x >untracked
    + }
    + 
    +
    + ## t/t7406-submodule-update.sh ##
    +@@ t/t7406-submodule-update.sh: test_expect_success 'submodule update --quiet passes quietness to fetch with a s
    + 	)
    + '
    + 
    ++test_expect_success 'submodule update adds submodule.hasSuperproject to older repos' '
    ++	(cd super &&
    ++	 git -C submodule config --unset submodule.hasSuperproject &&
    ++	 git submodule update &&
    ++	 git -C submodule config submodule.hasSuperproject
    ++	)
    ++'
    ++
    + test_done
    +
      ## t/t7412-submodule-absorbgitdirs.sh ##
     @@ t/t7412-submodule-absorbgitdirs.sh: test_expect_success 'absorb the git dir' '
      	git status >actual.1 &&
    @@ t/t7412-submodule-absorbgitdirs.sh: test_expect_success 'absorb the git dir' '
     -	test_cmp expect.2 actual.2
     +	test_cmp expect.2 actual.2 &&
     +
    -+	# make sure the submodule cached the superproject gitdir correctly
    -+	submodule_gitdir="$(git -C sub1 rev-parse --path-format=absolute --git-common-dir)" &&
    -+	superproject_gitdir="$(git rev-parse --path-format=absolute --git-common-dir)" &&
    -+
    -+	test-tool path-utils relative_path "$superproject_gitdir" \
    -+		"$submodule_gitdir" >expect &&
    -+	git -C sub1 config submodule.superprojectGitDir >actual &&
    -+
    -+	test_cmp expect actual
    ++	git -C sub1 config submodule.hasSuperproject
      '
      
      test_expect_success 'absorbing does not fail for deinitialized submodules' '
    @@ t/t7412-submodule-absorbgitdirs.sh: test_expect_success 'absorb the git dir in a
     -	test_cmp expect.2 actual.2
     +	test_cmp expect.2 actual.2 &&
     +
    -+	sub1_gitdir="$(git -C sub1 rev-parse --path-format=absolute --git-common-dir)" &&
    -+	sub1_nested_gitdir="$(git -C sub1/nested rev-parse --path-format=absolute --git-common-dir)" &&
    -+
    -+	test-tool path-utils relative_path "$sub1_gitdir" "$sub1_nested_gitdir" \
    -+		>expect &&
    -+	git -C sub1/nested config submodule.superprojectGitDir >actual &&
    -+
    -+	test_cmp expect actual
    ++	git -C sub1/nested config submodule.hasSuperproject
      '
      
      test_expect_success 're-setup nested submodule' '
    @@ t/t7412-submodule-absorbgitdirs.sh: test_expect_success 'absorbing fails for a s
     +	# absorb the git dir
     +	git submodule absorbgitdirs sub4 &&
     +
    -+	# make sure the submodule noted the superproject gitdir correctly
    -+	submodule_gitdir="$(git -C sub4 rev-parse --absolute-git-dir)" &&
    -+	superproject_gitdir="$(git rev-parse --absolute-git-dir)" &&
    -+
    -+	test-tool path-utils relative_path "$superproject_gitdir" \
    -+		"$submodule_gitdir" >expect &&
    -+	git -C sub4 config submodule.superprojectGitDir >actual &&
    -+
    -+	test_cmp expect actual
    ++	# make sure the submodule noted the superproject
    ++	git -C sub4 config submodule.hasSuperproject
     +	)
     +'
     +
    @@ t/t7412-submodule-absorbgitdirs.sh: test_expect_success 'absorbing fails for a s
     +	# absorb the git dir
     +	git submodule absorbgitdirs sub5 &&
     +
    -+	# make sure the submodule noted the superproject gitdir correctly
    -+	submodule_gitdir="$(git -C sub5 rev-parse --absolute-git-dir)" &&
    -+	superproject_gitdir="$(git rev-parse --absolute-git-dir)" &&
    -+
    -+	test-tool path-utils relative_path "$superproject_gitdir" \
    -+		"$submodule_gitdir" >expect &&
    -+	git -C sub5 config submodule.superprojectGitDir >actual &&
    -+
    -+	test_cmp expect actual &&
    -+
    -+	# make sure the config went into the submodule config.worktree
    -+	test_file_not_empty "$submodule_gitdir/config.worktree"
    ++	# make sure the submodule noted the superproject
    ++	git -C sub5 config submodule.hasSuperproject
     +	)
     +'
     +
3:  63e736e69d < -:  ---------- submodule: record superproject gitdir during 'update'
-:  ---------- > 3:  c14ee8760f rev-parse: short-circuit superproject worktree when config unset
-- 
2.35.1.574.g5d30c73bfb-goog


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v8 1/3] t7400-submodule-basic: modernize inspect() helper
  2022-03-01  0:26   ` [PATCH v8 0/3] " Emily Shaffer
@ 2022-03-01  0:26     ` Emily Shaffer
  2022-03-01  0:26     ` [PATCH v8 2/3] introduce submodule.hasSuperproject record Emily Shaffer
                       ` (3 subsequent siblings)
  4 siblings, 0 replies; 64+ messages in thread
From: Emily Shaffer @ 2022-03-01  0:26 UTC (permalink / raw)
  To: git; +Cc: Emily Shaffer

Since the inspect() helper in the submodule-basic test suite was
written, 'git -C <dir>' 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 <emilyshaffer@google.com>
---
 t/t7400-submodule-basic.sh | 40 +++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 24 deletions(-)

diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index e7cec2e457..40cf8d89aa 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -107,23 +107,15 @@ 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"
-	)
+	sub_dir=$1 &&
+
+	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 &&
+	git -C "$sub_dir" clean -n -d -x >untracked
 }
 
 test_expect_success 'submodule add' '
@@ -146,7 +138,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
@@ -248,7 +240,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
@@ -264,7 +256,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
@@ -280,7 +272,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
@@ -296,7 +288,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
@@ -312,7 +304,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
@@ -328,7 +320,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
@@ -359,7 +351,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
-- 
2.35.1.574.g5d30c73bfb-goog


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH v8 2/3] introduce submodule.hasSuperproject record
  2022-03-01  0:26   ` [PATCH v8 0/3] " Emily Shaffer
  2022-03-01  0:26     ` [PATCH v8 1/3] t7400-submodule-basic: modernize inspect() helper Emily Shaffer
@ 2022-03-01  0:26     ` Emily Shaffer
  2022-03-01  7:00       ` Junio C Hamano
  2022-03-08 22:13       ` Glen Choo
  2022-03-01  0:26     ` [PATCH v8 3/3] rev-parse: short-circuit superproject worktree when config unset Emily Shaffer
                       ` (2 subsequent siblings)
  4 siblings, 2 replies; 64+ messages in thread
From: Emily Shaffer @ 2022-03-01  0:26 UTC (permalink / raw)
  To: git; +Cc: Emily Shaffer, Junio C Hamano

Teach submodules a config variable indicating the fact that they are a
submodule. If this config is set to false or unset, Git may assume the
current repo is not a submodule.

Git commands can use this variable to decide whether to traverse the
filesystem and look for a superproject at all. 'git rev-parse
--show-superproject-working-tree' can learn to exit early if this config
is unset or false. Other newly added or implicit behavior - like "git
status" showing the submodule's status in relation to the superproject,
or a config shared between the superproject and submodule - can use this
config to decide whether to search the parent directory to find a
superproject.

Introduce this config everywhere we add a new submodule, or touch one
that already exists, so that we can proliferate it in repos which are
already out in the world using submodules.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/config/submodule.txt |  6 ++++
 builtin/submodule--helper.c        |  5 +++
 git-submodule.sh                   |  3 ++
 submodule.c                        | 18 +++++++++++
 t/t7400-submodule-basic.sh         |  4 +++
 t/t7406-submodule-update.sh        |  8 +++++
 t/t7412-submodule-absorbgitdirs.sh | 50 ++++++++++++++++++++++++++++--
 7 files changed, 92 insertions(+), 2 deletions(-)

diff --git a/Documentation/config/submodule.txt b/Documentation/config/submodule.txt
index ee454f8126..99d5260b8e 100644
--- a/Documentation/config/submodule.txt
+++ b/Documentation/config/submodule.txt
@@ -91,3 +91,9 @@ 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.hasSuperproject::
+	Indicates whether this repository is a submodule. If this config is set
+	to 'true', Git may traverse the filesystem above this submodule in order
+	to identify the superproject. It is set automatically during submodule
+	creation, update, and 'git submodule absorbgitdir'.
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index c5d3fc3817..92986646bc 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1839,6 +1839,11 @@ static int clone_submodule(struct module_clone_data *clone_data)
 		git_config_set_in_file(p, "submodule.alternateErrorStrategy",
 				       error_strategy);
 
+	/*
+	 * Teach the submodule that it's a submodule.
+	 */
+	git_config_set_in_file(p, "submodule.hasSuperproject", "true");
+
 	free(sm_alternate);
 	free(error_strategy);
 
diff --git a/git-submodule.sh b/git-submodule.sh
index 652861aa66..59dffda775 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -449,6 +449,9 @@ cmd_update()
 			;;
 		esac
 
+		# Note that the submodule is a submodule.
+		git -C "$sm_path" config submodule.hasSuperproject "true"
+
 		if test -n "$recursive"
 		then
 			(
diff --git a/submodule.c b/submodule.c
index c689070524..741104af8a 100644
--- a/submodule.c
+++ b/submodule.c
@@ -2097,6 +2097,8 @@ 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;
 	struct strbuf new_gitdir = STRBUF_INIT;
 	const struct submodule *sub;
+	struct config_set sub_cs;
+	struct strbuf config_path = STRBUF_INIT, sb = STRBUF_INIT;
 
 	if (submodule_uses_worktrees(path))
 		die(_("relocate_gitdir for submodule '%s' with "
@@ -2127,6 +2129,22 @@ static void relocate_single_git_dir_into_superproject(const char *path)
 
 	relocate_gitdir(path, real_old_git_dir, real_new_git_dir);
 
+	/*
+	 * Note location of superproject's gitdir. Because the submodule already
+	 * has a gitdir and local config, we can store this pointer from
+	 * worktree config to worktree config, if the submodule has
+	 * extensions.worktreeConfig set.
+	 */
+	strbuf_addf(&config_path, "%s/config", real_new_git_dir);
+	git_configset_init(&sub_cs);
+	git_configset_add_file(&sub_cs, config_path.buf);
+
+	git_config_set_in_file(config_path.buf, "submodule.hasSuperproject",
+			       "true");
+
+	git_configset_clear(&sub_cs);
+	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/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 40cf8d89aa..833fa01961 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -115,6 +115,10 @@ inspect() {
 	git -C "$sub_dir" rev-parse HEAD >head-sha1 &&
 	git -C "$sub_dir" update-index --refresh &&
 	git -C "$sub_dir" diff-files --exit-code &&
+
+	# Ensure that submodule.hasSuperproject is set.
+	git -C "$sub_dir" config "submodule.hasSuperproject"
+
 	git -C "$sub_dir" clean -n -d -x >untracked
 }
 
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 11cccbb333..422c3cc343 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -1061,4 +1061,12 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s
 	)
 '
 
+test_expect_success 'submodule update adds submodule.hasSuperproject to older repos' '
+	(cd super &&
+	 git -C submodule config --unset submodule.hasSuperproject &&
+	 git submodule update &&
+	 git -C submodule config submodule.hasSuperproject
+	)
+'
+
 test_done
diff --git a/t/t7412-submodule-absorbgitdirs.sh b/t/t7412-submodule-absorbgitdirs.sh
index 1cfa150768..187fb6bbbc 100755
--- a/t/t7412-submodule-absorbgitdirs.sh
+++ b/t/t7412-submodule-absorbgitdirs.sh
@@ -30,7 +30,9 @@ 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 &&
+
+	git -C sub1 config submodule.hasSuperproject
 '
 
 test_expect_success 'absorbing does not fail for deinitialized submodules' '
@@ -61,7 +63,9 @@ test_expect_success 'absorb the git dir in a nested submodule' '
 	git status >actual.1 &&
 	git -C sub1/nested rev-parse HEAD >actual.2 &&
 	test_cmp expect.1 actual.1 &&
-	test_cmp expect.2 actual.2
+	test_cmp expect.2 actual.2 &&
+
+	git -C sub1/nested config submodule.hasSuperproject
 '
 
 test_expect_success 're-setup nested submodule' '
@@ -130,4 +134,46 @@ test_expect_success 'absorbing fails for a submodule with multiple worktrees' '
 	test_i18ngrep "not supported" error
 '
 
+test_expect_success 'absorbgitdirs works when called from a superproject worktree' '
+	# set up a worktree of the superproject
+	git worktree add wt &&
+	(
+	cd wt &&
+
+	# create a new unembedded git dir
+	git init sub4 &&
+	test_commit -C sub4 first &&
+	git submodule add ./sub4 &&
+	test_tick &&
+
+	# absorb the git dir
+	git submodule absorbgitdirs sub4 &&
+
+	# make sure the submodule noted the superproject
+	git -C sub4 config submodule.hasSuperproject
+	)
+'
+
+test_expect_success 'absorbgitdirs works with a submodule with worktree config' '
+	# reuse the worktree of the superproject
+	(
+	cd wt &&
+
+	# create a new unembedded git dir
+	git init sub5 &&
+	test_commit -C sub5 first &&
+	git submodule add ./sub5 &&
+	test_tick &&
+
+	# turn on worktree configs for submodule
+	git -C sub5 config extensions.worktreeConfig true &&
+
+	# absorb the git dir
+	git submodule absorbgitdirs sub5 &&
+
+	# make sure the submodule noted the superproject
+	git -C sub5 config submodule.hasSuperproject
+	)
+'
+
 test_done
-- 
2.35.1.574.g5d30c73bfb-goog


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH v8 3/3] rev-parse: short-circuit superproject worktree when config unset
  2022-03-01  0:26   ` [PATCH v8 0/3] " Emily Shaffer
  2022-03-01  0:26     ` [PATCH v8 1/3] t7400-submodule-basic: modernize inspect() helper Emily Shaffer
  2022-03-01  0:26     ` [PATCH v8 2/3] introduce submodule.hasSuperproject record Emily Shaffer
@ 2022-03-01  0:26     ` Emily Shaffer
  2022-03-01  7:06       ` Junio C Hamano
  2022-03-01  3:08     ` [PATCH v8 0/3] teach submodules to know they're submodules Junio C Hamano
  2022-03-10  0:44     ` [PATCH v9 " Emily Shaffer
  4 siblings, 1 reply; 64+ messages in thread
From: Emily Shaffer @ 2022-03-01  0:26 UTC (permalink / raw)
  To: git; +Cc: Emily Shaffer

In the previous commit, submodules learned a config
'submodule.hasSuperproject' to indicate whether or not we should attempt
to traverse the filesystem to find their superproject. To help test that
this config was added everywhere it should have been, begin using it to
decide whether to exit early from 'git rev-parse
--show-superproject-working-dir'.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>

---

Maybe it's actually better to warn instead of error here? Or maybe it's
best not to say anything, but to set 'submodule.hasSuperproject' after
we successfully find the superproject?

Either way - I ran the test suite with this early exit added and
everything still passed. I made this change hoping to get a little
signal on whether the series achieved its goal, and in that regard I'm
satisfied.
---
 submodule.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/submodule.c b/submodule.c
index 741104af8a..463e7f0c48 100644
--- a/submodule.c
+++ b/submodule.c
@@ -2237,6 +2237,7 @@ int get_superproject_working_tree(struct strbuf *buf)
 	struct strbuf sb = STRBUF_INIT;
 	struct strbuf one_up = STRBUF_INIT;
 	const char *cwd = xgetcwd();
+	int has_superproject_cfg = 0;
 	int ret = 0;
 	const char *subpath;
 	int code;
@@ -2250,6 +2251,17 @@ int get_superproject_working_tree(struct strbuf *buf)
 		 */
 		return 0;
 
+	if (git_config_get_bool("submodule.hassuperproject", &has_superproject_cfg)
+	    || !has_superproject_cfg) {
+		/*
+		 * If we don't have a superproject, then we're probably not a
+		 * submodule. If this is failing and shouldn't be, investigate
+		 * why the config was never set.
+		 */
+		error(_("Asked to find a superproject, but submodule.hasSuperproject != true"));
+		return 0;
+	}
+
 	if (!strbuf_realpath(&one_up, "../", 0))
 		return 0;
 
-- 
2.35.1.574.g5d30c73bfb-goog


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* Re: [PATCH v8 0/3] teach submodules to know they're submodules
  2022-03-01  0:26   ` [PATCH v8 0/3] " Emily Shaffer
                       ` (2 preceding siblings ...)
  2022-03-01  0:26     ` [PATCH v8 3/3] rev-parse: short-circuit superproject worktree when config unset Emily Shaffer
@ 2022-03-01  3:08     ` Junio C Hamano
  2022-03-08 18:54       ` Emily Shaffer
  2022-03-10  0:44     ` [PATCH v9 " Emily Shaffer
  4 siblings, 1 reply; 64+ messages in thread
From: Junio C Hamano @ 2022-03-01  3:08 UTC (permalink / raw)
  To: Emily Shaffer
  Cc: git, Albert Cui, Phillip Wood, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason,
	Matheus Tavares Bernardino, Jonathan Nieder, Jacob Keller,
	Atharva Raykar, Derrick Stolee, Jonathan Tan

Emily Shaffer <emilyshaffer@google.com> writes:

> One thing I'm not sure about: in the tests, I check whether the config
> is set, but not what the boolean value of it is. Is there a better way
> to do that?

Are you looking for value normalization during both setting and
retrieving, i.e.

	$ git config vari.able 0 ;# or "no" or "off"
	$ git config --type=bool vari.abble
	false
	$ git config vari.able 1 ;# or "yes" or "on"
	$ git config --type=bool vari.abble
	true

	$ git config --type=bool vari.able yes ;# or "1" or "on"
	$ git config vari.able
	true


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v8 2/3] introduce submodule.hasSuperproject record
  2022-03-01  0:26     ` [PATCH v8 2/3] introduce submodule.hasSuperproject record Emily Shaffer
@ 2022-03-01  7:00       ` Junio C Hamano
  2022-03-08 20:04         ` Emily Shaffer
  2022-03-08 22:13       ` Glen Choo
  1 sibling, 1 reply; 64+ messages in thread
From: Junio C Hamano @ 2022-03-01  7:00 UTC (permalink / raw)
  To: Emily Shaffer; +Cc: git

Emily Shaffer <emilyshaffer@google.com> writes:

> +	/*
> +	 * Note location of superproject's gitdir. Because the submodule already
> +	 * has a gitdir and local config, we can store this pointer from
> +	 * worktree config to worktree config, if the submodule has
> +	 * extensions.worktreeConfig set.
> +	 */

Probably the comment is a bit stale.  There is no longer a pointer
or location of superproject's gitdir recorded anywhere.

> +	strbuf_addf(&config_path, "%s/config", real_new_git_dir);
> +	git_configset_init(&sub_cs);
> +	git_configset_add_file(&sub_cs, config_path.buf);
> +
> +	git_config_set_in_file(config_path.buf, "submodule.hasSuperproject",
> +			       "true");
> +
> +	git_configset_clear(&sub_cs);
> +	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/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
> index 40cf8d89aa..833fa01961 100755
> --- a/t/t7400-submodule-basic.sh
> +++ b/t/t7400-submodule-basic.sh
> @@ -115,6 +115,10 @@ inspect() {
>  	git -C "$sub_dir" rev-parse HEAD >head-sha1 &&
>  	git -C "$sub_dir" update-index --refresh &&
>  	git -C "$sub_dir" diff-files --exit-code &&
> +
> +	# Ensure that submodule.hasSuperproject is set.
> +	git -C "$sub_dir" config "submodule.hasSuperproject"

Are we sufficiently happy to see the variable is set to anything, or
do we require it to be set to boolean true?

If the former, the above is fine, with trailing && added.

If the latter, then something like

	val=$(git config --type=bool "submodule.hasSuperproject") &&
	test "$val" = true &&

would be more appropriate, but I wonder something like

test_config_is () {
	local var expect val
	var="$1" expect="$2"
	shift 2
        val=$(git "$@" config --type=bool "$var") &&
	test "$val" = "$expect"
}

would be in order.  That would allow us to write

	test_config_is submodule.hasSuperproject true -C "$sub_dir" &&

>  	git -C "$sub_dir" clean -n -d -x >untracked
>  }
>  
> diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
> index 11cccbb333..422c3cc343 100755
> --- a/t/t7406-submodule-update.sh
> +++ b/t/t7406-submodule-update.sh
> @@ -1061,4 +1061,12 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s
>  	)
>  '
>  
> +test_expect_success 'submodule update adds submodule.hasSuperproject to older repos' '
> +	(cd super &&
> +	 git -C submodule config --unset submodule.hasSuperproject &&

Are we testing that submodule.hasSuperproject is set, and that
it can successfully be unset?  "config --unset no.such.var" will
exit with non-zero status.

> +	 git submodule update &&
> +	 git -C submodule config submodule.hasSuperproject

Ditto.

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v8 3/3] rev-parse: short-circuit superproject worktree when config unset
  2022-03-01  0:26     ` [PATCH v8 3/3] rev-parse: short-circuit superproject worktree when config unset Emily Shaffer
@ 2022-03-01  7:06       ` Junio C Hamano
  2022-03-09  0:38         ` Emily Shaffer
  0 siblings, 1 reply; 64+ messages in thread
From: Junio C Hamano @ 2022-03-01  7:06 UTC (permalink / raw)
  To: Emily Shaffer; +Cc: git

Emily Shaffer <emilyshaffer@google.com> writes:

> diff --git a/submodule.c b/submodule.c
> index 741104af8a..463e7f0c48 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -2237,6 +2237,7 @@ int get_superproject_working_tree(struct strbuf *buf)
>  	struct strbuf sb = STRBUF_INIT;
>  	struct strbuf one_up = STRBUF_INIT;
>  	const char *cwd = xgetcwd();
> +	int has_superproject_cfg = 0;
>  	int ret = 0;
>  	const char *subpath;
>  	int code;
> @@ -2250,6 +2251,17 @@ int get_superproject_working_tree(struct strbuf *buf)
>  		 */
>  		return 0;
>  
> +	if (git_config_get_bool("submodule.hassuperproject", &has_superproject_cfg)
> +	    || !has_superproject_cfg) {

git_config_get_bool() returns 0 when it successfully finds the
variable, so the above says "If submodule.hasSuperproject is not set
at all, or if it is set to false, then..."

> +		/*
> +		 * If we don't have a superproject, then we're probably not a
> +		 * submodule. If this is failing and shouldn't be, investigate
> +		 * why the config was never set.
> +		 */
> +		error(_("Asked to find a superproject, but submodule.hasSuperproject != true"));
> +		return 0;

But given that this thing is new, I am not sure if that is a
sensible guard to use here.  Shouldn't we say 

 - If submodule.hasSuperproject is EXPLICITLY set to false then ...

instead?  I.e.

	if (!git_config_get_bool("submodule.hassuperproject", &value) &&
	    !value) {
		error(_("asked to ..."));
		return 0;
	}


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v8 0/3] teach submodules to know they're submodules
  2022-03-01  3:08     ` [PATCH v8 0/3] teach submodules to know they're submodules Junio C Hamano
@ 2022-03-08 18:54       ` Emily Shaffer
  0 siblings, 0 replies; 64+ messages in thread
From: Emily Shaffer @ 2022-03-08 18:54 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Albert Cui, Phillip Wood, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason,
	Matheus Tavares Bernardino, Jonathan Nieder, Jacob Keller,
	Atharva Raykar, Derrick Stolee, Jonathan Tan

On Mon, Feb 28, 2022 at 07:08:35PM -0800, Junio C Hamano wrote:
> 
> Emily Shaffer <emilyshaffer@google.com> writes:
> 
> > One thing I'm not sure about: in the tests, I check whether the config
> > is set, but not what the boolean value of it is. Is there a better way
> > to do that?
> 
> Are you looking for value normalization during both setting and
> retrieving, i.e.
> 
> 	$ git config vari.able 0 ;# or "no" or "off"
> 	$ git config --type=bool vari.abble
> 	false
> 	$ git config vari.able 1 ;# or "yes" or "on"
> 	$ git config --type=bool vari.abble
> 	true
> 
> 	$ git config --type=bool vari.able yes ;# or "1" or "on"
> 	$ git config vari.able
> 	true
> 

Ah, thanks! This helps. But that means I still need to check the return
value, and associate "didn't find anything" (1) with the default as
documented in Docs/config/submodule.txt, right?

Either way, this is useful. Thanks!

 - Emily

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v8 2/3] introduce submodule.hasSuperproject record
  2022-03-01  7:00       ` Junio C Hamano
@ 2022-03-08 20:04         ` Emily Shaffer
  0 siblings, 0 replies; 64+ messages in thread
From: Emily Shaffer @ 2022-03-08 20:04 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Mon, Feb 28, 2022 at 11:00:57PM -0800, Junio C Hamano wrote:
> 
> Emily Shaffer <emilyshaffer@google.com> writes:
> 
> > +	/*
> > +	 * Note location of superproject's gitdir. Because the submodule already
> > +	 * has a gitdir and local config, we can store this pointer from
> > +	 * worktree config to worktree config, if the submodule has
> > +	 * extensions.worktreeConfig set.
> > +	 */
> 
> Probably the comment is a bit stale.  There is no longer a pointer
> or location of superproject's gitdir recorded anywhere.

Thanks. I considered replacing it with a new comment about "now we'll
note that it's got a superproject", but I think that's clear enough from
the config set line, so I deleted the comment entirely.

> 
> > +	strbuf_addf(&config_path, "%s/config", real_new_git_dir);
> > +	git_configset_init(&sub_cs);
> > +	git_configset_add_file(&sub_cs, config_path.buf);
> > +
> > +	git_config_set_in_file(config_path.buf, "submodule.hasSuperproject",
> > +			       "true");
> > +
> > +	git_configset_clear(&sub_cs);
> > +	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/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
> > index 40cf8d89aa..833fa01961 100755
> > --- a/t/t7400-submodule-basic.sh
> > +++ b/t/t7400-submodule-basic.sh
> > @@ -115,6 +115,10 @@ inspect() {
> >  	git -C "$sub_dir" rev-parse HEAD >head-sha1 &&
> >  	git -C "$sub_dir" update-index --refresh &&
> >  	git -C "$sub_dir" diff-files --exit-code &&
> > +
> > +	# Ensure that submodule.hasSuperproject is set.
> > +	git -C "$sub_dir" config "submodule.hasSuperproject"
> 
> Are we sufficiently happy to see the variable is set to anything, or
> do we require it to be set to boolean true?
> 
> If the former, the above is fine, with trailing && added.
> 
> If the latter, then something like
> 
> 	val=$(git config --type=bool "submodule.hasSuperproject") &&
> 	test "$val" = true &&
> 
> would be more appropriate, but I wonder something like
> 
> test_config_is () {
> 	local var expect val
> 	var="$1" expect="$2"
> 	shift 2
>         val=$(git "$@" config --type=bool "$var") &&
> 	test "$val" = "$expect"
> }
> 
> would be in order.  That would allow us to write
> 
> 	test_config_is submodule.hasSuperproject true -C "$sub_dir" &&
> 

This seemed neat, so I started to look into implementing it, and found
`test_cmp_config()` which takes additional args to pass to `git config`
- so I should be able to achieve this same thing with
`test_config_is -C "$sub_dir" --type=bool true submodule.hasSuperproject`.

> >  	git -C "$sub_dir" clean -n -d -x >untracked
> >  }
> >  
> > diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
> > index 11cccbb333..422c3cc343 100755
> > --- a/t/t7406-submodule-update.sh
> > +++ b/t/t7406-submodule-update.sh
> > @@ -1061,4 +1061,12 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s
> >  	)
> >  '
> >  
> > +test_expect_success 'submodule update adds submodule.hasSuperproject to older repos' '
> > +	(cd super &&
> > +	 git -C submodule config --unset submodule.hasSuperproject &&
> 
> Are we testing that submodule.hasSuperproject is set, and that
> it can successfully be unset?  "config --unset no.such.var" will
> exit with non-zero status.
> 
> > +	 git submodule update &&
> > +	 git -C submodule config submodule.hasSuperproject
> 
> Ditto.

Ah, thanks.

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v8 2/3] introduce submodule.hasSuperproject record
  2022-03-01  0:26     ` [PATCH v8 2/3] introduce submodule.hasSuperproject record Emily Shaffer
  2022-03-01  7:00       ` Junio C Hamano
@ 2022-03-08 22:13       ` Glen Choo
  2022-03-08 22:29         ` Glen Choo
  1 sibling, 1 reply; 64+ messages in thread
From: Glen Choo @ 2022-03-08 22:13 UTC (permalink / raw)
  To: Emily Shaffer, git; +Cc: Emily Shaffer, Junio C Hamano


Reviewing this series lightly because I will need to base
'ar/submodule-update reroll pt 2' on this (pt.1 is at
https://lore.kernel.org/git/20220305001401.20888-1-chooglen@google.com).

Emily Shaffer <emilyshaffer@google.com> writes:

> diff --git a/git-submodule.sh b/git-submodule.sh
> index 652861aa66..59dffda775 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -449,6 +449,9 @@ cmd_update()
>  			;;
>  		esac
>  
> +		# Note that the submodule is a submodule.
> +		git -C "$sm_path" config submodule.hasSuperproject "true"
> +
>  		if test -n "$recursive"
>  		then
>  			(

This hunk has a textual conflict with 'ar/submodule-update reroll pt
2', but the fix is easy - just teach "git submodule--helper update" to
set the config in C.

> diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
> index 11cccbb333..422c3cc343 100755
> --- a/t/t7406-submodule-update.sh
> +++ b/t/t7406-submodule-update.sh
> @@ -1061,4 +1061,12 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s
>  	)
>  '
>  
> +test_expect_success 'submodule update adds submodule.hasSuperproject to older repos' '
> +	(cd super &&
> +	 git -C submodule config --unset submodule.hasSuperproject &&
> +	 git submodule update &&
> +	 git -C submodule config submodule.hasSuperproject
> +	)
> +'
> +
>  test_done


I think there is a gap in the test coverage. I notice that this doesn't
test that we set submodule.hasSuperproject when the submodule is cloned
for the first time with 'git submodule update'. I thought that maybe the
test for this was here...

> diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
> index 40cf8d89aa..833fa01961 100755
> --- a/t/t7400-submodule-basic.sh
> +++ b/t/t7400-submodule-basic.sh
> @@ -115,6 +115,10 @@ inspect() {
>  	git -C "$sub_dir" rev-parse HEAD >head-sha1 &&
>  	git -C "$sub_dir" update-index --refresh &&
>  	git -C "$sub_dir" diff-files --exit-code &&
> +
> +	# Ensure that submodule.hasSuperproject is set.
> +	git -C "$sub_dir" config "submodule.hasSuperproject"
> +
>  	git -C "$sub_dir" clean -n -d -x >untracked
>  }
>  

But when I removed the "set submodule.hasSuperproject in submodule"
line, i.e. 

 		git -C "$sm_path" config submodule.hasSuperproject "true"

t7400 still passes.

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v8 2/3] introduce submodule.hasSuperproject record
  2022-03-08 22:13       ` Glen Choo
@ 2022-03-08 22:29         ` Glen Choo
  0 siblings, 0 replies; 64+ messages in thread
From: Glen Choo @ 2022-03-08 22:29 UTC (permalink / raw)
  To: Emily Shaffer, git; +Cc: Emily Shaffer, Junio C Hamano

Glen Choo <chooglen@google.com> writes:

> Emily Shaffer <emilyshaffer@google.com> writes:
>
>> diff --git a/git-submodule.sh b/git-submodule.sh
>> index 652861aa66..59dffda775 100755
>> --- a/git-submodule.sh
>> +++ b/git-submodule.sh
>> @@ -449,6 +449,9 @@ cmd_update()
>>  			;;
>>  		esac
>>  
>> +		# Note that the submodule is a submodule.
>> +		git -C "$sm_path" config submodule.hasSuperproject "true"
>> +
>>  		if test -n "$recursive"
>>  		then
>>  			(
>
> This hunk has a textual conflict with 'ar/submodule-update reroll pt
> 2', but the fix is easy - just teach "git submodule--helper update" to
> set the config in C.

From our dicussion (offline), it turns out this statement isn't really
correct because we do set the config in C, but we do it in clone_submodule():

   diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
   index c5d3fc3817..92986646bc 100644
   --- a/builtin/submodule--helper.c
   +++ b/builtin/submodule--helper.c
   @@ -1839,6 +1839,11 @@ static int clone_submodule(struct module_clone_data *clone_data)
       git_config_set_in_file(p, "submodule.alternateErrorStrategy",
                  error_strategy);

   +	/*
   +	 * Teach the submodule that it's a submodule.
   +	 */
   +	git_config_set_in_file(p, "submodule.hasSuperproject", "true");
   +
     free(sm_alternate);
     free(error_strategy);

>> diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
>> index 11cccbb333..422c3cc343 100755
>> --- a/t/t7406-submodule-update.sh
>> +++ b/t/t7406-submodule-update.sh
>> @@ -1061,4 +1061,12 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s
>>  	)
>>  '
>>  
>> +test_expect_success 'submodule update adds submodule.hasSuperproject to older repos' '
>> +	(cd super &&
>> +	 git -C submodule config --unset submodule.hasSuperproject &&
>> +	 git submodule update &&
>> +	 git -C submodule config submodule.hasSuperproject
>> +	)
>> +'
>> +
>>  test_done
>
>
> I think there is a gap in the test coverage. I notice that this doesn't
> test that we set submodule.hasSuperproject when the submodule is cloned
> for the first time with 'git submodule update'. I thought that maybe the
> test for this was here...
>
>> diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
>> index 40cf8d89aa..833fa01961 100755
>> --- a/t/t7400-submodule-basic.sh
>> +++ b/t/t7400-submodule-basic.sh
>> @@ -115,6 +115,10 @@ inspect() {
>>  	git -C "$sub_dir" rev-parse HEAD >head-sha1 &&
>>  	git -C "$sub_dir" update-index --refresh &&
>>  	git -C "$sub_dir" diff-files --exit-code &&
>> +
>> +	# Ensure that submodule.hasSuperproject is set.
>> +	git -C "$sub_dir" config "submodule.hasSuperproject"
>> +
>>  	git -C "$sub_dir" clean -n -d -x >untracked
>>  }
>>  
>
> But when I removed the "set submodule.hasSuperproject in submodule"
> line, i.e. 
>
>  		git -C "$sm_path" config submodule.hasSuperproject "true"
>
> t7400 still passes.

So we would expect that newly cloned submodules would pass even without
this .sh line.

I don't think we need to do this twice in C and in shell. We can move
this line:

   +	git_config_set_in_file(p, "submodule.hasSuperproject", "true");

into run-update-procedure (and out of clone_submodule()). This way it's
guaranteed to touch every submodule (newly cloned or not).

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v8 3/3] rev-parse: short-circuit superproject worktree when config unset
  2022-03-01  7:06       ` Junio C Hamano
@ 2022-03-09  0:38         ` Emily Shaffer
  0 siblings, 0 replies; 64+ messages in thread
From: Emily Shaffer @ 2022-03-09  0:38 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Mon, Feb 28, 2022 at 11:06:07PM -0800, Junio C Hamano wrote:
> 
> Emily Shaffer <emilyshaffer@google.com> writes:
> 
> > diff --git a/submodule.c b/submodule.c
> > index 741104af8a..463e7f0c48 100644
> > --- a/submodule.c
> > +++ b/submodule.c
> > @@ -2237,6 +2237,7 @@ int get_superproject_working_tree(struct strbuf *buf)
> >  	struct strbuf sb = STRBUF_INIT;
> >  	struct strbuf one_up = STRBUF_INIT;
> >  	const char *cwd = xgetcwd();
> > +	int has_superproject_cfg = 0;
> >  	int ret = 0;
> >  	const char *subpath;
> >  	int code;
> > @@ -2250,6 +2251,17 @@ int get_superproject_working_tree(struct strbuf *buf)
> >  		 */
> >  		return 0;
> >  
> > +	if (git_config_get_bool("submodule.hassuperproject", &has_superproject_cfg)
> > +	    || !has_superproject_cfg) {
> 
> git_config_get_bool() returns 0 when it successfully finds the
> variable, so the above says "If submodule.hasSuperproject is not set
> at all, or if it is set to false, then..."
> 
> > +		/*
> > +		 * If we don't have a superproject, then we're probably not a
> > +		 * submodule. If this is failing and shouldn't be, investigate
> > +		 * why the config was never set.
> > +		 */
> > +		error(_("Asked to find a superproject, but submodule.hasSuperproject != true"));
> > +		return 0;
> 
> But given that this thing is new, I am not sure if that is a
> sensible guard to use here.  Shouldn't we say 
> 
>  - If submodule.hasSuperproject is EXPLICITLY set to false then ...

Ah, interesting. I think that makes sense. I wrote this patch hoping to
get an additional check for completeness of the previous patch (that is
- if I can rely on that value for this other operation, and all the
tests still pass without me touching them, then I seem to have wired
the new config through everywhere) and I think it's served that purpose;
for the real world, that's a little more dangerous, so I think relying
on explicit false makes sense. Will do.

> 
> instead?  I.e.
> 
> 	if (!git_config_get_bool("submodule.hassuperproject", &value) &&
> 	    !value) {
> 		error(_("asked to ..."));
> 		return 0;
> 	}
> 

^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v9 0/3] teach submodules to know they're submodules
  2022-03-01  0:26   ` [PATCH v8 0/3] " Emily Shaffer
                       ` (3 preceding siblings ...)
  2022-03-01  3:08     ` [PATCH v8 0/3] teach submodules to know they're submodules Junio C Hamano
@ 2022-03-10  0:44     ` Emily Shaffer
  2022-03-10  0:44       ` [PATCH v9 1/3] t7400-submodule-basic: modernize inspect() helper Emily Shaffer
                         ` (3 more replies)
  4 siblings, 4 replies; 64+ messages in thread
From: Emily Shaffer @ 2022-03-10  0:44 UTC (permalink / raw)
  To: git
  Cc: Emily Shaffer, Albert Cui, Phillip Wood, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason, Junio C Hamano,
	Matheus Tavares Bernardino, Jonathan Nieder, Jacob Keller,
	Atharva Raykar, Derrick Stolee, Jonathan Tan, Glen Choo

For the original cover letter, see
https://lore.kernel.org/git/20210611225428.1208973-1-emilyshaffer%40google.com.

CI run: https://github.com/nasamuffin/git/actions/runs/1954710601

Since v8:

Only a couple of minor fixes.

Junio pointed out that I could write the tests better using --type=bool
and 'test_cmp_config', and that we could be a little more careful about
when to give up on 'git rev-parse --show-superproject-working-dir'.

Glen mentioned that builtin/submodule--helper.c:run_update_procedure() is called
unconditionally earlier in the same function where I had added the
config in git-submodule.sh. So, I moved the config set into
submodule--helper.c to reduce possible edge cases where the config might
not be set.

Otherwise, this series is pretty much unchanged.

Since v7:

Actually a fairly large rework. Rather than keeping the path from gitdir
to gitdir, just keep a boolean under 'submodule.hasSuperproject'. The
idea is that from this boolean, we can decide whether to traverse the
filesystem looking for a superproject.

Because this simplifies the implementation, I compressed the three
middle commits into one. As proof-of-concept, I added a patch at the end
to check for this boolean when running `git rev-parse
--show-superproject-working-tree`.

One thing I'm not sure about: in the tests, I check whether the config
is set, but not what the boolean value of it is. Is there a better way
to do that? For example, I could imagine someone deciding to set
`submodule.hasSuperproject = false` and the tests would not function
correctly in that case. I think we don't really normalize the value on a
boolean config like that, so I didn't want to write a lot of comparison
to check if the value is 1 or true or True or TRUE or Yes or .... Am I
overthinking it?

The other thing I'm not sure about: since it's just a bool, we're not
restricted to setting this config only when we have both gitdir paths
available. That makes me want to set the config any time we are doing
something with submodules anyway, like any time 'git-submodule--helper'
is used. But that helper seems to be called in the context of the
superproject, not of the submodules, so adding this config for each
submodule we touch would be a second child process. Is there some other
common entry point for submodules that we can use?

 - Emily

Since v6:

I've dropped the fifth commit to use this new config for `git rev-parse
--show-superproject-working-tree`. I think it did more harm than good -
that tool uses an odd way to determine whether the superproject is
actually the superproject, anyways.

I poked a little bit at trying to find some benchmark to demonstrate
that "submodule.superprojectGitDir" is actually faster - but I didn't
end up able to write one without writing a ton of new code to traverse
the filesystem. To be honest, I'm not all that interested in performance
- I want the config added for correctness, instead.

So, the only real changes between v6 and v7 are some documentation
changes suggested by Jonathan Tan
(https://lore.kernel.org/git/20211117234300.2598132-1-jonathantanmy%40google.com).

Since v5:

A couple things. Firstly, a semantics change *back* to the semantics of
v3 - we map from gitdir to gitdir, *not* from common dir to common dir,
so that theoretically a submodule with multiple worktrees in multiple
superproject worktrees will be able to figure out which worktree of the
superproject it's in. (Realistically, that's not really possible right
now, but I'd like to change that soon.)

Secondly, a rewording of comments and commit messages to indicate that
this isn't a cache of some expensive operation, but rather intended to
be the source of truth for all submodules. I also added a fifth commit
rewriting `git rev-parse --show-superproject-working-tree` to
demonstrate what that means in practice - but from a practical
standpoint, I'm a little worried about that fifth patch. More details in
the patch 5 description.

I did discuss Ævar's idea of relying on in-process filesystem digging to
find the superproject's gitdir with the rest of the Google team, but in
the end decided that there are some worries about filesystem digging in
this way (namely, some ugly interactions with network drives that are
actually already an issue for Googler Linux machines). Plus, the allure
of being able to definitively know that we're a submodule is pretty
strong. ;) But overall, this is the direction I'd prefer to keep going
in, rather than trying to guess from the filesystem going forward.

Since v4:

The only real change here is a slight semantics change to map from
<submodule gitdir> to <superproject common git dir>. In every case
*except* for when the superproject has a worktree, this changes nothing.
For the case when the superproject has a worktree, this means that now
submodules will refer to the general superproject common dir (e.g. no
worktree-specific refs or configs or whatnot).

I *think* that because a submodule should exist in the context of the
common dir, not the worktree gitdir, that is ok. However, it does mean
it would be difficult to do something like sharing a config specific to
the worktree (the initial goal of this series).

$ROOT/.git
$ROOT/.git/config.superproject <- shared by $ROOT/.git/modules/sub
$ROOT/.git/modules/sub <- points to $ROOT/.git
$ROOT/.git/worktrees/wt
$ROOT/.git/worktrees/wt/config.superproject <- contains a certain config-based pre-commit hook

If the submodule only knows about the common dir, that is tough, because
the submodule would basically have to guess which worktree it's in from
its own path. There would be no way for '$WT/sub' to inherit
'$ROOT/.git/worktrees/wt/config.superproject'.

That said... right now, we don't support submodules in worktrees very
well at all. A submodule in a worktree will get a brand new gitdir in
$ROOT/.git/worktrees/modules/ (and that brand new gitdir would point to
the super's common dir). So I think we can punt on this entire question
until we teach submodules and worktrees to play more gracefully together
(it's on my long list...), and at that time we can probably introduce a
pointer from $ROOT/.git/modules/sub/worktrees/wt/ to
$ROOT/.git/worktrees/wt/....

Or, to summarize the long ramble above: "this is still kind of weird
with worktrees, but let's fix it later when we fix worktrees more
thoroughly".

(More rambling about worktree weirdness here:
https://lore.kernel.org/git/YYRaII8YWVxlBqsF%40google.com )


Since v3, a pretty major change: the semantics of
submodule.superprojectGitDir has changed, to point from the submodule's
gitdir to the superproject's gitdir (in v3 and earlier, we kept a path
from the submodule's *worktree* to the superproject's gitdir instead).
This cleans up some of the confusions about the behavior when a
submodule worktree moves around in the superproject's tree, or in a
future when we support submodules having multiple worktrees.

I also tried to simplify the tests to use 'test-tool path-utils
relative_path' everywhere - I think that makes them much more clear for
a test reader, but if you're reviewing and it isn't obvious what we're
testing for, please speak up.

I think this is pretty mature and there was a lot of general agreement
that the gitdir->gitdir association was the way to go, so please be
brutal and look for nits, leaks, etc. this round ;)
[/v4 cover letter]

Emily Shaffer (3):
  t7400-submodule-basic: modernize inspect() helper
  introduce submodule.hasSuperproject record
  rev-parse: short-circuit superproject worktree when config unset

 Documentation/config/submodule.txt |  6 ++++
 builtin/submodule--helper.c        | 11 +++++++
 submodule.c                        | 30 ++++++++++++++++++
 t/t1500-rev-parse.sh               | 10 +++++-
 t/t7400-submodule-basic.sh         | 42 ++++++++++++-------------
 t/t7406-submodule-update.sh        |  8 +++++
 t/t7412-submodule-absorbgitdirs.sh | 50 ++++++++++++++++++++++++++++--
 7 files changed, 131 insertions(+), 26 deletions(-)

Range-diff against v8:
-:  ---------- > 1:  251510c687 t7400-submodule-basic: modernize inspect() helper
1:  34cbfd81ee ! 2:  da01dc7c10 introduce submodule.hasSuperproject record
    @@ builtin/submodule--helper.c: static int clone_submodule(struct module_clone_data
      	free(sm_alternate);
      	free(error_strategy);
      
    -
    - ## git-submodule.sh ##
    -@@ git-submodule.sh: cmd_update()
    - 			;;
    - 		esac
    +@@ builtin/submodule--helper.c: static int run_update_procedure(int argc, const char **argv, const char *prefix)
    + 
    + 	free(prefixed_path);
      
    -+		# Note that the submodule is a submodule.
    -+		git -C "$sm_path" config submodule.hasSuperproject "true"
    ++	/*
    ++	 * This entry point is always called from a submodule, so this is a
    ++	 * good place to set a hint that this repo is a submodule.
    ++	 */
    ++	git_config_set("submodule.hasSuperproject", "true");
     +
    - 		if test -n "$recursive"
    - 		then
    - 			(
    + 	if (!oideq(&update_data.oid, &update_data.suboid) || update_data.force)
    + 		return do_run_update_procedure(&update_data);
    + 
     
      ## submodule.c ##
     @@ submodule.c: static void relocate_single_git_dir_into_superproject(const char *path)
    @@ submodule.c: static void relocate_single_git_dir_into_superproject(const char *p
      
      	relocate_gitdir(path, real_old_git_dir, real_new_git_dir);
      
    -+	/*
    -+	 * Note location of superproject's gitdir. Because the submodule already
    -+	 * has a gitdir and local config, we can store this pointer from
    -+	 * worktree config to worktree config, if the submodule has
    -+	 * extensions.worktreeConfig set.
    -+	 */
     +	strbuf_addf(&config_path, "%s/config", real_new_git_dir);
     +	git_configset_init(&sub_cs);
     +	git_configset_add_file(&sub_cs, config_path.buf);
    @@ t/t7400-submodule-basic.sh: inspect() {
      	git -C "$sub_dir" diff-files --exit-code &&
     +
     +	# Ensure that submodule.hasSuperproject is set.
    -+	git -C "$sub_dir" config "submodule.hasSuperproject"
    ++	test_cmp_config -C "$sub_dir" true --type=bool "submodule.hasSuperproject"
     +
      	git -C "$sub_dir" clean -n -d -x >untracked
      }
    @@ t/t7406-submodule-update.sh: test_expect_success 'submodule update --quiet passe
      
     +test_expect_success 'submodule update adds submodule.hasSuperproject to older repos' '
     +	(cd super &&
    -+	 git -C submodule config --unset submodule.hasSuperproject &&
    ++	 test_unconfig submodule.hasSuperproject &&
     +	 git submodule update &&
    -+	 git -C submodule config submodule.hasSuperproject
    ++	 test_cmp_config -C submodule true --type=bool submodule.hasSuperproject
     +	)
     +'
     +
    @@ t/t7412-submodule-absorbgitdirs.sh: test_expect_success 'absorb the git dir' '
     -	test_cmp expect.2 actual.2
     +	test_cmp expect.2 actual.2 &&
     +
    -+	git -C sub1 config submodule.hasSuperproject
    ++	test_cmp_config -C sub1 true --type=bool submodule.hasSuperproject
      '
      
      test_expect_success 'absorbing does not fail for deinitialized submodules' '
    @@ t/t7412-submodule-absorbgitdirs.sh: test_expect_success 'absorb the git dir in a
     -	test_cmp expect.2 actual.2
     +	test_cmp expect.2 actual.2 &&
     +
    -+	git -C sub1/nested config submodule.hasSuperproject
    ++	test_cmp_config -C sub1/nested true --type=bool submodule.hasSuperproject
      '
      
      test_expect_success 're-setup nested submodule' '
    @@ t/t7412-submodule-absorbgitdirs.sh: test_expect_success 'absorbing fails for a s
     +	git submodule absorbgitdirs sub4 &&
     +
     +	# make sure the submodule noted the superproject
    -+	git -C sub4 config submodule.hasSuperproject
    ++	test_cmp_config -C sub4 true --type=bool submodule.hasSuperproject
     +	)
     +'
     +
    @@ t/t7412-submodule-absorbgitdirs.sh: test_expect_success 'absorbing fails for a s
     +	git submodule absorbgitdirs sub5 &&
     +
     +	# make sure the submodule noted the superproject
    -+	git -C sub5 config submodule.hasSuperproject
    ++	test_cmp_config -C sub5 true --type=bool submodule.hasSuperproject
     +	)
     +'
     +
2:  c14ee8760f < -:  ---------- rev-parse: short-circuit superproject worktree when config unset
-:  ---------- > 3:  1893a84fdc rev-parse: short-circuit superproject worktree when config unset
-- 
2.35.1.616.g0bdcbb4464-goog


^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH v9 1/3] t7400-submodule-basic: modernize inspect() helper
  2022-03-10  0:44     ` [PATCH v9 " Emily Shaffer
@ 2022-03-10  0:44       ` Emily Shaffer
  2022-03-10  0:44       ` [PATCH v9 2/3] introduce submodule.hasSuperproject record Emily Shaffer
                         ` (2 subsequent siblings)
  3 siblings, 0 replies; 64+ messages in thread
From: Emily Shaffer @ 2022-03-10  0:44 UTC (permalink / raw)
  To: git; +Cc: Emily Shaffer

Since the inspect() helper in the submodule-basic test suite was
written, 'git -C <dir>' 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 <emilyshaffer@google.com>
---
 t/t7400-submodule-basic.sh | 40 +++++++++++++++-----------------------
 1 file changed, 16 insertions(+), 24 deletions(-)

diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index e7cec2e457..40cf8d89aa 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -107,23 +107,15 @@ 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"
-	)
+	sub_dir=$1 &&
+
+	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 &&
+	git -C "$sub_dir" clean -n -d -x >untracked
 }
 
 test_expect_success 'submodule add' '
@@ -146,7 +138,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
@@ -248,7 +240,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
@@ -264,7 +256,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
@@ -280,7 +272,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
@@ -296,7 +288,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
@@ -312,7 +304,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
@@ -328,7 +320,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
@@ -359,7 +351,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
-- 
2.35.1.616.g0bdcbb4464-goog


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH v9 2/3] introduce submodule.hasSuperproject record
  2022-03-10  0:44     ` [PATCH v9 " Emily Shaffer
  2022-03-10  0:44       ` [PATCH v9 1/3] t7400-submodule-basic: modernize inspect() helper Emily Shaffer
@ 2022-03-10  0:44       ` Emily Shaffer
  2022-03-10  2:09         ` Junio C Hamano
                           ` (2 more replies)
  2022-03-10  0:44       ` [PATCH v9 3/3] rev-parse: short-circuit superproject worktree when config unset Emily Shaffer
  2022-03-11  9:09       ` [PATCH v9 0/3] teach submodules to know they're submodules Ævar Arnfjörð Bjarmason
  3 siblings, 3 replies; 64+ messages in thread
From: Emily Shaffer @ 2022-03-10  0:44 UTC (permalink / raw)
  To: git; +Cc: Emily Shaffer, Junio C Hamano

Teach submodules a config variable indicating the fact that they are a
submodule. If this config is set to false or unset, Git may assume the
current repo is not a submodule.

Git commands can use this variable to decide whether to traverse the
filesystem and look for a superproject at all. 'git rev-parse
--show-superproject-working-tree' can learn to exit early if this config
is unset or false. Other newly added or implicit behavior - like "git
status" showing the submodule's status in relation to the superproject,
or a config shared between the superproject and submodule - can use this
config to decide whether to search the parent directory to find a
superproject.

Introduce this config everywhere we add a new submodule, or touch one
that already exists, so that we can proliferate it in repos which are
already out in the world using submodules.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/config/submodule.txt |  6 ++++
 builtin/submodule--helper.c        | 11 +++++++
 submodule.c                        | 12 +++++++
 t/t7400-submodule-basic.sh         |  4 +++
 t/t7406-submodule-update.sh        |  8 +++++
 t/t7412-submodule-absorbgitdirs.sh | 50 ++++++++++++++++++++++++++++--
 6 files changed, 89 insertions(+), 2 deletions(-)

diff --git a/Documentation/config/submodule.txt b/Documentation/config/submodule.txt
index ee454f8126..99d5260b8e 100644
--- a/Documentation/config/submodule.txt
+++ b/Documentation/config/submodule.txt
@@ -91,3 +91,9 @@ 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.hasSuperproject::
+	Indicates whether this repository is a submodule. If this config is set
+	to 'true', Git may traverse the filesystem above this submodule in order
+	to identify the superproject. It is set automatically during submodule
+	creation, update, and 'git submodule absorbgitdir'.
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index c5d3fc3817..eda9ed550e 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1839,6 +1839,11 @@ static int clone_submodule(struct module_clone_data *clone_data)
 		git_config_set_in_file(p, "submodule.alternateErrorStrategy",
 				       error_strategy);
 
+	/*
+	 * Teach the submodule that it's a submodule.
+	 */
+	git_config_set_in_file(p, "submodule.hasSuperproject", "true");
+
 	free(sm_alternate);
 	free(error_strategy);
 
@@ -2617,6 +2622,12 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
 
 	free(prefixed_path);
 
+	/*
+	 * This entry point is always called from a submodule, so this is a
+	 * good place to set a hint that this repo is a submodule.
+	 */
+	git_config_set("submodule.hasSuperproject", "true");
+
 	if (!oideq(&update_data.oid, &update_data.suboid) || update_data.force)
 		return do_run_update_procedure(&update_data);
 
diff --git a/submodule.c b/submodule.c
index c689070524..aafbd628ad 100644
--- a/submodule.c
+++ b/submodule.c
@@ -2097,6 +2097,8 @@ 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;
 	struct strbuf new_gitdir = STRBUF_INIT;
 	const struct submodule *sub;
+	struct config_set sub_cs;
+	struct strbuf config_path = STRBUF_INIT, sb = STRBUF_INIT;
 
 	if (submodule_uses_worktrees(path))
 		die(_("relocate_gitdir for submodule '%s' with "
@@ -2127,6 +2129,16 @@ static void relocate_single_git_dir_into_superproject(const char *path)
 
 	relocate_gitdir(path, real_old_git_dir, real_new_git_dir);
 
+	strbuf_addf(&config_path, "%s/config", real_new_git_dir);
+	git_configset_init(&sub_cs);
+	git_configset_add_file(&sub_cs, config_path.buf);
+
+	git_config_set_in_file(config_path.buf, "submodule.hasSuperproject",
+			       "true");
+
+	git_configset_clear(&sub_cs);
+	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/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 40cf8d89aa..53c8bf699d 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -115,6 +115,10 @@ inspect() {
 	git -C "$sub_dir" rev-parse HEAD >head-sha1 &&
 	git -C "$sub_dir" update-index --refresh &&
 	git -C "$sub_dir" diff-files --exit-code &&
+
+	# Ensure that submodule.hasSuperproject is set.
+	test_cmp_config -C "$sub_dir" true --type=bool "submodule.hasSuperproject"
+
 	git -C "$sub_dir" clean -n -d -x >untracked
 }
 
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 11cccbb333..ec2397fc69 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -1061,4 +1061,12 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s
 	)
 '
 
+test_expect_success 'submodule update adds submodule.hasSuperproject to older repos' '
+	(cd super &&
+	 test_unconfig submodule.hasSuperproject &&
+	 git submodule update &&
+	 test_cmp_config -C submodule true --type=bool submodule.hasSuperproject
+	)
+'
+
 test_done
diff --git a/t/t7412-submodule-absorbgitdirs.sh b/t/t7412-submodule-absorbgitdirs.sh
index 1cfa150768..4c33a98efa 100755
--- a/t/t7412-submodule-absorbgitdirs.sh
+++ b/t/t7412-submodule-absorbgitdirs.sh
@@ -30,7 +30,9 @@ 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 &&
+
+	test_cmp_config -C sub1 true --type=bool submodule.hasSuperproject
 '
 
 test_expect_success 'absorbing does not fail for deinitialized submodules' '
@@ -61,7 +63,9 @@ test_expect_success 'absorb the git dir in a nested submodule' '
 	git status >actual.1 &&
 	git -C sub1/nested rev-parse HEAD >actual.2 &&
 	test_cmp expect.1 actual.1 &&
-	test_cmp expect.2 actual.2
+	test_cmp expect.2 actual.2 &&
+
+	test_cmp_config -C sub1/nested true --type=bool submodule.hasSuperproject
 '
 
 test_expect_success 're-setup nested submodule' '
@@ -130,4 +134,46 @@ test_expect_success 'absorbing fails for a submodule with multiple worktrees' '
 	test_i18ngrep "not supported" error
 '
 
+test_expect_success 'absorbgitdirs works when called from a superproject worktree' '
+	# set up a worktree of the superproject
+	git worktree add wt &&
+	(
+	cd wt &&
+
+	# create a new unembedded git dir
+	git init sub4 &&
+	test_commit -C sub4 first &&
+	git submodule add ./sub4 &&
+	test_tick &&
+
+	# absorb the git dir
+	git submodule absorbgitdirs sub4 &&
+
+	# make sure the submodule noted the superproject
+	test_cmp_config -C sub4 true --type=bool submodule.hasSuperproject
+	)
+'
+
+test_expect_success 'absorbgitdirs works with a submodule with worktree config' '
+	# reuse the worktree of the superproject
+	(
+	cd wt &&
+
+	# create a new unembedded git dir
+	git init sub5 &&
+	test_commit -C sub5 first &&
+	git submodule add ./sub5 &&
+	test_tick &&
+
+	# turn on worktree configs for submodule
+	git -C sub5 config extensions.worktreeConfig true &&
+
+	# absorb the git dir
+	git submodule absorbgitdirs sub5 &&
+
+	# make sure the submodule noted the superproject
+	test_cmp_config -C sub5 true --type=bool submodule.hasSuperproject
+	)
+'
+
 test_done
-- 
2.35.1.616.g0bdcbb4464-goog


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH v9 3/3] rev-parse: short-circuit superproject worktree when config unset
  2022-03-10  0:44     ` [PATCH v9 " Emily Shaffer
  2022-03-10  0:44       ` [PATCH v9 1/3] t7400-submodule-basic: modernize inspect() helper Emily Shaffer
  2022-03-10  0:44       ` [PATCH v9 2/3] introduce submodule.hasSuperproject record Emily Shaffer
@ 2022-03-10  0:44       ` Emily Shaffer
  2022-03-10  1:47         ` Junio C Hamano
  2022-03-11  9:09       ` [PATCH v9 0/3] teach submodules to know they're submodules Ævar Arnfjörð Bjarmason
  3 siblings, 1 reply; 64+ messages in thread
From: Emily Shaffer @ 2022-03-10  0:44 UTC (permalink / raw)
  To: git; +Cc: Emily Shaffer

In the previous commit, submodules learned a config
'submodule.hasSuperproject' to indicate whether or not we should attempt
to traverse the filesystem to find their superproject. To help test that
this config was added everywhere it should have been, begin using it to
decide whether to exit early from 'git rev-parse
--show-superproject-working-dir'. Because that command is fairly old,
only short-circuit if the new config was explicitly set to false.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
---
 submodule.c          | 18 ++++++++++++++++++
 t/t1500-rev-parse.sh | 10 +++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/submodule.c b/submodule.c
index aafbd628ad..64760f1e3a 100644
--- a/submodule.c
+++ b/submodule.c
@@ -2231,6 +2231,7 @@ int get_superproject_working_tree(struct strbuf *buf)
 	struct strbuf sb = STRBUF_INIT;
 	struct strbuf one_up = STRBUF_INIT;
 	const char *cwd = xgetcwd();
+	int has_superproject_cfg = 0;
 	int ret = 0;
 	const char *subpath;
 	int code;
@@ -2244,6 +2245,23 @@ int get_superproject_working_tree(struct strbuf *buf)
 		 */
 		return 0;
 
+	/*
+	 * Because get_superproject_working_tree() is older than
+	 * submodule.hasSuperproject, don't rely on the default "unset = false"
+	 * - instead, only rely on if submodule.hasSuperproject was explicitly
+	 * set to false.
+	 */
+	if (! git_config_get_bool("submodule.hassuperproject", &has_superproject_cfg)
+	    && !has_superproject_cfg) {
+		/*
+		 * If we don't have a superproject, then we're probably not a
+		 * submodule. If this is failing and shouldn't be, investigate
+		 * why the config was set to false.
+		 */
+		error(_("Asked to find a superproject, but submodule.hasSuperproject == false"));
+		return 0;
+	}
+
 	if (!strbuf_realpath(&one_up, "../", 0))
 		return 0;
 
diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh
index 1c2df08333..dd35036bd6 100755
--- a/t/t1500-rev-parse.sh
+++ b/t/t1500-rev-parse.sh
@@ -244,7 +244,15 @@ test_expect_success 'showing the superproject correctly' '
 	test_must_fail git -C super merge branch1 &&
 
 	git -C super/dir/sub rev-parse --show-superproject-working-tree >out &&
-	test_cmp expect out
+	test_cmp expect out &&
+
+	# When submodule.hasSuperproject=false, --show-superproject-working-tree
+	# should fail instead of checking the filesystem.
+	test_config -C super/dir/sub submodule.hasSuperproject false &&
+	git -C super/dir/sub rev-parse --show-superproject-working-tree >out &&
+	# --show-superproject-working-tree should print an error about the
+	# broken config
+	! grep "error:.*hasSuperproject" out
 '
 
 # at least one external project depends on this behavior:
-- 
2.35.1.616.g0bdcbb4464-goog


^ permalink raw reply related	[flat|nested] 64+ messages in thread

* Re: [PATCH v9 3/3] rev-parse: short-circuit superproject worktree when config unset
  2022-03-10  0:44       ` [PATCH v9 3/3] rev-parse: short-circuit superproject worktree when config unset Emily Shaffer
@ 2022-03-10  1:47         ` Junio C Hamano
  2022-03-10  4:39           ` Eric Sunshine
  0 siblings, 1 reply; 64+ messages in thread
From: Junio C Hamano @ 2022-03-10  1:47 UTC (permalink / raw)
  To: Emily Shaffer; +Cc: git

Emily Shaffer <emilyshaffer@google.com> writes:

> +	/*
> +	 * Because get_superproject_working_tree() is older than
> +	 * submodule.hasSuperproject, don't rely on the default "unset = false"
> +	 * - instead, only rely on if submodule.hasSuperproject was explicitly
> +	 * set to false.
> +	 */

That's a round-about way to say that submodule.hassuperproject
defaults to true, isn't it ;-)?

> +	if (! git_config_get_bool("submodule.hassuperproject", &has_superproject_cfg)
> +	    && !has_superproject_cfg) {
> +		/*
> +		 * If we don't have a superproject, then we're probably not a
> +		 * submodule. If this is failing and shouldn't be, investigate
> +		 * why the config was set to false.
> +		 */
> +		error(_("Asked to find a superproject, but submodule.hasSuperproject == false"));

s/Asked to/asked to/, probably.

> +		return 0;
> +	}
> +
>  	if (!strbuf_realpath(&one_up, "../", 0))
>  		return 0;
>  
> diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh
> index 1c2df08333..dd35036bd6 100755
> --- a/t/t1500-rev-parse.sh
> +++ b/t/t1500-rev-parse.sh
> @@ -244,7 +244,15 @@ test_expect_success 'showing the superproject correctly' '
>  	test_must_fail git -C super merge branch1 &&
>  
>  	git -C super/dir/sub rev-parse --show-superproject-working-tree >out &&
> -	test_cmp expect out
> +	test_cmp expect out &&
> +
> +	# When submodule.hasSuperproject=false, --show-superproject-working-tree
> +	# should fail instead of checking the filesystem.
> +	test_config -C super/dir/sub submodule.hasSuperproject false &&
> +	git -C super/dir/sub rev-parse --show-superproject-working-tree >out &&
> +	# --show-superproject-working-tree should print an error about the
> +	# broken config
> +	! grep "error:.*hasSuperproject" out
>  '
>  
>  # at least one external project depends on this behavior:

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v9 2/3] introduce submodule.hasSuperproject record
  2022-03-10  0:44       ` [PATCH v9 2/3] introduce submodule.hasSuperproject record Emily Shaffer
@ 2022-03-10  2:09         ` Junio C Hamano
  2022-03-10 21:29           ` Glen Choo
  2022-03-10 21:40           ` Glen Choo
  2022-03-10  2:32         ` Junio C Hamano
  2022-03-10 21:54         ` Glen Choo
  2 siblings, 2 replies; 64+ messages in thread
From: Junio C Hamano @ 2022-03-10  2:09 UTC (permalink / raw)
  To: Emily Shaffer; +Cc: git

Emily Shaffer <emilyshaffer@google.com> writes:

> @@ -2617,6 +2622,12 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
>  
>  	free(prefixed_path);
>  
> +	/*
> +	 * This entry point is always called from a submodule, so this is a
> +	 * good place to set a hint that this repo is a submodule.
> +	 */
> +	git_config_set("submodule.hasSuperproject", "true");
> +
>  	if (!oideq(&update_data.oid, &update_data.suboid) || update_data.force)
>  		return do_run_update_procedure(&update_data);

In Glen's update to rewrite "submodule update" in C, this part is
replaced with a call to update_submodule2().  I am not sure what the
current repository is at this point of the code with and without
Glen's topic, but are we sure we are in a submodule we discovered?

builtin/submodule--helper.c::run_update_procedure() takes sm_path to
the path to the submodule, presumably from superproject's point of
view, and the callchain leads to a call to run_update_command()
eventually, which uses run_command_v_opt_cd_env() to go in to the
submodule repository and run an external git command (like
"checkout"), so it looks like what git_config_set() updates is the
superprojects' configuration, not the configuration of a particular
submodule being updated.

The other one, where cmd_clone() sets the variable in submodule's
configuration file, looks good, but I am not sure about this one.

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v9 2/3] introduce submodule.hasSuperproject record
  2022-03-10  0:44       ` [PATCH v9 2/3] introduce submodule.hasSuperproject record Emily Shaffer
  2022-03-10  2:09         ` Junio C Hamano
@ 2022-03-10  2:32         ` Junio C Hamano
  2022-03-10 21:54         ` Glen Choo
  2 siblings, 0 replies; 64+ messages in thread
From: Junio C Hamano @ 2022-03-10  2:32 UTC (permalink / raw)
  To: Emily Shaffer; +Cc: git

Emily Shaffer <emilyshaffer@google.com> writes:

> +test_expect_success 'submodule update adds submodule.hasSuperproject to older repos' '
> +	(cd super &&
> +	 test_unconfig submodule.hasSuperproject &&

So, before we run the test, we unconfig the variable in the SUPER
repository, and then

> +	 git submodule update &&

update the submodule, and then

> +	 test_cmp_config -C submodule true --type=bool submodule.hasSuperproject

go in to the submodule and check the value of the variable?

Shouldn't the first part be more like

	(cd super &&
	 test_unconfig -C submodule submodule.hasSuperproject &&

if we want to make sure "submodule update" sets it there?

> +	)
> +'

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v9 3/3] rev-parse: short-circuit superproject worktree when config unset
  2022-03-10  1:47         ` Junio C Hamano
@ 2022-03-10  4:39           ` Eric Sunshine
  0 siblings, 0 replies; 64+ messages in thread
From: Eric Sunshine @ 2022-03-10  4:39 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Emily Shaffer, Git List

On Wed, Mar 9, 2022 at 10:57 PM Junio C Hamano <gitster@pobox.com> wrote:
> Emily Shaffer <emilyshaffer@google.com> writes:
> > +             error(_("Asked to find a superproject, but submodule.hasSuperproject == false"));
>
> s/Asked to/asked to/, probably.

This is a user-facing error message, not just a programmer-facing
message, correct? If so, then perhaps: s/==/is/

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v9 2/3] introduce submodule.hasSuperproject record
  2022-03-10  2:09         ` Junio C Hamano
@ 2022-03-10 21:29           ` Glen Choo
  2022-03-10 21:40           ` Glen Choo
  1 sibling, 0 replies; 64+ messages in thread
From: Glen Choo @ 2022-03-10 21:29 UTC (permalink / raw)
  To: Junio C Hamano, Emily Shaffer; +Cc: git

Junio C Hamano <gitster@pobox.com> writes:

> Emily Shaffer <emilyshaffer@google.com> writes:
>
>> @@ -2617,6 +2622,12 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
>>  
>>  	free(prefixed_path);
>>  
>> +	/*
>> +	 * This entry point is always called from a submodule, so this is a
>> +	 * good place to set a hint that this repo is a submodule.
>> +	 */
>> +	git_config_set("submodule.hasSuperproject", "true");
>> +
>>  	if (!oideq(&update_data.oid, &update_data.suboid) || update_data.force)
>>  		return do_run_update_procedure(&update_data);
>
> In Glen's update to rewrite "submodule update" in C, this part is
> replaced with a call to update_submodule2().  I am not sure what the
> current repository is at this point of the code with and without
> Glen's topic, but are we sure we are in a submodule we discovered?

With my topic, this call would be moved into update_submodule2(). The
repository at that point is the superproject.

> builtin/submodule--helper.c::run_update_procedure() takes sm_path to
> the path to the submodule, presumably from superproject's point of
> view, and the callchain leads to a call to run_update_command()
> eventually, which uses run_command_v_opt_cd_env() to go in to the
> submodule repository and run an external git command (like
> "checkout"), so it looks like what git_config_set() updates is the
> superprojects' configuration, not the configuration of a particular
> submodule being updated.
>
> The other one, where cmd_clone() sets the variable in submodule's
> configuration file, looks good, but I am not sure about this one.

But in this series, the current repository is the submodule because this
part happens in a "run-update-procedure" child process.

So there is a slight conflict here, but the conflict existed even before
this change (we used to do this twice in git-submodule.sh and
module_clone()).

Because of that conflict, I was planning to base "part2" on this series
anyway, and if anything, this change makes the conflict better because
we now set "submodule.hasSuperproject" in only one place
(run_update_procedure()) instead of two.

So I think this change improves this series and improves the interaction
with mine.

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v9 2/3] introduce submodule.hasSuperproject record
  2022-03-10  2:09         ` Junio C Hamano
  2022-03-10 21:29           ` Glen Choo
@ 2022-03-10 21:40           ` Glen Choo
  2022-03-10 22:10             ` Junio C Hamano
  1 sibling, 1 reply; 64+ messages in thread
From: Glen Choo @ 2022-03-10 21:40 UTC (permalink / raw)
  To: Junio C Hamano, Emily Shaffer; +Cc: git

Junio C Hamano <gitster@pobox.com> writes:

> Emily Shaffer <emilyshaffer@google.com> writes:
>
>> @@ -2617,6 +2622,12 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
>>  
>>  	free(prefixed_path);
>>  
>> +	/*
>> +	 * This entry point is always called from a submodule, so this is a
>> +	 * good place to set a hint that this repo is a submodule.
>> +	 */
>> +	git_config_set("submodule.hasSuperproject", "true");
>> +
>>  	if (!oideq(&update_data.oid, &update_data.suboid) || update_data.force)
>>  		return do_run_update_procedure(&update_data);
>
> In Glen's update to rewrite "submodule update" in C, this part is
> replaced with a call to update_submodule2().  I am not sure what the
> current repository is at this point of the code with and without
> Glen's topic, but are we sure we are in a submodule we discovered?

Rereading this, I realize you probably meant that this conflicts with
part1, not part2...

At the end of part1, update_submodule2() is called from inside the
submodule (specifically from run_update_procedure()). So a good merge
conflict resolution would be to set the config _before_ calling
update_submodule2(). e.g.

----- >8 --------- >8 --------- >8 --------- >8 --------- >8 ----
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index bef9ab22d4..f53808d995 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -2672,6 +2677,11 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
                                            &update_data.update_strategy);

        free(prefixed_path);
+       /*
+        * This entry point is always called from a submodule, so this is a
+        * good place to set a hint that this repo is a submodule.
+        */
+       git_config_set("submodule.hasSuperproject", "true");
        return update_submodule2(&update_data);
 }

^ permalink raw reply related	[flat|nested] 64+ messages in thread

* Re: [PATCH v9 2/3] introduce submodule.hasSuperproject record
  2022-03-10  0:44       ` [PATCH v9 2/3] introduce submodule.hasSuperproject record Emily Shaffer
  2022-03-10  2:09         ` Junio C Hamano
  2022-03-10  2:32         ` Junio C Hamano
@ 2022-03-10 21:54         ` Glen Choo
  2022-03-15 18:27           ` Emily Shaffer
  2 siblings, 1 reply; 64+ messages in thread
From: Glen Choo @ 2022-03-10 21:54 UTC (permalink / raw)
  To: Emily Shaffer, git; +Cc: Emily Shaffer, Junio C Hamano

Emily Shaffer <emilyshaffer@google.com> writes:

> diff --git a/Documentation/config/submodule.txt b/Documentation/config/submodule.txt
> index ee454f8126..99d5260b8e 100644
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index c5d3fc3817..eda9ed550e 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -1839,6 +1839,11 @@ static int clone_submodule(struct module_clone_data *clone_data)
>  		git_config_set_in_file(p, "submodule.alternateErrorStrategy",
>  				       error_strategy);
>  
> +	/*
> +	 * Teach the submodule that it's a submodule.
> +	 */
> +	git_config_set_in_file(p, "submodule.hasSuperproject", "true");
> +
>  	free(sm_alternate);
>  	free(error_strategy);

This git_config_set_* is superfluous - it sets the config in newly
cloned submodules..

>  
> @@ -2617,6 +2622,12 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
>  
>  	free(prefixed_path);
>  
> +	/*
> +	 * This entry point is always called from a submodule, so this is a
> +	 * good place to set a hint that this repo is a submodule.
> +	 */
> +	git_config_set("submodule.hasSuperproject", "true");
> +
>  	if (!oideq(&update_data.oid, &update_data.suboid) || update_data.force)
>  		return do_run_update_procedure(&update_data);
>  

but this is called over *all* submodules, so we're guaranteed to always
set the config if "git submodule update" isn't interrupted halfway.

I don't think we guarantee correctness if it is interrupted halfway e.g.
core.worktree can be unset if it is interrupted halfway (because
ensure-core-worktree is called adjacent to run-update-procedure, not
inside of update-clone).

So I think it's better to just drop the previous hunk - it will
disappear anyway in gc/submodule-update-part2.

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v9 2/3] introduce submodule.hasSuperproject record
  2022-03-10 21:40           ` Glen Choo
@ 2022-03-10 22:10             ` Junio C Hamano
  2022-03-10 23:42               ` Glen Choo
  2022-03-15 18:39               ` Emily Shaffer
  0 siblings, 2 replies; 64+ messages in thread
From: Junio C Hamano @ 2022-03-10 22:10 UTC (permalink / raw)
  To: Glen Choo; +Cc: Emily Shaffer, git

Glen Choo <chooglen@google.com> writes:

> Junio C Hamano <gitster@pobox.com> writes:
>
>> Emily Shaffer <emilyshaffer@google.com> writes:
>>
>>> @@ -2617,6 +2622,12 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
>>>  
>>>  	free(prefixed_path);
>>>  
>>> +	/*
>>> +	 * This entry point is always called from a submodule, so this is a
>>> +	 * good place to set a hint that this repo is a submodule.
>>> +	 */
>>> +	git_config_set("submodule.hasSuperproject", "true");
>>> +
>>>  	if (!oideq(&update_data.oid, &update_data.suboid) || update_data.force)
>>>  		return do_run_update_procedure(&update_data);
>>
>> In Glen's update to rewrite "submodule update" in C, this part is
>> replaced with a call to update_submodule2().  I am not sure what the
>> current repository is at this point of the code with and without
>> Glen's topic, but are we sure we are in a submodule we discovered?
>
> Rereading this, I realize you probably meant that this conflicts with
> part1, not part2...
>
> At the end of part1, update_submodule2() is called from inside the
> submodule (specifically from run_update_procedure()). So a good merge
> conflict resolution would be to set the config _before_ calling
> update_submodule2(). e.g.
>
> ----- >8 --------- >8 --------- >8 --------- >8 --------- >8 ----
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index bef9ab22d4..f53808d995 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -2672,6 +2677,11 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
>                                             &update_data.update_strategy);
>
>         free(prefixed_path);
> +       /*
> +        * This entry point is always called from a submodule, so this is a
> +        * good place to set a hint that this repo is a submodule.
> +        */
> +       git_config_set("submodule.hasSuperproject", "true");
>         return update_submodule2(&update_data);
>  }

That matched my tentative resolution I made last night, but what do
you think about this part of the test added by the patch?

diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 11cccbb333..ec2397fc69 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -1061,4 +1061,12 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s
 	)
 '
 
+test_expect_success 'submodule update adds submodule.hasSuperproject to older repos' '
+	(cd super &&
+	 test_unconfig submodule.hasSuperproject &&
+	 git submodule update &&
+	 test_cmp_config -C submodule true --type=bool submodule.hasSuperproject
+	)
+'
+
 test_done

We go to "super", make sure that superproject does not have
submodule.hasSuperproject set, run "git submodule update", and see
if the configuration file in "submodule" subdirectory has the
variable set.  It does not clear the variable from the submodule
before starting, so the variable given to the submodule when it was
cloned would be there, even if "git submodule update" failed to set
it.

I am wondering if it should do something like the attached instead.

We

 * clear the variable from "super" and "super/submodule"
   repositories;

 * run "git submodule update";

 * ensure that "git submodule update" did not touch "super/.git/config";

 * ensure that "git submodule update" added the variable to
   "super/submodule/.git/config".

Clearing the variable from "super" is technically wrong because the
repository is set up as a submodule of "recursivesuper" and if we
had further tests, we should restore it in "super", but the point is
that we are makng sure "git submodule update" sets the variable in
the configuration file of the submodule, and not in the superproject's. 

With the conflict resolution above, this "corrected" test fails and
shows that superproject's configuration file is updated after "git
submodule update".

This series alone, without your topic, this "corrected" test fails,
and that is where my "are we sure we are mucking with the
configuration file in the submodule"? comes from.

diff --git c/t/t7406-submodule-update.sh w/t/t7406-submodule-update.sh
index 000e055811..c9912bb242 100755
--- c/t/t7406-submodule-update.sh
+++ w/t/t7406-submodule-update.sh
@@ -1083,4 +1083,16 @@ test_expect_success 'submodule update --filter sets partial clone settings' '
 	test_cmp_config -C super-filter/submodule blob:none remote.origin.partialclonefilter
 '
 
+test_expect_success 'submodule update adds submodule.hasSuperproject to older repos' '
+	(cd super &&
+	 test_unconfig submodule.hasSuperproject &&
+	 test_unconfig -C submodule submodule.hasSuperproject &&
+	 git submodule update &&
+	 echo in super &&
+	 test_cmp_config false --type=bool submodule.hasSuperproject &&
+	 echo in submodule &&
+	 test_cmp_config -C submodule true --type=bool submodule.hasSuperproject
+	)
+'
+
 test_done

^ permalink raw reply related	[flat|nested] 64+ messages in thread

* Re: [PATCH v9 2/3] introduce submodule.hasSuperproject record
  2022-03-10 22:10             ` Junio C Hamano
@ 2022-03-10 23:42               ` Glen Choo
  2022-03-10 23:53                 ` Glen Choo
  2022-03-15 18:39               ` Emily Shaffer
  1 sibling, 1 reply; 64+ messages in thread
From: Glen Choo @ 2022-03-10 23:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Emily Shaffer, git

Junio C Hamano <gitster@pobox.com> writes:

>> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
>> index bef9ab22d4..f53808d995 100644
>> --- a/builtin/submodule--helper.c
>> +++ b/builtin/submodule--helper.c
>> @@ -2672,6 +2677,11 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
>>                                             &update_data.update_strategy);
>>
>>         free(prefixed_path);
>> +       /*
>> +        * This entry point is always called from a submodule, so this is a
>> +        * good place to set a hint that this repo is a submodule.
>> +        */
>> +       git_config_set("submodule.hasSuperproject", "true");
>>         return update_submodule2(&update_data);
>>  }
>
> That matched my tentative resolution I made last night, but what do
> you think about this part of the test added by the patch?
>
> diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
> index 11cccbb333..ec2397fc69 100755
> --- a/t/t7406-submodule-update.sh
> +++ b/t/t7406-submodule-update.sh
> @@ -1061,4 +1061,12 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s
>  	)
>  '
>  
> +test_expect_success 'submodule update adds submodule.hasSuperproject to older repos' '
> +	(cd super &&
> +	 test_unconfig submodule.hasSuperproject &&
> +	 git submodule update &&
> +	 test_cmp_config -C submodule true --type=bool submodule.hasSuperproject
> +	)
> +'
> +
>  test_done
>
> We go to "super", make sure that superproject does not have
> submodule.hasSuperproject set, run "git submodule update", and see
> if the configuration file in "submodule" subdirectory has the
> variable set.  It does not clear the variable from the submodule
> before starting, so the variable given to the submodule when it was
> cloned would be there, even if "git submodule update" failed to set
> it.
>
> I am wondering if it should do something like the attached instead.
>
> We
>
>  * clear the variable from "super" and "super/submodule"
>    repositories;
>
>  * run "git submodule update";
>
>  * ensure that "git submodule update" did not touch "super/.git/config";
>
>  * ensure that "git submodule update" added the variable to
>    "super/submodule/.git/config".
>
> Clearing the variable from "super" is technically wrong because the
> repository is set up as a submodule of "recursivesuper" and if we
> had further tests, we should restore it in "super", but the point is
> that we are makng sure "git submodule update" sets the variable in
> the configuration file of the submodule, and not in the superproject's. 

Yes, the test you've described is closer to what I thought the original
test was trying to do. Seeing this test pass gave me a false sense of
confidence hm..

> With the conflict resolution above, this "corrected" test fails and
> shows that superproject's configuration file is updated after "git
> submodule update".
>
> This series alone, without your topic, this "corrected" test fails,
> and that is where my "are we sure we are mucking with the
> configuration file in the submodule"? comes from.

Yeah looks like we aren't in the submodule after all:

		out=$(git submodule--helper run-update-procedure \
			  ${wt_prefix:+--prefix "$wt_prefix"} \
			  ${GIT_QUIET:+--quiet} \
			  ${force:+--force} \
			  ${just_cloned:+--just-cloned} \
			  ${nofetch:+--no-fetch} \
			  ${depth:+"$depth"} \
			  ${update:+--update "$update"} \
			  ${prefix:+--recursive-prefix "$prefix"} \
			  ${sha1:+--oid "$sha1"} \
			  ${subsha1:+--suboid "$subsha1"} \
			  "--" \
			  "$sm_path")

This says "do the update at this submodule path", but this is being run
from the superproject.

So I suppose the way forward is one of the following:

- Revert my original suggestion
- Revert my original suggestion AND remove the git_config_set from
  "module_clone()" (before this, we unconditionally set this value in
  git-submodule.sh anyway)
- Set the config in the submodule even though we are running from the
  superproject (this is possible, ensure_core_worktree() does this).

In any case, sorry for the faulty suggestion :(

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v9 2/3] introduce submodule.hasSuperproject record
  2022-03-10 23:42               ` Glen Choo
@ 2022-03-10 23:53                 ` Glen Choo
  2022-03-15 20:48                   ` Emily Shaffer
  0 siblings, 1 reply; 64+ messages in thread
From: Glen Choo @ 2022-03-10 23:53 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Emily Shaffer, git

Glen Choo <chooglen@google.com> writes:

> Junio C Hamano <gitster@pobox.com> writes:
>
>>> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
>>> index bef9ab22d4..f53808d995 100644
>>> --- a/builtin/submodule--helper.c
>>> +++ b/builtin/submodule--helper.c
>>> @@ -2672,6 +2677,11 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
>>>                                             &update_data.update_strategy);
>>>
>>>         free(prefixed_path);
>>> +       /*
>>> +        * This entry point is always called from a submodule, so this is a
>>> +        * good place to set a hint that this repo is a submodule.
>>> +        */
>>> +       git_config_set("submodule.hasSuperproject", "true");
>>>         return update_submodule2(&update_data);
>>>  }
>>
>> That matched my tentative resolution I made last night, but what do
>> you think about this part of the test added by the patch?
>>
>> diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
>> index 11cccbb333..ec2397fc69 100755
>> --- a/t/t7406-submodule-update.sh
>> +++ b/t/t7406-submodule-update.sh
>> @@ -1061,4 +1061,12 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s
>>  	)
>>  '
>>  
>> +test_expect_success 'submodule update adds submodule.hasSuperproject to older repos' '
>> +	(cd super &&
>> +	 test_unconfig submodule.hasSuperproject &&
>> +	 git submodule update &&
>> +	 test_cmp_config -C submodule true --type=bool submodule.hasSuperproject
>> +	)
>> +'
>> +
>>  test_done
>>
>> We go to "super", make sure that superproject does not have
>> submodule.hasSuperproject set, run "git submodule update", and see
>> if the configuration file in "submodule" subdirectory has the
>> variable set.  It does not clear the variable from the submodule
>> before starting, so the variable given to the submodule when it was
>> cloned would be there, even if "git submodule update" failed to set
>> it.
>>
>> I am wondering if it should do something like the attached instead.
>>
>> We
>>
>>  * clear the variable from "super" and "super/submodule"
>>    repositories;
>>
>>  * run "git submodule update";
>>
>>  * ensure that "git submodule update" did not touch "super/.git/config";
>>
>>  * ensure that "git submodule update" added the variable to
>>    "super/submodule/.git/config".
>>
>> Clearing the variable from "super" is technically wrong because the
>> repository is set up as a submodule of "recursivesuper" and if we
>> had further tests, we should restore it in "super", but the point is
>> that we are makng sure "git submodule update" sets the variable in
>> the configuration file of the submodule, and not in the superproject's. 
>
> Yes, the test you've described is closer to what I thought the original
> test was trying to do. Seeing this test pass gave me a false sense of
> confidence hm..

Correction, seeing the _original_ test pass gave me false sense of
confidence.

>> With the conflict resolution above, this "corrected" test fails and
>> shows that superproject's configuration file is updated after "git
>> submodule update".
>>
>> This series alone, without your topic, this "corrected" test fails,
>> and that is where my "are we sure we are mucking with the
>> configuration file in the submodule"? comes from.
> - Set the config in the submodule even though we are running from the
>   superproject (this is possible, ensure_core_worktree() does this).

If it helps, I was able to do this up by copying
ensure_core_worktree(), and this passes the amended test.

----- >8 --------- >8 --------- >8 --------- >8 --------- >8 ----

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 4d02dd05ca..3bb7a65762 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1838,11 +1838,6 @@ static int clone_submodule(struct module_clone_data *clone_data)
    git_config_set_in_file(p, "submodule.alternateErrorStrategy",
              error_strategy);

-	/*
-	 * Teach the submodule that it's a submodule.
-	 */
-	git_config_set_in_file(p, "submodule.hasSuperproject", "true");
-
  free(sm_alternate);
  free(error_strategy);

@@ -2560,6 +2555,20 @@ static int update_clone(int argc, const char **argv, const char *prefix)
  return update_submodules(&suc);
}

+static void set_hassuperproject(const char *sm_path)
+{
+	struct repository subrepo;
+	char *cfg_file;
+
+	if (repo_submodule_init(&subrepo, the_repository, sm_path, null_oid()))
+		die(_("could not get a repository handle for submodule '%s'"), sm_path);
+
+	cfg_file = repo_git_path(&subrepo, "config");
+	git_config_set_in_file(cfg_file, "submodule.hasSuperproject", "true");
+
+	free(cfg_file);
+}
+
static int run_update_procedure(int argc, const char **argv, const char *prefix)
{
  int force = 0, quiet = 0, nofetch = 0, just_cloned = 0;
@@ -2622,10 +2631,9 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
  free(prefixed_path);

  /*
-	 * This entry point is always called from a submodule, so this is a
-	 * good place to set a hint that this repo is a submodule.
+	 * Teach the submodule that it's a submodule.
  */
-	git_config_set("submodule.hasSuperproject", "true");
+	set_hassuperproject(update_data.sm_path);

  if (!oideq(&update_data.oid, &update_data.suboid) || update_data.force)
    return do_run_update_procedure(&update_data);

^ permalink raw reply related	[flat|nested] 64+ messages in thread

* Re: [PATCH v9 0/3] teach submodules to know they're submodules
  2022-03-10  0:44     ` [PATCH v9 " Emily Shaffer
                         ` (2 preceding siblings ...)
  2022-03-10  0:44       ` [PATCH v9 3/3] rev-parse: short-circuit superproject worktree when config unset Emily Shaffer
@ 2022-03-11  9:09       ` Ævar Arnfjörð Bjarmason
  2022-03-13  5:43         ` Junio C Hamano
  3 siblings, 1 reply; 64+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-03-11  9:09 UTC (permalink / raw)
  To: Emily Shaffer
  Cc: git, Albert Cui, Phillip Wood, Johannes Schindelin,
	Junio C Hamano, Matheus Tavares Bernardino, Jonathan Nieder,
	Jacob Keller, Atharva Raykar, Derrick Stolee, Jonathan Tan,
	Glen Choo


On Wed, Mar 09 2022, Emily Shaffer wrote:

> For the original cover letter, see
> https://lore.kernel.org/git/20210611225428.1208973-1-emilyshaffer%40google.com.
>
> CI run: https://github.com/nasamuffin/git/actions/runs/1954710601
>
> Since v8:
>
> Only a couple of minor fixes.
>
> Junio pointed out that I could write the tests better using --type=bool
> and 'test_cmp_config', and that we could be a little more careful about
> when to give up on 'git rev-parse --show-superproject-working-dir'.
>
> Glen mentioned that builtin/submodule--helper.c:run_update_procedure() is called
> unconditionally earlier in the same function where I had added the
> config in git-submodule.sh. So, I moved the config set into
> submodule--helper.c to reduce possible edge cases where the config might
> not be set.
>
> Otherwise, this series is pretty much unchanged.
>
> Since v7:
>
> Actually a fairly large rework. Rather than keeping the path from gitdir
> to gitdir, just keep a boolean under 'submodule.hasSuperproject'. The
> idea is that from this boolean, we can decide whether to traverse the
> filesystem looking for a superproject.
>
> Because this simplifies the implementation, I compressed the three
> middle commits into one. As proof-of-concept, I added a patch at the end
> to check for this boolean when running `git rev-parse
> --show-superproject-working-tree`.
>
> One thing I'm not sure about: in the tests, I check whether the config
> is set, but not what the boolean value of it is. Is there a better way
> to do that? For example, I could imagine someone deciding to set
> `submodule.hasSuperproject = false` and the tests would not function
> correctly in that case. I think we don't really normalize the value on a
> boolean config like that, so I didn't want to write a lot of comparison
> to check if the value is 1 or true or True or TRUE or Yes or .... Am I
> overthinking it?
>
> The other thing I'm not sure about: since it's just a bool, we're not
> restricted to setting this config only when we have both gitdir paths
> available. That makes me want to set the config any time we are doing
> something with submodules anyway, like any time 'git-submodule--helper'
> is used. But that helper seems to be called in the context of the
> superproject, not of the submodules, so adding this config for each
> submodule we touch would be a second child process. Is there some other
> common entry point for submodules that we can use?

I really don't mean to bring up the same points again, but I'm still
genuinely unsure what this is intended to solve in the end.

I.e. from the original RFC we went from it being for optimizations for
the shellscript "git rev-parse", to suggestions that the configured path
would be "canonical" in a way we couldn't discover on-the-fly (i.e. some
of Jonathan's noted edge cases [1]).

But now it's a boolean indicating "it's there, discover it", and the
implied (but not really explicitly stated) reason in 2/3 is that it's
purely for optimization purposes at this point.

But it's an optimization without a benchmark.

In [1] Jonathan (if I understood it correctly, see [2]) might have
suggested this is important to deal with some Google in-house NFS-a-like
auto-mounting software, i.e. the "walking up" is truly expensive in some
scenarios.

I do worry a bit that we'll be creating behavior edge cases related to
this, and if the problem being solved is for a relatively obscure setup
is it worth it, and in that case perhaps there should be a "I need this
optimization" setting guarding it?

But I don't know, a concrete case where this series makes a difference
would really help.

I tried to come up with one before[3] and all I could find was fleeting
cases we'd see go away with the migration of the remaining parts of
git-submodule.sh to C, which we already have in-flight patches for (or
rather, Glen is AFAIK at series 1/2 of submitting those, with 1/2
in-flight).

In any case I think lifting the bits of [3] where we assert that this
doesn't introduce any behavior change with a GIT_TEST_* knob would be
valuable.

I.e. as long a the intent isn't a behavior change let's test that
get_superproject_working_tree() doesn't need this across the entire test
suite, with specific tests that opt-in to the behavior (or do a whole
test suite run in that mode), rather than the default being
opt-out.

An opt-out is just a recipe for growing accidental implicit
dependencies, which explicitly isn't what we want for a "just an
optimization" knob. We do the same sort of opt-in/out-out testing for
e.g. split index, untracked cache etc (see the GIT_TEST_* bits in
ci/run-build-and-tests.sh). AFAICT a fix-up of just adding the
git_env_bool() here to this code in your 3/3 would do it:

	if (!git_env_bool("GIT_TEST_NO_SUBMODULE_HAS_SUPERPROJECT", 0) &&
	    !git_config_get_bool("submodule.hassuperproject", &has_superproject_cfg)
	    && !has_superproject_cfg)

And then adding GIT_TEST_NO_SUBMODULE_HAS_SUPERPROJECT=true to
linux-TEST-vars in ci/run-build-and-tests.sh. The tests that do rely on
submodule.hassuperproject would need to set
GIT_TEST_NO_SUBMODULE_HAS_SUPERPROJECT=false of course...

1. https://lore.kernel.org/git/YgF5V2Y0Btr8B4cd@google.com/
2. https://lore.kernel.org/git/220212.864k53yfws.gmgdl@evledraar.gmail.com/
3. https://lore.kernel.org/git/RFC-cover-0.2-00000000000-20211117T113134Z-avarab@gmail.com/

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v9 0/3] teach submodules to know they're submodules
  2022-03-11  9:09       ` [PATCH v9 0/3] teach submodules to know they're submodules Ævar Arnfjörð Bjarmason
@ 2022-03-13  5:43         ` Junio C Hamano
  0 siblings, 0 replies; 64+ messages in thread
From: Junio C Hamano @ 2022-03-13  5:43 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Emily Shaffer, git, Albert Cui, Phillip Wood, Johannes Schindelin,
	Matheus Tavares Bernardino, Jonathan Nieder, Jacob Keller,
	Atharva Raykar, Derrick Stolee, Jonathan Tan, Glen Choo

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> But now it's a boolean indicating "it's there, discover it", and the
> implied (but not really explicitly stated) reason in 2/3 is that it's
> purely for optimization purposes at this point.

You may know that I have a separate checkout of the 'todo' branch at
path "Meta" in my working tree.

I could use the hasSuperproject=false setting there, to say "this is
*NOT* a submodule, even the parent directory is a working tree of a
different repository, it is not our superproject, so do *NOT* bother
to go up to discover anything".

If that configuration weren't there in the "Meta/.git/config", the
parent directory of "Meta" (which has its own ".git") cannot tell if
that "Meta" thing is a submodule being prepared that hasn't been
added yet, or it will never intended to be a submodule.  I would
imagine that "git add X" can later be taught to refuse to add X if
there is X/.git and X/.git/config says it explicitly says that it
does not have a superproject.

So, I am not sure if it is a good characterization that it is for
optimization at all.

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v9 2/3] introduce submodule.hasSuperproject record
  2022-03-10 21:54         ` Glen Choo
@ 2022-03-15 18:27           ` Emily Shaffer
  0 siblings, 0 replies; 64+ messages in thread
From: Emily Shaffer @ 2022-03-15 18:27 UTC (permalink / raw)
  To: Glen Choo; +Cc: git, Junio C Hamano

On Thu, Mar 10, 2022 at 01:54:12PM -0800, Glen Choo wrote:
> 
> Emily Shaffer <emilyshaffer@google.com> writes:
> 
> > diff --git a/Documentation/config/submodule.txt b/Documentation/config/submodule.txt
> > index ee454f8126..99d5260b8e 100644
> > diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> > index c5d3fc3817..eda9ed550e 100644
> > --- a/builtin/submodule--helper.c
> > +++ b/builtin/submodule--helper.c
> > @@ -1839,6 +1839,11 @@ static int clone_submodule(struct module_clone_data *clone_data)
> >  		git_config_set_in_file(p, "submodule.alternateErrorStrategy",
> >  				       error_strategy);
> >  
> > +	/*
> > +	 * Teach the submodule that it's a submodule.
> > +	 */
> > +	git_config_set_in_file(p, "submodule.hasSuperproject", "true");
> > +
> >  	free(sm_alternate);
> >  	free(error_strategy);
> 
> This git_config_set_* is superfluous - it sets the config in newly
> cloned submodules..
> 
> >  
> > @@ -2617,6 +2622,12 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
> >  
> >  	free(prefixed_path);
> >  
> > +	/*
> > +	 * This entry point is always called from a submodule, so this is a
> > +	 * good place to set a hint that this repo is a submodule.
> > +	 */
> > +	git_config_set("submodule.hasSuperproject", "true");
> > +
> >  	if (!oideq(&update_data.oid, &update_data.suboid) || update_data.force)
> >  		return do_run_update_procedure(&update_data);
> >  
> 
> but this is called over *all* submodules, so we're guaranteed to always
> set the config if "git submodule update" isn't interrupted halfway.
> 
> I don't think we guarantee correctness if it is interrupted halfway e.g.
> core.worktree can be unset if it is interrupted halfway (because
> ensure-core-worktree is called adjacent to run-update-procedure, not
> inside of update-clone).
> 
> So I think it's better to just drop the previous hunk - it will
> disappear anyway in gc/submodule-update-part2.

Ah, this makes sense. Sure, will do.

 - Emily


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v9 2/3] introduce submodule.hasSuperproject record
  2022-03-10 22:10             ` Junio C Hamano
  2022-03-10 23:42               ` Glen Choo
@ 2022-03-15 18:39               ` Emily Shaffer
  2022-03-15 19:19                 ` Junio C Hamano
  1 sibling, 1 reply; 64+ messages in thread
From: Emily Shaffer @ 2022-03-15 18:39 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Glen Choo, git

On Thu, Mar 10, 2022 at 02:10:55PM -0800, Junio C Hamano wrote:
> 
> Glen Choo <chooglen@google.com> writes:
> 
> > Junio C Hamano <gitster@pobox.com> writes:
> >
> >> Emily Shaffer <emilyshaffer@google.com> writes:
> >>
> >>> @@ -2617,6 +2622,12 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
> >>>  
> >>>  	free(prefixed_path);
> >>>  
> >>> +	/*
> >>> +	 * This entry point is always called from a submodule, so this is a
> >>> +	 * good place to set a hint that this repo is a submodule.
> >>> +	 */
> >>> +	git_config_set("submodule.hasSuperproject", "true");
> >>> +
> >>>  	if (!oideq(&update_data.oid, &update_data.suboid) || update_data.force)
> >>>  		return do_run_update_procedure(&update_data);
> >>
> >> In Glen's update to rewrite "submodule update" in C, this part is
> >> replaced with a call to update_submodule2().  I am not sure what the
> >> current repository is at this point of the code with and without
> >> Glen's topic, but are we sure we are in a submodule we discovered?
> >
> > Rereading this, I realize you probably meant that this conflicts with
> > part1, not part2...
> >
> > At the end of part1, update_submodule2() is called from inside the
> > submodule (specifically from run_update_procedure()). So a good merge
> > conflict resolution would be to set the config _before_ calling
> > update_submodule2(). e.g.
> >
> > ----- >8 --------- >8 --------- >8 --------- >8 --------- >8 ----
> > diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> > index bef9ab22d4..f53808d995 100644
> > --- a/builtin/submodule--helper.c
> > +++ b/builtin/submodule--helper.c
> > @@ -2672,6 +2677,11 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
> >                                             &update_data.update_strategy);
> >
> >         free(prefixed_path);
> > +       /*
> > +        * This entry point is always called from a submodule, so this is a
> > +        * good place to set a hint that this repo is a submodule.
> > +        */
> > +       git_config_set("submodule.hasSuperproject", "true");
> >         return update_submodule2(&update_data);
> >  }
> 
> That matched my tentative resolution I made last night, but what do
> you think about this part of the test added by the patch?
> 
> diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
> index 11cccbb333..ec2397fc69 100755
> --- a/t/t7406-submodule-update.sh
> +++ b/t/t7406-submodule-update.sh
> @@ -1061,4 +1061,12 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s
>  	)
>  '
>  
> +test_expect_success 'submodule update adds submodule.hasSuperproject to older repos' '
> +	(cd super &&
> +	 test_unconfig submodule.hasSuperproject &&
> +	 git submodule update &&
> +	 test_cmp_config -C submodule true --type=bool submodule.hasSuperproject
> +	)
> +'
> +
>  test_done
> 
> We go to "super", make sure that superproject does not have
> submodule.hasSuperproject set, run "git submodule update", and see
> if the configuration file in "submodule" subdirectory has the
> variable set.  It does not clear the variable from the submodule
> before starting, so the variable given to the submodule when it was
> cloned would be there, even if "git submodule update" failed to set
> it.
> 
> I am wondering if it should do something like the attached instead.
> 
> We
> 
>  * clear the variable from "super" and "super/submodule"
>    repositories;
> 
>  * run "git submodule update";
> 
>  * ensure that "git submodule update" did not touch "super/.git/config";

Yeah, this is a good idea, and indeed when I add this step the bug
pointed out downthread becomes clear. Thanks.

> 
>  * ensure that "git submodule update" added the variable to
>    "super/submodule/.git/config".
> 
> Clearing the variable from "super" is technically wrong because the
> repository is set up as a submodule of "recursivesuper" and if we
> had further tests, we should restore it in "super", but the point is
> that we are makng sure "git submodule update" sets the variable in
> the configuration file of the submodule, and not in the superproject's. 
> 
> With the conflict resolution above, this "corrected" test fails and
> shows that superproject's configuration file is updated after "git
> submodule update".
> 
> This series alone, without your topic, this "corrected" test fails,
> and that is where my "are we sure we are mucking with the
> configuration file in the submodule"? comes from.
> 
> diff --git c/t/t7406-submodule-update.sh w/t/t7406-submodule-update.sh
> index 000e055811..c9912bb242 100755
> --- c/t/t7406-submodule-update.sh
> +++ w/t/t7406-submodule-update.sh
> @@ -1083,4 +1083,16 @@ test_expect_success 'submodule update --filter sets partial clone settings' '
>  	test_cmp_config -C super-filter/submodule blob:none remote.origin.partialclonefilter
>  '
>  
> +test_expect_success 'submodule update adds submodule.hasSuperproject to older repos' '
> +	(cd super &&
> +	 test_unconfig submodule.hasSuperproject &&
> +	 test_unconfig -C submodule submodule.hasSuperproject &&
> +	 git submodule update &&
> +	 echo in super &&
> +	 test_cmp_config false --type=bool submodule.hasSuperproject &&
> +	 echo in submodule &&
> +	 test_cmp_config -C submodule true --type=bool submodule.hasSuperproject
> +	)
> +'
> +
>  test_done

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v9 2/3] introduce submodule.hasSuperproject record
  2022-03-15 18:39               ` Emily Shaffer
@ 2022-03-15 19:19                 ` Junio C Hamano
  0 siblings, 0 replies; 64+ messages in thread
From: Junio C Hamano @ 2022-03-15 19:19 UTC (permalink / raw)
  To: Emily Shaffer; +Cc: Glen Choo, git

Emily Shaffer <emilyshaffer@google.com> writes:

>> Clearing the variable from "super" is technically wrong because the
>> repository is set up as a submodule of "recursivesuper" and if we
>> had further tests, we should restore it in "super", but the point is
>> that we are makng sure "git submodule update" sets the variable in
>> the configuration file of the submodule, and not in the superproject's. 

If we wanted to be kosher about this, we could start the test with

    git config submodule.hassuperproject 1

in the "super" repository, clear the variable in the "submodule"
repository, before running the "git submodule update" step, which
(1) should not touch the "super" configuration and (2) should touch
the "submodule" configuration.

If we inspect in the "super" repository after "submodule update"

    value=$(git config submodule.hassuperproject) &&
    test "$value" = 1

I think we can tell if a buggy "submodule update" overwrites the
"super" configuration from "1" to "true".  And downstream tests
will take "1" as true just fine.

And of course, in "submodule", the variable after "submodule update"
must be set to true, which can be checked with

    value=$(git -C submodule config --type=bool submodule.hassuperproject) &&
    test "$value" = true

The trick depends on the hardcoded value to represent "true" in the
code this patch adds, but that is the canonical way to spell true in
the config, according to "git config --type=bool", so the dependency
may not be too bad.

Just a thought.



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v9 2/3] introduce submodule.hasSuperproject record
  2022-03-10 23:53                 ` Glen Choo
@ 2022-03-15 20:48                   ` Emily Shaffer
  2022-03-15 20:56                     ` Emily Shaffer
  0 siblings, 1 reply; 64+ messages in thread
From: Emily Shaffer @ 2022-03-15 20:48 UTC (permalink / raw)
  To: Glen Choo; +Cc: Junio C Hamano, git

On Thu, Mar 10, 2022 at 03:53:17PM -0800, Glen Choo wrote:
> 
> Glen Choo <chooglen@google.com> writes:
> 
> > Junio C Hamano <gitster@pobox.com> writes:
> >
> >>> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> >>> index bef9ab22d4..f53808d995 100644
> >>> --- a/builtin/submodule--helper.c
> >>> +++ b/builtin/submodule--helper.c
> >>> @@ -2672,6 +2677,11 @@ static int run_update_procedure(int argc, const char **argv, const char *prefix)
> >>>                                             &update_data.update_strategy);
> >>>
> >>>         free(prefixed_path);
> >>> +       /*
> >>> +        * This entry point is always called from a submodule, so this is a
> >>> +        * good place to set a hint that this repo is a submodule.
> >>> +        */
> >>> +       git_config_set("submodule.hasSuperproject", "true");
> >>>         return update_submodule2(&update_data);
> >>>  }
> >>
> >> That matched my tentative resolution I made last night, but what do
> >> you think about this part of the test added by the patch?
> >>
> >> diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
> >> index 11cccbb333..ec2397fc69 100755
> >> --- a/t/t7406-submodule-update.sh
> >> +++ b/t/t7406-submodule-update.sh
> >> @@ -1061,4 +1061,12 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s
> >>  	)
> >>  '
> >>  
> >> +test_expect_success 'submodule update adds submodule.hasSuperproject to older repos' '
> >> +	(cd super &&
> >> +	 test_unconfig submodule.hasSuperproject &&
> >> +	 git submodule update &&
> >> +	 test_cmp_config -C submodule true --type=bool submodule.hasSuperproject
> >> +	)
> >> +'
> >> +
> >>  test_done
> >>
> >> We go to "super", make sure that superproject does not have
> >> submodule.hasSuperproject set, run "git submodule update", and see
> >> if the configuration file in "submodule" subdirectory has the
> >> variable set.  It does not clear the variable from the submodule
> >> before starting, so the variable given to the submodule when it was
> >> cloned would be there, even if "git submodule update" failed to set
> >> it.
> >>
> >> I am wondering if it should do something like the attached instead.
> >>
> >> We
> >>
> >>  * clear the variable from "super" and "super/submodule"
> >>    repositories;
> >>
> >>  * run "git submodule update";
> >>
> >>  * ensure that "git submodule update" did not touch "super/.git/config";
> >>
> >>  * ensure that "git submodule update" added the variable to
> >>    "super/submodule/.git/config".
> >>
> >> Clearing the variable from "super" is technically wrong because the
> >> repository is set up as a submodule of "recursivesuper" and if we
> >> had further tests, we should restore it in "super", but the point is
> >> that we are makng sure "git submodule update" sets the variable in
> >> the configuration file of the submodule, and not in the superproject's. 
> >
> > Yes, the test you've described is closer to what I thought the original
> > test was trying to do. Seeing this test pass gave me a false sense of
> > confidence hm..
> 
> Correction, seeing the _original_ test pass gave me false sense of
> confidence.
> 
> >> With the conflict resolution above, this "corrected" test fails and
> >> shows that superproject's configuration file is updated after "git
> >> submodule update".
> >>
> >> This series alone, without your topic, this "corrected" test fails,
> >> and that is where my "are we sure we are mucking with the
> >> configuration file in the submodule"? comes from.
> > - Set the config in the submodule even though we are running from the
> >   superproject (this is possible, ensure_core_worktree() does this).
> 
> If it helps, I was able to do this up by copying
> ensure_core_worktree(), and this passes the amended test.
> 
> ----- >8 --------- >8 --------- >8 --------- >8 --------- >8 ----
> 
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index 4d02dd05ca..3bb7a65762 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -1838,11 +1838,6 @@ static int clone_submodule(struct module_clone_data *clone_data)
>     git_config_set_in_file(p, "submodule.alternateErrorStrategy",
>               error_strategy);
> 
> -	/*
> -	 * Teach the submodule that it's a submodule.
> -	 */
> -	git_config_set_in_file(p, "submodule.hasSuperproject", "true");
> -
>   free(sm_alternate);
>   free(error_strategy);
> 
> @@ -2560,6 +2555,20 @@ static int update_clone(int argc, const char **argv, const char *prefix)
>   return update_submodules(&suc);
> }
> 
> +static void set_hassuperproject(const char *sm_path)
> +{
> +	struct repository subrepo;
> +	char *cfg_file;
> +
> +	if (repo_submodule_init(&subrepo, the_repository, sm_path, null_oid()))
> +		die(_("could not get a repository handle for submodule '%s'"), sm_path);

Isn't the repo_submodule_init() fairly expensive? I think this is doing
a whole repo_init() call we would not otherwise be doing.... Is it good
enough to generate the config from sm_path, by using
strbuf_repo_worktree_path(), and simply be tolerant of the failure if
<sm-gitdir>/config doesn't exist?

Otherwise, this is a good workaround I think. Thanks.

 - Emily

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v9 2/3] introduce submodule.hasSuperproject record
  2022-03-15 20:48                   ` Emily Shaffer
@ 2022-03-15 20:56                     ` Emily Shaffer
  2022-03-15 21:19                       ` Glen Choo
  0 siblings, 1 reply; 64+ messages in thread
From: Emily Shaffer @ 2022-03-15 20:56 UTC (permalink / raw)
  To: Glen Choo; +Cc: Junio C Hamano, git

On Tue, Mar 15, 2022 at 01:48:25PM -0700, Emily Shaffer wrote:
> > +static void set_hassuperproject(const char *sm_path)
> > +{
> > +	struct repository subrepo;
> > +	char *cfg_file;
> > +
> > +	if (repo_submodule_init(&subrepo, the_repository, sm_path, null_oid()))
> > +		die(_("could not get a repository handle for submodule '%s'"), sm_path);
> 
> Isn't the repo_submodule_init() fairly expensive? I think this is doing
> a whole repo_init() call we would not otherwise be doing.... Is it good
> enough to generate the config from sm_path, by using
> strbuf_repo_worktree_path(), and simply be tolerant of the failure if
> <sm-gitdir>/config doesn't exist?

Ah, I was misreading the implementation of repo_submodule_init() and I
see now that won't work. I guess it is fine to just invoke
repo_submodule_init() then, unless someone has another idea.

^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH v9 2/3] introduce submodule.hasSuperproject record
  2022-03-15 20:56                     ` Emily Shaffer
@ 2022-03-15 21:19                       ` Glen Choo
  0 siblings, 0 replies; 64+ messages in thread
From: Glen Choo @ 2022-03-15 21:19 UTC (permalink / raw)
  To: Emily Shaffer; +Cc: Junio C Hamano, git

Emily Shaffer <emilyshaffer@google.com> writes:

> On Tue, Mar 15, 2022 at 01:48:25PM -0700, Emily Shaffer wrote:
>> > +static void set_hassuperproject(const char *sm_path)
>> > +{
>> > +	struct repository subrepo;
>> > +	char *cfg_file;
>> > +
>> > +	if (repo_submodule_init(&subrepo, the_repository, sm_path, null_oid()))
>> > +		die(_("could not get a repository handle for submodule '%s'"), sm_path);
>> 
>> Isn't the repo_submodule_init() fairly expensive? I think this is doing
>> a whole repo_init() call we would not otherwise be doing.... Is it good
>> enough to generate the config from sm_path, by using
>> strbuf_repo_worktree_path(), and simply be tolerant of the failure if
>> <sm-gitdir>/config doesn't exist?
>
> Ah, I was misreading the implementation of repo_submodule_init() and I
> see now that won't work. I guess it is fine to just invoke
> repo_submodule_init() then, unless someone has another idea.

Yes, it's difficult to avoid calling repo_submodule_init() because it's
hard to get the gitdir using just the path to the submodule in the
working tree (sm_path).

Are we particular about avoiding calls to repo_submodule_init()? I don't
recall hearing this as an objection before. If so, I'll keep this in
mind as I work on more submodule things.

As an aside, ensure_core_worktree() already calls repo_submodule_init(),
so this wouldn't be the first time "submodule update" calls
repo_submodule_init(), and a potential optimization might be to cache
the result in between invocations of repo_submodule_init().

^ permalink raw reply	[flat|nested] 64+ messages in thread

end of thread, other threads:[~2022-03-15 21:19 UTC | newest]

Thread overview: 64+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-17  0:56 [PATCH v6 0/5] teach submodules to know they're submodules Emily Shaffer
2021-11-17  0:56 ` [PATCH v6 1/5] t7400-submodule-basic: modernize inspect() helper Emily Shaffer
2021-11-17  0:56 ` [PATCH v6 2/5] introduce submodule.superprojectGitDir record Emily Shaffer
2021-11-17 23:43   ` Jonathan Tan
2021-11-17  0:56 ` [PATCH v6 3/5] submodule: record superproject gitdir during absorbgitdirs Emily Shaffer
2021-11-17  0:57 ` [PATCH v6 4/5] submodule: record superproject gitdir during 'update' Emily Shaffer
2021-11-17  0:57 ` [PATCH v6 5/5] submodule: use config to find superproject worktree Emily Shaffer
2021-11-17 11:43 ` [RFC PATCH 0/2] submodule: test what happens if submodule.superprojectGitDir isn't around Ævar Arnfjörð Bjarmason
2021-11-17 11:43   ` [RFC PATCH 1/2] submodule tests: fix potentially broken "config .. --unset" Ævar Arnfjörð Bjarmason
2021-11-17 11:43   ` [RFC PATCH 2/2] submodule: add test mode for checking absence of "superProjectGitDir" Ævar Arnfjörð Bjarmason
2021-11-23 20:08   ` [RFC PATCH 0/2] submodule: test what happens if submodule.superprojectGitDir isn't around Emily Shaffer
2021-11-24  1:38     ` Ævar Arnfjörð Bjarmason
2021-11-17 23:28 ` [PATCH v6 0/5] teach submodules to know they're submodules Jonathan Tan
2021-11-23 20:28   ` Emily Shaffer
2022-02-03 21:59 ` Emily Shaffer
2022-02-03 21:59   ` [PATCH v7 1/4] t7400-submodule-basic: modernize inspect() helper Emily Shaffer
2022-02-03 21:59   ` [PATCH v7 2/4] introduce submodule.superprojectGitDir record Emily Shaffer
2022-02-03 21:59   ` [PATCH v7 3/4] submodule: record superproject gitdir during absorbgitdirs Emily Shaffer
2022-02-03 21:59   ` [PATCH v7 4/4] submodule: record superproject gitdir during 'update' Emily Shaffer
2022-02-03 22:39   ` [PATCH v6 0/5] teach submodules to know they're submodules Junio C Hamano
2022-02-04  1:15   ` Ævar Arnfjörð Bjarmason
2022-02-04 16:20     ` Junio C Hamano
2022-02-07 19:56     ` Jonathan Nieder
2022-02-07 23:21       ` Junio C Hamano
2022-02-08  1:18         ` Jonathan Nieder
2022-02-08 18:24           ` Junio C Hamano
2022-02-10 22:12             ` Emily Shaffer
2022-02-10 22:53               ` Jonathan Nieder
2022-02-12 20:35       ` Ævar Arnfjörð Bjarmason
2022-02-13  6:25         ` Junio C Hamano
2022-03-01  0:26   ` [PATCH v8 0/3] " Emily Shaffer
2022-03-01  0:26     ` [PATCH v8 1/3] t7400-submodule-basic: modernize inspect() helper Emily Shaffer
2022-03-01  0:26     ` [PATCH v8 2/3] introduce submodule.hasSuperproject record Emily Shaffer
2022-03-01  7:00       ` Junio C Hamano
2022-03-08 20:04         ` Emily Shaffer
2022-03-08 22:13       ` Glen Choo
2022-03-08 22:29         ` Glen Choo
2022-03-01  0:26     ` [PATCH v8 3/3] rev-parse: short-circuit superproject worktree when config unset Emily Shaffer
2022-03-01  7:06       ` Junio C Hamano
2022-03-09  0:38         ` Emily Shaffer
2022-03-01  3:08     ` [PATCH v8 0/3] teach submodules to know they're submodules Junio C Hamano
2022-03-08 18:54       ` Emily Shaffer
2022-03-10  0:44     ` [PATCH v9 " Emily Shaffer
2022-03-10  0:44       ` [PATCH v9 1/3] t7400-submodule-basic: modernize inspect() helper Emily Shaffer
2022-03-10  0:44       ` [PATCH v9 2/3] introduce submodule.hasSuperproject record Emily Shaffer
2022-03-10  2:09         ` Junio C Hamano
2022-03-10 21:29           ` Glen Choo
2022-03-10 21:40           ` Glen Choo
2022-03-10 22:10             ` Junio C Hamano
2022-03-10 23:42               ` Glen Choo
2022-03-10 23:53                 ` Glen Choo
2022-03-15 20:48                   ` Emily Shaffer
2022-03-15 20:56                     ` Emily Shaffer
2022-03-15 21:19                       ` Glen Choo
2022-03-15 18:39               ` Emily Shaffer
2022-03-15 19:19                 ` Junio C Hamano
2022-03-10  2:32         ` Junio C Hamano
2022-03-10 21:54         ` Glen Choo
2022-03-15 18:27           ` Emily Shaffer
2022-03-10  0:44       ` [PATCH v9 3/3] rev-parse: short-circuit superproject worktree when config unset Emily Shaffer
2022-03-10  1:47         ` Junio C Hamano
2022-03-10  4:39           ` Eric Sunshine
2022-03-11  9:09       ` [PATCH v9 0/3] teach submodules to know they're submodules Ævar Arnfjörð Bjarmason
2022-03-13  5:43         ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).