Skip to content

Commit 451d3b7

Browse files
committed
Merge branch 'perl5lib'
With this topic branch, the PERL5LIB variable is unset to avoid external settings from interfering with Git's own Perl interpreter. This branch also cleans up some of our Windows-only config setting code (and this will need to be rearranged in the next merging rebase so that the cleanup comes first, and fscache and longPaths support build on top). Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 1767877 + a0efc0d commit 451d3b7

File tree

8 files changed

+121
-35
lines changed

8 files changed

+121
-35
lines changed

Documentation/config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,12 @@ core.longpaths::
775775
(msys, bash, tcl, perl...). Only enable this if you know what you're
776776
doing and are prepared to live with a few quirks.
777777

778+
core.unsetenvvars::
779+
EXPERIMENTAL, Windows-only: comma-separated list of environment
780+
variables' names that need to be unset before spawning any other
781+
process. Defaults to `PERL5LIB` to account for the fact that Git
782+
for Windows insists on using its own Perl interpreter.
783+
778784
core.createObject::
779785
You can set this to 'link', in which case a hardlink followed by
780786
a delete of the source are used to make sure that object creation

cache.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -737,18 +737,6 @@ extern int ref_paranoia;
737737
extern char comment_line_char;
738738
extern int auto_comment_line_char;
739739

740-
/* Windows only */
741-
enum hide_dotfiles_type {
742-
HIDE_DOTFILES_FALSE = 0,
743-
HIDE_DOTFILES_TRUE,
744-
HIDE_DOTFILES_DOTGITONLY
745-
};
746-
extern enum hide_dotfiles_type hide_dotfiles;
747-
748-
extern int core_fscache;
749-
750-
extern int core_long_paths;
751-
752740
enum branch_track {
753741
BRANCH_TRACK_UNSPECIFIED = -1,
754742
BRANCH_TRACK_NEVER = 0,

compat/mingw.c

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,46 @@ static int retry_ask_yes_no(int *tries, const char *format, ...)
228228
return result;
229229
}
230230

231+
/* Windows only */
232+
enum hide_dotfiles_type {
233+
HIDE_DOTFILES_FALSE = 0,
234+
HIDE_DOTFILES_TRUE,
235+
HIDE_DOTFILES_DOTGITONLY
236+
};
237+
238+
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
239+
int core_fscache;
240+
int core_long_paths;
241+
static char *unset_environment_variables;
242+
243+
int mingw_core_config(const char *var, const char *value)
244+
{
245+
if (!strcmp(var, "core.hidedotfiles")) {
246+
if (value && !strcasecmp(value, "dotgitonly"))
247+
hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
248+
else
249+
hide_dotfiles = git_config_bool(var, value);
250+
return 0;
251+
}
252+
253+
if (!strcmp(var, "core.fscache")) {
254+
core_fscache = git_config_bool(var, value);
255+
return 0;
256+
}
257+
258+
if (!strcmp(var, "core.longpaths")) {
259+
core_long_paths = git_config_bool(var, value);
260+
return 0;
261+
}
262+
263+
if (!strcmp(var, "core.unsetenvvars")) {
264+
free(unset_environment_variables);
265+
unset_environment_variables = xstrdup(value);
266+
return 0;
267+
}
268+
269+
return 0;
270+
}
231271

232272
DECLARE_PROC_ADDR(kernel32.dll, BOOL, CreateSymbolicLinkW, LPCWSTR, LPCWSTR, DWORD);
233273

@@ -1399,6 +1439,27 @@ static wchar_t *make_environment_block(char **deltaenv)
13991439

14001440
#endif
14011441

1442+
static void do_unset_environment_variables(void)
1443+
{
1444+
static int done;
1445+
char *p = unset_environment_variables;
1446+
1447+
if (done || !p)
1448+
return;
1449+
done = 1;
1450+
1451+
for (;;) {
1452+
char *comma = strchr(p, ',');
1453+
1454+
if (comma)
1455+
*comma = '\0';
1456+
unsetenv(p);
1457+
if (!comma)
1458+
break;
1459+
p = comma + 1;
1460+
}
1461+
}
1462+
14021463
struct pinfo_t {
14031464
struct pinfo_t *next;
14041465
pid_t pid;
@@ -1417,9 +1478,12 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
14171478
wchar_t wcmd[MAX_PATH], wdir[MAX_PATH], *wargs, *wenvblk = NULL;
14181479
unsigned flags = CREATE_UNICODE_ENVIRONMENT;
14191480
BOOL ret;
1481+
HANDLE cons;
1482+
1483+
do_unset_environment_variables();
14201484

14211485
/* Determine whether or not we are associated to a console */
1422-
HANDLE cons = CreateFile("CONOUT$", GENERIC_WRITE,
1486+
cons = CreateFile("CONOUT$", GENERIC_WRITE,
14231487
FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
14241488
FILE_ATTRIBUTE_NORMAL, NULL);
14251489
if (cons == INVALID_HANDLE_VALUE) {
@@ -3002,6 +3066,8 @@ int msc_startup(int argc, wchar_t **w_argv, wchar_t **w_env)
30023066
/* fix Windows specific environment settings */
30033067
setup_windows_environment();
30043068

3069+
unset_environment_variables = xstrdup("PERL5LIB");
3070+
30053071
/* initialize critical section for waitpid pinfo_t list */
30063072
InitializeCriticalSection(&pinfo_cs);
30073073
InitializeCriticalSection(&phantom_symlinks_cs);
@@ -3078,6 +3144,8 @@ void mingw_startup(void)
30783144
/* fix Windows specific environment settings */
30793145
setup_windows_environment();
30803146

3147+
unset_environment_variables = xstrdup("PERL5LIB");
3148+
30813149
/*
30823150
* Avoid a segmentation fault when cURL tries to set the CHARSET
30833151
* variable and putenv() barfs at our nedmalloc'ed environment.

compat/mingw.h

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

14+
extern int core_fscache;
15+
16+
extern int core_long_paths;
17+
18+
extern int mingw_core_config(const char *var, const char *value);
19+
#define platform_core_config mingw_core_config
20+
1421
/*
1522
* things that are not available in header files
1623
*/

config.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -999,26 +999,8 @@ static int git_default_core_config(const char *var, const char *value)
999999
return 0;
10001000
}
10011001

1002-
if (!strcmp(var, "core.hidedotfiles")) {
1003-
if (value && !strcasecmp(value, "dotgitonly"))
1004-
hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
1005-
else
1006-
hide_dotfiles = git_config_bool(var, value);
1007-
return 0;
1008-
}
1009-
1010-
if (!strcmp(var, "core.fscache")) {
1011-
core_fscache = git_config_bool(var, value);
1012-
return 0;
1013-
}
1014-
1015-
if (!strcmp(var, "core.longpaths")) {
1016-
core_long_paths = git_config_bool(var, value);
1017-
return 0;
1018-
}
1019-
10201002
/* Add other config variables here and to Documentation/config.txt. */
1021-
return 0;
1003+
return platform_core_config(var, value);
10221004
}
10231005

10241006
static int git_default_i18n_config(const char *var, const char *value)

environment.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ int core_apply_sparse_checkout;
6363
int merge_log_config = -1;
6464
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
6565
unsigned long pack_size_limit_cfg;
66-
enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
67-
int core_fscache;
68-
int core_long_paths;
6966

7067
#ifndef PROTECT_HFS_DEFAULT
7168
#define PROTECT_HFS_DEFAULT 0

git-compat-util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,14 @@ static inline size_t msvc_iconv(iconv_t conv,
367367
#define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin"
368368
#endif
369369

370+
#ifndef platform_core_config
371+
static inline int noop_core_config(const char *var, const char *value)
372+
{
373+
return 0;
374+
}
375+
#define platform_core_config noop_core_config
376+
#endif
377+
370378
#ifndef has_dos_drive_prefix
371379
static inline int git_has_dos_drive_prefix(const char *path)
372380
{

t/t0028-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)