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,36 +1632,53 @@ static bool is_filesystem_case_insensitive(const char *gitdir_path) ...@@ -1632,36 +1632,53 @@ 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 symlinks = 0; int error;
/*
* To emulate Git for Windows, symlinks on Windows must be explicitly
* opted-in. We examine the system configuration for a core.symlinks
* set to true. If found, we then examine the filesystem to see if
* symlinks are _actually_ supported by the current user. If that is
* _not_ set, then we do not test or enable symlink support.
*/
#ifdef GIT_WIN32
git_config__find_global(&global_buf); git_config__find_global(&global_buf);
git_config__find_xdg(&xdg_buf); git_config__find_xdg(&xdg_buf);
git_config__find_system(&system_buf); git_config__find_system(&system_buf);
git_config__find_programdata(&programdata_buf); git_config__find_programdata(&programdata_buf);
if (load_config(&config, NULL, error = load_config(config, NULL,
path_unless_empty(&global_buf), path_unless_empty(&global_buf),
path_unless_empty(&xdg_buf), path_unless_empty(&xdg_buf),
path_unless_empty(&system_buf), path_unless_empty(&system_buf),
path_unless_empty(&programdata_buf)) < 0) path_unless_empty(&programdata_buf));
goto done;
git_str_dispose(&global_buf);
git_str_dispose(&xdg_buf);
git_str_dispose(&system_buf);
git_str_dispose(&programdata_buf);
if (git_config_get_bool(&symlinks, config, "core.symlinks") < 0 || !symlinks) return error;
}
static bool are_symlinks_supported(const char *wd_path)
{
git_config *config = NULL;
int symlinks = 0;
/*
* To emulate Git for Windows, symlinks on Windows must be explicitly
* opted-in. We examine the system configuration for a core.symlinks
* set to true. If found, we then examine the filesystem to see if
* symlinks are _actually_ supported by the current user. If that is
* _not_ set, then we do not test or enable symlink support.
*/
#ifdef GIT_WIN32
if (load_global_config(&config) < 0 ||
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