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

2017-05-16 Thread Linus Torvalds
On Tue, May 16, 2017 at 1:12 PM, Johannes Schindelin wrote: >> >> I think it would be better to just >> >> (a) get rid of the magic strcspn() entirely >> >> (b) make the 'can we optimize this' test be simply just looking up >> 'argv[0]' in $PATH > > What about > > ABC=1 my-executable my-

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

2017-05-16 Thread Johannes Schindelin
Hi Linus, On Tue, 16 May 2017, Linus Torvalds wrote: > On Tue, May 16, 2017 at 10:23 AM, Jeff King wrote: > > > > I think the logic here would be more like: > > > > 1. During prepare_shell_cmd(), even if we optimize out the shell call, > > still prepare a fallback argv (since we can't all

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

2017-05-16 Thread Linus Torvalds
On Tue, May 16, 2017 at 10:23 AM, Jeff King wrote: > > I think the logic here would be more like: > > 1. During prepare_shell_cmd(), even if we optimize out the shell call, > still prepare a fallback argv (since we can't allocate memory > post-fork). > > 2. In the forked child, if we

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

2017-05-16 Thread Jeff King
On Tue, May 16, 2017 at 10:29:31AM -0700, Eric Rannaud wrote: > > It does not really work that way. Git runs in a separate process that > > does not have access to your current shell. That's why you need to do > > 'export -f foo'. > > > > If you want git to be able to ecute the foo shell function,

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

2017-05-16 Thread Jeff King
On Tue, May 16, 2017 at 10:21:51AM -0700, Eric Rannaud wrote: > On Tue, May 16, 2017 at 9:59 AM, Eric Rannaud wrote: > > When I use "git rebase --exec " I'm basically writing a "foreach > > commit in range { }" in my shell. Same idea with git bisect run. > > > > A transparent optimization that t

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

2017-05-16 Thread Jonathan Nieder
Jeff King wrote: >>> On Mon, May 15, 2017 at 11:25:03PM -0400, Jeff King wrote: One hack would be to look for BASH_FUNC_* in the environment and disable the optimization in that case. I think that would make your case Just Work. It doesn't help other oddball cases, like: [...] >> Hm

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

2017-05-16 Thread Brandon Williams
On 05/16, Jeff King wrote: > On Tue, May 16, 2017 at 10:15:40AM -0700, Brandon Williams wrote: > > > > > > So I was thinking something like the patch below, though I guess > > > > > technically you could look for BASH_FUNC_$argv[0]%%, which seems to be > > > > > bash's magic variable name. I hate

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

2017-05-16 Thread Eric Rannaud
On Tue, May 16, 2017 at 10:14 AM, Kevin Daudt wrote: >> A transparent optimization that tries execve() then falls back to the >> user's shell sounds like a good idea. > > It does not really work that way. Git runs in a separate process that > does not have access to your current shell. That's why

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

2017-05-16 Thread Jeff King
On Tue, May 16, 2017 at 10:15:40AM -0700, Brandon Williams wrote: > > > > So I was thinking something like the patch below, though I guess > > > > technically you could look for BASH_FUNC_$argv[0]%%, which seems to be > > > > bash's magic variable name. I hate to get too intimate with those > > >

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

2017-05-16 Thread Eric Rannaud
On Tue, May 16, 2017 at 9:59 AM, Eric Rannaud wrote: > When I use "git rebase --exec " I'm basically writing a "foreach > commit in range { }" 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 id

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

2017-05-16 Thread Brandon Williams
On 05/16, Jeff King wrote: > On Tue, May 16, 2017 at 09:41:24AM -0700, Jonathan Nieder wrote: > > > Jeff King wrote: > > > On Mon, May 15, 2017 at 11:25:03PM -0400, Jeff King wrote: > > > > >> One hack would be to look for BASH_FUNC_* in the environment and disable > > >> the optimization in that

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

2017-05-16 Thread Kevin Daudt
On Tue, May 16, 2017 at 09:59:03AM -0700, Eric Rannaud wrote: > On Tue, May 16, 2017 at 9:18 AM, Jeff King wrote: > > On Tue, May 16, 2017 at 12:23:02PM +0200, Johannes Schindelin wrote: > >> It would appear to me that you used a side effect of an implementation > >> detail: that `git rebase -i` w

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

2017-05-16 Thread Eric Rannaud
On Tue, May 16, 2017 at 9:47 AM, Jeff King wrote: >> I think we want to behave consistently for shell builtins and for >> exported functions --- they are different sides of the same problem, >> and behaving differently between the two feels confusing. > > Yes, I think ideally we'd handle it all tr

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

2017-05-16 Thread Eric Rannaud
On Tue, May 16, 2017 at 9:18 AM, Jeff King wrote: > On Tue, May 16, 2017 at 12:23:02PM +0200, Johannes Schindelin wrote: >> It would appear to me that you used a side effect of an implementation >> detail: that `git rebase -i` was implemented entirely as a shell script. > > I don't think that's tr

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

2017-05-16 Thread Jeff King
On Tue, May 16, 2017 at 09:41:24AM -0700, Jonathan Nieder wrote: > Jeff King wrote: > > On Mon, May 15, 2017 at 11:25:03PM -0400, Jeff King wrote: > > >> One hack would be to look for BASH_FUNC_* in the environment and disable > >> the optimization in that case. I think that would make your case

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

2017-05-16 Thread Eric Rannaud
On Mon, May 15, 2017 at 8:53 PM, Jeff King wrote: >> > So I suspect if you added an extraneous semi-colon, your case would work >> > again (and that would confirm for us that this is indeed the problem). >> >> Wow, that's a brilliant analysis. > > If it's right. :) It's all theory at this point. >

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

2017-05-16 Thread Jonathan Nieder
(+Brandon Williams, who may have more context for execvp-related things) Hi, Jeff King wrote: > On Mon, May 15, 2017 at 11:25:03PM -0400, Jeff King wrote: >> One hack would be to look for BASH_FUNC_* in the environment and disable >> the optimization in that case. I think that would make your cas

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

2017-05-16 Thread Jeff King
On Tue, May 16, 2017 at 12:23:02PM +0200, Johannes Schindelin wrote: > On Mon, 15 May 2017, Eric Rannaud wrote: > > > It used to be possible to run a sequence like: > > > > foo() { echo X; } > > export -f foo > > git rebase --exec foo HEAD~10 > > It would appear to me that you used a side

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

2017-05-16 Thread Johannes Schindelin
Hi Junio, On Tue, 16 May 2017, Junio C Hamano wrote: > The point of rewriting things in C and using run_command() interface was > to avoid shell overhead. That statement is missing the point. It is true that converting shell scripts to proper builtins avoids the shell overhead. It is even more

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

2017-05-16 Thread Johannes Schindelin
Hi Eric, On Mon, 15 May 2017, Eric Rannaud wrote: > It used to be possible to run a sequence like: > > foo() { echo X; } > export -f foo > git rebase --exec foo HEAD~10 It would appear to me that you used a side effect of an implementation detail: that `git rebase -i` was implemented enti

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

2017-05-15 Thread Jeff King
On Mon, May 15, 2017 at 11:53:57PM -0400, Jeff King wrote: > My /bin/sh isn't bash, but I should be able to build with > SHELL_PATH=/bin/bash to reproduce. But I can't: > >$ bash >$ foo() { echo >&2 "in foo"; } >$ export -f foo >$ bash -c foo >in foo > >$ strace -f 2>&1 g

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

2017-05-15 Thread Jeff King
On Tue, May 16, 2017 at 12:40:51PM +0900, Junio C Hamano wrote: > Jeff King writes: > > > Interesting. The "exec" string is still run with a shell. E.g.: > > ... > > I wonder if this is falling afoul of the optimization in run-command's > > prepare_shell_cmd() to skip shell invocations for "simp

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

2017-05-15 Thread Junio C Hamano
Jeff King writes: > Interesting. The "exec" string is still run with a shell. E.g.: > ... > I wonder if this is falling afoul of the optimization in run-command's > prepare_shell_cmd() to skip shell invocations for "simple" commands. > ... > So I suspect if you added an extraneous semi-colon, you

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

2017-05-15 Thread Jeff King
On Mon, May 15, 2017 at 11:25:03PM -0400, Jeff King wrote: > One hack would be to look for BASH_FUNC_* in the environment and disable > the optimization in that case. I think that would make your case Just > Work. It doesn't help other oddball cases, like: > > - you're trying to run a shell bui

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

2017-05-15 Thread Jeff King
On Mon, May 15, 2017 at 11:08:39AM -0700, Eric Rannaud wrote: > It used to be possible to run a sequence like: > > foo() { echo X; } > export -f foo > git rebase --exec foo HEAD~10 > > Since upgrading to 2.13.0, I had to update my scripts to run: > > git rebase --exec "bash -c foo" HEAD

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

2017-05-15 Thread Eric Rannaud
Hi all, It used to be possible to run a sequence like: foo() { echo X; } export -f foo git rebase --exec foo HEAD~10 Since upgrading to 2.13.0, I had to update my scripts to run: git rebase --exec "bash -c foo" HEAD~10 I'm not sure if this was an intended change. Bisecting with the fol