Skip to content

Commit f7f7e83

Browse files
committed
repo: refactor global config loader function
Pull the global configuration loader out of the symlink check so that it can be re-used.
1 parent 90d2b61 commit f7f7e83

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

src/libgit2/repository.c

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,13 +1632,40 @@ static bool is_filesystem_case_insensitive(const char *gitdir_path)
16321632
return is_insensitive;
16331633
}
16341634

1635-
static bool are_symlinks_supported(const char *wd_path)
1635+
/*
1636+
* Return a configuration object with only the global and system
1637+
* configurations; no repository-level configuration.
1638+
*/
1639+
static int load_global_config(git_config **config)
16361640
{
1637-
git_config *config = NULL;
16381641
git_str global_buf = GIT_STR_INIT;
16391642
git_str xdg_buf = GIT_STR_INIT;
16401643
git_str system_buf = GIT_STR_INIT;
16411644
git_str programdata_buf = GIT_STR_INIT;
1645+
int error;
1646+
1647+
git_config__find_global(&global_buf);
1648+
git_config__find_xdg(&xdg_buf);
1649+
git_config__find_system(&system_buf);
1650+
git_config__find_programdata(&programdata_buf);
1651+
1652+
error = load_config(config, NULL,
1653+
path_unless_empty(&global_buf),
1654+
path_unless_empty(&xdg_buf),
1655+
path_unless_empty(&system_buf),
1656+
path_unless_empty(&programdata_buf));
1657+
1658+
git_str_dispose(&global_buf);
1659+
git_str_dispose(&xdg_buf);
1660+
git_str_dispose(&system_buf);
1661+
git_str_dispose(&programdata_buf);
1662+
1663+
return error;
1664+
}
1665+
1666+
static bool are_symlinks_supported(const char *wd_path)
1667+
{
1668+
git_config *config = NULL;
16421669
int symlinks = 0;
16431670

16441671
/*
@@ -1649,30 +1676,16 @@ static bool are_symlinks_supported(const char *wd_path)
16491676
* _not_ set, then we do not test or enable symlink support.
16501677
*/
16511678
#ifdef GIT_WIN32
1652-
git_config__find_global(&global_buf);
1653-
git_config__find_xdg(&xdg_buf);
1654-
git_config__find_system(&system_buf);
1655-
git_config__find_programdata(&programdata_buf);
1656-
1657-
if (load_config(&config, NULL,
1658-
path_unless_empty(&global_buf),
1659-
path_unless_empty(&xdg_buf),
1660-
path_unless_empty(&system_buf),
1661-
path_unless_empty(&programdata_buf)) < 0)
1662-
goto done;
1663-
1664-
if (git_config_get_bool(&symlinks, config, "core.symlinks") < 0 || !symlinks)
1679+
if (load_global_config(&config) < 0 ||
1680+
git_config_get_bool(&symlinks, config, "core.symlinks") < 0 ||
1681+
!symlinks)
16651682
goto done;
16661683
#endif
16671684

16681685
if (!(symlinks = git_fs_path_supports_symlinks(wd_path)))
16691686
goto done;
16701687

16711688
done:
1672-
git_str_dispose(&global_buf);
1673-
git_str_dispose(&xdg_buf);
1674-
git_str_dispose(&system_buf);
1675-
git_str_dispose(&programdata_buf);
16761689
git_config_free(config);
16771690
return symlinks != 0;
16781691
}

0 commit comments

Comments
 (0)