[PATCH 11/19] bash prompt: use bash builtins to find out current branch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



__git_ps1() runs the '$(git symbolic-ref HEAD)' command substitution
to find out whether we are on a branch and to find out the name of
that branch.  This imposes the overhead of fork()ing a subshell and
fork()+exec()ing a git process.

Since HEAD is a single-line file and the symbolic ref format is quite
simple to recognize and parse, read and parse it using only bash
builtins, thereby sparing all that fork()+exec() overhead.

Signed-off-by: SZEDER Gábor <szeder@xxxxxxxxxx>
---
 contrib/completion/git-completion.bash | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index dd69e56e..ed372c41 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -293,8 +293,11 @@ __git_ps1 ()
 			r="|BISECTING"
 		fi
 
-		b="$(git symbolic-ref HEAD 2>/dev/null)" || {
-
+		local head=""
+		read head 2>/dev/null <"$__git_dir/HEAD" || return
+		# is it a symbolic ref?
+		b="${head#ref: }"
+		if [ "$head" = "$b" ]; then
 			b="$(
 			case "${GIT_PS1_DESCRIBE_STYLE-}" in
 			(contains)
@@ -310,7 +313,7 @@ __git_ps1 ()
 			b="$(cut -c1-7 "$__git_dir/HEAD" 2>/dev/null)..." ||
 			return
 			b="($b)"
-		}
+		fi
 	fi
 
 	local w=""
-- 
1.7.10.1.541.gb1be298

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]