Merge branch 'js/mingw-perl5lib'
[gitweb.git] / compat / mingw.c
index 3b44dd99d79aed48a325b1e59b28d98d0c0790b9..e8e538a2e048a17ff7e07c411cd7b51021c90a4a 100644 (file)
@@ -6,6 +6,7 @@
 #include "../run-command.h"
 #include "../cache.h"
 #include "win32/lazyload.h"
+#include "../config.h"
 
 #define HCAST(type, handle) ((type)(intptr_t)handle)
 
@@ -203,6 +204,35 @@ static int ask_yes_no_if_possible(const char *format, ...)
        }
 }
 
+/* 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;
+static char *unset_environment_variables;
+
+int mingw_core_config(const char *var, const char *value, void *cb)
+{
+       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.unsetenvvars")) {
+               free(unset_environment_variables);
+               unset_environment_variables = xstrdup(value);
+               return 0;
+       }
+
+       return 0;
+}
+
 /* Normalizes NT paths as returned by some low-level APIs. */
 static wchar_t *normalize_ntpath(wchar_t *wbuf)
 {
@@ -1181,6 +1211,27 @@ static wchar_t *make_environment_block(char **deltaenv)
        return wenvblk;
 }
 
+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;
@@ -1199,9 +1250,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) {
@@ -2438,6 +2492,8 @@ void mingw_startup(void)
        /* fix Windows specific environment settings */
        setup_windows_environment();
 
+       unset_environment_variables = xstrdup("PERL5LIB");
+
        /* initialize critical section for waitpid pinfo_t list */
        InitializeCriticalSection(&pinfo_cs);