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

Re: [PATCH 1/6] config.c: avoid git_path() in do_git_config_sequence()

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 10, 2019, 21:38 UTC
Message-ID
<xmqqa7k819dx.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20181227155611.10585-2-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
> This function has both $GIT_COMMON_DIR and $GIT_DIR in "opts". Use it
> to construct config.worktree path instead because git_pathdup() is
> tied to the current worktree, but the given $GIT_DIR could be from
> another one.
Given that git_pathdup() does
	do_git_path(the_repository, NULL, pathname, fmt, args);

I am not sure what you mean by "tied to the current worktree" above. As do_git_path() uses strbuf_worktree_gitdir() that does

	if (!wt)
		strbuf_addstr(buf, repo->gitdir);

you meant s/current worktree/current repository/, perhaps? In which case I think the description makes sense to me.

Thanks.
Show 51 quoted lines
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  config.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/config.c b/config.c
> index ff521eb27a..79fbe65da8 100644
> --- a/config.c
> +++ b/config.c
> @@ -1665,6 +1665,7 @@ static int do_git_config_sequence(const struct config_options *opts,
>  	char *xdg_config = xdg_config_home("config");
>  	char *user_config = expand_user_path("~/.gitconfig", 0);
>  	char *repo_config;
> +	char *worktree_config;
>  
>  	if (opts->commondir)
>  		repo_config = mkpathdup("%s/config", opts->commondir);
> @@ -1672,6 +1673,10 @@ static int do_git_config_sequence(const struct config_options *opts,
>  		BUG("git_dir without commondir");
>  	else
>  		repo_config = NULL;
> +	if (repository_format_worktree_config)
> +		worktree_config = mkpathdup("%s/config.worktree", opts->git_dir);
> +	else
> +		worktree_config = NULL;
>  
>  	current_parsing_scope = CONFIG_SCOPE_SYSTEM;
>  	if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK, 0))
> @@ -1693,12 +1698,8 @@ static int do_git_config_sequence(const struct config_options *opts,
>  	 * Note: this should have a new scope, CONFIG_SCOPE_WORKTREE.
>  	 * But let's not complicate things before it's actually needed.
>  	 */
> -	if (repository_format_worktree_config) {
> -		char *path = git_pathdup("config.worktree");
> -		if (!access_or_die(path, R_OK, 0))
> -			ret += git_config_from_file(fn, path, data);
> -		free(path);
> -	}
> +	if (worktree_config && !access_or_die(worktree_config, R_OK, 0))
> +		ret += git_config_from_file(fn, worktree_config, data);
>  
>  	current_parsing_scope = CONFIG_SCOPE_CMDLINE;
>  	if (git_config_from_parameters(fn, data) < 0)
> @@ -1708,6 +1709,7 @@ static int do_git_config_sequence(const struct config_options *opts,
>  	free(xdg_config);
>  	free(user_config);
>  	free(repo_config);
> +	free(worktree_config);
>  	return ret;
>  }
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 3 of 12 in “Add "git config --move-to"”
  1. 0/6 Add "git config --move-to"Nguyễn Thái Ngọc Duy, Dec 27, 2018
  2. 1/6 config.c: avoid git_path() in do_git_config_sequence()Nguyễn Thái Ngọc Duy, Dec 27, 2018
  3. Junio C HamanoJan 10, 2019
  4. 2/6 worktree.c: add get_worktree_config()Nguyễn Thái Ngọc Duy, Dec 27, 2018
  5. Eric SunshineDec 27, 2018
  6. 3/6 config.c: add repo_config_set_worktree_gently()Nguyễn Thái Ngọc Duy, Dec 27, 2018
  7. Derrick StoleeApr 30, 2019
  8. Duy NguyenMay 1, 2019
  9. 4/6 config: use OPT_FILENAME()Nguyễn Thái Ngọc Duy, Dec 27, 2018
  10. Eric SunshineDec 27, 2018
  11. 5/6 config: factor out set_config_source_file()Nguyễn Thái Ngọc Duy, Dec 27, 2018
  12. 6/6 config: add --move-toNguyễn Thái Ngọc Duy, Dec 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.