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

[PATCH] prepare_shell_cmd: add code comment

From
AGAlexandr Miloslavskiy via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 6, 2020, 12:41 UTC
Message-ID
<pull.574.git.1583498508362.gitgitgadget@gmail.com>
From: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
While debugging something else, I was quite puzzled to see that
`prepare_shell_cmd()` duplicates the command before sending to sh, like:
    sh -c "git-upload-pack '../testrepo/.git'" "git-upload-pack '../testrepo/.git'"
A Windows programmer myself, initially I thought that it's a bug.
Add a clarifying comment.
Signed-off-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
---
    prepare_shell_cmd: add code comment
    
    While debugging something else, I was quite puzzled to see that
    prepare_shell_cmd() duplicates the command before sending to sh, like:
    sh -c "git-upload-pack '../testrepo/.git'" "git-upload-pack
    '../testrepo/.git'"
    
    A Windows programmer myself, initially I thought that it's a bug.
    
    Add a clarifying comment.
    
    Signed-off-by: Alexandr Miloslavskiy alexandr.miloslavskiy@syntevo.com
    [alexandr.miloslavskiy@syntevo.com]
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-574%2FSyntevoAlex%2F%230259(git)_doubled_prepare_shell_cmd-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-574/SyntevoAlex/#0259(git)_doubled_prepare_shell_cmd-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/574
 run-command.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff --git a/run-command.c b/run-command.c
index f5e1149f9b3..95ab3c168bc 100644
--- a/run-command.c
+++ b/run-command.c
@@ -284,6 +284,12 @@ static const char **prepare_shell_cmd(struct argv_array *out, const char **argv)
 			argv_array_push(out, argv[0]);
 		else
 			argv_array_pushf(out, "%s \"$@\"", argv[0]);
+
+		/*
+		 * -c expects shell_name after command_string.
+		 * Pushing entire original argv below will pass argv[0]
+		 * as shell name.
+		 */
 	}
 
 	argv_array_pushv(out, argv);

base-commit: 076cbdcd739aeb33c1be87b73aebae5e43d7bcc5
-- 
gitgitgadget
Next: Alexandr Miloslavskiy
Message 1 of 2 in “prepare_shell_cmd: add code comment”
  1. prepare_shell_cmd: add code commentAlexandr Miloslavskiy via GitGitGadget, Mar 6, 2020
  2. Alexandr MiloslavskiyMar 26, 2020

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.