completion: fill COMPREPLY directly when completing fetch refspecs

The __git_complete_fetch_refspecs() has to iterate over __git_refs()'s output anyway to turn the listed matching refs into refspecs, and it knows about the prefix and suffix that has to be added to each refspec. Modify this function to add the prefix and suffix to each refspec while iterating and feed the result, since it doesn't need further processing, to the new __gitcomp_direct() helper added in the previous commit, because it should be faster when there are a lot of refspecs to list. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Mar 23, 2017 at 16:29 UTC 745d655dc9fd2a9a02497240b4e254059f9d54f1
1 file changed +3 -3
contrib/completion/git-completion.bash
+3 -3
@@ -536,11 +536,11 @@ __git_complete_fetch_refspecs ()
536 {
537 local i remote="$1" pfx="${2-}" cur_="${3-$cur}" sfx="${4- }"
538
539 - __gitcomp_nl "$(
539 + __gitcomp_direct "$(
540 for i in $(__git_refs "$remote" "" "" "$cur_") ; do
541 - echo "$i:$i"
541 + echo "$pfx$i:$i$sfx"
542 done
543 - )" "$pfx" "$cur_" "$sfx"
543 + )"
544 }
545
546 # __git_refs_remotes requires 1 argument (to pass to ls-remote)