git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 3/4] completion: cleanup __gitcomp*

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 30, 2012, 19:03 UTC
Message-ID
<7vpqe1au7f.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20120130175004.GG10618@burratino>
Jonathan Nieder <jrnieder@gmail.com> writes:
Show 12 quoted lines
> I imagine it would have been enough to say something along the lines of
> "The __gitcomp and __gitcomp_nl functions are unnecessarily verbose.
> __gitcomp_nl sets IFS to " \t\n" unnecessarily before setting it to "\n"
> by mistake.  Both functions use 'if' statements to read parameters
> with defaults, where the ${parameter:-default} idiom would be just as
> clear.  By fixing these, we can make each function almost a one-liner."
>
> By the way, the subject ("clean up __gitcomp*") tells me almost as
> little as something like "fix __gitcomp*".  A person reading the
> shortlog would like to know _how_ you are fixing it, or what the
> impact of the change will be --- e.g., something like "simplify
> __gitcomp and __gitcomp_nl" would be clearer.
I love both of the above two paragraphs.  Thanks.
Show 25 quoted lines
> [...]
>> --- a/contrib/completion/git-completion.bash
>> +++ b/contrib/completion/git-completion.bash
> [...]
>> @@ -524,18 +520,8 @@ __gitcomp ()
>>  #    appended.
>>  __gitcomp_nl ()
>>  {
>> -	local s=$'\n' IFS=' '$'\t'$'\n'
>> -	local cur_="$cur" suffix=" "
>> -
>> -	if [ $# -gt 2 ]; then
>> -		cur_="$3"
>> -		if [ $# -gt 3 ]; then
>> -			suffix="$4"
>> -		fi
>> -	fi
>> -
>> -	IFS=$s
>> -	COMPREPLY=($(compgen -P "${2-}" -S "$suffix" -W "$1" -- "$cur_"))
>> +	local IFS=$'\n'
>> +	COMPREPLY=($(compgen -P "${2-}" -S "${4:- }" -W "$1" -- "${3:-$cur}"))
>
> This loses the nice name $suffix for the -S argument.  Not a problem,
> just noticing.
The patch looks good, including the localness that is kept for IFS.
Previous: Jonathan NiederNext: Junio C Hamano
Message 6 of 17 in “completion: trivial cleanups”
  1. 0/4 completion: trivial cleanupsFelipe Contreras, Jan 30, 2012
  2. 2/4 completion: remove unused codeFelipe Contreras, Jan 30, 2012
  3. Jonathan NiederJan 30, 2012
  4. Junio C HamanoJan 30, 2012
  5. Jonathan NiederJan 30, 2012
  6. Junio C HamanoJan 30, 2012
  7. Junio C HamanoJan 30, 2012
  8. SZEDER GáborJan 31, 2012
  9. Jonathan NiederJan 31, 2012
  10. Jonathan NiederJan 30, 2012
  11. Felipe ContrerasJan 30, 2012
  12. Jonathan NiederJan 30, 2012
  13. Felipe ContrerasJan 30, 2012
  14. Jonathan NiederJan 30, 2012
  15. Junio C HamanoJan 30, 2012
  16. Felipe ContrerasJan 30, 2012
  17. Jonathan NiederJan 30, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.