Skip to content

Commit 23af48d

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 b195442 + ee0c8fb commit 23af48d

File tree

8 files changed

+104
-19
lines changed

8 files changed

+104
-19
lines changed

Documentation/config.txt

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

763+
core.unsetenvvars::
764+
EXPERIMENTAL, Windows-only: comma-separated list of environment
765+
variables' names that need to be unset before spawning any other
766+
process. Defaults to `PERL5LIB` to account for the fact that Git
767+
for Windows insists on using its own Perl interpreter.
768+
763769
core.createObject::
764770
You can set this to 'link', in which case a hardlink followed by
765771
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
@@ -721,14 +721,6 @@ extern int ref_paranoia;
721721
extern char comment_line_char;
722722
extern int auto_comment_line_char;
723723

724-
/* Windows only */
725-
enum hide_dotfiles_type {
726-
HIDE_DOTFILES_FALSE = 0,
727-
HIDE_DOTFILES_TRUE,
728-
HIDE_DOTFILES_DOTGITONLY
729-
};
730-
extern enum hide_dotfiles_type hide_dotfiles;
731-
732724
enum branch_track {
733725
BRANCH_TRACK_UNSPECIFIED = -1,
734726
BRANCH_TRACK_NEVER = 0,

compat/mingw.c

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,35 @@ static int ask_yes_no_if_possible(const char *format, ...)
202202
}
203203
}
204204

205+
/* Windows only */
206+
enum hide_dotfiles_type {
207+
HIDE_DOTFILES_FALSE = 0,
208+
HIDE_DOTFILES_TRUE,
209+
HIDE_DOTFILES_DOTGITONLY
210+
};
211+
212+
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
213+
static char *unset_environment_variables;
214+
215+
int mingw_core_config(const char *var, const char *value)
216+
{
217+
if (!strcmp(var, "core.hidedotfiles")) {
218+
if (value && !strcasecmp(value, "dotgitonly"))
219+
hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
220+
else
221+
hide_dotfiles = git_config_bool(var, value);
222+
return 0;
223+
}
224+
225+
if (!strcmp(var, "core.unsetenvvars")) {
226+
free(unset_environment_variables);
227+
unset_environment_variables = xstrdup(value);
228+
return 0;
229+
}
230+
231+
return 0;
232+
}
233+
205234
int mingw_unlink(const char *pathname)
206235
{
207236
int ret, tries = 0;
@@ -1068,6 +1097,27 @@ static wchar_t *make_environment_block(char **deltaenv)
10681097
return wenvblk;
10691098
}
10701099

1100+
static void do_unset_environment_variables(void)
1101+
{
1102+
static int done;
1103+
char *p = unset_environment_variables;
1104+
1105+
if (done || !p)
1106+
return;
1107+
done = 1;
1108+
1109+
for (;;) {
1110+
char *comma = strchr(p, ',');
1111+
1112+
if (comma)
1113+
*comma = '\0';
1114+
unsetenv(p);
1115+
if (!comma)
1116+
break;
1117+
p = comma + 1;
1118+
}
1119+
}
1120+
10711121
struct pinfo_t {
10721122
struct pinfo_t *next;
10731123
pid_t pid;
@@ -1086,9 +1136,12 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
10861136
wchar_t wcmd[MAX_PATH], wdir[MAX_PATH], *wargs, *wenvblk = NULL;
10871137
unsigned flags = CREATE_UNICODE_ENVIRONMENT;
10881138
BOOL ret;
1139+
HANDLE cons;
1140+
1141+
do_unset_environment_variables();
10891142

10901143
/* Determine whether or not we are associated to a console */
1091-
HANDLE cons = CreateFile("CONOUT$", GENERIC_WRITE,
1144+
cons = CreateFile("CONOUT$", GENERIC_WRITE,
10921145
FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
10931146
FILE_ATTRIBUTE_NORMAL, NULL);
10941147
if (cons == INVALID_HANDLE_VALUE) {
@@ -2229,6 +2282,8 @@ void mingw_startup(void)
22292282
/* fix Windows specific environment settings */
22302283
setup_windows_environment();
22312284

2285+
unset_environment_variables = xstrdup("PERL5LIB");
2286+
22322287
/* initialize critical section for waitpid pinfo_t list */
22332288
InitializeCriticalSection(&pinfo_cs);
22342289

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);
15+
#define platform_core_config mingw_core_config
16+
1417
/*
1518
* things that are not available in header files
1619
*/

config.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -999,16 +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-
10101002
/* Add other config variables here and to Documentation/config.txt. */
1011-
return 0;
1003+
return platform_core_config(var, value);
10121004
}
10131005

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

environment.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +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;
6766

6867
#ifndef PROTECT_HFS_DEFAULT
6968
#define PROTECT_HFS_DEFAULT 0

git-compat-util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,14 @@ extern char *gitdirname(char *);
330330
#define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin"
331331
#endif
332332

333+
#ifndef platform_core_config
334+
static inline int noop_core_config(const char *var, const char *value)
335+
{
336+
return 0;
337+
}
338+
#define platform_core_config noop_core_config
339+
#endif
340+
333341
#ifndef has_dos_drive_prefix
334342
static inline int git_has_dos_drive_prefix(const char *path)
335343
{

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)