bash: use for-each-ref format 'refname:short'
Using this format simplifies the code for completing refs and (in some cases) improves performance significantly. For repositories like the current git.git (with more than 200 refs) there is no real performance difference, but for a repository with 2000 refs the total time needed to complete the refs is reduced by ~25% (from around 400ms to around 305ms). Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> Acked-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
SZEDER Gábor committed
Sep 20, 2008 at 00:15 UTC
05e8b3d6f43bd28aef85ec6e7658536510d6f959
1 file changed
+6
-20
contrib/completion/git-completion.bash
+6
-20
@@ -154,11 +154,8 @@ __git_heads ()
154
{
155
local cmd i is_hash=y dir="$(__gitdir "$1")"
156
if [ -d "$dir" ]; then
157
- for i in $(git --git-dir="$dir" \
158
- for-each-ref --format='%(refname)' \
159
- refs/heads ); do
160
- echo "${i#refs/heads/}"
161
- done
157
+ git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
158
+ refs/heads
159
return
160
fi
161
for i in $(git ls-remote "$1" 2>/dev/null); do
@@ -175,11 +172,8 @@ __git_tags ()
172
{
173
local cmd i is_hash=y dir="$(__gitdir "$1")"
174
if [ -d "$dir" ]; then
178
- for i in $(git --git-dir="$dir" \
179
- for-each-ref --format='%(refname)' \
180
- refs/tags ); do
181
- echo "${i#refs/tags/}"
182
- done
175
+ git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
176
+ refs/tags
177
return
178
fi
179
for i in $(git ls-remote "$1" 2>/dev/null); do
@@ -197,16 +191,8 @@ __git_refs ()
191
local cmd i is_hash=y dir="$(__gitdir "$1")"
192
if [ -d "$dir" ]; then
193
if [ -e "$dir/HEAD" ]; then echo HEAD; fi
200
- for i in $(git --git-dir="$dir" \
201
- for-each-ref --format='%(refname)' \
202
- refs/tags refs/heads refs/remotes); do
203
- case "$i" in
204
- refs/tags/*) echo "${i#refs/tags/}" ;;
205
- refs/heads/*) echo "${i#refs/heads/}" ;;
206
- refs/remotes/*) echo "${i#refs/remotes/}" ;;
207
- *) echo "$i" ;;
208
- esac
209
- done
194
+ git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
195
+ refs/tags refs/heads refs/remotes
196
return
197
fi
198
for i in $(git ls-remote "$dir" 2>/dev/null); do