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. */
207237static 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+
11841235struct 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
0 commit comments