summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ac0ba18)
raw | patch | inline | side by side (parent: ac0ba18)
author | Jeff King <peff@peff.net> | |
Wed, 30 Dec 2009 10:55:36 +0000 (05:55 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 6 Jan 2010 07:41:50 +0000 (23:41 -0800) |
If there are no metacharacters in the program to be run, we
can just skip running the shell entirely and directly exec
the program.
The metacharacter test is pulled verbatim from
launch_editor, which already implements this optimization.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
can just skip running the shell entirely and directly exec
the program.
The metacharacter test is pulled verbatim from
launch_editor, which already implements this optimization.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
run-command.c | patch | blob | history |
diff --git a/run-command.c b/run-command.c
index b2bdcfda3df9cc9a50453dae33926da7377a7b57..47ced570bd58d7146bf226fcbb0fdfdf06b99be5 100644 (file)
--- a/run-command.c
+++ b/run-command.c
if (argc < 1)
die("BUG: shell command is empty");
- nargv[nargc++] = "sh";
- nargv[nargc++] = "-c";
-
- if (argc < 2)
- nargv[nargc++] = argv[0];
- else {
- struct strbuf arg0 = STRBUF_INIT;
- strbuf_addf(&arg0, "%s \"$@\"", argv[0]);
- nargv[nargc++] = strbuf_detach(&arg0, NULL);
+ if (strcspn(argv[0], "|&;<>()$`\\\"' \t\n*?[#~=%") != strlen(argv[0])) {
+ nargv[nargc++] = "sh";
+ nargv[nargc++] = "-c";
+
+ if (argc < 2)
+ nargv[nargc++] = argv[0];
+ else {
+ struct strbuf arg0 = STRBUF_INIT;
+ strbuf_addf(&arg0, "%s \"$@\"", argv[0]);
+ nargv[nargc++] = strbuf_detach(&arg0, NULL);
+ }
}
for (argc = 0; argv[argc]; argc++)