From: SZEDER Gábor Date: Tue, 18 Jun 2013 02:17:02 GMT Subject: [PATCH v2 09/13] bash prompt: use bash builtins to get detached HEAD abbrev. object name Message-ID: <1371521826-3225-10-git-send-email-szeder@ira.uka.de> In-Reply-To: <1371521826-3225-1-git-send-email-szeder@ira.uka.de> From: SZEDER Gábor 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 the previous patch at this point the contents of HEAD has already been read into a 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 --- contrib/completion/git-prompt.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index 4e5c8efa..10ec6902 100644 --- a/contrib/completion/git-prompt.sh +++ b/contrib/completion/git-prompt.sh @@ -378,9 +378,8 @@ __git_ps1 () (* | default) git describe --tags --exact-match HEAD ;; esac 2>/dev/null)" || - - b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." || - b="unknown" + # detached head abbreviated object name + b="${head%${head#???????}}..." b="($b)" fi fi -- 1.8.3.1.487.g8f4672d