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 <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2016-11-18 13:40:02 +01:00
9 changed files with 123 additions and 42 deletions

View File

@@ -775,6 +775,12 @@ core.longpaths::
(msys, bash, tcl, perl...). Only enable this if you know what you're
doing and are prepared to live with a few quirks.
core.unsetenvvars::
EXPERIMENTAL, Windows-only: comma-separated list of environment
variables' names that need to be unset before spawning any other
process. Defaults to `PERL5LIB` to account for the fact that Git
for Windows insists on using its own Perl interpreter.
core.createObject::
You can set this to 'link', in which case a hardlink followed by
a delete of the source are used to make sure that object creation

View File

@@ -154,13 +154,8 @@ static int git_init_db_config(const char *k, const char *v, void *cb)
if (!strcmp(k, "init.templatedir"))
return git_config_pathname(&init_db_template_dir, k, v);
if (!strcmp(k, "core.hidedotfiles")) {
if (v && !strcasecmp(v, "dotgitonly"))
hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
else
hide_dotfiles = git_config_bool(k, v);
return 0;
}
if (starts_with(k, "core."))
return platform_core_config(k, v);
return 0;
}

12
cache.h
View File

@@ -720,18 +720,6 @@ extern int ref_paranoia;
extern char comment_line_char;
extern int auto_comment_line_char;
/* Windows only */
enum hide_dotfiles_type {
HIDE_DOTFILES_FALSE = 0,
HIDE_DOTFILES_TRUE,
HIDE_DOTFILES_DOTGITONLY
};
extern enum hide_dotfiles_type hide_dotfiles;
extern int core_fscache;
extern int core_long_paths;
enum branch_track {
BRANCH_TRACK_UNSPECIFIED = -1,
BRANCH_TRACK_NEVER = 0,

View File

@@ -228,6 +228,46 @@ static int retry_ask_yes_no(int *tries, const char *format, ...)
return result;
}
/* Windows only */
enum hide_dotfiles_type {
HIDE_DOTFILES_FALSE = 0,
HIDE_DOTFILES_TRUE,
HIDE_DOTFILES_DOTGITONLY
};
static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
int core_fscache;
int core_long_paths;
static char *unset_environment_variables;
int mingw_core_config(const char *var, const char *value)
{
if (!strcmp(var, "core.hidedotfiles")) {
if (value && !strcasecmp(value, "dotgitonly"))
hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
else
hide_dotfiles = git_config_bool(var, value);
return 0;
}
if (!strcmp(var, "core.fscache")) {
core_fscache = git_config_bool(var, value);
return 0;
}
if (!strcmp(var, "core.longpaths")) {
core_long_paths = git_config_bool(var, value);
return 0;
}
if (!strcmp(var, "core.unsetenvvars")) {
free(unset_environment_variables);
unset_environment_variables = xstrdup(value);
return 0;
}
return 0;
}
DECLARE_PROC_ADDR(kernel32.dll, BOOL, CreateSymbolicLinkW, LPCWSTR, LPCWSTR, DWORD);
@@ -1399,6 +1439,27 @@ static wchar_t *make_environment_block(char **deltaenv)
#endif
static void do_unset_environment_variables(void)
{
static int done;
char *p = unset_environment_variables;
if (done || !p)
return;
done = 1;
for (;;) {
char *comma = strchr(p, ',');
if (comma)
*comma = '\0';
unsetenv(p);
if (!comma)
break;
p = comma + 1;
}
}
struct pinfo_t {
struct pinfo_t *next;
pid_t pid;
@@ -1417,9 +1478,12 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
wchar_t wcmd[MAX_PATH], wdir[MAX_PATH], *wargs, *wenvblk = NULL;
unsigned flags = CREATE_UNICODE_ENVIRONMENT;
BOOL ret;
HANDLE cons;
do_unset_environment_variables();
/* Determine whether or not we are associated to a console */
HANDLE cons = CreateFile("CONOUT$", GENERIC_WRITE,
cons = CreateFile("CONOUT$", GENERIC_WRITE,
FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
if (cons == INVALID_HANDLE_VALUE) {
@@ -3002,6 +3066,8 @@ int msc_startup(int argc, wchar_t **w_argv, wchar_t **w_env)
/* fix Windows specific environment settings */
setup_windows_environment();
unset_environment_variables = xstrdup("PERL5LIB");
/* initialize critical section for waitpid pinfo_t list */
InitializeCriticalSection(&pinfo_cs);
InitializeCriticalSection(&phantom_symlinks_cs);
@@ -3078,6 +3144,8 @@ void mingw_startup(void)
/* fix Windows specific environment settings */
setup_windows_environment();
unset_environment_variables = xstrdup("PERL5LIB");
/*
* Avoid a segmentation fault when cURL tries to set the CHARSET
* variable and putenv() barfs at our nedmalloc'ed environment.

View File

@@ -11,6 +11,13 @@ typedef _sigset_t sigset_t;
#undef _POSIX_THREAD_SAFE_FUNCTIONS
#endif
extern int core_fscache;
extern int core_long_paths;
extern int mingw_core_config(const char *var, const char *value);
#define platform_core_config mingw_core_config
/*
* things that are not available in header files
*/

View File

@@ -999,26 +999,8 @@ static int git_default_core_config(const char *var, const char *value)
return 0;
}
if (!strcmp(var, "core.hidedotfiles")) {
if (value && !strcasecmp(value, "dotgitonly"))
hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
else
hide_dotfiles = git_config_bool(var, value);
return 0;
}
if (!strcmp(var, "core.fscache")) {
core_fscache = git_config_bool(var, value);
return 0;
}
if (!strcmp(var, "core.longpaths")) {
core_long_paths = git_config_bool(var, value);
return 0;
}
/* Add other config variables here and to Documentation/config.txt. */
return 0;
return platform_core_config(var, value);
}
static int git_default_i18n_config(const char *var, const char *value)

View File

@@ -64,9 +64,6 @@ int core_apply_sparse_checkout;
int merge_log_config = -1;
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
unsigned long pack_size_limit_cfg;
enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
int core_fscache;
int core_long_paths;
#ifndef PROTECT_HFS_DEFAULT
#define PROTECT_HFS_DEFAULT 0

View File

@@ -367,6 +367,14 @@ static inline size_t msvc_iconv(iconv_t conv,
#define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin"
#endif
#ifndef platform_core_config
static inline int noop_core_config(const char *var, const char *value)
{
return 0;
}
#define platform_core_config noop_core_config
#endif
#ifndef has_dos_drive_prefix
static inline int git_has_dos_drive_prefix(const char *path)
{

30
t/t0028-core-unsetenvvars.sh Executable file
View File

@@ -0,0 +1,30 @@
#!/bin/sh
test_description='test the Windows-only core.unsetenvvars setting'
. ./test-lib.sh
if ! test_have_prereq MINGW
then
skip_all='skipping Windows-specific tests'
test_done
fi
test_expect_success 'setup' '
mkdir -p "$TRASH_DIRECTORY/.git/hooks" &&
write_script "$TRASH_DIRECTORY/.git/hooks/pre-commit" <<-\EOF
echo $HOBBES >&2
EOF
'
test_expect_success 'core.unsetenvvars works' '
HOBBES=Calvin &&
export HOBBES &&
git commit --allow-empty -m with 2>err &&
grep Calvin err &&
git -c core.unsetenvvars=FINDUS,HOBBES,CALVIN \
commit --allow-empty -m without 2>err &&
! grep Calvin err
'
test_done