From: "SZEDER Gábor" <szeder@ira.uka.de>
To: git@vger.kernel.org
Cc: "Shawn O. Pearce" <spearce@spearce.org>,
"Jonathan Nieder" <jrnieder@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>,
"SZEDER Gábor" <szeder@ira.uka.de>
Subject: [PATCH 4/9] completion: improve ls-remote output filtering in __git_refs()
Date: Sat, 8 Oct 2011 16:54:38 +0200 [thread overview]
Message-ID: <1318085683-29830-5-git-send-email-szeder@ira.uka.de> (raw)
In-Reply-To: <1318085683-29830-1-git-send-email-szeder@ira.uka.de>
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>
---
contrib/completion/git-completion.bash | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 6b5dc5cd..c6ab742d 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -579,7 +579,7 @@ __git_tags ()
# by checkout for tracking branches
__git_refs ()
{
- local i is_hash=y dir="$(__gitdir "${1-}")" track="${2-}"
+ local i hash dir="$(__gitdir "${1-}")" track="${2-}"
local format refs
if [ -d "$dir" ]; then
case "$cur" in
@@ -615,12 +615,12 @@ __git_refs ()
fi
return
fi
- for i in $(git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null); do
- case "$is_hash,$i" in
- y,*) is_hash=n ;;
- n,*^{}) is_hash=y ;;
- n,refs/*) is_hash=y; echo "${i#refs/*/}" ;;
- n,*) is_hash=y; echo "$i" ;;
+ git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \
+ while read hash i; do
+ case "$i" in
+ *^{}) ;;
+ refs/*) echo "${i#refs/*/}" ;;
+ *) echo "$i" ;;
esac
done
}
--
1.7.7.187.ga41de
next prev parent reply other threads:[~2011-10-08 14:56 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-08 14:54 [PATCH 0/9] ref completion optimizations, fixes, and cleanups SZEDER Gábor
2011-10-08 14:54 ` [PATCH 1/9] completion: document __gitcomp() SZEDER Gábor
2011-10-08 14:54 ` [PATCH 2/9] completion: optimize refs completion SZEDER Gábor
2011-10-13 0:50 ` Junio C Hamano
2011-10-13 10:40 ` SZEDER Gábor
2011-10-13 17:28 ` Junio C Hamano
2011-10-14 12:16 ` SZEDER Gábor
2011-10-15 12:57 ` [PATCH 2/9 v2] " SZEDER Gábor
2011-10-16 3:29 ` Junio C Hamano
2011-10-08 14:54 ` [PATCH 3/9] completion: make refs completion consistent for local and remote repos SZEDER Gábor
2011-10-08 14:54 ` SZEDER Gábor [this message]
2011-10-08 14:54 ` [PATCH 5/9] completion: support full refs from remote repositories SZEDER Gábor
2011-10-08 14:54 ` [PATCH 6/9] completion: query only refs/heads/ in __git_refs_remotes() SZEDER Gábor
2011-10-08 14:54 ` [PATCH 7/9] completion: improve ls-remote output filtering " SZEDER Gábor
2011-10-08 14:54 ` [PATCH 8/9] completion: fast initial completion for config 'remote.*.fetch' value SZEDER Gábor
2011-10-08 14:54 ` [PATCH 9/9] completion: remove broken dead code from __git_heads() and __git_tags() SZEDER Gábor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1318085683-29830-5-git-send-email-szeder@ira.uka.de \
--to=szeder@ira.uka.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).