[PATCH 15/19] bash prompt: use bash builtins to get detached HEAD abbrev. object name
- From
SZEDER Gábor <szeder@ira.uka.de>
- Date
- May 9, 2012, 00:44 UTC
- Message-ID
- <1336524290-30023-16-git-send-email-szeder@ira.uka.de>
- In-Reply-To
- <1336524290-30023-1-git-send-email-szeder@ira.uka.de>
When describing a detached HEAD according to the $GIT_PS1_DESCRIBE environment variable fails, __git_ps1() runs the '$(cut -c1-7 .git/HEAD)' command substitution to put the 7 hexdigits abbreviated commit object name in the prompt. This imposes the overhead of fork()ing a subshell and fork(+exec()ing 'cut'.
Thanks to an earlier commit in this series the contents of HEAD is already read into a local variable, so we can get the 7 hexdigits using only parameter expansions, sparing the fork()+exec() overhead.
Since zsh doesn't implement substring expansion we can't just use ${head:0:7}, hence the "remove everything except the first 7 chars" parameter expansion combination.
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> --- contrib/completion/git-completion.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 671032bf..2346962d 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -310,8 +310,8 @@ __git_ps1 () git describe --tags --exact-match HEAD ;; esac 2>/dev/null)" || - b="$(cut -c1-7 "$__git_dir/HEAD" 2>/dev/null)..." || - return + # detached head abbreviated object name + b="${head%${head#???????}}..." b="($b)" fi fi
-- 1.7.10.1.541.gb1be298