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>
This commit is contained in:
SZEDER Gábor 2008-09-20 00:15:25 +02:00 committed by Junio C Hamano
parent 3791f77c28
commit 05e8b3d6f4

View File

@ -154,11 +154,8 @@ __git_heads ()
{ {
local cmd i is_hash=y dir="$(__gitdir "$1")" local cmd i is_hash=y dir="$(__gitdir "$1")"
if [ -d "$dir" ]; then if [ -d "$dir" ]; then
for i in $(git --git-dir="$dir" \ git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
for-each-ref --format='%(refname)' \ refs/heads
refs/heads ); do
echo "${i#refs/heads/}"
done
return return
fi fi
for i in $(git ls-remote "$1" 2>/dev/null); do for i in $(git ls-remote "$1" 2>/dev/null); do
@ -175,11 +172,8 @@ __git_tags ()
{ {
local cmd i is_hash=y dir="$(__gitdir "$1")" local cmd i is_hash=y dir="$(__gitdir "$1")"
if [ -d "$dir" ]; then if [ -d "$dir" ]; then
for i in $(git --git-dir="$dir" \ git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
for-each-ref --format='%(refname)' \ refs/tags
refs/tags ); do
echo "${i#refs/tags/}"
done
return return
fi fi
for i in $(git ls-remote "$1" 2>/dev/null); do for i in $(git ls-remote "$1" 2>/dev/null); do
@ -197,16 +191,8 @@ __git_refs ()
local cmd i is_hash=y dir="$(__gitdir "$1")" local cmd i is_hash=y dir="$(__gitdir "$1")"
if [ -d "$dir" ]; then if [ -d "$dir" ]; then
if [ -e "$dir/HEAD" ]; then echo HEAD; fi if [ -e "$dir/HEAD" ]; then echo HEAD; fi
for i in $(git --git-dir="$dir" \ git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
for-each-ref --format='%(refname)' \ refs/tags refs/heads refs/remotes
refs/tags refs/heads refs/remotes); do
case "$i" in
refs/tags/*) echo "${i#refs/tags/}" ;;
refs/heads/*) echo "${i#refs/heads/}" ;;
refs/remotes/*) echo "${i#refs/remotes/}" ;;
*) echo "$i" ;;
esac
done
return return
fi fi
for i in $(git ls-remote "$dir" 2>/dev/null); do for i in $(git ls-remote "$dir" 2>/dev/null); do