From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Jeff King <peff@peff.net>
Cc: Junio C Hamano <gitster@pobox.com>,
Armin Kunaschik <megabreit@googlemail.com>,
Git List <git@vger.kernel.org>
Subject: Re: syntax error in git-rebase while running t34* tests
Date: Wed, 11 May 2016 15:28:35 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.20.1605111518470.4092@virtualbox> (raw)
In-Reply-To: <20160510210709.GD19958@sigill.intra.peff.net>
Hi,
On Tue, 10 May 2016, Jeff King wrote:
> On Tue, May 10, 2016 at 01:53:56PM -0700, Junio C Hamano wrote:
>
> > Jeff King <peff@peff.net> writes:
> >
> > > I think it is clear why it works. If $strategy_opts is empty, then the
> > > code we generate looks like:
> > >
> > > for strategy_opt in
> > > do
> > > ...
> > > done
> >
> > Ah, of course. Thanks.
>
> Here it is as a patch and commit message.
>
> -- >8 --
> Subject: [PATCH] rebase--interactive: avoid empty list in shell for-loop
>
> The $strategy_opts variable contains a space-separated list
> of strategy options, each individually shell-quoted. To loop
> over each, we "unwrap" them by doing an eval like:
>
> eval '
> for opt in '"$strategy_opts"'
> do
> ...
> done
> '
>
> Note the quoting that means we expand $strategy_opts inline
> in the code to be evaluated (which is the right thing
> because we want the IFS-split and de-quoting). If the
> variable is empty, however, we ask the shell to eval the
> following code:
>
> for opt in
> do
> ...
> done
>
> without anything between "in" and "do". Most modern shells
> are happy to treat that like a noop, but reportedly ksh88 on
> AIX considers it a syntax error. So let's catch the case
> that the variable is empty and skip the eval altogether
> (since we know the loop would be a noop anyway).
>
> Reported-by: Armin Kunaschik <megabreit@googlemail.com>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> git-rebase--interactive.sh | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
> index 9ea3075..1c6dfb6 100644
> --- a/git-rebase--interactive.sh
> +++ b/git-rebase--interactive.sh
> @@ -82,6 +82,7 @@ rewritten_pending="$state_dir"/rewritten-pending
> cr=$(printf "\015")
>
> strategy_args=${strategy:+--strategy=$strategy}
> +test -n "$strategy_opts" &&
> eval '
> for strategy_opt in '"$strategy_opts"'
> do
Looks obviously correct to me.
I had a look at our other shell scripts and it looks as if there is only
one more candidate for this issue: git-bisect.sh has a couple of 'for arg
in "$@"' constructs. But from a cursory look, it appears that none of
these "$@" can be empty lists because at least one parameter is passed to
those functions (check_expected_revs() is only called from bisect_state()
with 1 or 2 parameters, bisect_skip() makes no sense without parameters,
and bisect_state() has another for loop if it got 2 parameters).
So I think we're fine.
Ciao,
Dscho
next prev parent reply other threads:[~2016-05-11 13:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-10 17:29 syntax error in git-rebase while running t34* tests Armin Kunaschik
2016-05-10 19:11 ` Junio C Hamano
2016-05-10 20:47 ` Jeff King
2016-05-10 20:53 ` Junio C Hamano
2016-05-10 21:07 ` Jeff King
2016-05-11 13:28 ` Johannes Schindelin [this message]
2016-05-11 13:36 ` Jeff King
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=alpine.DEB.2.20.1605111518470.4092@virtualbox \
--to=johannes.schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=megabreit@googlemail.com \
--cc=peff@peff.net \
/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