config: allow for platform-specific core.* config settings

In the Git for Windows project, we have ample precendent for config settings that apply to Windows, and to Windows only. Let's formalize this concept by introducing a platform_core_config() function that can be #define'd in a platform-specific manner. This will allow us to contain platform-specific code better, as the corresponding variables no longer need to be exported so that they can be defined in environment.c and be set in config.c Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Oct 30, 2018 at 11:40 UTC 70fc5793dfdf8ba8586ca130674f6896eb3eb37a
4 files changed +19 -3
compat/mingw.c
+5
@@ -203,6 +203,11 @@ static int ask_yes_no_if_possible(const char *format, ...)
203 }
204 }
205
206 +int mingw_core_config(const char *var, const char *value, void *cb)
207 +{
208 + return 0;
209 +}
210 +
211 /* Normalizes NT paths as returned by some low-level APIs. */
212 static wchar_t *normalize_ntpath(wchar_t *wbuf)
213 {
compat/mingw.h
+3
@@ -11,6 +11,9 @@ typedef _sigset_t sigset_t;
11 #undef _POSIX_THREAD_SAFE_FUNCTIONS
12 #endif
13
14 +extern int mingw_core_config(const char *var, const char *value, void *cb);
15 +#define platform_core_config mingw_core_config
16 +
17 /*
18 * things that are not available in header files
19 */
config.c
+3 -3
@@ -1093,7 +1093,7 @@ int git_config_color(char *dest, const char *var, const char *value)
1093 return 0;
1094 }
1095
1096 -static int git_default_core_config(const char *var, const char *value)
1096 +static int git_default_core_config(const char *var, const char *value, void *cb)
1097 {
1098 /* This needs a better name */
1099 if (!strcmp(var, "core.filemode")) {
@@ -1363,7 +1363,7 @@ static int git_default_core_config(const char *var, const char *value)
1363 }
1364
1365 /* Add other config variables here and to Documentation/config.txt. */
1366 - return 0;
1366 + return platform_core_config(var, value, cb);
1367 }
1368
1369 static int git_default_i18n_config(const char *var, const char *value)
@@ -1451,7 +1451,7 @@ static int git_default_mailmap_config(const char *var, const char *value)
1451 int git_default_config(const char *var, const char *value, void *cb)
1452 {
1453 if (starts_with(var, "core."))
1454 - return git_default_core_config(var, value);
1454 + return git_default_core_config(var, value, cb);
1455
1456 if (starts_with(var, "user."))
1457 return git_ident_config(var, value, cb);
git-compat-util.h
+8
@@ -342,6 +342,14 @@ typedef uintmax_t timestamp_t;
342 #define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin"
343 #endif
344
345 +#ifndef platform_core_config
346 +static inline int noop_core_config(const char *var, const char *value, void *cb)
347 +{
348 + return 0;
349 +}
350 +#define platform_core_config noop_core_config
351 +#endif
352 +
353 #ifndef has_dos_drive_prefix
354 static inline int git_has_dos_drive_prefix(const char *path)
355 {