From: Rick van Hattem <wolph@wol.ph>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: "SZEDER Gábor" <szeder.dev@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>,
"Matthew Coleman" <matt@1eanda.com>,
"Stephon Harris" <theonestep4@gmail.com>,
"Duy Nguyen" <pclouds@gmail.com>,
"Jakub Narębski" <jnareb@gmail.com>,
git@vger.kernel.org, "Dave Borowitz" <dborowitz@google.com>
Subject: Re: [PATCH v2] completion: reduce overhead of clearing cached --options
Date: Thu, 7 Jun 2018 14:41:47 +0200 [thread overview]
Message-ID: <CAJAwA=z2cwy7A3oG=0RPCrh4i41NxPk6jAFhjtisAPvndOKC9Q@mail.gmail.com> (raw)
In-Reply-To: <20180607054834.GB6567@aiede.svl.corp.google.com>
The zsh script expects the bash completion script to be available so
that might be the issue here.
To reproduce this is what I do. First, a sparse checkout:
# mkdir ~/git
# cd ~/git
# git init
# git remote add origin git@github.com:git/git.git
# git config core.sparseCheckout true
# mkdir .git/info
# echo contrib/completion >> .git/info/sparse-checkout
# git pull origin master --depth 1
After that I simply link the zsh script to _git:
# cd git/contrib/completion
# ln git-completion.zsh _git
And add the following to a new .zshrc file:
autoload -U compinit; compinit
autoload -U bashcompinit; bashcompinit
fpath=(~/git/contrib/completion $fpath)
And that appears to be enough to reproduce:
# git<tab>
git/contrib/completion/git-completion.bash:354: read-only variable: QISUFFIX
zsh:12: command not found: ___main
zsh:15: _default: function definition file not found
_dispatch:70: bad math expression: operand expected at `/usr/bin/g...'
zsh: segmentation fault zsh
~rick
On 7 June 2018 at 07:48, Jonathan Nieder <jrnieder@gmail.com> wrote:
> Hi,
>
> SZEDER Gábor wrote:
>
>> Other Bash versions, notably 4.4.19 on macOS via homebrew (i.e. a
>> newer version on the same platform) and 3.2.25 on CentOS (i.e. a
>> slightly earlier version, though on a different platform) are not
>> affected. ZSH in macOS (the versions shipped by default or installed
>> via homebrew) or on other platforms isn't affected either.
> [...]
>> --- a/contrib/completion/git-completion.bash
>> +++ b/contrib/completion/git-completion.bash
>> @@ -282,7 +282,11 @@ __gitcomp ()
>>
>> # Clear the variables caching builtins' options when (re-)sourcing
>> # the completion script.
>> -unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null
>> +if [[ -n ${ZSH_VERSION-} ]]; then
>> + unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null
>> +else
>> + unset $(compgen -v __gitcomp_builtin_)
>> +fi
>
> As discussed at [1], this fails catastrophically when sourced by
> git-completion.zsh, which explicitly clears ZSH_VERSION. By
> catastrophically, I mean that Rick van Hattem and Dave Borowitz report
> that it segfaults.
>
> I can't reproduce it since I am having trouble following the
> instructions at the top of git-completion.zsh to get the recommended
> zsh completion script loading mechanism working at all. (I've
> succeeded in using git's bash completion on zsh before, but that was
> many years ago.) First attempt:
>
> 1. rm -fr ~/.zsh ~/.zshrc
> # you can move them out of the way instead for a less destructive
> # reproduction recipe
> 2. zsh
> 3. hit "q"
> 4. zstyle ':completion:*:*:git:*' script \
> $(pwd)/contrib/completion/git-completion.zsh
> 5. git checkout <TAB>
>
> Expected result: segfault
>
> Actual result: succeeds, using zsh's standard completion script (not
> git's).
>
> I also tried
>
> 1. rm -fr ~/.zsh ~/.zshrc
> # you can move them out of the way instead for a less destructive
> # reproduction recipe
> 2. zsh
> 3. hit "2"
> 4. mkdir ~/.zsh; cp contrib/completion/git-completion.zsh ~/.zsh/_git
> 5. echo 'fpath=(~/.zsh $fpath)' >>~/.zshrc
> 6. ^D; zsh
> 7. git checkout <TAB>
>
> and a similar process with fpath earlier in the zshrc file. Whatever
> I try, I end up with one of two results: either it uses zsh's standard
> completion, or it spews a stream of errors about missing functions
> like compgen. What am I doing wrong?
>
> Related question: what would it take to add a zsh completion sanity
> check to t/t9902-completion.sh?
>
> When running with "set -x", here is what Dave Borowitz gets before the
> segfault. I don't have a stacktrace because, as mentioned above, I
> haven't been able to reproduce it.
>
> str=git
> [[ -n git ]]
> service=git
> i=
> _compskip=default
> eval ''
> ret=0
> [[ default = *patterns* ]]
> [[ default = all ]]
> str=/usr/bin/git
> [[ -n /usr/bin/git ]]
> service=_dispatch:70: bad math expression: operand expected at `/usr/bin/g...'
>
> zsh: segmentation fault zsh
>
> Here's a minimal fix, untested. As a followup, as Gábor suggests at [2],
> it would presumably make sense to stop overriding ZSH_VERSION, using
> this GIT_ scoped variable everywhere instead.
>
> Thoughts?
>
> Reported-by: Rick van Hattem <wolph@wol.ph>
> Reported-by: Dave Borowitz <dborowitz@google.com>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
>
> [1] https://public-inbox.org/git/01020163c683e753-04629405-15f8-4a30-9dc3-e4e3f2a5aa26-000000@eu-west-1.amazonses.com/
> [2] https://public-inbox.org/git/20180606114147.7753-1-szeder.dev@gmail.com/
>
> diff --git i/contrib/completion/git-completion.bash w/contrib/completion/git-completion.bash
> index 12814e9bbf..e4bcc435ea 100644
> --- i/contrib/completion/git-completion.bash
> +++ w/contrib/completion/git-completion.bash
> @@ -348,7 +348,7 @@ __gitcomp ()
>
> # Clear the variables caching builtins' options when (re-)sourcing
> # the completion script.
> -if [[ -n ${ZSH_VERSION-} ]]; then
> +if [[ -n ${ZSH_VERSION-} || -n ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
> unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null
> else
> unset $(compgen -v __gitcomp_builtin_)
> diff --git i/contrib/completion/git-completion.zsh w/contrib/completion/git-completion.zsh
> index 53cb0f934f..c7be9fd4dc 100644
> --- i/contrib/completion/git-completion.zsh
> +++ w/contrib/completion/git-completion.zsh
> @@ -39,7 +39,7 @@ if [ -z "$script" ]; then
> test -f $e && script="$e" && break
> done
> fi
> -ZSH_VERSION='' . "$script"
> +GIT_SOURCING_ZSH_COMPLETION=1 ZSH_VERSION='' . "$script"
>
> __gitcomp ()
> {
next prev parent reply other threads:[~2018-06-07 12:42 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-05 3:10 [PATCH] specify encoding for sed command Stephon Harris
2018-04-05 6:53 ` Ævar Arnfjörð Bjarmason
2018-04-05 9:42 ` Eric Sunshine
2018-04-05 9:43 ` SZEDER Gábor
2018-04-10 7:18 ` Matt Coleman
2018-04-11 20:42 ` Matt Coleman
2018-04-12 22:12 ` Matthew Coleman
2018-04-13 0:01 ` SZEDER Gábor
2018-04-13 3:00 ` Matthew Coleman
2018-04-13 10:30 ` [PATCH] completion: reduce overhead of clearing cached --options SZEDER Gábor
2018-04-13 21:44 ` Jakub Narebski
2018-04-13 22:23 ` SZEDER Gábor
2018-04-14 13:27 ` Jakub Narebski
2018-04-16 18:23 ` Jacob Keller
2018-04-16 20:35 ` Matthew Coleman
2018-04-16 5:10 ` Junio C Hamano
2018-04-16 13:15 ` SZEDER Gábor
2018-04-16 13:29 ` Jakub Narębski
2018-04-16 22:43 ` Junio C Hamano
2018-04-17 22:02 ` [PATCH v2] " SZEDER Gábor
2018-04-17 23:45 ` Junio C Hamano
2018-05-07 15:05 ` Matthew Coleman
2018-05-08 2:28 ` Todd Zullinger
2018-05-08 3:28 ` Junio C Hamano
2018-06-07 5:48 ` Jonathan Nieder
2018-06-07 12:07 ` Dave Borowitz
2018-06-07 12:41 ` Rick van Hattem [this message]
2018-06-08 21:16 ` SZEDER Gábor
2018-06-08 21:23 ` Jonathan Nieder
2018-06-08 21:41 ` SZEDER Gábor
2018-06-08 21:52 ` Jonathan Nieder
2018-06-08 21:58 ` SZEDER Gábor
2018-06-11 17:53 ` Junio C Hamano
2018-06-11 18:20 ` [PATCH] completion: correct zsh detection when run from git-completion.zsh (Re: [PATCH v2] completion: reduce overhead of clearing cached --options) Jonathan Nieder
2018-06-12 8:46 ` SZEDER Gábor
2018-06-12 9:48 ` SZEDER Gábor
2018-06-12 9:51 ` Rick van Hattem
2018-04-08 23:17 ` [PATCH] specify encoding for sed command 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='CAJAwA=z2cwy7A3oG=0RPCrh4i41NxPk6jAFhjtisAPvndOKC9Q@mail.gmail.com' \
--to=wolph@wol.ph \
--cc=dborowitz@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jnareb@gmail.com \
--cc=jrnieder@gmail.com \
--cc=matt@1eanda.com \
--cc=pclouds@gmail.com \
--cc=szeder.dev@gmail.com \
--cc=theonestep4@gmail.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).