Skip to content

Commit 6c268fd

Browse files
committed
Merge branch 'js/mingw-perl5lib'
Windows fix. * js/mingw-perl5lib: mingw: unset PERL5LIB by default config: move Windows-specific config settings into compat/mingw.c config: allow for platform-specific core.* config settings config: rename `dummy` parameter to `cb` in git_default_config()
2 parents fbfdc07 + 0e218f9 commit 6c268fd

File tree

8 files changed

+109
-23
lines changed

8 files changed

+109
-23
lines changed

Documentation/config/core.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,12 @@ relatively high IO latencies. When enabled, Git will do the
548548
index comparison to the filesystem data in parallel, allowing
549549
overlapping IO's. Defaults to true.
550550

551+
core.unsetenvvars::
552+
Windows-only: comma-separated list of environment variables'
553+
names that need to be unset before spawning any other process.
554+
Defaults to `PERL5LIB` to account for the fact that Git for
555+
Windows insists on using its own Perl interpreter.
556+
551557
core.createObject::
552558
You can set this to 'link', in which case a hardlink followed by
553559
a delete of the source are used to make sure that object creation

cache.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -906,14 +906,6 @@ int use_optional_locks(void);
906906
extern char comment_line_char;
907907
extern int auto_comment_line_char;
908908

909-
/* Windows only */
910-
enum hide_dotfiles_type {
911-
HIDE_DOTFILES_FALSE = 0,
912-
HIDE_DOTFILES_TRUE,
913-
HIDE_DOTFILES_DOTGITONLY
914-
};
915-
extern enum hide_dotfiles_type hide_dotfiles;
916-
917909
enum log_refs_config {
918910
LOG_REFS_UNSET = -1,
919911
LOG_REFS_NONE = 0,

compat/mingw.c

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "../run-command.h"
77
#include "../cache.h"
88
#include "win32/lazyload.h"
9+
#include "../config.h"
910

1011
#define HCAST(type, handle) ((type)(intptr_t)handle)
1112

@@ -203,6 +204,35 @@ static int ask_yes_no_if_possible(const char *format, ...)
203204
}
204205
}
205206

207+
/* Windows only */
208+
enum hide_dotfiles_type {
209+
HIDE_DOTFILES_FALSE = 0,
210+
HIDE_DOTFILES_TRUE,
211+
HIDE_DOTFILES_DOTGITONLY
212+
};
213+
214+
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
215+
static char *unset_environment_variables;
216+
217+
int mingw_core_config(const char *var, const char *value, void *cb)
218+
{
219+
if (!strcmp(var, "core.hidedotfiles")) {
220+
if (value && !strcasecmp(value, "dotgitonly"))
221+
hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
222+
else
223+
hide_dotfiles = git_config_bool(var, value);
224+
return 0;
225+
}
226+
227+
if (!strcmp(var, "core.unsetenvvars")) {
228+
free(unset_environment_variables);
229+
unset_environment_variables = xstrdup(value);
230+
return 0;
231+
}
232+
233+
return 0;
234+
}
235+
206236
/* Normalizes NT paths as returned by some low-level APIs. */
207237
static wchar_t *normalize_ntpath(wchar_t *wbuf)
208238
{
@@ -1181,6 +1211,27 @@ static wchar_t *make_environment_block(char **deltaenv)
11811211
return wenvblk;
11821212
}
11831213

1214+
static void do_unset_environment_variables(void)
1215+
{
1216+
static int done;
1217+
char *p = unset_environment_variables;
1218+
1219+
if (done || !p)
1220+
return;
1221+
done = 1;
1222+
1223+
for (;;) {
1224+
char *comma = strchr(p, ',');
1225+
1226+
if (comma)
1227+
*comma = '\0';
1228+
unsetenv(p);
1229+
if (!comma)
1230+
break;
1231+
p = comma + 1;
1232+
}
1233+
}
1234+
11841235
struct pinfo_t {
11851236
struct pinfo_t *next;
11861237
pid_t pid;
@@ -1199,9 +1250,12 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
11991250
wchar_t wcmd[MAX_PATH], wdir[MAX_PATH], *wargs, *wenvblk = NULL;
12001251
unsigned flags = CREATE_UNICODE_ENVIRONMENT;
12011252
BOOL ret;
1253+
HANDLE cons;
1254+
1255+
do_unset_environment_variables();
12021256

12031257
/* Determine whether or not we are associated to a console */
1204-
HANDLE cons = CreateFile("CONOUT$", GENERIC_WRITE,
1258+
cons = CreateFile("CONOUT$", GENERIC_WRITE,
12051259
FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
12061260
FILE_ATTRIBUTE_NORMAL, NULL);
12071261
if (cons == INVALID_HANDLE_VALUE) {
@@ -2438,6 +2492,8 @@ void mingw_startup(void)
24382492
/* fix Windows specific environment settings */
24392493
setup_windows_environment();
24402494

2495+
unset_environment_variables = xstrdup("PERL5LIB");
2496+
24412497
/* initialize critical section for waitpid pinfo_t list */
24422498
InitializeCriticalSection(&pinfo_cs);
24432499

compat/mingw.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ typedef _sigset_t sigset_t;
1111
#undef _POSIX_THREAD_SAFE_FUNCTIONS
1212
#endif
1313

14+
extern int mingw_core_config(const char *var, const char *value, void *cb);
15+
#define platform_core_config mingw_core_config
16+
1417
/*
1518
* things that are not available in header files
1619
*/

config.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ int git_config_color(char *dest, const char *var, const char *value)
10931093
return 0;
10941094
}
10951095

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)
10971097
{
10981098
/* This needs a better name */
10991099
if (!strcmp(var, "core.filemode")) {
@@ -1344,14 +1344,6 @@ static int git_default_core_config(const char *var, const char *value)
13441344
return 0;
13451345
}
13461346

1347-
if (!strcmp(var, "core.hidedotfiles")) {
1348-
if (value && !strcasecmp(value, "dotgitonly"))
1349-
hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
1350-
else
1351-
hide_dotfiles = git_config_bool(var, value);
1352-
return 0;
1353-
}
1354-
13551347
if (!strcmp(var, "core.partialclonefilter")) {
13561348
return git_config_string(&core_partial_clone_filter_default,
13571349
var, value);
@@ -1363,7 +1355,7 @@ static int git_default_core_config(const char *var, const char *value)
13631355
}
13641356

13651357
/* Add other config variables here and to Documentation/config.txt. */
1366-
return 0;
1358+
return platform_core_config(var, value, cb);
13671359
}
13681360

13691361
static int git_default_i18n_config(const char *var, const char *value)
@@ -1448,13 +1440,13 @@ static int git_default_mailmap_config(const char *var, const char *value)
14481440
return 0;
14491441
}
14501442

1451-
int git_default_config(const char *var, const char *value, void *dummy)
1443+
int git_default_config(const char *var, const char *value, void *cb)
14521444
{
14531445
if (starts_with(var, "core."))
1454-
return git_default_core_config(var, value);
1446+
return git_default_core_config(var, value, cb);
14551447

14561448
if (starts_with(var, "user."))
1457-
return git_ident_config(var, value, dummy);
1449+
return git_ident_config(var, value, cb);
14581450

14591451
if (starts_with(var, "i18n."))
14601452
return git_default_i18n_config(var, value);

environment.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ int core_apply_sparse_checkout;
7272
int merge_log_config = -1;
7373
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
7474
unsigned long pack_size_limit_cfg;
75-
enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
7675
enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET;
7776

7877
#ifndef PROTECT_HFS_DEFAULT

git-compat-util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,14 @@ typedef uintmax_t timestamp_t;
342342
#define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin"
343343
#endif
344344

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+
345353
#ifndef has_dos_drive_prefix
346354
static inline int git_has_dos_drive_prefix(const char *path)
347355
{

t/t0029-core-unsetenvvars.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
test_description='test the Windows-only core.unsetenvvars setting'
4+
5+
. ./test-lib.sh
6+
7+
if ! test_have_prereq MINGW
8+
then
9+
skip_all='skipping Windows-specific tests'
10+
test_done
11+
fi
12+
13+
test_expect_success 'setup' '
14+
mkdir -p "$TRASH_DIRECTORY/.git/hooks" &&
15+
write_script "$TRASH_DIRECTORY/.git/hooks/pre-commit" <<-\EOF
16+
echo $HOBBES >&2
17+
EOF
18+
'
19+
20+
test_expect_success 'core.unsetenvvars works' '
21+
HOBBES=Calvin &&
22+
export HOBBES &&
23+
git commit --allow-empty -m with 2>err &&
24+
grep Calvin err &&
25+
git -c core.unsetenvvars=FINDUS,HOBBES,CALVIN \
26+
commit --allow-empty -m without 2>err &&
27+
! grep Calvin err
28+
'
29+
30+
test_done

0 commit comments

Comments
 (0)