From: Junio C Hamano <gitster@pobox.com>
To: Ben Jackson <ben@ben.com>
Cc: git@vger.kernel.org, nanako3@lavabit.com, gitster@pobox.com
Subject: Re: [PATCH] Work around ash "alternate value" expansion bug
Date: Sat, 18 Apr 2009 11:30:58 -0700 [thread overview]
Message-ID: <7vfxg5x199.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 1240044459-57227-1-git-send-email-ben@ben.com
Ben Jackson <ben@ben.com> writes:
> Ash (used as /bin/sh on many distros) has a shell expansion bug
> for the form ${var:+word word}. The result is a single argument
> "word word". Work around by using ${var:+word} ${var:+word} or
> equivalent.
>
> Signed-off-by: Ben Jackson <ben@ben.com>
> ---
>
> I found this by accident while testing another trivial git-am patch.
> It was broken about a week ago in git-am.sh by f79d4c8a and one of the
> test cases caught it on FreeBSD.
>
> The other instance has been around longer and I found it by grepping.
> I added a new testcase (none too exciting) which exposes the problem.
> There are more instances of ${x:+alt} which don't have spaces which I
> did not touch.
>
> For the curious:
>
> bash on linux:
> $ parent=ok
> $ echo ${parent:+-p $parent}
> -p ok
> $ for i in ${parent:+-p $parent} ; do echo .$i; done
> .-p
> .ok
>
> ash (/bin/sh) on freebsd:
> $ parent=ok
> $ echo ${parent:+-p $parent}
> -p ok
> $ for i in ${parent:+-p $parent} ; do echo .$i; done
> .-p ok
>
> This is probably a bug in ash. It does expand ${foo:+*} into many words.
>
> git-am.sh | 2 +-
> git-submodule.sh | 2 +-
> t/t7400-submodule-basic.sh | 8 ++++++++
> 3 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/git-am.sh b/git-am.sh
> index bfc50c9..e539c60 100755
> --- a/git-am.sh
> +++ b/git-am.sh
> @@ -570,7 +570,7 @@ do
> GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
> export GIT_COMMITTER_DATE
> fi &&
> - git commit-tree $tree ${parent:+-p $parent} <"$dotest/final-commit"
> + git commit-tree $tree ${parent:+-p} $parent <"$dotest/final-commit"
> ) &&
> git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent ||
> stop_here $this
I do not mind this one, but
> diff --git a/git-submodule.sh b/git-submodule.sh
> index 7c2e060..bb3766d 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -204,7 +204,7 @@ cmd_add()
> else
>
> module_clone "$path" "$realrepo" || exit
> - (unset GIT_DIR; cd "$path" && git checkout -f -q ${branch:+-b "$branch" "origin/$branch"}) ||
> + (unset GIT_DIR; cd "$path" && git checkout -f -q ${branch:+-b} ${branch:+"$branch"} ${branch:+"origin/$branch"}) ||
this is too ugly to live in our codebase, and without an accompanying code
comment, I am sure somebody (if not myself) will "fix" it again.
(
unset GIT_DIR
cd "$path" &&
# BSD ash mishandles ${branch:+-b "$branch" ...}, sheesh.
case "$branch" in
'') git checkout -f -q ;;
?*) git checkout -f -q -b "$branch" "origin/$branch" ;;
esac
) ||
...
next prev parent reply other threads:[~2009-04-18 18:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-18 8:47 [PATCH] Work around ash "alternate value" expansion bug Ben Jackson
2009-04-18 18:30 ` Junio C Hamano [this message]
2009-04-19 3:42 ` [PATCH v2] " Ben Jackson
2009-04-19 4:38 ` Junio C Hamano
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vfxg5x199.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=ben@ben.com \
--cc=git@vger.kernel.org \
--cc=nanako3@lavabit.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).