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>
SZEDER Gábor committed
Oct 8, 2011 at 16:54 UTC
d8c0453e1a81db03880a9f237675d82cdc290d2c
1 file changed
+7
-7
contrib/completion/git-completion.bash
+7
-7
@@ -580,7 +580,7 @@ __git_tags ()
580
# by checkout for tracking branches
581
__git_refs ()
582
{
583
- local i is_hash=y dir="$(__gitdir "${1-}")" track="${2-}"
583
+ local i hash dir="$(__gitdir "${1-}")" track="${2-}"
584
local format refs
585
if [ -d "$dir" ]; then
586
case "$cur" in
@@ -616,12 +616,12 @@ __git_refs ()
616
fi
617
return
618
fi
619
- for i in $(git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null); do
620
- case "$is_hash,$i" in
621
- y,*) is_hash=n ;;
622
- n,*^{}) is_hash=y ;;
623
- n,refs/*) is_hash=y; echo "${i#refs/*/}" ;;
624
- n,*) is_hash=y; echo "$i" ;;
619
+ git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \
620
+ while read hash i; do
621
+ case "$i" in
622
+ *^{}) ;;
623
+ refs/*) echo "${i#refs/*/}" ;;
624
+ *) echo "$i" ;;
625
esac
626
done
627
}