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

Re: git rebase regression: cannot pass a shell expression directly to --exec

From
Jeff King <peff@peff.net>
Date
May 16, 2017, 17:37 UTC
Message-ID
<20170516173727.5zstcg2g5bradhcf@sigill.intra.peff.net>
In-Reply-To
<CA+zRj8XLQiTmiVbsJZ7XjdW4bQvMSJpCtKW8xx5JvMKOhBDmLQ@mail.gmail.com>
On Tue, May 16, 2017 at 10:21:51AM -0700, Eric Rannaud wrote:
Show 12 quoted lines
> On Tue, May 16, 2017 at 9:59 AM, Eric Rannaud <eric.rannaud@gmail.com> wrote:
> > When I use "git rebase --exec <cmd>" I'm basically writing a "foreach
> > commit in range { <cmd> }" in my shell. Same idea with git bisect run.
> >
> > A transparent optimization that tries execve() then falls back to the
> > user's shell sounds like a good idea.
> 
> One issue with the execve-else-shell optimization is that sometimes a
> binary exists that will shadow an exported function or a shell
> builtin:
> 
>   git rebase --exec true master^^  # OK but in fact this runs /usr/bin/true

Yeah, this is the builtin thing I mentioned elsewhere. I think it's pretty rare to run a builtin with no arguments and care about the behavior differences.

Show 8 quoted lines
> /usr/bin/time requires an argument. Even though the bash builtin time
> runs fine without argument.
> 
>   $ time
> 
>   real    0m0.000s
>   user    0m0.000s
>   sys     0m0.000s

I've run into the "time" distinction even when running things from the shell, because the time builtin is special. E.g.:

  $ time true
  real	0m0.000s
  user	0m0.000s
  sys	0m0.000s
  $ (echo foo | time true) 2>&1
  0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 1136maxresident)k
  0inputs+0outputs (0major+61minor)pagefaults 0swaps

So to some degree, depending on builtins versus external commands (especially when you're round-tripping through another program running a second shell) is going to have some surprises.

> But if the optimization is applied to more complex commands, then we
> will have problems. For instance, the builtin echo supports \E, but
> /usr/bin/echo doesn't support it.
No, it shouldn't. If any of
     |&;<>()$`\\\"' \t\n*?[#~=%
appear in the string, we always run the shell.
> In any case, the manpage says --exec <cmd> and "<cmd> will be
> interpreted as one or more shell commands.", it doesn't say "--exec
> <executable>".

Right, it's clearly supposed to use the shell, or behave as if the shell were invoked (within reason).

-Peff
Previous: Eric Rannaud
Message 29 of 29 in “git rebase regression: cannot pass a shell expression directly to --exec”
  1. Eric RannaudMay 15, 2017
  2. Jeff KingMay 16, 2017
  3. Jeff KingMay 16, 2017
  4. Jonathan NiederMay 16, 2017
  5. Jeff KingMay 16, 2017
  6. Eric RannaudMay 16, 2017
  7. Brandon WilliamsMay 16, 2017
  8. Jeff KingMay 16, 2017
  9. Brandon WilliamsMay 16, 2017
  10. Linus TorvaldsMay 16, 2017
  11. [TANGENT] run-command: use vfork instead of forkEric Wong, May 16, 2017
  12. Linus TorvaldsMay 16, 2017
  13. Brandon WilliamsMay 16, 2017
  14. Johannes SchindelinMay 16, 2017
  15. Linus TorvaldsMay 16, 2017
  16. Jonathan NiederMay 16, 2017
  17. Junio C HamanoMay 16, 2017
  18. Jeff KingMay 16, 2017
  19. Jeff KingMay 16, 2017
  20. Eric RannaudMay 16, 2017
  21. Johannes SchindelinMay 16, 2017
  22. Johannes SchindelinMay 16, 2017
  23. Jeff KingMay 16, 2017
  24. Eric RannaudMay 16, 2017
  25. Kevin DaudtMay 16, 2017
  26. Eric RannaudMay 16, 2017
  27. Jeff KingMay 16, 2017
  28. Eric RannaudMay 16, 2017
  29. Jeff KingMay 16, 2017

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.