Re: [PATCH 3/6] run-command: optimize out useless shell calls
- From
Johannes Sixt <j6t@kdbg.org>
- Date
- Dec 31, 2009, 16:54 UTC
- Message-ID
- <4B3CD74D.7020605@kdbg.org>
- In-Reply-To
- <20091230105536.GC22959@coredump.intra.peff.net>
Jeff King schrieb:
Show 13 quoted lines
> 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> > --- > Something inside me feels wrong with a catch-known-metacharacter test > instead of an allow-known-good check. But this is the same test we have > been using with launch_editor for some time, so I decided not to mess > with it.
The git version that msysgit ships (and the one that I use on Windows) has this sequence in pager.c:
static const char *pager_argv[] = { "sh", "-c", NULL, NULL };
...
pager_process.argv = &pager_argv[2];
pager_process.in = -1;
if (start_command(&pager_process)) {
pager_process.argv = pager_argv;
pager_process.in = -1;
if (start_command(&pager_process))
return;
}to help people set
PAGER=C:\Program Files\cygwin\bin\less
That is, we first try to run the program without the shell, then retry wrapped in sh -c.
Wouldn't it be possible to do the same here, assuming that we don't have programs such as "editor -f" in the path?
It does assume that we are able to detect execvp failure due to ENOENT which is currently proposed elsewhere by Ilari Liusvaara (and which is already possible on Windows).
-- Hannes