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

Re: [PATCH 7/9] submodule: fetch in submodules git directory instead of in worktree

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Oct 17, 2018, 22:58 UTC
Message-ID
<20181017225811.66554-1-jonathantanmy@google.com>
In-Reply-To
<20181016181327.107186-8-sbeller@google.com>
> This patch started as a refactoring to make 'get_next_submodule' more
> readable, but upon doing so, I realized that "git fetch" of the submodule
> actually doesn't need to be run in the submodules worktree. So let's run
> it in its git dir instead.

The commit message needs to be updated, I think - this patch does significantly more than fetching in the gitdir.

> This patch leaks the cp->dir in get_next_submodule, as any further
> callback in run_processes_parallel doesn't have access to the child
> process any more.

The cp->dir is already leaked - probably better to write "cp->dir in get_next_submodule() is still leaked, but this will be fixed in a subsequent patch".

> +static void prepare_submodule_repo_env_in_gitdir(struct argv_array *out)
> +{
> +	prepare_submodule_repo_env_no_git_dir(out);
> +	argv_array_pushf(out, "%s=.", GIT_DIR_ENVIRONMENT);

Why does GIT_DIR need to be set? Is it to avoid subcommands recursively checking the parent directories in case the CWD is a malformed Git repository? If yes, maybe it's worth adding a comment.

Show 22 quoted lines
> +static struct repository *get_submodule_repo_for(struct repository *r,
> +						 const struct submodule *sub)
> +{
> +	struct repository *ret = xmalloc(sizeof(*ret));
> +
> +	if (repo_submodule_init(ret, r, sub)) {
> +		/*
> +		 * No entry in .gitmodules? Technically not a submodule,
> +		 * but historically we supported repositories that happen to be
> +		 * in-place where a gitlink is. Keep supporting them.
> +		 */
> +		struct strbuf gitdir = STRBUF_INIT;
> +		strbuf_repo_worktree_path(&gitdir, r, "%s/.git", sub->path);
> +		if (repo_init(ret, gitdir.buf, NULL)) {
> +			strbuf_release(&gitdir);
> +			return NULL;
> +		}
> +		strbuf_release(&gitdir);
> +	}
> +
> +	return ret;
> +}

This is the significant thing that this patch does more - an unskipped submodule is now something that either passes the checks in repo_submodule_init() or the checks in repo_init(), which seems to be stricter than the current check that ".git" points to a directory or is one. This means that we skip certain broken repositories, and this necessitates a change in the test.

I think we should be more particular about what we're allowed to skip - in particular, maybe if we're planning to skip this submodule, its corresponding directory in the worktree (if one exists) needs to be empty.

> -			cp->dir = strbuf_detach(&submodule_path, NULL);
> -			prepare_submodule_repo_env(&cp->env_array);
> +			prepare_submodule_repo_env_in_gitdir(&cp->env_array);
> +			cp->dir = xstrdup(repo->gitdir);

Here is where the functionality change (fetch in ".git") described in the commit message occurs.

Previous: Stefan BellerNext: Stefan Beller
Message 15 of 28 in “Resending sb/submodule-recursive-fetch-gets-the-tip”
  1. 0/9 Resending sb/submodule-recursive-fetch-gets-the-tipStefan Beller, Oct 16, 2018
  2. 1/9 sha1-array: provide oid_array_filterStefan Beller, Oct 16, 2018
  3. 2/9 submodule.c: fix indentationStefan Beller, Oct 16, 2018
  4. 3/9 submodule.c: sort changed_submodule_names before searching itStefan Beller, Oct 16, 2018
  5. Jonathan TanOct 17, 2018
  6. 4/9 submodule.c: move global changed_submodule_names into fetch submodule structStefan Beller, Oct 16, 2018
  7. Jonathan TanOct 17, 2018
  8. Stefan BellerOct 18, 2018
  9. 5/9 submodule.c: do not copy around submodule listStefan Beller, Oct 16, 2018
  10. Jonathan TanOct 17, 2018
  11. Junio C HamanoOct 18, 2018
  12. 6/9 repository: repo_submodule_init to take a submodule structStefan Beller, Oct 16, 2018
  13. Jonathan TanOct 17, 2018
  14. 7/9 submodule: fetch in submodules git directory instead of in worktreeStefan Beller, Oct 16, 2018
  15. Jonathan TanOct 17, 2018
  16. Stefan BellerOct 23, 2018
  17. Jonathan TanOct 23, 2018
  18. Stefan BellerOct 23, 2018
  19. 8/9 fetch: retry fetching submodules if needed objects were not fetchedStefan Beller, Oct 16, 2018
  20. Jonathan TanOct 18, 2018
  21. Stefan BellerOct 23, 2018
  22. Jonathan TanOct 23, 2018
  23. Stefan BellerOct 25, 2018
  24. 9/9 builtin/fetch: check for submodule updates for non branch fetchesStefan Beller, Oct 16, 2018
  25. Jonathan TanOct 18, 2018
  26. Junio C HamanoOct 18, 2018
  27. Junio C HamanoOct 18, 2018
  28. Stefan BellerOct 18, 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.