diff mbox series

[v3,1/7] run-command: refactor getting the Unix shell path into its own function

Message ID e0970381042e4e35074c5f095959d3379aad6d9d.1720904905.git.gitgitgadget@gmail.com (mailing list archive)
State Accepted
Commit 0593c1ea30737cf2d61f7c191d3687b37badf3be
Headers show
Series var(win32): do report the GIT_SHELL_PATH that is actually used | expand

Commit Message

Johannes Schindelin July 13, 2024, 9:08 p.m. UTC
From: Johannes Schindelin <johannes.schindelin@gmx.de>

This encapsulates the platform-specific logic better.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 run-command.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/run-command.c b/run-command.c
index d9f80fabe6e..59e433bf91c 100644
--- a/run-command.c
+++ b/run-command.c
@@ -274,17 +274,22 @@  int sane_execvp(const char *file, char * const argv[])
 	return -1;
 }
 
+static const char *git_shell_path(void)
+{
+#ifndef GIT_WINDOWS_NATIVE
+	return SHELL_PATH;
+#else
+	return "sh";
+#endif
+}
+
 static const char **prepare_shell_cmd(struct strvec *out, const char **argv)
 {
 	if (!argv[0])
 		BUG("shell command is empty");
 
 	if (strcspn(argv[0], "|&;<>()$`\\\"' \t\n*?[#~=%") != strlen(argv[0])) {
-#ifndef GIT_WINDOWS_NATIVE
-		strvec_push(out, SHELL_PATH);
-#else
-		strvec_push(out, "sh");
-#endif
+		strvec_push(out, git_shell_path());
 		strvec_push(out, "-c");
 
 		/*