Browse Source

completion: improve ls-remote output filtering in __git_refs()

The remote-handling part of __git_refs() has a nice for loop and state
machine case statement to iterate over all words from the output of
'git ls-remote' to identify object names and ref names.  Since each
line in the output of 'git ls-remote' consists of an object name and a
ref name, we can do more effective filtering by using a while-read
loop and letting bash's word splitting take care of object names.
This way the code is easier to understand and the loop will need only
half the number of iterations than before.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
SZEDER Gábor 14 years ago committed by Junio C Hamano
parent
commit
d8c0453e1a
  1. 14
      contrib/completion/git-completion.bash

14
contrib/completion/git-completion.bash

@ -580,7 +580,7 @@ __git_tags ()
# by checkout for tracking branches # by checkout for tracking branches
__git_refs () __git_refs ()
{ {
local i is_hash=y dir="$(__gitdir "${1-}")" track="${2-}" local i hash dir="$(__gitdir "${1-}")" track="${2-}"
local format refs local format refs
if [ -d "$dir" ]; then if [ -d "$dir" ]; then
case "$cur" in case "$cur" in
@ -616,12 +616,12 @@ __git_refs ()
fi fi
return return
fi fi
for i in $(git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null); do git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \
case "$is_hash,$i" in while read hash i; do
y,*) is_hash=n ;; case "$i" in
n,*^{}) is_hash=y ;; *^{}) ;;
n,refs/*) is_hash=y; echo "${i#refs/*/}" ;; refs/*) echo "${i#refs/*/}" ;;
n,*) is_hash=y; echo "$i" ;; *) echo "$i" ;;
esac esac
done done
} }

Loading…
Cancel
Save