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

[PATCH/RFC] alias: use run_command api to execute aliases

From
Erik Faye-Lund <kusmabite@gmail.com>
Date
Jan 6, 2011, 19:13 UTC
Message-ID
<1294341187-3956-1-git-send-email-kusmabite@gmail.com>

On Windows, system() executes with cmd.exe instead of /bin/sh. This means that aliases currently has to be batch-scripts instead of bourne-scripts. On top of that, cmd.exe does not handle single quotes, which is what the code-path currently uses to handle arguments with spaces.

To solve both problems in one go, use run_command_v_opt() to execute the alias. It already does the right thing prepend "sh -c " to the alias.

Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
---
This fixes issue 553 in the msysGit issue tracker.
 git.c |   25 +++++++++++++------------
 1 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/git.c b/git.c
index 68334f6..5b0b9d8 100644
--- a/git.c
+++ b/git.c
@@ -177,19 +177,20 @@ static int handle_alias(int *argcp, const char ***argv)
 	alias_string = alias_lookup(alias_command);
 	if (alias_string) {
 		if (alias_string[0] == '!') {
+			const char **alias_argv;
+			int i;
+
 			commit_pager_choice();
-			if (*argcp > 1) {
-				struct strbuf buf;
-
-				strbuf_init(&buf, PATH_MAX);
-				strbuf_addstr(&buf, alias_string);
-				sq_quote_argv(&buf, (*argv) + 1, PATH_MAX);
-				free(alias_string);
-				alias_string = buf.buf;
-			}
-			trace_printf("trace: alias to shell cmd: %s => %s\n",
-				     alias_command, alias_string + 1);
-			ret = system(alias_string + 1);
+
+			/* build alias_argv */
+			alias_argv = malloc(sizeof(char *) * *argcp + 1);
+			alias_argv[0] = alias_string + 1;
+			for (i = 1; i < *argcp; ++i)
+				alias_argv[i] = (*argv)[i];
+			alias_argv[*argcp] = NULL;
+
+			ret = run_command_v_opt(alias_argv, RUN_USING_SHELL);
+
 			if (ret >= 0 && WIFEXITED(ret) &&
 			    WEXITSTATUS(ret) != 127)
 				exit(WEXITSTATUS(ret));
-- 
1.7.3.3.585.g74f6e
Next: Jonathan Nieder
Message 1 of 7 in “alias: use run_command api to execute aliases”
  1. alias: use run_command api to execute aliasesErik Faye-Lund, Jan 6, 2011
  2. Jonathan NiederJan 6, 2011
  3. Erik Faye-LundJan 6, 2011
  4. Johannes SchindelinJan 7, 2011
  5. Erik Faye-LundJan 7, 2011
  6. Johannes SchindelinJan 7, 2011
  7. Junio C HamanoJan 7, 2011

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.