* [PATCH v2] alias: use run_command api to execute aliases
@ 2011-01-06 19:54 Erik Faye-Lund
2011-01-06 20:05 ` Jonathan Nieder
2011-01-06 20:27 ` Johannes Sixt
0 siblings, 2 replies; 4+ messages in thread
From: Erik Faye-Lund @ 2011-01-06 19:54 UTC (permalink / raw)
To: git; +Cc: msysgit, j6t, jrnieder
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>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
---
Fixed the issues pointed out by Jonathan Nieder.
git.c | 30 +++++++++++++++---------------
1 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/git.c b/git.c
index 68334f6..f3666a8 100644
--- a/git.c
+++ b/git.c
@@ -177,22 +177,22 @@ 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 argc = *argcp, 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);
- if (ret >= 0 && WIFEXITED(ret) &&
- WEXITSTATUS(ret) != 127)
- exit(WEXITSTATUS(ret));
+
+ /* build alias_argv */
+ alias_argv = xmalloc(sizeof(char *) * argc + 1);
+ alias_argv[0] = alias_string + 1;
+ for (i = 1; i < argc; ++i)
+ alias_argv[i] = (*argv)[i];
+ alias_argv[argc] = NULL;
+
+ ret = run_command_v_opt(alias_argv, RUN_USING_SHELL);
+ if (ret >= 0) /* normal exit */
+ exit(ret);
+
die("Failed to run '%s' when expanding alias '%s'",
alias_string + 1, alias_command);
}
--
1.7.3.3.585.g74f6e
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] alias: use run_command api to execute aliases
2011-01-06 19:54 [PATCH v2] alias: use run_command api to execute aliases Erik Faye-Lund
@ 2011-01-06 20:05 ` Jonathan Nieder
2011-01-06 20:14 ` Erik Faye-Lund
2011-01-06 20:27 ` Johannes Sixt
1 sibling, 1 reply; 4+ messages in thread
From: Jonathan Nieder @ 2011-01-06 20:05 UTC (permalink / raw)
To: Erik Faye-Lund; +Cc: git, msysgit, j6t
Erik Faye-Lund wrote:
> --- a/git.c
> +++ b/git.c
> @@ -177,22 +177,22 @@ static int handle_alias(int *argcp, const char ***argv)
[...]
> + alias_argv = xmalloc(sizeof(char *) * argc + 1);
Missed a spot? (missing parens)
Thanks for this. It also should provide a minor speedup in the case
of commands with no shell metacharacters.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] alias: use run_command api to execute aliases
2011-01-06 20:05 ` Jonathan Nieder
@ 2011-01-06 20:14 ` Erik Faye-Lund
0 siblings, 0 replies; 4+ messages in thread
From: Erik Faye-Lund @ 2011-01-06 20:14 UTC (permalink / raw)
To: Jonathan Nieder; +Cc: git, msysgit, j6t
[-- Attachment #1: Type: text/plain, Size: 600 bytes --]
On Jan 6, 2011 9:05 PM, "Jonathan Nieder" <jrnieder@gmail.com> wrote:
>
> Erik Faye-Lund wrote:
>
> > --- a/git.c
> > +++ b/git.c
> > @@ -177,22 +177,22 @@ static int handle_alias(int *argcp, const char
***argv)
> [...]
> > + alias_argv = xmalloc(sizeof(char *) * argc + 1);
>
> Missed a spot? (missing parens)
>
Blergh... I guess that teaches me a lesson about sending out patches in a
hurry. New version a bit later, then ;)
> Thanks for this. It also should provide a minor speedup in the case
> of commands with no shell metacharacters.
Nice. Not intentional, but hey :)
[-- Attachment #2: Type: text/html, Size: 796 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] alias: use run_command api to execute aliases
2011-01-06 19:54 [PATCH v2] alias: use run_command api to execute aliases Erik Faye-Lund
2011-01-06 20:05 ` Jonathan Nieder
@ 2011-01-06 20:27 ` Johannes Sixt
1 sibling, 0 replies; 4+ messages in thread
From: Johannes Sixt @ 2011-01-06 20:27 UTC (permalink / raw)
To: Erik Faye-Lund; +Cc: git, msysgit, jrnieder
On Donnerstag, 6. Januar 2011, Erik Faye-Lund wrote:
> @@ -177,22 +177,22 @@ 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 argc = *argcp, 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);
> - if (ret >= 0 && WIFEXITED(ret) &&
> - WEXITSTATUS(ret) != 127)
> - exit(WEXITSTATUS(ret));
> +
> + /* build alias_argv */
> + alias_argv = xmalloc(sizeof(char *) * argc + 1);
> + alias_argv[0] = alias_string + 1;
> + for (i = 1; i < argc; ++i)
> + alias_argv[i] = (*argv)[i];
> + alias_argv[argc] = NULL;
> +
> + ret = run_command_v_opt(alias_argv, RUN_USING_SHELL);
> + if (ret >= 0) /* normal exit */
> + exit(ret);
> +
> die("Failed to run '%s' when expanding alias '%s'",
> alias_string + 1, alias_command);
At this point, errno has a meaning. I'd perhaps change this to:
die_errno("While expanding alias '%s': '%s'",
alias_command, alias_string + 1);
-- Hannes
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-01-06 20:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-06 19:54 [PATCH v2] alias: use run_command api to execute aliases Erik Faye-Lund
2011-01-06 20:05 ` Jonathan Nieder
2011-01-06 20:14 ` Erik Faye-Lund
2011-01-06 20:27 ` Johannes Sixt
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 NNTP newsgroup(s).