git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Felipe Contreras <felipe.contreras@gmail.com>
Cc: git@vger.kernel.org, "SZEDER Gábor" <szeder@ira.uka.de>,
	"Jonathan Nieder" <jrnieder@gmail.com>,
	"Thomas Rast" <trast@inf.ethz.ch>,
	"Shawn O. Pearce" <spearce@spearce.org>
Subject: Re: [PATCH v4 1/4] completion: work around zsh option propagation bug
Date: Mon, 06 Feb 2012 15:20:08 -0800	[thread overview]
Message-ID: <7vvcnj4kif.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <CAMP44s3SruBpM74BjWuTLfS=_66p7r6rkjJ+ObLr4bLq0nERNA@mail.gmail.com> (Felipe Contreras's message of "Tue, 7 Feb 2012 00:59:34 +0200")

Felipe Contreras <felipe.contreras@gmail.com> writes:

>> I find that what Jonathan gave you helps them much better:
>>        ...
>>        fn () {
>>                var='one two'
>>                printf '%s\n' $var
>>        }
>>        x=$(fn)
>>        : ${y=$(fn)}
>>
>>    printing "$x" results in two lines as expected, but printing "$y" results
>>    in a single line because $var is expanded as a single word when evaluating
>>    fn to compute y.
>>
>>    So avoid the construct, and use an explicit 'test -n "$foo" || foo=$(bar)'
>>    instead.
>>
>> So I'll take the first two lines of the message (good bits), and simplify
>> the "This fixes a bug tht caused..." from the last paragraph (or perhaps
>> even drop it).
>
> I'm not sure about it, because this relies on knowledge of how printf
> works, and it's not used that often; an example with 'for' would be
> much more clear IMO.

Meaning, replace the fn() definition with something like:

	fn () {
		var='one two'
                for v in $var
                do
                	echo "$v"
		done
	}

I can see that may make the issue easier to see; as you pointed out, it
requires no implicit knowledge that printf "loops" over the arguments
and applies the format string as manu times as needed to eat them.
Let me update the log message before I merge it to 'next'.

My main point was to illustrate the problematic pattern for people who
write for bash, not for zsh, and that does not change with the above
improvement, though ;-).

  reply	other threads:[~2012-02-06 23:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-02 20:30 [PATCH v4 0/4] completion: couple of cleanups Felipe Contreras
     [not found] ` <1328214625-3576-2-git-send-email-felipe.contreras@gmail.com>
2012-02-03 20:23   ` [PATCH v4 1/4] completion: work around zsh option propagation bug Junio C Hamano
2012-02-06 22:59     ` Felipe Contreras
2012-02-06 23:20       ` Junio C Hamano [this message]
2012-02-06 23:57         ` Felipe Contreras
     [not found] ` <1328214625-3576-5-git-send-email-felipe.contreras@gmail.com>
2012-02-03 20:23   ` [PATCH v4 4/4] completion: simplify __gitcomp* Junio C Hamano
2012-02-04 13:54     ` SZEDER Gábor
2012-02-05 20:45       ` Junio C Hamano
2012-02-05 21:14         ` Felipe Contreras
     [not found] ` <1328214625-3576-3-git-send-email-felipe.contreras@gmail.com>
2012-02-06 20:53   ` [PATCH v4 2/4] completion: simplify __git_remotes SZEDER Gábor
2012-02-06 21:04     ` Felipe Contreras

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=7vvcnj4kif.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    --cc=spearce@spearce.org \
    --cc=szeder@ira.uka.de \
    --cc=trast@inf.ethz.ch \
    /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;
as well as URLs for NNTP newsgroup(s).