Skip to content

Commit d8c0453

Browse files
szedergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent abf0598 commit d8c0453

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

contrib/completion/git-completion.bash

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ __git_tags ()
580580
# by checkout for tracking branches
581581
__git_refs ()
582582
{
583-
local i is_hash=y dir="$(__gitdir "${1-}")" track="${2-}"
583+
local i hash dir="$(__gitdir "${1-}")" track="${2-}"
584584
local format refs
585585
if [ -d "$dir" ]; then
586586
case "$cur" in
@@ -616,12 +616,12 @@ __git_refs ()
616616
fi
617617
return
618618
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" ;;
625625
esac
626626
done
627627
}

0 commit comments

Comments
 (0)