Skip to content

Commit 17a2fa0

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 65971e3 + 3e47115 commit 17a2fa0

File tree

8 files changed

+109
-23
lines changed

8 files changed

+109
-23
lines changed

Documentation/config.txt

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

912+
core.unsetenvvars::
913+
EXPERIMENTAL, Windows-only: comma-separated list of environment
914+
variables' names that need to be unset before spawning any other
915+
process. Defaults to `PERL5LIB` to account for the fact that Git
916+
for Windows insists on using its own Perl interpreter.
917+
912918
core.createObject::
913919
You can set this to 'link', in which case a hardlink followed by
914920
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
@@ -901,14 +901,6 @@ int use_optional_locks(void);
901901
extern char comment_line_char;
902902
extern int auto_comment_line_char;
903903

904-
/* Windows only */
905-
enum hide_dotfiles_type {
906-
HIDE_DOTFILES_FALSE = 0,
907-
HIDE_DOTFILES_TRUE,
908-
HIDE_DOTFILES_DOTGITONLY
909-
};
910-
extern enum hide_dotfiles_type hide_dotfiles;
911-
912904
enum log_refs_config {
913905
LOG_REFS_UNSET = -1,
914906
LOG_REFS_NONE = 0,

compat/mingw.c

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "../strbuf.h"
66
#include "../run-command.h"
77
#include "../cache.h"
8+
#include "../config.h"
89

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

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

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

1113+
static void do_unset_environment_variables(void)
1114+
{
1115+
static int done;
1116+
char *p = unset_environment_variables;
1117+
1118+
if (done || !p)
1119+
return;
1120+
done = 1;
1121+
1122+
for (;;) {
1123+
char *comma = strchr(p, ',');
1124+
1125+
if (comma)
1126+
*comma = '\0';
1127+
unsetenv(p);
1128+
if (!comma)
1129+
break;
1130+
p = comma + 1;
1131+
}
1132+
}
1133+
10831134
struct pinfo_t {
10841135
struct pinfo_t *next;
10851136
pid_t pid;
@@ -1098,9 +1149,12 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
10981149
wchar_t wcmd[MAX_PATH], wdir[MAX_PATH], *wargs, *wenvblk = NULL;
10991150
unsigned flags = CREATE_UNICODE_ENVIRONMENT;
11001151
BOOL ret;
1152+
HANDLE cons;
1153+
1154+
do_unset_environment_variables();
11011155

11021156
/* Determine whether or not we are associated to a console */
1103-
HANDLE cons = CreateFile("CONOUT$", GENERIC_WRITE,
1157+
cons = CreateFile("CONOUT$", GENERIC_WRITE,
11041158
FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
11051159
FILE_ATTRIBUTE_NORMAL, NULL);
11061160
if (cons == INVALID_HANDLE_VALUE) {
@@ -2291,6 +2345,8 @@ void mingw_startup(void)
22912345
/* fix Windows specific environment settings */
22922346
setup_windows_environment();
22932347

2348+
unset_environment_variables = xstrdup("PERL5LIB");
2349+
22942350
/* initialize critical section for waitpid pinfo_t list */
22952351
InitializeCriticalSection(&pinfo_cs);
22962352

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
@@ -71,7 +71,6 @@ int core_apply_sparse_checkout;
7171
int merge_log_config = -1;
7272
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
7373
unsigned long pack_size_limit_cfg;
74-
enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
7574
enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET;
7675

7776
#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)