repo: refactor global config loader function Pull the global configuration loader out of the symlink check so that it can be re-used.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c
index 7562fc2..bd4242e 100644
--- a/src/libgit2/repository.c
+++ b/src/libgit2/repository.c
@@ -1632,13 +1632,40 @@ static bool is_filesystem_case_insensitive(const char *gitdir_path)
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 xdg_buf = GIT_STR_INIT;
git_str system_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;
/*
@@ -1649,19 +1676,9 @@ static bool are_symlinks_supported(const char *wd_path)
* _not_ set, then we do not test or enable symlink support.
*/
#ifdef GIT_WIN32
- git_config__find_global(&global_buf);
- git_config__find_xdg(&xdg_buf);
- git_config__find_system(&system_buf);
- 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)
+ if (load_global_config(&config) < 0 ||
+ git_config_get_bool(&symlinks, config, "core.symlinks") < 0 ||
+ !symlinks)
goto done;
#endif
@@ -1669,10 +1686,6 @@ static bool are_symlinks_supported(const char *wd_path)
goto 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);
return symlinks != 0;
}