From: Jonathan Nieder <jrnieder@gmail.com>
To: Erik Faye-Lund <kusmabite@gmail.com>
Cc: git@vger.kernel.org, msysgit@googlegroups.com, j6t@kdbg.org
Subject: Re: [PATCH/RFC] alias: use run_command api to execute aliases
Date: Thu, 6 Jan 2011 13:41:01 -0600 [thread overview]
Message-ID: <20110106194101.GA14750@burratino> (raw)
In-Reply-To: <1294341187-3956-1-git-send-email-kusmabite@gmail.com>
Erik Faye-Lund wrote:
> --- a/git.c
> +++ b/git.c
> @@ -177,19 +177,20 @@ static int handle_alias(int *argcp, const char ***argv)
[...]
> - trace_printf("trace: alias to shell cmd: %s => %s\n",
> - alias_command, alias_string + 1);
Replaced by
trace: run_command: ...
(followed by "trace: exec: ..." on non-Windows (execv_shell_cmd)).
Ok.
> - ret = system(alias_string + 1);
> +
> + /* build alias_argv */
> + alias_argv = malloc(sizeof(char *) * *argcp + 1);
This seems to be missing parentheses, so valgrind will complain
except on 8-bit systems. ;-)
What if malloc fails?
> + alias_argv[0] = alias_string + 1;
> + for (i = 1; i < *argcp; ++i)
> + alias_argv[i] = (*argv)[i];
> + alias_argv[*argcp] = NULL;
Nit: all these *argcp are noisy.
> +
> + ret = run_command_v_opt(alias_argv, RUN_USING_SHELL);
> +
> if (ret >= 0 && WIFEXITED(ret) &&
The return value from run_command and from system do not mean
the same thing.
> die("Failed to run '%s' when expanding alias '%s'",
> alias_string + 1, alias_command);
run_command already prints an error message, but this one still
seems useful since it mentions the alias.
Except as noted above,
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Thanks.
diff --git a/git.c b/git.c
index 5b0b9d8..dbf061d 100644
--- a/git.c
+++ b/git.c
@@ -178,22 +178,20 @@ static int handle_alias(int *argcp, const char ***argv)
if (alias_string) {
if (alias_string[0] == '!') {
const char **alias_argv;
- int i;
+ int argc = *argcp, i;
commit_pager_choice();
- /* build alias_argv */
- alias_argv = malloc(sizeof(char *) * *argcp + 1);
+ alias_argv = xmalloc(sizeof(*alias_argv) * (argc + 1));
alias_argv[0] = alias_string + 1;
- for (i = 1; i < *argcp; ++i)
+ for (i = 1; i < argc; ++i)
alias_argv[i] = (*argv)[i];
- alias_argv[*argcp] = NULL;
+ alias_argv[argc] = NULL;
ret = run_command_v_opt(alias_argv, RUN_USING_SHELL);
+ if (ret >= 0) /* normal exit */
+ exit(ret);
- if (ret >= 0 && WIFEXITED(ret) &&
- WEXITSTATUS(ret) != 127)
- exit(WEXITSTATUS(ret));
die("Failed to run '%s' when expanding alias '%s'",
alias_string + 1, alias_command);
}
next prev parent reply other threads:[~2011-01-06 19:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-06 19:13 [PATCH/RFC] alias: use run_command api to execute aliases Erik Faye-Lund
2011-01-06 19:41 ` Jonathan Nieder [this message]
2011-01-06 19:52 ` Erik Faye-Lund
2011-01-07 1:17 ` [msysGit] " Johannes Schindelin
2011-01-07 14:24 ` Erik Faye-Lund
2011-01-07 14:51 ` Johannes Schindelin
2011-01-07 19:21 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110106194101.GA14750@burratino \
--to=jrnieder@gmail.com \
--cc=git@vger.kernel.org \
--cc=j6t@kdbg.org \
--cc=kusmabite@gmail.com \
--cc=msysgit@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).