All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 1/6] config.c: avoid git_path() in do_git_config_sequence()
Date: Thu, 27 Dec 2018 16:56:06 +0100	[thread overview]
Message-ID: <20181227155611.10585-2-pclouds@gmail.com> (raw)
In-Reply-To: <20181227155611.10585-1-pclouds@gmail.com>

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.

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;
 }
 
-- 
2.20.0.482.g66447595a7


  reply	other threads:[~2018-12-27 15:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-27 15:56 [PATCH 0/6] Add "git config --move-to" Nguyễn Thái Ngọc Duy
2018-12-27 15:56 ` Nguyễn Thái Ngọc Duy [this message]
2019-01-10 21:38   ` [PATCH 1/6] config.c: avoid git_path() in do_git_config_sequence() Junio C Hamano
2018-12-27 15:56 ` [PATCH 2/6] worktree.c: add get_worktree_config() Nguyễn Thái Ngọc Duy
2018-12-27 20:36   ` Eric Sunshine
2018-12-27 15:56 ` [PATCH 3/6] config.c: add repo_config_set_worktree_gently() Nguyễn Thái Ngọc Duy
2019-04-30 16:40   ` Derrick Stolee
2019-05-01  9:55     ` Duy Nguyen
2018-12-27 15:56 ` [PATCH 4/6] config: use OPT_FILENAME() Nguyễn Thái Ngọc Duy
2018-12-27 20:40   ` Eric Sunshine
2018-12-27 15:56 ` [PATCH 5/6] config: factor out set_config_source_file() Nguyễn Thái Ngọc Duy
2018-12-27 15:56 ` [PATCH 6/6] config: add --move-to Nguyễn Thái Ngọc Duy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181227155611.10585-2-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.