git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Do not use SHELL_PATH from build system in prepare_shell_cmd on Windows

From
Johannes Sixt <j.sixt@viscovery.net>
Date
Apr 17, 2012, 07:03 UTC
Message-ID
<4F8D15B9.70803@viscovery.net>
In-Reply-To
<1333157601-6458-1-git-send-email-bwalton@artsci.utoronto.ca>
From: Johannes Sixt <j6t@kdbg.org>

The recent change to use SHELL_PATH instead of "sh" to spawn shell commands is not suited for Windows:

- The default setting, "/bin/sh", does not work when git has to run the
  shell because it is a POSIX style path, but not a proper Windows style
  path.
- If it worked, it would hard-code a position in the files system where
  the shell is expected, making git (more precisely, the POSIX toolset that
  is needed alongside git) non-relocatable. But we cannot sacrifice
  relocatability on Windows.
- Apart from that, even though the Makefile leaves SHELL_PATH set to
  "/bin/sh" for the Windows builds, the build system passes a mangled path
  to the compiler, and something like "D:/Src/msysgit/bin/sh" is used,
  which is doubly bad because it points to where /bin/sh resolves to on
  the system where git was built.
- Finally, the system's CreateProcess() function that is used under
  mingw.c's hood does not work with forward slashes and cannot find the
  shell.
Undo the earlier change on Windows.
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
Am 3/31/2012 3:33, schrieb Ben Walton:
Show 16 quoted lines
> +#ifndef SHELL_PATH
> +# define SHELL_PATH "/bin/sh"
> +#endif
> +
>  struct child_to_clean {
>  	pid_t pid;
>  	struct child_to_clean *next;
> @@ -90,7 +94,7 @@ static const char **prepare_shell_cmd(const char **argv)
>  		die("BUG: shell command is empty");
>  
>  	if (strcspn(argv[0], "|&;<>()$`\\\"' \t\n*?[#~=%") != strlen(argv[0])) {
> -		nargv[nargc++] = "sh";
> +		nargv[nargc++] = SHELL_PATH;
>  		nargv[nargc++] = "-c";
>  
>  		if (argc < 2)

This looked so obviously correct, that I carelessly did not test the change. But given that the first two points addressed in the commit message above are actually dealbreakers, I should have noticed this issue much earlier.

-- Hannes
 run-command.c |    4 ++++
 1 file changed, 4 insertions(+)
diff --git a/run-command.c b/run-command.c
index 2af3e0f..e4edede 100644
--- a/run-command.c
+++ b/run-command.c
@@ -94,7 +94,11 @@ static const char **prepare_shell_cmd(const char **argv)
 		die("BUG: shell command is empty");
 
 	if (strcspn(argv[0], "|&;<>()$`\\\"' \t\n*?[#~=%") != strlen(argv[0])) {
+#ifndef WIN32
 		nargv[nargc++] = SHELL_PATH;
+#else
+		nargv[nargc++] = "sh";
+#endif
 		nargv[nargc++] = "-c";
 
 		if (argc < 2)
-- 
1.7.10.1370.ga6f62.dirty
Previous: Junio C HamanoNext: Ben Walton
Message 7 of 16 in “Use SHELL_PATH from build system in run_command.c:prepare_shell_cmd”
  1. Use SHELL_PATH from build system in run_command.c:prepare_shell_cmdBen Walton, Mar 31, 2012
  2. Jonathan NiederMar 31, 2012
  3. Junio C HamanoMar 31, 2012
  4. Jonathan NiederMar 31, 2012
  5. Junio C HamanoMar 31, 2012
  6. Junio C HamanoMar 31, 2012
  7. Do not use SHELL_PATH from build system in prepare_shell_cmd on WindowsJohannes Sixt, Apr 17, 2012
  8. Ben WaltonApr 17, 2012
  9. Johannes SixtApr 17, 2012
  10. Ben WaltonApr 17, 2012
  11. Jeff KingApr 17, 2012
  12. Johannes SixtApr 18, 2012
  13. Jeff KingApr 18, 2012
  14. Junio C HamanoApr 18, 2012
  15. Johannes SixtApr 19, 2012
  16. Junio C HamanoApr 19, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.