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

Re: [PATCH 5/6] submodule: fixup nested submodules after moving the submodule

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Mar 28, 2018, 17:46 UTC
Message-ID
<20180328104657.2396071270905628fd2fdca3@google.com>
In-Reply-To
<20180328172449.27012-6-sbeller@google.com>

On Wed, 28 Mar 2018 10:24:48 -0700 Stefan Beller <sbeller@google.com> wrote:

Show 12 quoted lines
> +static void connect_wt_gitdir_in_nested(const char *sub_worktree,
> +					const char *sub_gitdir)
> +{
> +	int i;
> +	struct repository subrepo;
> +	struct strbuf sub_wt = STRBUF_INIT;
> +	struct strbuf sub_gd = STRBUF_INIT;
> +
> +	const struct submodule *sub;
> +
> +	if (repo_init(&subrepo, sub_gitdir, sub_worktree))
> +		return;

If repo_init() fails, is it because the working tree doesn't exist on disk, so we don't need to perform any connections on submodules? I think a comment should be added to describe this.

Show 24 quoted lines
> +
> +	if (repo_read_index(&subrepo) < 0)
> +		die("index file corrupt in repo %s", subrepo.gitdir);
> +
> +	for (i = 0; i < subrepo.index->cache_nr; i++) {
> +		const struct cache_entry *ce = subrepo.index->cache[i];
> +
> +		if (!S_ISGITLINK(ce->ce_mode))
> +			continue;
> +
> +		while (i + 1 < subrepo.index->cache_nr &&
> +		       !strcmp(ce->name, subrepo.index->cache[i + 1]->name))
> +			/*
> +			 * Skip entries with the same name in different stages
> +			 * to make sure an entry is returned only once.
> +			 */
> +			i++;
> +
> +		sub = submodule_from_path(&subrepo, &null_oid, ce->name);
> +		if (!sub)
> +			/* submodule not checked out? */
> +			continue;
> +
> +		if (is_submodule_active(&subrepo, ce->name)) {
Optional: This could be combined with the previous "if" block, so that
the following lines don't need to be indented.
Show 5 quoted lines
> +			strbuf_addf(&sub_wt, "%s/%s", sub_worktree, sub->path);
> +			strbuf_addf(&sub_gd, "%s/modules/%s", sub_gitdir, sub->name);
> +
> +			connect_work_tree_and_git_dir(sub_wt.buf, sub_gd.buf, 0);
> +			connect_wt_gitdir_in_nested(sub_wt.buf, sub_gd.buf);

What's the difference between having this call to connect_wt_gitdir_in_nested() and just passing 1 instead of 0 to connect_work_tree_and_git_dir()? I see that the latter uses absolute paths, but that would seem to have the same effect. (If not, I think a comment is warranted.)

> +
> +			strbuf_reset(&sub_wt);
> +			strbuf_reset(&sub_gd);

I think we normally write the resets before the strbuf_addf(), so that it's clearer that sub_wt and sub_gd are meant to start from scratch in every iteration.

Overall, this version of the patch is clearer - thanks.
Previous: Stefan BellerNext: Stefan Beller
Message 23 of 36 in “Moving submodules with nested submodules”
  1. 0/5 Moving submodules with nested submodulesStefan Beller, Mar 27, 2018
  2. 1/5 submodule.h: drop declaration of connect_work_tree_and_git_dirStefan Beller, Mar 27, 2018
  3. 3/5 submodule-config: add repository argument to submodule_from_{name, path}Stefan Beller, Mar 27, 2018
  4. Jonathan TanMar 27, 2018
  5. Stefan BellerMar 27, 2018
  6. 2/5 submodule-config: allow submodule_free to handle arbitrary repositoriesStefan Beller, Mar 27, 2018
  7. Brandon WilliamsMar 27, 2018
  8. grep: remove "repo" arg from non-supporting funcsJonathan Tan, Mar 27, 2018
  9. Stefan BellerMar 27, 2018
  10. Jonathan TanMar 28, 2018
  11. Stefan BellerMar 28, 2018
  12. 5/5 submodule: fixup nested submodules after moving the submoduleStefan Beller, Mar 27, 2018
  13. Brandon WilliamsMar 27, 2018
  14. Jonathan TanMar 28, 2018
  15. Stefan BellerMar 28, 2018
  16. 0/6 Moving submodules with nested submodulesStefan Beller, Mar 28, 2018
  17. 1/6 submodule.h: drop declaration of connect_work_tree_and_git_dirStefan Beller, Mar 28, 2018
  18. 2/6 submodule-config: allow submodule_free to handle arbitrary repositoriesStefan Beller, Mar 28, 2018
  19. 4/6 submodule-config: remove submodule_from_cacheStefan Beller, Mar 28, 2018
  20. 5/6 submodule: fixup nested submodules after moving the submoduleStefan Beller, Mar 28, 2018
  21. Brandon WilliamsMar 28, 2018
  22. Stefan BellerMar 28, 2018
  23. Jonathan TanMar 28, 2018
  24. 3/6 submodule-config: add repository argument to submodule_from_{name, path}Stefan Beller, Mar 28, 2018
  25. 6/6 grep: remove "repo" arg from non-supporting funcsStefan Beller, Mar 28, 2018
  26. Jonathan TanMar 28, 2018
  27. 0/6 Moving submodules with nested submodulesStefan Beller, Mar 28, 2018
  28. 1/6 submodule.h: drop declaration of connect_work_tree_and_git_dirStefan Beller, Mar 28, 2018
  29. 2/6 grep: remove "repo" arg from non-supporting funcsStefan Beller, Mar 28, 2018
  30. 3/6 submodule-config: allow submodule_free to handle arbitrary repositoriesStefan Beller, Mar 28, 2018
  31. 6/6 submodule: fixup nested submodules after moving the submoduleStefan Beller, Mar 28, 2018
  32. 4/6 submodule-config: add repository argument to submodule_from_{name, path}Stefan Beller, Mar 28, 2018
  33. 5/6 submodule-config: remove submodule_from_cacheStefan Beller, Mar 28, 2018
  34. Jonathan TanMar 28, 2018
  35. 4/5 submodule-config: remove submodule_from_cacheStefan Beller, Mar 27, 2018
  36. Jonathan TanMar 27, 2018

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

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