Skip to content

Commit 0680023

Browse files
pcloudsgitster
authored andcommitted
config.c: avoid git_path() in do_git_config_sequence()
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 repository, but the given $GIT_DIR could be from another one. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ecbdaf0 commit 0680023

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

config.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,13 +1665,18 @@ static int do_git_config_sequence(const struct config_options *opts,
16651665
char *xdg_config = xdg_config_home("config");
16661666
char *user_config = expand_user_path("~/.gitconfig", 0);
16671667
char *repo_config;
1668+
char *worktree_config;
16681669

16691670
if (opts->commondir)
16701671
repo_config = mkpathdup("%s/config", opts->commondir);
16711672
else if (opts->git_dir)
16721673
BUG("git_dir without commondir");
16731674
else
16741675
repo_config = NULL;
1676+
if (repository_format_worktree_config)
1677+
worktree_config = mkpathdup("%s/config.worktree", opts->git_dir);
1678+
else
1679+
worktree_config = NULL;
16751680

16761681
current_parsing_scope = CONFIG_SCOPE_SYSTEM;
16771682
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,
16931698
* Note: this should have a new scope, CONFIG_SCOPE_WORKTREE.
16941699
* But let's not complicate things before it's actually needed.
16951700
*/
1696-
if (repository_format_worktree_config) {
1697-
char *path = git_pathdup("config.worktree");
1698-
if (!access_or_die(path, R_OK, 0))
1699-
ret += git_config_from_file(fn, path, data);
1700-
free(path);
1701-
}
1701+
if (worktree_config && !access_or_die(worktree_config, R_OK, 0))
1702+
ret += git_config_from_file(fn, worktree_config, data);
17021703

17031704
current_parsing_scope = CONFIG_SCOPE_CMDLINE;
17041705
if (git_config_from_parameters(fn, data) < 0)
@@ -1708,6 +1709,7 @@ static int do_git_config_sequence(const struct config_options *opts,
17081709
free(xdg_config);
17091710
free(user_config);
17101711
free(repo_config);
1712+
free(worktree_config);
17111713
return ret;
17121714
}
17131715

0 commit comments

Comments
 (0)