From: SZEDER Gábor Date: Wed, 09 May 2012 00:44:43 GMT Subject: [PATCH 12/19] bash prompt: use bash builtins to check whether inside git dir Message-ID: <1336524290-30023-13-git-send-email-szeder@ira.uka.de> In-Reply-To: <1336524290-30023-1-git-send-email-szeder@ira.uka.de> __git_ps1() runs the '$(git rev-parse --is-inside-git-dir)' command substitution to check whether we are inside a .git directory and the bash prompt needs to be adjusted accordingly (i.e. display 'BARE!' or 'GIT_DIR!'). This imposes the overhead of fork()ing a subshell and fork()+exec()ing a git process. Perform this check by comparing the path to the repository and the current directory using only bash builtins, thereby sparing all that fork()+exec() overhead. Signed-off-by: SZEDER Gábor --- contrib/completion/git-completion.bash | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index ed372c41..72f7d0ed 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -323,7 +323,11 @@ __git_ps1 () local c="" local p="" - if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then + local pwd_p + __git_pwd_p pwd_p + # inside .git dir? + if [ "$__git_dir" = "." -o \ + "${pwd_p#$__git_dir}" != "$pwd_p" ]; then if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then c="BARE:" else -- 1.7.10.1.541.gb1be298