git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bash: use for-each-ref format 'refname:short'
@ 2008-09-19 22:15 SZEDER Gábor
  2008-09-19 23:51 ` Shawn O. Pearce
  0 siblings, 1 reply; 2+ messages in thread
From: SZEDER Gábor @ 2008-09-19 22:15 UTC (permalink / raw)
  To: Junio C Hamano, Shawn O. Pearce; +Cc: git, SZEDER Gábor

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>
---

 OK, so after the refname:short patch hit master, here is the updated
 patch to use it in bash completion.  The patch itself is the same as
 the original one, except, of course, the for-each-ref format name.  I
 have also adjusted the performance numbers in the commit message.

 contrib/completion/git-completion.bash |   26 ++++++--------------------
 1 files changed, 6 insertions(+), 20 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index d3fb6ae..fccb499 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -154,11 +154,8 @@ __git_heads ()
 {
 	local cmd i is_hash=y dir="$(__gitdir "$1")"
 	if [ -d "$dir" ]; then
-		for i in $(git --git-dir="$dir" \
-			for-each-ref --format='%(refname)' \
-			refs/heads ); do
-			echo "${i#refs/heads/}"
-		done
+		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
+			refs/heads
 		return
 	fi
 	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")"
 	if [ -d "$dir" ]; then
-		for i in $(git --git-dir="$dir" \
-			for-each-ref --format='%(refname)' \
-			refs/tags ); do
-			echo "${i#refs/tags/}"
-		done
+		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
+			refs/tags
 		return
 	fi
 	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")"
 	if [ -d "$dir" ]; then
 		if [ -e "$dir/HEAD" ]; then echo HEAD; fi
-		for i in $(git --git-dir="$dir" \
-			for-each-ref --format='%(refname)' \
-			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
+		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
+			refs/tags refs/heads refs/remotes
 		return
 	fi
 	for i in $(git ls-remote "$dir" 2>/dev/null); do
-- 
1.6.0.2.294.g50836f

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] bash: use for-each-ref format 'refname:short'
  2008-09-19 22:15 [PATCH] bash: use for-each-ref format 'refname:short' SZEDER Gábor
@ 2008-09-19 23:51 ` Shawn O. Pearce
  0 siblings, 0 replies; 2+ messages in thread
From: Shawn O. Pearce @ 2008-09-19 23:51 UTC (permalink / raw)
  To: SZEDER GGGbor; +Cc: Junio C Hamano, git

SZEDER GGGbor <szeder@ira.uka.de> wrote:
> 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>

Nice improvement.

Acked-by: Shawn O. Pearce <spearce@spearce.org>


>  OK, so after the refname:short patch hit master, here is the updated
>  patch to use it in bash completion.  The patch itself is the same as
>  the original one, except, of course, the for-each-ref format name.  I
>  have also adjusted the performance numbers in the commit message.
> 
>  contrib/completion/git-completion.bash |   26 ++++++--------------------
>  1 files changed, 6 insertions(+), 20 deletions(-)
> 
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index d3fb6ae..fccb499 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -154,11 +154,8 @@ __git_heads ()
>  {
>  	local cmd i is_hash=y dir="$(__gitdir "$1")"
>  	if [ -d "$dir" ]; then
> -		for i in $(git --git-dir="$dir" \
> -			for-each-ref --format='%(refname)' \
> -			refs/heads ); do
> -			echo "${i#refs/heads/}"
> -		done
> +		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
> +			refs/heads
>  		return
>  	fi
>  	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")"
>  	if [ -d "$dir" ]; then
> -		for i in $(git --git-dir="$dir" \
> -			for-each-ref --format='%(refname)' \
> -			refs/tags ); do
> -			echo "${i#refs/tags/}"
> -		done
> +		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
> +			refs/tags
>  		return
>  	fi
>  	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")"
>  	if [ -d "$dir" ]; then
>  		if [ -e "$dir/HEAD" ]; then echo HEAD; fi
> -		for i in $(git --git-dir="$dir" \
> -			for-each-ref --format='%(refname)' \
> -			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
> +		git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
> +			refs/tags refs/heads refs/remotes
>  		return
>  	fi
>  	for i in $(git ls-remote "$dir" 2>/dev/null); do

-- 
Shawn.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-09-19 23:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-19 22:15 [PATCH] bash: use for-each-ref format 'refname:short' SZEDER Gábor
2008-09-19 23:51 ` Shawn O. Pearce

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).