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

Re: [PATCH 1/3] submodule: use absolute path for computing relative path connecting

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 21, 2016, 21:01 UTC
Message-ID
<xmqq8tscim31.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20161121204146.13665-2-sbeller@google.com>
Stefan Beller <sbeller@google.com> writes:
> Subject: Re: [PATCH 1/3] submodule: use absolute path for computing relative path connecting
connecting what?  IOW, has the subject line somehow truncated?
Show 6 quoted lines
> This addresses a similar concern as in f8eaa0ba98b (submodule--helper,
> module_clone: always operate on absolute paths, 2016-03-31)
>
> When computing the relative path from one to another location, we
> need to provide both locations as absolute paths to make sure the
> computation of the relative path is correct.

Can the effect of this change demonstrated in a new test? There must be a scenario where the current behaviour is broken and this change fixes an incorrect computation of relative path, no?

Show 6 quoted lines
>
> While at it, change `real_work_tree` to be non const as we own
> the memory.
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
Show 38 quoted lines
>  submodule.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/submodule.c b/submodule.c
> index 6f7d883de9..66c5ce5a24 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -1227,23 +1227,25 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
>  {
>  	struct strbuf file_name = STRBUF_INIT;
>  	struct strbuf rel_path = STRBUF_INIT;
> -	const char *real_work_tree = xstrdup(real_path(work_tree));
> +	char *real_git_dir = xstrdup(real_path(git_dir));
> +	char *real_work_tree = xstrdup(real_path(work_tree));
>  
>  	/* Update gitfile */
>  	strbuf_addf(&file_name, "%s/.git", work_tree);
>  	write_file(file_name.buf, "gitdir: %s",
> -		   relative_path(git_dir, real_work_tree, &rel_path));
> +		   relative_path(real_git_dir, real_work_tree, &rel_path));
>  
>  	/* Update core.worktree setting */
>  	strbuf_reset(&file_name);
> -	strbuf_addf(&file_name, "%s/config", git_dir);
> +	strbuf_addf(&file_name, "%s/config", real_git_dir);
>  	git_config_set_in_file(file_name.buf, "core.worktree",
> -			       relative_path(real_work_tree, git_dir,
> +			       relative_path(real_work_tree, real_git_dir,
>  					     &rel_path));
>  
>  	strbuf_release(&file_name);
>  	strbuf_release(&rel_path);
> -	free((void *)real_work_tree);
> +	free(real_work_tree);
> +	free(real_git_dir);
>  }
>  
>  int parallel_submodules(void)
Previous: Stefan BellerNext: Stefan Beller
Message 3 of 17 in “Introduce `submodule interngitdirs`”
  1. 0/3 Introduce `submodule interngitdirs`Stefan Beller, Nov 21, 2016
  2. 1/3 submodule: use absolute path for computing relative path connectingStefan Beller, Nov 21, 2016
  3. Junio C HamanoNov 21, 2016
  4. Stefan BellerNov 21, 2016
  5. Stefan BellerNov 22, 2016
  6. Junio C HamanoNov 22, 2016
  7. 2/3 test-lib-functions.sh: teach test_commit -C <dir>Stefan Beller, Nov 21, 2016
  8. Junio C HamanoNov 21, 2016
  9. 3/3 submodule--helper: add intern-git-dir functionStefan Beller, Nov 21, 2016
  10. Junio C HamanoNov 21, 2016
  11. Stefan BellerNov 22, 2016
  12. Junio C HamanoNov 22, 2016
  13. Stefan BellerNov 22, 2016
  14. Junio C HamanoNov 22, 2016
  15. Brandon WilliamsNov 21, 2016
  16. Junio C HamanoNov 21, 2016
  17. Stefan BellerNov 21, 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.