From: SZEDER Gábor Date: Tue, 18 Jun 2013 02:17:04 GMT Subject: [PATCH v2 11/13] bash prompt: use bash builtins to check stash state Message-ID: <1371521826-3225-12-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 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. Signed-off-by: SZEDER Gábor --- contrib/completion/git-prompt.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh index b73cebf7..208e2ec7 100644 --- a/contrib/completion/git-prompt.sh +++ b/contrib/completion/git-prompt.sh @@ -421,8 +421,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-}" ] && -- 1.8.3.1.487.g8f4672d