From: Junio C Hamano <gitster@pobox.com>
To: Felipe Contreras <felipe.contreras@gmail.com>
Cc: git@vger.kernel.org, "Junio C Hamano" <gitster@pobox.com>,
"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: Fri, 03 Feb 2012 12:23:02 -0800 [thread overview]
Message-ID: <7v1uqbpsyh.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: 1328214625-3576-2-git-send-email-felipe.contreras@gmail.com
Felipe Contreras <felipe.contreras@gmail.com> writes:
> Right now when listing commands in zsh (git <TAB><TAB>), all of them
> will show up, instead of only porcelain ones.
Jonathan's rewrite goes straight to the root cause instead, which is
another way to describe the problem.
Explaining user-visible symptoms at the beginning like you did is a good
strategy that I would want to see more contributors follow, though.
> Basically, in zsh, this:
>
> for i in $__git_all_commands
>
> Should be:
>
> for i in ${=__git_all_commands}
>
> Otherwise there's no word-splitting expansion (unless SH_WORD_SPLIT is
> set). sh emulation should take care of that, but the subshell is messing
> up with that. So __git_list_porcelain_commands does not do any
> filtering.
Let me step back a bit and see if we are on the same page wrt the root
cause of the problem and for whom we are explaining the change.
The adaptation of the bash completion script to zsh is done by asking zsh
to obey POSIXy word splitting rules to honor $IFS that is in effect when
the words are split. However zsh does not do a good job at it in some
cases, and your patch works it around by avoiding a construct known to be
troublesome to zsh.
Am I correct so far? If so, especially if the first sentence of the above
paragraph is correct, then how would it help others to teach "this is the
right way to do a word-split if we were writing in native zsh" when we are
not?
While it probably is a good description to have in a bug report given to
zsh folks, it is useless for people who read the history of Git. Unless
you are writing zsh-native completion script and this patch is not about
git-completion.bash, that is.
The readers need to read the solution described in order to understand why
the updated construct is written in an unnatural (to people who write to
POSIXy shells) way, or to avoid reintroducing a similar problem elsewhere
in the future. 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).
Thanks.
next prev parent reply other threads:[~2012-02-03 20:23 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 ` Junio C Hamano [this message]
2012-02-06 22:59 ` [PATCH v4 1/4] completion: work around zsh option propagation bug Felipe Contreras
2012-02-06 23:20 ` Junio C Hamano
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=7v1uqbpsyh.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).