[PATCH 11/19] bash prompt: use bash builtins to find out current branch
- From
SZEDER Gábor <szeder@ira.uka.de>
- Date
- May 9, 2012, 00:44 UTC
- Message-ID
- <1336524290-30023-12-git-send-email-szeder@ira.uka.de>
- In-Reply-To
- <1336524290-30023-1-git-send-email-szeder@ira.uka.de>
__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@ira.uka.de> --- 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