threads / patch / 37150

patch, 13 partsWin32: fix environment memory leaks

Subject: [PATCH 04/13] Win32: fix environment memory leaks

## tl;dr

23 messages between Jul 17, 2014 and Jul 21, 2014. Diffs are folded; open one to read it.

replies: 22people: 3as markdown or json

Stepan Kasal· Jul 17, 2014, 15:37 UTC · lore

[PATCH 00/13] mingw unicode environment

Hello,

this is the remainder of Karsten's unicode branch, that is a time proven part of msysGit. (If this code is accepted, only one patch would only remain: gitk and git-gui fixes.)

When rebasing Karsten's work, I have eliminated two commits: https://github.com/msysgit/git/commit/f967550 https://github.com/msysgit/git/commit/290bf81

These commits only moved code down and up; this was not necessary, one forward declaration was all I needed.

One of the patches differs from the original version: "Enable color..." Following Karsten's suggestion, I have changed the value of env. var. TERM from "winterm" to "cygwin". This is because the subprocesses see the variable and may try to find it in (their copy of) termcap.

Enjoy,
   Stepan
Karsten Blees (13):
  Revert "Windows: teach getenv to do a case-sensitive search"
  Win32: Unicode environment (outgoing)
  Win32: Unicode environment (incoming)
  Win32: fix environment memory leaks
  Win32: unify environment case-sensitivity
  Win32: unify environment function names
  Win32: factor out environment block creation
  Win32: don't copy the environment twice when spawning child processes
  Win32: reduce environment array reallocations
  Win32: use low-level memory allocation during initialization
  Win32: keep the environment sorted
  Win32: patch Windows environment on startup
  Enable color output in Windows cmd.exe
 compat/mingw.c   | 290 +++++++++++++++++++++++++++++++------------------------
 compat/mingw.h   |  11 +--
 config.mak.uname |   2 -
 run-command.c    |  10 +-
 4 files changed, 170 insertions(+), 143 deletions(-)
-- 
2.0.0.9635.g0be03cb

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stepan Kasal· Jul 17, 2014, 15:37 UTC · re: Stepan Kasal · lore

[PATCH 01/13] Revert "Windows: teach getenv to do a case-sensitive search"

From: Karsten Blees <blees@dcon.de>
This reverts commit df599e9612788b728ce43a03159b85f1fe624d6a.

As of 5e9637c6 "i18n: add infrastructure for translating Git with gettext", eval_gettext uses MinGW envsubst.exe instead of git-sh-i18n--envsubst.exe for variable substitution. This breaks git-submodule.sh messages and tests, as envsubst.exe doesn't support case-sensitive environment lookup (the same is true for almost everything on Windows, including MSys and Cygwin tools).

30a615ac "Windows/i18n: rename $path to prevent clashes with $PATH" renames the conflicting variable in git-submodule.sh, so that it works on Windows (i.e. with case-insensitive environment, regardless of the toolset).

Revert to the documented behaviour of case-insensitive environment on Windows.

Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
 compat/mingw.c | 23 +++--------------------
 1 file changed, 3 insertions(+), 20 deletions(-)
Show changes to compat/mingw.c +3 −20
diff --git a/compat/mingw.c b/compat/mingw.c
index c19e3d9..ca1b6bd 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1245,31 +1245,14 @@ char **make_augmented_environ(const char *const *vars)
 }
 
 #undef getenv
-
-/*
- * The system's getenv looks up the name in a case-insensitive manner.
- * This version tries a case-sensitive lookup and falls back to
- * case-insensitive if nothing was found.  This is necessary because,
- * as a prominent example, CMD sets 'Path', but not 'PATH'.
- * Warning: not thread-safe.
- */
-static char *getenv_cs(const char *name)
-{
-	size_t len = strlen(name);
-	int i = lookup_env(environ, name, len);
-	if (i >= 0)
-		return environ[i] + len + 1;	/* skip past name and '=' */
-	return getenv(name);
-}
-
 char *mingw_getenv(const char *name)
 {
-	char *result = getenv_cs(name);
+	char *result = getenv(name);
 	if (!result && !strcmp(name, "TMPDIR")) {
 		/* on Windows it is TMP and TEMP */
-		result = getenv_cs("TMP");
+		result = getenv("TMP");
 		if (!result)
-			result = getenv_cs("TEMP");
+			result = getenv("TEMP");
 	}
 	return result;
 }
-- 
2.0.0.9635.g0be03cb

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stepan Kasal· Jul 17, 2014, 15:37 UTC · re: Stepan Kasal · lore

[PATCH 02/13] Win32: Unicode environment (outgoing)

From: Karsten Blees <blees@dcon.de>
Convert environment from UTF-8 to UTF-16 when creating other processes.
Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
 compat/mingw.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
Show changes to compat/mingw.c +13 −11
diff --git a/compat/mingw.c b/compat/mingw.c
index ca1b6bd..bd45950 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -919,9 +919,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
 {
 	STARTUPINFOW si;
 	PROCESS_INFORMATION pi;
-	struct strbuf envblk, args;
-	wchar_t wcmd[MAX_PATH], wdir[MAX_PATH], *wargs;
-	unsigned flags;
+	struct strbuf args;
+	wchar_t wcmd[MAX_PATH], wdir[MAX_PATH], *wargs, *wenvblk = NULL;
+	unsigned flags = CREATE_UNICODE_ENVIRONMENT;
 	BOOL ret;
 
 	/* Determine whether or not we are associated to a console */
@@ -938,7 +938,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
 		 * instead of CREATE_NO_WINDOW to make ssh
 		 * recognize that it has no console.
 		 */
-		flags = DETACHED_PROCESS;
+		flags |= DETACHED_PROCESS;
 	} else {
 		/* There is already a console. If we specified
 		 * DETACHED_PROCESS here, too, Windows would
@@ -946,7 +946,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
 		 * The same is true for CREATE_NO_WINDOW.
 		 * Go figure!
 		 */
-		flags = 0;
 		CloseHandle(cons);
 	}
 	memset(&si, 0, sizeof(si));
@@ -985,6 +984,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
 	if (env) {
 		int count = 0;
 		char **e, **sorted_env;
+		int size = 0, wenvsz = 0, wenvpos = 0;
 
 		for (e = env; *e; e++)
 			count++;
@@ -994,20 +994,22 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
 		memcpy(sorted_env, env, sizeof(*sorted_env) * (count + 1));
 		qsort(sorted_env, count, sizeof(*sorted_env), env_compare);
 
-		strbuf_init(&envblk, 0);
+		/* create environment block from temporary environment */
 		for (e = sorted_env; *e; e++) {
-			strbuf_addstr(&envblk, *e);
-			strbuf_addch(&envblk, '\0');
+			size = 2 * strlen(*e) + 2; /* +2 for final \0 */
+			ALLOC_GROW(wenvblk, (wenvpos + size) * sizeof(wchar_t), wenvsz);
+			wenvpos += xutftowcs(&wenvblk[wenvpos], *e, size) + 1;
 		}
+		/* add final \0 terminator */
+		wenvblk[wenvpos] = 0;
 		free(sorted_env);
 	}
 
 	memset(&pi, 0, sizeof(pi));
 	ret = CreateProcessW(wcmd, wargs, NULL, NULL, TRUE, flags,
-		env ? envblk.buf : NULL, dir ? wdir : NULL, &si, &pi);
+		wenvblk, dir ? wdir : NULL, &si, &pi);
 
-	if (env)
-		strbuf_release(&envblk);
+	free(wenvblk);
 	free(wargs);
 
 	if (!ret) {
-- 
2.0.0.9635.g0be03cb

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Karsten Blees· Jul 19, 2014, 19:13 UTC · re: Stepan Kasal · lore

[PATCH] fixup! Win32: Unicode environment (outgoing)

compat/mingw.c needs to #include "cache.h" for ALLOC_GROW.
Signed-off-by: Karsten Blees <blees@dcon.de>
---
 compat/mingw.c | 1 +
 1 file changed, 1 insertion(+)
Show changes to compat/mingw.c +1 −0
diff --git a/compat/mingw.c b/compat/mingw.c
index bd45950..c725a3e 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -4,6 +4,7 @@
 #include <wchar.h>
 #include "../strbuf.h"
 #include "../run-command.h"
+#include "../cache.h"
 
 static const int delay[] = { 0, 1, 10, 20, 40 };
 
-- 
2.0.2.897.g7f80809.dirty

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Junio C Hamano· Jul 21, 2014, 16:32 UTC · re: Karsten Blees · lore

Re: [PATCH] fixup! Win32: Unicode environment (outgoing)

Karsten Blees <karsten.blees@gmail.com> writes:
> compat/mingw.c needs to #include "cache.h" for ALLOC_GROW.
>
> Signed-off-by: Karsten Blees <blees@dcon.de>
> ---
Thanks!
Show 19 quoted lines
>  compat/mingw.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/compat/mingw.c b/compat/mingw.c
> index bd45950..c725a3e 100644
> --- a/compat/mingw.c
> +++ b/compat/mingw.c
> @@ -4,6 +4,7 @@
>  #include <wchar.h>
>  #include "../strbuf.h"
>  #include "../run-command.h"
> +#include "../cache.h"
>  
>  static const int delay[] = { 0, 1, 10, 20, 40 };
>  
> -- 
> 2.0.2.897.g7f80809.dirty
>
> -- 
-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stepan Kasal· Jul 17, 2014, 15:37 UTC · re: Stepan Kasal · lore

[PATCH 03/13] Win32: Unicode environment (incoming)

From: Karsten Blees <blees@dcon.de>
Convert environment from UTF-16 to UTF-8 on startup.

No changes to getenv() are necessary, as the MSVCRT version is implemented on top of char **environ.

However, putenv / _wputenv from MSVCRT no longer work, for two reasons:
1. they try to keep environ, _wenviron and the Win32 process environment
in sync, using the default system encoding instead of UTF-8 to convert
between charsets
2. msysgit and MSVCRT use different allocators, memory allocated in git
cannot be freed by the CRT and vice versa

Implement mingw_putenv using the env_setenv helper function from the environment merge code.

Note that in case of memory allocation failure, putenv now dies with error message (due to xrealloc) instead of failing with ENOMEM. As git assumes setenv / putenv to always succeed, this prevents it from continuing with incorrect settings.

Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
 compat/mingw.c | 15 +++++++++++++++
 compat/mingw.h |  2 ++
 2 files changed, 17 insertions(+)
Show changes to 2 files +17 −0

compat/mingw.c, compat/mingw.h

diff --git a/compat/mingw.c b/compat/mingw.c
index bd45950..eadba8a 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1259,6 +1259,12 @@ char *mingw_getenv(const char *name)
 	return result;
 }
 
+int mingw_putenv(const char *namevalue)
+{
+	environ = env_setenv(environ, namevalue);
+	return 0;
+}
+
 /*
  * Note, this isn't a complete replacement for getaddrinfo. It assumes
  * that service contains a numerical port, or that it is null. It
@@ -2051,6 +2057,11 @@ void mingw_startup()
 	maxlen = wcslen(_wpgmptr);
 	for (i = 1; i < argc; i++)
 		maxlen = max(maxlen, wcslen(wargv[i]));
+	for (i = 0; wenv[i]; i++)
+		maxlen = max(maxlen, wcslen(wenv[i]));
+
+	/* nedmalloc can't free CRT memory, allocate resizable environment list */
+	environ = xcalloc(i + 1, sizeof(char*));
 
 	/* allocate buffer (wchar_t encodes to max 3 UTF-8 bytes) */
 	maxlen = 3 * maxlen + 1;
@@ -2063,6 +2074,10 @@ void mingw_startup()
 		len = xwcstoutf(buffer, wargv[i], maxlen);
 		__argv[i] = xmemdupz(buffer, len);
 	}
+	for (i = 0; wenv[i]; i++) {
+		len = xwcstoutf(buffer, wenv[i], maxlen);
+		environ[i] = xmemdupz(buffer, len);
+	}
 	free(buffer);
 
 	/* initialize critical section for waitpid pinfo_t list */
diff --git a/compat/mingw.h b/compat/mingw.h
index 510530c..c3889ca 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -210,6 +210,8 @@ char *mingw_getcwd(char *pointer, int len);
 
 char *mingw_getenv(const char *name);
 #define getenv mingw_getenv
+int mingw_putenv(const char *namevalue);
+#define putenv mingw_putenv
 
 int mingw_gethostname(char *host, int namelen);
 #define gethostname mingw_gethostname
-- 
2.0.0.9635.g0be03cb

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stepan Kasal· Jul 17, 2014, 15:37 UTC · re: Stepan Kasal · lore
From: Karsten Blees <blees@dcon.de>
All functions that modify the environment have memory leaks.

Disable gitunsetenv in the Makefile and use env_setenv (via mingw_putenv) instead (this frees removed environment entries).

Move xstrdup from env_setenv to make_augmented_environ, so that mingw_putenv no longer copies the environment entries (according to POSIX [1], "the string [...] shall become part of the environment"). This also fixes the memory leak in gitsetenv, which expects a POSIX compliant putenv.

[1] http://pubs.opengroup.org/onlinepubs/009695399/functions/putenv.html
Note: This patch depends on taking control of char **environ and having
our own mingw_putenv (both introduced in "Win32: Unicode environment
(incoming)").
Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
 compat/mingw.c   | 10 ++++++----
 compat/mingw.h   |  1 +
 config.mak.uname |  2 --
 3 files changed, 7 insertions(+), 6 deletions(-)
Show changes to 3 files +7 −6

compat/mingw.c, compat/mingw.h, config.mak.uname

diff --git a/compat/mingw.c b/compat/mingw.c
index eadba8a..47e866c 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1219,14 +1219,14 @@ static char **env_setenv(char **env, const char *name)
 			for (i = 0; env[i]; i++)
 				;
 			env = xrealloc(env, (i+2)*sizeof(*env));
-			env[i] = xstrdup(name);
+			env[i] = (char*) name;
 			env[i+1] = NULL;
 		}
 	}
 	else {
 		free(env[i]);
 		if (*eq)
-			env[i] = xstrdup(name);
+			env[i] = (char*) name;
 		else
 			for (; env[i]; i++)
 				env[i] = env[i+1];
@@ -1241,8 +1241,10 @@ char **make_augmented_environ(const char *const *vars)
 {
 	char **env = copy_environ();
 
-	while (*vars)
-		env = env_setenv(env, *vars++);
+	while (*vars) {
+		const char *v = *vars++;
+		env = env_setenv(env, strchr(v, '=') ? xstrdup(v) : v);
+	}
 	return env;
 }
 
diff --git a/compat/mingw.h b/compat/mingw.h
index c3889ca..ef94194 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -212,6 +212,7 @@ char *mingw_getenv(const char *name);
 #define getenv mingw_getenv
 int mingw_putenv(const char *namevalue);
 #define putenv mingw_putenv
+#define unsetenv mingw_putenv
 
 int mingw_gethostname(char *host, int namelen);
 #define gethostname mingw_gethostname
diff --git a/config.mak.uname b/config.mak.uname
index 00cf4c6..15ee15e 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -327,7 +327,6 @@ ifeq ($(uname_S),Windows)
 	NO_IPV6 = YesPlease
 	NO_UNIX_SOCKETS = YesPlease
 	NO_SETENV = YesPlease
-	NO_UNSETENV = YesPlease
 	NO_STRCASESTR = YesPlease
 	NO_STRLCPY = YesPlease
 	NO_MEMMEM = YesPlease
@@ -480,7 +479,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
 	NO_SYMLINK_HEAD = YesPlease
 	NO_UNIX_SOCKETS = YesPlease
 	NO_SETENV = YesPlease
-	NO_UNSETENV = YesPlease
 	NO_STRCASESTR = YesPlease
 	NO_STRLCPY = YesPlease
 	NO_MEMMEM = YesPlease
-- 
2.0.0.9635.g0be03cb

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stepan Kasal· Jul 17, 2014, 15:37 UTC · re: Stepan Kasal · lore

[PATCH 05/13] Win32: unify environment case-sensitivity

From: Karsten Blees <blees@dcon.de>

The environment on Windows is case-insensitive. Some environment functions (such as unsetenv and make_augmented_environ) have always used case- sensitive comparisons instead, while others (getenv, putenv, sorting in spawn*) were case-insensitive.

Prevent potential inconsistencies by using case-insensitive comparison in lookup_env (used by putenv, unsetenv and make_augmented_environ).

Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
 compat/mingw.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Show changes to compat/mingw.c +1 −2
diff --git a/compat/mingw.c b/compat/mingw.c
index 47e866c..fe869ed 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1198,8 +1198,7 @@ static int lookup_env(char **env, const char *name, size_t nmln)
 	int i;
 
 	for (i = 0; env[i]; i++) {
-		if (0 == strncmp(env[i], name, nmln)
-		    && '=' == env[i][nmln])
+		if (!strncasecmp(env[i], name, nmln) && '=' == env[i][nmln])
 			/* matches */
 			return i;
 	}
-- 
2.0.0.9635.g0be03cb

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stepan Kasal· Jul 17, 2014, 15:37 UTC · re: Stepan Kasal · lore

[PATCH 06/13] Win32: unify environment function names

From: Karsten Blees <blees@dcon.de>

Environment helper functions use random naming ('env' prefix or suffix or both, with or without '_'). Change to POSIX naming scheme ('env' suffix, no '_').

Env_setenv has more in common with putenv than setenv. Change to do_putenv.
Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
 compat/mingw.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
Show changes to compat/mingw.c +7 −7
diff --git a/compat/mingw.c b/compat/mingw.c
index fe869ed..89fe62b 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -898,7 +898,7 @@ static char *path_lookup(const char *cmd, char **path, int exe_only)
 	return prog;
 }
 
-static int env_compare(const void *a, const void *b)
+static int compareenv(const void *a, const void *b)
 {
 	char *const *ea = a;
 	char *const *eb = b;
@@ -992,7 +992,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
 		/* environment must be sorted */
 		sorted_env = xmalloc(sizeof(*sorted_env) * (count + 1));
 		memcpy(sorted_env, env, sizeof(*sorted_env) * (count + 1));
-		qsort(sorted_env, count, sizeof(*sorted_env), env_compare);
+		qsort(sorted_env, count, sizeof(*sorted_env), compareenv);
 
 		/* create environment block from temporary environment */
 		for (e = sorted_env; *e; e++) {
@@ -1193,7 +1193,7 @@ void free_environ(char **env)
 	free(env);
 }
 
-static int lookup_env(char **env, const char *name, size_t nmln)
+static int lookupenv(char **env, const char *name, size_t nmln)
 {
 	int i;
 
@@ -1208,10 +1208,10 @@ static int lookup_env(char **env, const char *name, size_t nmln)
 /*
  * If name contains '=', then sets the variable, otherwise it unsets it
  */
-static char **env_setenv(char **env, const char *name)
+static char **do_putenv(char **env, const char *name)
 {
 	char *eq = strchrnul(name, '=');
-	int i = lookup_env(env, name, eq-name);
+	int i = lookupenv(env, name, eq-name);
 
 	if (i < 0) {
 		if (*eq) {
@@ -1242,7 +1242,7 @@ char **make_augmented_environ(const char *const *vars)
 
 	while (*vars) {
 		const char *v = *vars++;
-		env = env_setenv(env, strchr(v, '=') ? xstrdup(v) : v);
+		env = do_putenv(env, strchr(v, '=') ? xstrdup(v) : v);
 	}
 	return env;
 }
@@ -1262,7 +1262,7 @@ char *mingw_getenv(const char *name)
 
 int mingw_putenv(const char *namevalue)
 {
-	environ = env_setenv(environ, namevalue);
+	environ = do_putenv(environ, namevalue);
 	return 0;
 }
 
-- 
2.0.0.9635.g0be03cb

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stepan Kasal· Jul 17, 2014, 15:38 UTC · re: Stepan Kasal · lore

[PATCH 07/13] Win32: factor out environment block creation

From: Karsten Blees <blees@dcon.de>
Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
 compat/mingw.c | 55 ++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 32 insertions(+), 23 deletions(-)
Show changes to compat/mingw.c +32 −23
diff --git a/compat/mingw.c b/compat/mingw.c
index 89fe62b..3f81c90 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -905,6 +905,36 @@ static int compareenv(const void *a, const void *b)
 	return strcasecmp(*ea, *eb);
 }
 
+/*
+ * Create environment block suitable for CreateProcess.
+ */
+static wchar_t *make_environment_block(char **env)
+{
+	wchar_t *wenvblk = NULL;
+	int count = 0;
+	char **e, **tmpenv;
+	int size = 0, wenvsz = 0, wenvpos = 0;
+
+	for (e = env; *e; e++)
+		count++;
+
+	/* environment must be sorted */
+	tmpenv = xmalloc(sizeof(*tmpenv) * (count + 1));
+	memcpy(tmpenv, env, sizeof(*tmpenv) * (count + 1));
+	qsort(tmpenv, count, sizeof(*tmpenv), compareenv);
+
+	/* create environment block from temporary environment */
+	for (e = tmpenv; *e; e++) {
+		size = 2 * strlen(*e) + 2; /* +2 for final \0 */
+		ALLOC_GROW(wenvblk, (wenvpos + size) * sizeof(wchar_t), wenvsz);
+		wenvpos += xutftowcs(&wenvblk[wenvpos], *e, size) + 1;
+	}
+	/* add final \0 terminator */
+	wenvblk[wenvpos] = 0;
+	free(tmpenv);
+	return wenvblk;
+}
+
 struct pinfo_t {
 	struct pinfo_t *next;
 	pid_t pid;
@@ -981,29 +1011,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
 	xutftowcs(wargs, args.buf, 2 * args.len + 1);
 	strbuf_release(&args);
 
-	if (env) {
-		int count = 0;
-		char **e, **sorted_env;
-		int size = 0, wenvsz = 0, wenvpos = 0;
-
-		for (e = env; *e; e++)
-			count++;
-
-		/* environment must be sorted */
-		sorted_env = xmalloc(sizeof(*sorted_env) * (count + 1));
-		memcpy(sorted_env, env, sizeof(*sorted_env) * (count + 1));
-		qsort(sorted_env, count, sizeof(*sorted_env), compareenv);
-
-		/* create environment block from temporary environment */
-		for (e = sorted_env; *e; e++) {
-			size = 2 * strlen(*e) + 2; /* +2 for final \0 */
-			ALLOC_GROW(wenvblk, (wenvpos + size) * sizeof(wchar_t), wenvsz);
-			wenvpos += xutftowcs(&wenvblk[wenvpos], *e, size) + 1;
-		}
-		/* add final \0 terminator */
-		wenvblk[wenvpos] = 0;
-		free(sorted_env);
-	}
+	if (env)
+		wenvblk = make_environment_block(env);
 
 	memset(&pi, 0, sizeof(pi));
 	ret = CreateProcessW(wcmd, wargs, NULL, NULL, TRUE, flags,
-- 
2.0.0.9635.g0be03cb

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stepan Kasal· Jul 17, 2014, 15:38 UTC · re: Stepan Kasal · lore

[PATCH 08/13] Win32: don't copy the environment twice when spawning child processes

From: Karsten Blees <blees@dcon.de>

When spawning child processes via start_command(), the environment and all environment entries are copied twice. First by make_augmented_environ / copy_environ to merge with child_process.env. Then a second time by make_environment_block to create a sorted environment block string as required by CreateProcess.

Move the merge logic to make_environment_block so that we only need to copy the environment once. This changes semantics of the env parameter: it now expects a delta (such as child_process.env) rather than a full environment. This is not a problem as the parameter is only used by start_command() (all other callers previously passed char **environ, and now pass NULL).

The merge logic no longer xstrdup()s the environment strings, so do_putenv must not free them. Add a parameter to distinguish this from normal putenv.

Remove the now unused make_augmented_environ / free_environ API.
Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
 compat/mingw.c | 76 ++++++++++++++++++++--------------------------------------
 compat/mingw.h |  8 ++-----
 run-command.c  | 10 ++------
 3 files changed, 30 insertions(+), 64 deletions(-)
Show changes to 3 files +30 −64

compat/mingw.c, compat/mingw.h, run-command.c

diff --git a/compat/mingw.c b/compat/mingw.c
index 3f81c90..ffff592 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -898,6 +898,8 @@ static char *path_lookup(const char *cmd, char **path, int exe_only)
 	return prog;
 }
 
+static char **do_putenv(char **env, const char *name, int free_old);
+
 static int compareenv(const void *a, const void *b)
 {
 	char *const *ea = a;
@@ -906,21 +908,30 @@ static int compareenv(const void *a, const void *b)
 }
 
 /*
- * Create environment block suitable for CreateProcess.
+ * Create environment block suitable for CreateProcess. Merges current
+ * process environment and the supplied environment changes.
  */
-static wchar_t *make_environment_block(char **env)
+static wchar_t *make_environment_block(char **deltaenv)
 {
 	wchar_t *wenvblk = NULL;
 	int count = 0;
 	char **e, **tmpenv;
 	int size = 0, wenvsz = 0, wenvpos = 0;
 
-	for (e = env; *e; e++)
+	while (environ[count])
 		count++;
 
-	/* environment must be sorted */
+	/* copy the environment */
 	tmpenv = xmalloc(sizeof(*tmpenv) * (count + 1));
-	memcpy(tmpenv, env, sizeof(*tmpenv) * (count + 1));
+	memcpy(tmpenv, environ, sizeof(*tmpenv) * (count + 1));
+
+	/* merge supplied environment changes into the temporary environment */
+	for (e = deltaenv; e && *e; e++)
+		tmpenv = do_putenv(tmpenv, *e, 0);
+
+	/* environment must be sorted */
+	for (count = 0; tmpenv[count]; )
+		count++;
 	qsort(tmpenv, count, sizeof(*tmpenv), compareenv);
 
 	/* create environment block from temporary environment */
@@ -943,7 +954,7 @@ struct pinfo_t {
 static struct pinfo_t *pinfo = NULL;
 CRITICAL_SECTION pinfo_cs;
 
-static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
+static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
 			      const char *dir,
 			      int prepend_cmd, int fhin, int fhout, int fherr)
 {
@@ -1011,8 +1022,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
 	xutftowcs(wargs, args.buf, 2 * args.len + 1);
 	strbuf_release(&args);
 
-	if (env)
-		wenvblk = make_environment_block(env);
+	wenvblk = make_environment_block(deltaenv);
 
 	memset(&pi, 0, sizeof(pi));
 	ret = CreateProcessW(wcmd, wargs, NULL, NULL, TRUE, flags,
@@ -1050,10 +1060,10 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **env,
 
 static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
 {
-	return mingw_spawnve_fd(cmd, argv, environ, NULL, prepend_cmd, 0, 1, 2);
+	return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
 }
 
-pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env,
+pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
 		     const char *dir,
 		     int fhin, int fhout, int fherr)
 {
@@ -1077,14 +1087,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **env,
 				pid = -1;
 			}
 			else {
-				pid = mingw_spawnve_fd(iprog, argv, env, dir, 1,
+				pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
 						       fhin, fhout, fherr);
 				free(iprog);
 			}
 			argv[0] = argv0;
 		}
 		else
-			pid = mingw_spawnve_fd(prog, argv, env, dir, 0,
+			pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
 					       fhin, fhout, fherr);
 		free(prog);
 	}
@@ -1181,27 +1191,6 @@ int mingw_kill(pid_t pid, int sig)
 	return -1;
 }
 
-static char **copy_environ(void)
-{
-	char **env;
-	int i = 0;
-	while (environ[i])
-		i++;
-	env = xmalloc((i+1)*sizeof(*env));
-	for (i = 0; environ[i]; i++)
-		env[i] = xstrdup(environ[i]);
-	env[i] = NULL;
-	return env;
-}
-
-void free_environ(char **env)
-{
-	int i;
-	for (i = 0; env[i]; i++)
-		free(env[i]);
-	free(env);
-}
-
 static int lookupenv(char **env, const char *name, size_t nmln)
 {
 	int i;
@@ -1217,7 +1206,7 @@ static int lookupenv(char **env, const char *name, size_t nmln)
 /*
  * If name contains '=', then sets the variable, otherwise it unsets it
  */
-static char **do_putenv(char **env, const char *name)
+static char **do_putenv(char **env, const char *name, int free_old)
 {
 	char *eq = strchrnul(name, '=');
 	int i = lookupenv(env, name, eq-name);
@@ -1232,7 +1221,8 @@ static char **do_putenv(char **env, const char *name)
 		}
 	}
 	else {
-		free(env[i]);
+		if (free_old)
+			free(env[i]);
 		if (*eq)
 			env[i] = (char*) name;
 		else
@@ -1242,20 +1232,6 @@ static char **do_putenv(char **env, const char *name)
 	return env;
 }
 
-/*
- * Copies global environ and adjusts variables as specified by vars.
- */
-char **make_augmented_environ(const char *const *vars)
-{
-	char **env = copy_environ();
-
-	while (*vars) {
-		const char *v = *vars++;
-		env = do_putenv(env, strchr(v, '=') ? xstrdup(v) : v);
-	}
-	return env;
-}
-
 #undef getenv
 char *mingw_getenv(const char *name)
 {
@@ -1271,7 +1247,7 @@ char *mingw_getenv(const char *name)
 
 int mingw_putenv(const char *namevalue)
 {
-	environ = do_putenv(environ, namevalue);
+	environ = do_putenv(environ, namevalue, 1);
 	return 0;
 }
 
diff --git a/compat/mingw.h b/compat/mingw.h
index ef94194..df0e320 100644
--- a/compat/mingw.h
+++ b/compat/mingw.h
@@ -360,12 +360,8 @@ int mingw_offset_1st_component(const char *path);
 void mingw_open_html(const char *path);
 #define open_html mingw_open_html
 
-/*
- * helpers
- */
-
-char **make_augmented_environ(const char *const *vars);
-void free_environ(char **env);
+void mingw_mark_as_git_dir(const char *dir);
+#define mark_as_git_dir mingw_mark_as_git_dir
 
 /**
  * Converts UTF-8 encoded string to UTF-16LE.
diff --git a/run-command.c b/run-command.c
index 614b8ac..8e558ad 100644
--- a/run-command.c
+++ b/run-command.c
@@ -454,7 +454,6 @@ fail_pipe:
 {
 	int fhin = 0, fhout = 1, fherr = 2;
 	const char **sargv = cmd->argv;
-	char **env = environ;
 
 	if (cmd->no_stdin)
 		fhin = open("/dev/null", O_RDWR);
@@ -479,24 +478,19 @@ fail_pipe:
 	else if (cmd->out > 1)
 		fhout = dup(cmd->out);
 
-	if (cmd->env)
-		env = make_augmented_environ(cmd->env);
-
 	if (cmd->git_cmd)
 		cmd->argv = prepare_git_cmd(cmd->argv);
 	else if (cmd->use_shell)
 		cmd->argv = prepare_shell_cmd(cmd->argv);
 
-	cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env, cmd->dir,
-				  fhin, fhout, fherr);
+	cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, (char**) cmd->env,
+			cmd->dir, fhin, fhout, fherr);
 	failed_errno = errno;
 	if (cmd->pid < 0 && (!cmd->silent_exec_failure || errno != ENOENT))
 		error("cannot spawn %s: %s", cmd->argv[0], strerror(errno));
 	if (cmd->clean_on_exit && cmd->pid >= 0)
 		mark_child_for_cleanup(cmd->pid);
 
-	if (cmd->env)
-		free_environ(env);
 	if (cmd->git_cmd)
 		free(cmd->argv);
 
-- 
2.0.0.9635.g0be03cb

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stepan Kasal· Jul 17, 2014, 15:38 UTC · re: Stepan Kasal · lore

[PATCH 09/13] Win32: reduce environment array reallocations

From: Karsten Blees <blees@dcon.de>

Move environment array reallocation from do_putenv to the respective callers. Keep track of the environment size in a global variable. Use ALLOC_GROW in mingw_putenv to reduce reallocations. Allocate a sufficiently sized environment array in make_environment_block to prevent reallocations.

Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
 compat/mingw.c | 62 +++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 35 insertions(+), 27 deletions(-)
Show changes to compat/mingw.c +35 −27
diff --git a/compat/mingw.c b/compat/mingw.c
index ffff592..e63fd6a 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -898,7 +898,12 @@ static char *path_lookup(const char *cmd, char **path, int exe_only)
 	return prog;
 }
 
-static char **do_putenv(char **env, const char *name, int free_old);
+static int do_putenv(char **env, const char *name, int size, int free_old);
+
+/* used number of elements of environ array, including terminating NULL */
+static int environ_size = 0;
+/* allocated size of environ array, in bytes */
+static int environ_alloc = 0;
 
 static int compareenv(const void *a, const void *b)
 {
@@ -914,31 +919,28 @@ static int compareenv(const void *a, const void *b)
 static wchar_t *make_environment_block(char **deltaenv)
 {
 	wchar_t *wenvblk = NULL;
-	int count = 0;
-	char **e, **tmpenv;
-	int size = 0, wenvsz = 0, wenvpos = 0;
+	char **tmpenv;
+	int i = 0, size = environ_size, wenvsz = 0, wenvpos = 0;
 
-	while (environ[count])
-		count++;
+	while (deltaenv && deltaenv[i])
+		i++;
 
-	/* copy the environment */
-	tmpenv = xmalloc(sizeof(*tmpenv) * (count + 1));
-	memcpy(tmpenv, environ, sizeof(*tmpenv) * (count + 1));
+	/* copy the environment, leaving space for changes */
+	tmpenv = xmalloc((size + i) * sizeof(char*));
+	memcpy(tmpenv, environ, size * sizeof(char*));
 
 	/* merge supplied environment changes into the temporary environment */
-	for (e = deltaenv; e && *e; e++)
-		tmpenv = do_putenv(tmpenv, *e, 0);
+	for (i = 0; deltaenv && deltaenv[i]; i++)
+		size = do_putenv(tmpenv, deltaenv[i], size, 0);
 
 	/* environment must be sorted */
-	for (count = 0; tmpenv[count]; )
-		count++;
-	qsort(tmpenv, count, sizeof(*tmpenv), compareenv);
+	qsort(tmpenv, size - 1, sizeof(char*), compareenv);
 
 	/* create environment block from temporary environment */
-	for (e = tmpenv; *e; e++) {
-		size = 2 * strlen(*e) + 2; /* +2 for final \0 */
+	for (i = 0; tmpenv[i]; i++) {
+		size = 2 * strlen(tmpenv[i]) + 2; /* +2 for final \0 */
 		ALLOC_GROW(wenvblk, (wenvpos + size) * sizeof(wchar_t), wenvsz);
-		wenvpos += xutftowcs(&wenvblk[wenvpos], *e, size) + 1;
+		wenvpos += xutftowcs(&wenvblk[wenvpos], tmpenv[i], size) + 1;
 	}
 	/* add final \0 terminator */
 	wenvblk[wenvpos] = 0;
@@ -1205,19 +1207,19 @@ static int lookupenv(char **env, const char *name, size_t nmln)
 
 /*
  * If name contains '=', then sets the variable, otherwise it unsets it
+ * Size includes the terminating NULL. Env must have room for size + 1 entries
+ * (in case of insert). Returns the new size. Optionally frees removed entries.
  */
-static char **do_putenv(char **env, const char *name, int free_old)
+static int do_putenv(char **env, const char *name, int size, int free_old)
 {
 	char *eq = strchrnul(name, '=');
 	int i = lookupenv(env, name, eq-name);
 
 	if (i < 0) {
 		if (*eq) {
-			for (i = 0; env[i]; i++)
-				;
-			env = xrealloc(env, (i+2)*sizeof(*env));
-			env[i] = (char*) name;
-			env[i+1] = NULL;
+			env[size - 1] = (char*) name;
+			env[size] = NULL;
+			size++;
 		}
 	}
 	else {
@@ -1225,11 +1227,13 @@ static char **do_putenv(char **env, const char *name, int free_old)
 			free(env[i]);
 		if (*eq)
 			env[i] = (char*) name;
-		else
+		else {
 			for (; env[i]; i++)
 				env[i] = env[i+1];
+			size--;
+		}
 	}
-	return env;
+	return size;
 }
 
 #undef getenv
@@ -1247,7 +1251,8 @@ char *mingw_getenv(const char *name)
 
 int mingw_putenv(const char *namevalue)
 {
-	environ = do_putenv(environ, namevalue, 1);
+	ALLOC_GROW(environ, (environ_size + 1) * sizeof(char*), environ_alloc);
+	environ_size = do_putenv(environ, namevalue, environ_size, 1);
 	return 0;
 }
 
@@ -2047,7 +2052,9 @@ void mingw_startup()
 		maxlen = max(maxlen, wcslen(wenv[i]));
 
 	/* nedmalloc can't free CRT memory, allocate resizable environment list */
-	environ = xcalloc(i + 1, sizeof(char*));
+	environ = NULL;
+	environ_size = i + 1;
+	ALLOC_GROW(environ, environ_size * sizeof(char*), environ_alloc);
 
 	/* allocate buffer (wchar_t encodes to max 3 UTF-8 bytes) */
 	maxlen = 3 * maxlen + 1;
@@ -2064,6 +2071,7 @@ void mingw_startup()
 		len = xwcstoutf(buffer, wenv[i], maxlen);
 		environ[i] = xmemdupz(buffer, len);
 	}
+	environ[i] = NULL;
 	free(buffer);
 
 	/* initialize critical section for waitpid pinfo_t list */
-- 
2.0.0.9635.g0be03cb

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stepan Kasal· Jul 17, 2014, 15:38 UTC · re: Stepan Kasal · lore

[PATCH 10/13] Win32: use low-level memory allocation during initialization

From: Karsten Blees <blees@dcon.de>

As of d41489a6 "Add more large blob test cases", git's high-level memory allocation functions (xmalloc, xmemdupz etc.) access the environment to simulate limited memory in tests (see 'getenv("GIT_ALLOC_LIMIT")' in memory_limit_check()). These functions should not be used before the environment is fully initialized (particularly not to initialize the environment itself).

The current solution ('environ = NULL; ALLOC_GROW(environ...)') only works because MSVCRT's getenv() reinitializes environ when it is NULL (i.e. it leaves us with two sets of unusabe (non-UTF-8) and unfreeable (CRT- allocated) environments).

Add our own set of malloc-or-die functions to be used in startup code.

Also check the result of __wgetmainargs, which may fail if there's not enough memory for wide-char arguments and environment.

This patch is in preparation of the sorted environment feature, which completely replaces MSVCRT's getenv() implementation.

Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
 compat/mingw.c | 43 ++++++++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 15 deletions(-)
Show changes to compat/mingw.c +28 −15
diff --git a/compat/mingw.c b/compat/mingw.c
index e63fd6a..757a6b1 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -2032,9 +2032,23 @@ static NORETURN void die_startup()
 	exit(128);
 }
 
+static void *malloc_startup(size_t size)
+{
+	void *result = malloc(size);
+	if (!result)
+		die_startup();
+	return result;
+}
+
+static char *wcstoutfdup_startup(char *buffer, const wchar_t *wcs, size_t len)
+{
+	len = xwcstoutf(buffer, wcs, len) + 1;
+	return memcpy(malloc_startup(len), buffer, len);
+}
+
 void mingw_startup()
 {
-	int i, len, maxlen, argc;
+	int i, maxlen, argc;
 	char *buffer;
 	wchar_t **wenv, **wargv;
 	_startupinfo si;
@@ -2051,26 +2065,25 @@ void mingw_startup()
 	for (i = 0; wenv[i]; i++)
 		maxlen = max(maxlen, wcslen(wenv[i]));
 
-	/* nedmalloc can't free CRT memory, allocate resizable environment list */
-	environ = NULL;
+	/*
+	 * nedmalloc can't free CRT memory, allocate resizable environment
+	 * list. Note that xmalloc / xmemdupz etc. call getenv, so we cannot
+	 * use it while initializing the environment itself.
+	 */
 	environ_size = i + 1;
-	ALLOC_GROW(environ, environ_size * sizeof(char*), environ_alloc);
+	environ_alloc = alloc_nr(environ_size * sizeof(char*));
+	environ = malloc_startup(environ_alloc);
 
 	/* allocate buffer (wchar_t encodes to max 3 UTF-8 bytes) */
 	maxlen = 3 * maxlen + 1;
-	buffer = xmalloc(maxlen);
+	buffer = malloc_startup(maxlen);
 
 	/* convert command line arguments and environment to UTF-8 */
-	len = xwcstoutf(buffer, _wpgmptr, maxlen);
-	__argv[0] = xmemdupz(buffer, len);
-	for (i = 1; i < argc; i++) {
-		len = xwcstoutf(buffer, wargv[i], maxlen);
-		__argv[i] = xmemdupz(buffer, len);
-	}
-	for (i = 0; wenv[i]; i++) {
-		len = xwcstoutf(buffer, wenv[i], maxlen);
-		environ[i] = xmemdupz(buffer, len);
-	}
+	__argv[0] = wcstoutfdup_startup(buffer, _wpgmptr, maxlen);
+	for (i = 1; i < argc; i++)
+		__argv[i] = wcstoutfdup_startup(buffer, wargv[i], maxlen);
+	for (i = 0; wenv[i]; i++)
+		environ[i] = wcstoutfdup_startup(buffer, wenv[i], maxlen);
 	environ[i] = NULL;
 	free(buffer);
 
-- 
2.0.0.9635.g0be03cb

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stepan Kasal· Jul 17, 2014, 15:38 UTC · re: Stepan Kasal · lore

[PATCH 11/13] Win32: keep the environment sorted

From: Karsten Blees <blees@dcon.de>

The Windows environment is sorted, keep it that way for O(log n) environment access.

Change compareenv to compare only the keys, so that it can be used to find an entry irrespective of the value.

Change lookupenv to binary seach for an entry. Return one's complement of the insert position if not found (libc's bsearch returns NULL).

Replace MSVCRT's getenv with a minimal do_getenv based on the binary search function.

Change do_putenv to insert new entries at the correct position. Simplify the function by swapping if conditions and using memmove instead of for loops.

Move qsort from make_environment_block to mingw_startup. We still need to sort on startup to make sure that the environment is sorted according to our compareenv function (while Win32 / CreateProcess requires the environment block to be sorted case-insensitively, CreateProcess currently doesn't enforce this, and some applications such as bash just don't care).

Note that environment functions are _not_ thread-safe and are not required to be so by POSIX, the application is responsible for synchronizing access to the environment. MSVCRT's getenv and our new getenv implementation are better than that in that they are thread-safe with respect to other getenv calls as long as the environment is not modified. Git's indiscriminate use of getenv in background threads currently requires this property.

Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
 compat/mingw.c | 104 +++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 65 insertions(+), 39 deletions(-)
Show changes to compat/mingw.c +65 −39
diff --git a/compat/mingw.c b/compat/mingw.c
index 757a6b1..9dc6bf6 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -905,13 +905,6 @@ static int environ_size = 0;
 /* allocated size of environ array, in bytes */
 static int environ_alloc = 0;
 
-static int compareenv(const void *a, const void *b)
-{
-	char *const *ea = a;
-	char *const *eb = b;
-	return strcasecmp(*ea, *eb);
-}
-
 /*
  * Create environment block suitable for CreateProcess. Merges current
  * process environment and the supplied environment changes.
@@ -933,9 +926,6 @@ static wchar_t *make_environment_block(char **deltaenv)
 	for (i = 0; deltaenv && deltaenv[i]; i++)
 		size = do_putenv(tmpenv, deltaenv[i], size, 0);
 
-	/* environment must be sorted */
-	qsort(tmpenv, size - 1, sizeof(char*), compareenv);
-
 	/* create environment block from temporary environment */
 	for (i = 0; tmpenv[i]; i++) {
 		size = 2 * strlen(tmpenv[i]) + 2; /* +2 for final \0 */
@@ -1193,16 +1183,42 @@ int mingw_kill(pid_t pid, int sig)
 	return -1;
 }
 
-static int lookupenv(char **env, const char *name, size_t nmln)
-{
-	int i;
+/*
+ * Compare environment entries by key (i.e. stopping at '=' or '\0').
+ */
+static int compareenv(const void *v1, const void *v2)
+{
+	const char *e1 = *(const char**)v1;
+	const char *e2 = *(const char**)v2;
+
+	for (;;) {
+		int c1 = *e1++;
+		int c2 = *e2++;
+		c1 = (c1 == '=') ? 0 : tolower(c1);
+		c2 = (c2 == '=') ? 0 : tolower(c2);
+		if (c1 > c2)
+			return 1;
+		if (c1 < c2)
+			return -1;
+		if (c1 == 0)
+			return 0;
+	}
+}
 
-	for (i = 0; env[i]; i++) {
-		if (!strncasecmp(env[i], name, nmln) && '=' == env[i][nmln])
-			/* matches */
-			return i;
+static int bsearchenv(char **env, const char *name, size_t size)
+{
+	unsigned low = 0, high = size;
+	while (low < high) {
+		unsigned mid = low + ((high - low) >> 1);
+		int cmp = compareenv(&env[mid], &name);
+		if (cmp < 0)
+			low = mid + 1;
+		else if (cmp > 0)
+			high = mid;
+		else
+			return mid;
 	}
-	return -1;
+	return ~low; /* not found, return 1's complement of insert position */
 }
 
 /*
@@ -1212,39 +1228,46 @@ static int lookupenv(char **env, const char *name, size_t nmln)
  */
 static int do_putenv(char **env, const char *name, int size, int free_old)
 {
-	char *eq = strchrnul(name, '=');
-	int i = lookupenv(env, name, eq-name);
+	int i = bsearchenv(env, name, size - 1);
 
-	if (i < 0) {
-		if (*eq) {
-			env[size - 1] = (char*) name;
-			env[size] = NULL;
+	/* optionally free removed / replaced entry */
+	if (i >= 0 && free_old)
+		free(env[i]);
+
+	if (strchr(name, '=')) {
+		/* if new value ('key=value') is specified, insert or replace entry */
+		if (i < 0) {
+			i = ~i;
+			memmove(&env[i + 1], &env[i], (size - i) * sizeof(char*));
 			size++;
 		}
-	}
-	else {
-		if (free_old)
-			free(env[i]);
-		if (*eq)
-			env[i] = (char*) name;
-		else {
-			for (; env[i]; i++)
-				env[i] = env[i+1];
-			size--;
-		}
+		env[i] = (char*) name;
+	} else if (i >= 0) {
+		/* otherwise ('key') remove existing entry */
+		size--;
+		memmove(&env[i], &env[i + 1], (size - i) * sizeof(char*));
 	}
 	return size;
 }
 
-#undef getenv
+static char *do_getenv(const char *name)
+{
+	char *value;
+	int pos = bsearchenv(environ, name, environ_size - 1);
+	if (pos < 0)
+		return NULL;
+	value = strchr(environ[pos], '=');
+	return value ? &value[1] : NULL;
+}
+
 char *mingw_getenv(const char *name)
 {
-	char *result = getenv(name);
+	char *result = do_getenv(name);
 	if (!result && !strcmp(name, "TMPDIR")) {
 		/* on Windows it is TMP and TEMP */
-		result = getenv("TMP");
+		result = do_getenv("TMP");
 		if (!result)
-			result = getenv("TEMP");
+			result = do_getenv("TEMP");
 	}
 	return result;
 }
@@ -2087,6 +2110,9 @@ void mingw_startup()
 	environ[i] = NULL;
 	free(buffer);
 
+	/* sort environment for O(log n) getenv / putenv */
+	qsort(environ, i, sizeof(char*), compareenv);
+
 	/* initialize critical section for waitpid pinfo_t list */
 	InitializeCriticalSection(&pinfo_cs);
 
-- 
2.0.0.9635.g0be03cb

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stepan Kasal· Jul 17, 2014, 15:38 UTC · re: Stepan Kasal · lore

[PATCH 12/13] Win32: patch Windows environment on startup

From: Karsten Blees <blees@dcon.de>

Fix Windows specific environment settings on startup rather than checking for special values on every getenv call.

As a side effect, this makes the patched environment (i.e. with properly initialized TMPDIR and TERM) available to child processes.

Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
 compat/mingw.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
Show changes to compat/mingw.c +12 −13
diff --git a/compat/mingw.c b/compat/mingw.c
index 9dc6bf6..6d4ec56 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1250,7 +1250,7 @@ static int do_putenv(char **env, const char *name, int size, int free_old)
 	return size;
 }
 
-static char *do_getenv(const char *name)
+char *mingw_getenv(const char *name)
 {
 	char *value;
 	int pos = bsearchenv(environ, name, environ_size - 1);
@@ -1260,18 +1260,6 @@ static char *do_getenv(const char *name)
 	return value ? &value[1] : NULL;
 }
 
-char *mingw_getenv(const char *name)
-{
-	char *result = do_getenv(name);
-	if (!result && !strcmp(name, "TMPDIR")) {
-		/* on Windows it is TMP and TEMP */
-		result = do_getenv("TMP");
-		if (!result)
-			result = do_getenv("TEMP");
-	}
-	return result;
-}
-
 int mingw_putenv(const char *namevalue)
 {
 	ALLOC_GROW(environ, (environ_size + 1) * sizeof(char*), environ_alloc);
@@ -2113,6 +2101,17 @@ void mingw_startup()
 	/* sort environment for O(log n) getenv / putenv */
 	qsort(environ, i, sizeof(char*), compareenv);
 
+	/* fix Windows specific environment settings */
+
+	/* on Windows it is TMP and TEMP */
+	if (!mingw_getenv("TMPDIR")) {
+		const char *tmp = mingw_getenv("TMP");
+		if (!tmp)
+			tmp = mingw_getenv("TEMP");
+		if (tmp)
+			setenv("TMPDIR", tmp, 1);
+	}
+
 	/* initialize critical section for waitpid pinfo_t list */
 	InitializeCriticalSection(&pinfo_cs);
 
-- 
2.0.0.9635.g0be03cb

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stepan Kasal· Jul 17, 2014, 15:38 UTC · re: Stepan Kasal · lore

[PATCH 13/13] Enable color output in Windows cmd.exe

From: Karsten Blees <blees@dcon.de>

Git requires the TERM environment variable to be set for all color* settings. Simulate the TERM variable if it is not set (default on Windows).

Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Stepan Kasal <kasal@ucw.cz>
---
 compat/mingw.c | 4 ++++
 1 file changed, 4 insertions(+)
Show changes to compat/mingw.c +4 −0
diff --git a/compat/mingw.c b/compat/mingw.c
index 6d4ec56..19975fa 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -2112,6 +2112,10 @@ void mingw_startup()
 			setenv("TMPDIR", tmp, 1);
 	}
 
+	/* simulate TERM to enable auto-color (see color.c) */
+	if (!getenv("TERM"))
+		setenv("TERM", "cygwin", 1);
+
 	/* initialize critical section for waitpid pinfo_t list */
 	InitializeCriticalSection(&pinfo_cs);
 
-- 
2.0.0.9635.g0be03cb

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Junio C Hamano· Jul 17, 2014, 17:55 UTC · re: Stepan Kasal · lore

Re: [PATCH 00/13] mingw unicode environment

Stepan Kasal <kasal@ucw.cz> writes:
> ... only one patch
> would only remain: gitk and git-gui fixes.)
Nice.
Will queue.
Show 40 quoted lines
> When rebasing Karsten's work, I have eliminated two commits:
> https://github.com/msysgit/git/commit/f967550
> https://github.com/msysgit/git/commit/290bf81
>
> These commits only moved code down and up; this was not necessary, one
> forward declaration was all I needed.
>
> One of the patches differs from the original version: "Enable color..."
> Following Karsten's suggestion, I have changed the value of env. var.
> TERM from "winterm" to "cygwin".  This is because the subprocesses see
> the variable and may try to find it in (their copy of) termcap.
>
> Enjoy,
>    Stepan
>
> Karsten Blees (13):
>   Revert "Windows: teach getenv to do a case-sensitive search"
>   Win32: Unicode environment (outgoing)
>   Win32: Unicode environment (incoming)
>   Win32: fix environment memory leaks
>   Win32: unify environment case-sensitivity
>   Win32: unify environment function names
>   Win32: factor out environment block creation
>   Win32: don't copy the environment twice when spawning child processes
>   Win32: reduce environment array reallocations
>   Win32: use low-level memory allocation during initialization
>   Win32: keep the environment sorted
>   Win32: patch Windows environment on startup
>   Enable color output in Windows cmd.exe
>
>  compat/mingw.c   | 290 +++++++++++++++++++++++++++++++------------------------
>  compat/mingw.h   |  11 +--
>  config.mak.uname |   2 -
>  run-command.c    |  10 +-
>  4 files changed, 170 insertions(+), 143 deletions(-)
>
> -- 
> 2.0.0.9635.g0be03cb
>
> -- 
-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Karsten Blees· Jul 17, 2014, 18:09 UTC · re: Stepan Kasal · lore

Re: [PATCH 00/13] mingw unicode environment

Am 17.07.2014 17:37, schrieb Stepan Kasal:
Show 6 quoted lines
> Hello,
> 
> this is the remainder of Karsten's unicode branch, that is a time
> proven part of msysGit.  (If this code is accepted, only one patch
> would only remain: gitk and git-gui fixes.)
> 
Thank you so much!

I had to add '#include "../cache.h"' to compile, due to use of ALLOC_GROW and alloc_nr in some of the patches. In the msysgit HEAD, Erik's hideDotFile patch does that [1].

[1] https://github.com/msysgit/git/commit/d85d2b75

After that (and applying your mingw test fixes), only t7001 fails (the 'cp -P' issue).

Show 7 quoted lines
> When rebasing Karsten's work, I have eliminated two commits:
> https://github.com/msysgit/git/commit/f967550
> https://github.com/msysgit/git/commit/290bf81
> 
> These commits only moved code down and up; this was not necessary, one
> forward declaration was all I needed.
> 

I believe we prefer moving code to the right place over forward declarations (IIRC I got bashed for the latter in one of the first rounds of this patch series). If only to justify 'git-blame -M' :-D

Show 5 quoted lines
> One of the patches differs from the original version: "Enable color..."
> Following Karsten's suggestion, I have changed the value of env. var.
> TERM from "winterm" to "cygwin".  This is because the subprocesses see
> the variable and may try to find it in (their copy of) termcap.
> 
Good! One more step towards getting rid of the git-wrapper.
-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Junio C Hamano· Jul 17, 2014, 18:20 UTC · re: Karsten Blees · lore

Re: [PATCH 00/13] mingw unicode environment

Karsten Blees <karsten.blees@gmail.com> writes:
Show 12 quoted lines
> Am 17.07.2014 17:37, schrieb Stepan Kasal:
>
> I believe we prefer moving code to the right place over forward
> declarations (IIRC I got bashed for the latter in one of the first rounds
> of this patch series). If only to justify 'git-blame -M' :-D
>
>> One of the patches differs from the original version: "Enable color..."
>> Following Karsten's suggestion, I have changed the value of env. var.
>> TERM from "winterm" to "cygwin".  This is because the subprocesses see
>> the variable and may try to find it in (their copy of) termcap.
>
> Good! One more step towards getting rid of the git-wrapper.

OK, so the series may need further re-polishing of the polishing done by Stepan last-minute before sending them out. I'll still queue but will hold in 'pu' while Windows folks can agree all is well.

Thanks.
-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stepan Kasal· Jul 17, 2014, 19:00 UTC · re: Junio C Hamano · lore

Re: [PATCH 00/13] mingw unicode environment

Hi,
> Karsten Blees <karsten.blees@gmail.com> writes:
> > I believe we prefer moving code to the right place over forward
> > declarations (IIRC I got bashed for the latter in one of the first rounds
> > of this patch series). If only to justify 'git-blame -M' :-D
indeed, my position is the same, generally.

But it turned out that the current ordering is sane, mostly works as it is, and I needed _only one_ fwd decl to make things compile. This is why I decided to have things arranged this way.

If anyone thinks the resulting ordering is not OK, they can propose one re-order patch on top of this series.

Junio wrote:
> OK, so the series may need further re-polishing of the polishing
> done by Stepan last-minute before sending them out.  I'll still

No, it was not last minute work. It was done several weeks ago, after some planning, etc. It's my best. Corrections welcome, though.

Stepan
-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Junio C Hamano· Jul 17, 2014, 19:18 UTC · re: Stepan Kasal · lore

Re: [PATCH 00/13] mingw unicode environment

Stepan Kasal <kasal@ucw.cz> writes:
> If anyone thinks the resulting ordering is not OK, they can propose
> one re-order patch on top of this series.
I agree that that would be a good way to go.
Show 6 quoted lines
> Junio wrote:
>> OK, so the series may need further re-polishing of the polishing
>> done by Stepan last-minute before sending them out.  I'll still
>
> No, it was not last minute work.  It was done several weeks ago, after some
> planning, etc.  It's my best.  Corrections welcome, though.

I did not literally mean "minute", and I am sorry if I sounded like I was saying that you threw junk that are not well-thought-out into the mix.

The point I wanted to clarify was that the claim to be "time proven part of msysGit" in the first paragraph of the cover does not apply to some of the patches in the series, in which case I shouldn't merge it right to 'master' without waiting for responses.

In that context (I take "time proven" is like "more than 18 months"), weeks vs minutes do not make much of a difference anyway ;-).

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Karsten Blees· Jul 17, 2014, 19:24 UTC · re: Stepan Kasal · lore

Re: [PATCH 00/13] mingw unicode environment

Am 17.07.2014 21:00, schrieb Stepan Kasal:
Show 13 quoted lines
> Hi,
> 
>> Karsten Blees <karsten.blees@gmail.com> writes:
>>> I believe we prefer moving code to the right place over forward
>>> declarations (IIRC I got bashed for the latter in one of the first rounds
>>> of this patch series). If only to justify 'git-blame -M' :-D
> 
> indeed, my position is the same, generally.
> 
> But it turned out that the current ordering is sane, mostly works as it is,
> and I needed _only one_ fwd decl to make things compile.  This is why I
> decided to have things arranged this way.
> 
Fine with me.

However, if it *did* compile for you, I wonder where ALLOC_GROW (as of #02/13) and alloc_nr (as of #10/13) came from? Or did we recently remove '#include "cache.h"' from upstream mingw.c?

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stepan Kasal· Jul 18, 2014, 18:51 UTC · re: Karsten Blees · lore

Re: Re: [PATCH 00/13] mingw unicode environment

Hello Karsten,
you wrote:
> However, if it *did* compile for you, I wonder where ALLOC_GROW (as of #02/13)
> and alloc_nr (as of #10/13) came from? Or did we recently remove '#include "cache.h"'
> from upstream mingw.c?
you are right, the include needs to be added.

To test my modifications, I rebased all the rest of msysGit collection, built and run the test suite.

As you pointed out, https://github.com/msysgit/git/commit/d85d2b75 adds the include.

Unfortunately, I won't get to this for several weeks. Could you or Hannes be so kind and post the fixup?

Thank you for this comment. And big thanks for the orignal work. (I was only moving it and even that took some time. ;-)

Stepan
-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

← back to recent threads