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/ | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/contrib/completion/ b/contrib/completion/
index 4e5c8efa..10ec6902 100644
--- a/contrib/completion/
+++ b/contrib/completion/
@@ -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#???????}}..."

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to