Commit f7f7e835 by Edward Thomson

repo: refactor global config loader function

Pull the global configuration loader out of the symlink check so that it
can be re-used.
parent 90d2b619
...@@ -1632,13 +1632,40 @@ static bool is_filesystem_case_insensitive(const char *gitdir_path) ...@@ -1632,13 +1632,40 @@ static bool is_filesystem_case_insensitive(const char *gitdir_path)
return is_insensitive; return is_insensitive;
} }
static bool are_symlinks_supported(const char *wd_path) /*
* Return a configuration object with only the global and system
* configurations; no repository-level configuration.
*/
static int load_global_config(git_config **config)
{ {
git_config *config = NULL;
git_str global_buf = GIT_STR_INIT; git_str global_buf = GIT_STR_INIT;
git_str xdg_buf = GIT_STR_INIT; git_str xdg_buf = GIT_STR_INIT;
git_str system_buf = GIT_STR_INIT; git_str system_buf = GIT_STR_INIT;
git_str programdata_buf = GIT_STR_INIT; git_str programdata_buf = GIT_STR_INIT;
int error;
git_config__find_global(&global_buf);
git_config__find_xdg(&xdg_buf);
git_config__find_system(&system_buf);
git_config__find_programdata(&programdata_buf);
error = load_config(config, NULL,
path_unless_empty(&global_buf),
path_unless_empty(&xdg_buf),
path_unless_empty(&system_buf),
path_unless_empty(&programdata_buf));
git_str_dispose(&global_buf);
git_str_dispose(&xdg_buf);
git_str_dispose(&system_buf);
git_str_dispose(&programdata_buf);
return error;
}
static bool are_symlinks_supported(const char *wd_path)
{
git_config *config = NULL;
int symlinks = 0; int symlinks = 0;
/* /*
...@@ -1649,19 +1676,9 @@ static bool are_symlinks_supported(const char *wd_path) ...@@ -1649,19 +1676,9 @@ static bool are_symlinks_supported(const char *wd_path)
* _not_ set, then we do not test or enable symlink support. * _not_ set, then we do not test or enable symlink support.
*/ */
#ifdef GIT_WIN32 #ifdef GIT_WIN32
git_config__find_global(&global_buf); if (load_global_config(&config) < 0 ||
git_config__find_xdg(&xdg_buf); git_config_get_bool(&symlinks, config, "core.symlinks") < 0 ||
git_config__find_system(&system_buf); !symlinks)
git_config__find_programdata(&programdata_buf);
if (load_config(&config, NULL,
path_unless_empty(&global_buf),
path_unless_empty(&xdg_buf),
path_unless_empty(&system_buf),
path_unless_empty(&programdata_buf)) < 0)
goto done;
if (git_config_get_bool(&symlinks, config, "core.symlinks") < 0 || !symlinks)
goto done; goto done;
#endif #endif
...@@ -1669,10 +1686,6 @@ static bool are_symlinks_supported(const char *wd_path) ...@@ -1669,10 +1686,6 @@ static bool are_symlinks_supported(const char *wd_path)
goto done; goto done;
done: done:
git_str_dispose(&global_buf);
git_str_dispose(&xdg_buf);
git_str_dispose(&system_buf);
git_str_dispose(&programdata_buf);
git_config_free(config); git_config_free(config);
return symlinks != 0; return symlinks != 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment