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

Re: [PATCH v2 1/4] completion: simplify __git_remotes

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 30, 2012, 18:27 UTC
Message-ID
<7v8vkpcagd.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20120130173446.GF10618@burratino>
Jonathan Nieder <jrnieder@gmail.com> writes:
Show 13 quoted lines
> Felipe Contreras wrote:
>
>> From: Felipe Contreras <felipe.contreras@gmail.com>
>>
>> There's no need for all that complicated code that requires nullglob,
>> and the complexities related to such option.
>>
>> As an advantage, this would allow us to get rid of __git_shopt, which is
>> used only in this fuction to enable 'nullglob' in zsh.
>
> That is all a longwinded way to say "zsh doesn't support the same
> interface as bash for setting the nullglob option, so let's avoid
> it and use 'ls' which is simpler", right?
;-)
Show 15 quoted lines
>> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
>> index 1496c6d..086e38d 100755
>> --- a/contrib/completion/git-completion.bash
>> +++ b/contrib/completion/git-completion.bash
>> @@ -644,12 +644,7 @@ __git_refs_remotes ()
>>  __git_remotes ()
>>  {
>>  	local i ngoff IFS=$'\n' d="$(__gitdir)"
>> -	__git_shopt -q nullglob || ngoff=1
>> -	__git_shopt -s nullglob
>> -	for i in "$d/remotes"/*; do
>> -		echo ${i#$d/remotes/}
>> -	done
>> -	[ "$ngoff" ] && __git_shopt -u nullglob
>> +	test -d "$d/remotes" && ls -1 "$d/remotes"
Yeah, very nice reduction of unnecessary code.

The original loop might have been justifiable if it were doing something more meaningful inside (e.g. making sure the file really describes a remote), but as far as I can tell, it merely is a poor-man's emulation of "ls -1".

You updated it to make the code say what it wanted to say in the way it should have said from day one ;-).

Previous: Jonathan NiederNext: Jonathan Nieder
Message 4 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.