On Thu, Sep 27, 2012 at 02:43:38AM -0400, Jeff King wrote:
> Here are the numbers using sed[1]
> instead:
 
> -# Quotes each element of an IFS-delimited list for shell reuse
> +# Quotes each element of a newline-delimited list for shell reuse
>  __git_quote()
>  {
> -     local i
> -     local delim
> -     for i in $1; do
> -             local quoted=${i//\'/\'\\\'\'}
> -             printf "${delim:+$IFS}'%s'" "$quoted"
> -             delim=t
> -     done
> +     echo "$1" |
> +     sed "
> +       s/'/'\\\\''/g
> +       s/^/'/
> +       s/$/'/
> +     "
>  }
>  
>  # Generates completion reply with compgen, appending a space to possible

Your usage of sed got me thinking and come up with this.

The first two fix benign bugs in completion tests, and the third adds
tests for __gitcomp_nl().  These are good to go.

The fourth adds __gitcomp() and __gitcomp_nl() tests for this
expansion breakage.  The expected results might need some adjustments,
because they contain special characters unquoted, but I'm tempted to
say that a branch called $foo is so rare in practice, that we
shouldn't bother.

The final one is a proof of concept for inspiration.  It gets rid of
compgen and its crazy additional expansion replacing it with a small
sed script.  It needs further work to handle words with whitespaces
and special characters.


SZEDER Gábor (5):
  completion: fix non-critical bugs in __gitcomp() tests
  completion: fix args of run_completion() test helper
  completion: add tests for the __gitcomp_nl() completion helper
    function
  completion: test __gitcomp() and __gitcomp_nl() with expandable words
  completion: avoid compgen to fix expansion issues in __gitcomp_nl()

 contrib/completion/git-completion.bash |  6 ++-
 t/t9902-completion.sh                  | 91 +++++++++++++++++++++++++++++++---
 2 files changed, 90 insertions(+), 7 deletions(-)


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to