git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/1] mingw: support spawning programs with paths containing spacesnames
@ 2019-07-16 14:03 Johannes Schindelin via GitGitGadget
  2019-07-16 14:03 ` [PATCH 1/1] mingw: support spawning programs containing spaces in their names Johannes Schindelin via GitGitGadget
  0 siblings, 1 reply; 2+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2019-07-16 14:03 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

This is a patch to support older Windows versions (e.g. Windows 7) better.

I know, I know, Windows 7's End-Of-Life is now less than half a year away,
but... I am unsure just how long Git for Windows will support Windows 7
beyond its officially-supported life; We still support Windows Vista, after
all, which has been "sun-set" over two years ago.

Johannes Schindelin (1):
  mingw: support spawning programs containing spaces in their names

 compat/mingw.c         | 8 +++++---
 t/t0061-run-command.sh | 6 ++++++
 2 files changed, 11 insertions(+), 3 deletions(-)


base-commit: aa25c82427ae70aebf3b8f970f2afd54e9a2a8c6
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-220%2Fdscho%2Fspawn-with-spaces-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-220/dscho/spawn-with-spaces-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/220
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 1/1] mingw: support spawning programs containing spaces in their names
  2019-07-16 14:03 [PATCH 0/1] mingw: support spawning programs with paths containing spacesnames Johannes Schindelin via GitGitGadget
@ 2019-07-16 14:03 ` Johannes Schindelin via GitGitGadget
  0 siblings, 0 replies; 2+ messages in thread
From: Johannes Schindelin via GitGitGadget @ 2019-07-16 14:03 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Johannes Schindelin

From: Johannes Schindelin <johannes.schindelin@gmx.de>

On some older Windows versions (e.g. Windows 7), the CreateProcessW()
function does not really support spaces in its first argument,
lpApplicationName. But it supports passing NULL as lpApplicationName,
which makes it figure out the application from the (possibly quoted)
first argument of lpCommandLine.

Let's use that trick (if we are certain that the first argument matches
the executable's path) to support launching programs whose path contains
spaces.

We will abuse the test-fake-ssh.exe helper to verify that this works and
does not regress.

This fixes https://github.com/git-for-windows/git/issues/692

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 compat/mingw.c         | 8 +++++---
 t/t0061-run-command.sh | 6 ++++++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index 9b6d2400e1..6d7fc07a48 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1437,7 +1437,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
 	si.hStdOutput = winansi_get_osfhandle(fhout);
 	si.hStdError = winansi_get_osfhandle(fherr);
 
-	if (xutftowcs_path(wcmd, cmd) < 0)
+	if (*argv && !strcmp(cmd, *argv))
+		wcmd[0] = L'\0';
+	else if (xutftowcs_path(wcmd, cmd) < 0)
 		return -1;
 	if (dir && xutftowcs_path(wdir, dir) < 0)
 		return -1;
@@ -1466,8 +1468,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
 	wenvblk = make_environment_block(deltaenv);
 
 	memset(&pi, 0, sizeof(pi));
-	ret = CreateProcessW(wcmd, wargs, NULL, NULL, TRUE, flags,
-		wenvblk, dir ? wdir : NULL, &si, &pi);
+	ret = CreateProcessW(*wcmd ? wcmd : NULL, wargs, NULL, NULL, TRUE,
+		flags, wenvblk, dir ? wdir : NULL, &si, &pi);
 
 	free(wenvblk);
 	free(wargs);
diff --git a/t/t0061-run-command.sh b/t/t0061-run-command.sh
index ebc49561ac..015fac8b5d 100755
--- a/t/t0061-run-command.sh
+++ b/t/t0061-run-command.sh
@@ -210,4 +210,10 @@ test_expect_success MINGW 'verify curlies are quoted properly' '
 	test_cmp expect actual
 '
 
+test_expect_success MINGW 'can spawn with argv[0] containing spaces' '
+	cp "$GIT_BUILD_DIR/t/helper/test-fake-ssh$X" ./ &&
+	test_must_fail "$PWD/test-fake-ssh$X" 2>err &&
+	grep TRASH_DIRECTORY err
+'
+
 test_done
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-16 14:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-16 14:03 [PATCH 0/1] mingw: support spawning programs with paths containing spacesnames Johannes Schindelin via GitGitGadget
2019-07-16 14:03 ` [PATCH 1/1] mingw: support spawning programs containing spaces in their names Johannes Schindelin via GitGitGadget

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).