bash prompt: use bash builtins to check stash state
authorSZEDER Gábor <szeder@ira.uka.de>
Fri, 1 Apr 2011 15:47:37 +0000 (17:47 +0200)
committerSZEDER Gábor <szeder@ira.uka.de>
Mon, 24 Jun 2013 16:03:37 +0000 (18:03 +0200)
When the environment variable $GIT_PS1_SHOWSTASHSTATE is set
__git_ps1() checks the presence of stashes by running 'git rev-parse
--verify refs/stash'. This command not only checks that the
'refs/stash' ref exists but also, well, verifies that it's a valid
ref.

However, we don't need to be that thorough for the bash prompt. We
can omit that verification and only check whether 'refs/stash' exists
or not. Since 'git pack-refs' never packs 'refs/stash', it's a matter
of checking the existence of a ref file. Perform this check using
only bash builtins to spare the overhead of fork()+exec()ing a git
process.

Also run 'git pack-refs --all' in the corresponding test to document
that the prompt script depends on 'git pack-refs' not packing
'refs/stash' and to catch possible breakages should this behavior ever
change.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
contrib/completion/git-prompt.sh
t/t9903-bash-prompt.sh
index 6e8f486e6638d951d744a29d31a239a25a087302..afa867030de12916358d24e63c4335b4f43c8a91 100644 (file)
@@ -435,8 +435,9 @@ __git_ps1 ()
                                i="#"
                        fi
                fi
-               if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
-                       git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
+               if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ] &&
+                  [ -r "$g/refs/stash" ]; then
+                       s="$"
                fi
 
                if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] &&
index b9895c797c97e9547a8a5fef639292765f45bc99..c05458cbe671b4881af3596d9b06a120674519d7 100755 (executable)
@@ -328,6 +328,7 @@ test_expect_success 'prompt - stash status indicator - stash' '
        echo 2 >file &&
        git stash &&
        test_when_finished "git stash drop" &&
+       git pack-refs --all &&
        (
                GIT_PS1_SHOWSTASHSTATE=y &&
                __git_ps1 >"$actual"