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

Re: [PATCH 1/2] submodule--helper, module_clone: always operate on absolute paths

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 1, 2016, 19:18 UTC
Message-ID
<xmqq7fghi1ds.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1459469849-9643-2-git-send-email-sbeller@google.com>
Stefan Beller <sbeller@google.com> writes:
Show 12 quoted lines
> +	char *sm_gitdir_rel, *p, *path = NULL;
> +	const char *sm_gitdir;
>  	struct strbuf rel_path = STRBUF_INIT;
>  	struct strbuf sb = STRBUF_INIT;
>  
> @@ -198,7 +199,14 @@ static int module_clone(int argc, const char **argv, const char *prefix)
>  		die(_("submodule--helper: unspecified or empty --path"));
>  
>  	strbuf_addf(&sb, "%s/modules/%s", get_git_dir(), name);
> -	sm_gitdir = strbuf_detach(&sb, NULL);
> +	sm_gitdir_rel = strbuf_detach(&sb, NULL);
> +	sm_gitdir = absolute_path(sm_gitdir_rel);

With this change, sm_gitdir will always be absolute, which means the parameter to clone_submodule() call (immedately after this hunk) will now be always absolute. I do not think "git clone" called from there will leave anything in the resulting repository that depends on the --separate-git-dir=<dir> being relative or absolute, so this change should not cause us new problems.

By the way, this line is the last use of sm_gitdir_rel before it gets freed. I wonder

	sm_gitdir = absolute_path(sb.buf);

would be sufficient. We can lose the variable, and free() on it at the end of this function, and an extra allocation if we can do so.

Show 8 quoted lines
> +	if (!is_absolute_path(path)) {
> +		strbuf_addf(&sb, "%s/%s", get_git_work_tree(), path);
> +		path = strbuf_detach(&sb, 0);
> +	} else
> +		path = xstrdup(path);
>  
>  	if (!file_exists(sm_gitdir)) {
>  		if (safe_create_leading_directories_const(sm_gitdir) < 0)
Other than that, looks good to me.
Thanks.
Previous: Stefan BellerNext: Junio C Hamano
Message 3 of 15 in “[PATCHv3 0/2] Fix relative path issues in recursive submodules.”
  1. Stefan BellerApr 1, 2016
  2. 1/2 submodule--helper, module_clone: always operate on absolute pathsStefan Beller, Apr 1, 2016
  3. Junio C HamanoApr 1, 2016
  4. Junio C HamanoApr 1, 2016
  5. Eric SunshineApr 1, 2016
  6. Junio C HamanoApr 1, 2016
  7. 2/2 submodule--helper, module_clone: catch fprintf failureStefan Beller, Apr 1, 2016
  8. Ramsay JonesApr 1, 2016
  9. Stefan BellerApr 12, 2016
  10. Ramsay JonesApr 13, 2016
  11. Stefan BellerApr 13, 2016
  12. Junio C HamanoApr 13, 2016
  13. Stefan BellerApr 13, 2016
  14. Junio C HamanoApr 13, 2016
  15. Junio C HamanoApr 13, 2016

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.