Skip to content

Commit a656f09

Browse files
committed
lib/theme: improve performance of scm()
- Don't invoke the source control utility when all we want to know is if we're somewhere inside the repository; use `_bash-it-find-in-ancestor()`.
1 parent a0ec647 commit a656f09

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

themes/base.theme.bash

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,13 @@ _bash_it_library_finalize_hook+=('_bash_it_appearance_scm_init')
118118
function scm() {
119119
if [[ "${SCM_CHECK:-true}" == "false" ]]; then
120120
SCM="${SCM_NONE-NONE}"
121-
elif [[ -f .git/HEAD ]] && [[ -x "${GIT_EXE-}" ]]; then
121+
elif [[ -x "${GIT_EXE-}" ]] && _bash-it-find-in-ancestor '.git' > /dev/null; then
122122
SCM="${SCM_GIT?}"
123-
elif [[ -d .hg ]] && [[ -x "${HG_EXE-}" ]]; then
123+
elif [[ -x "${HG_EXE-}" ]] && _bash-it-find-in-ancestor '.hg' > /dev/null; then
124124
SCM="${SCM_HG?}"
125-
elif [[ -d .svn ]] && [[ -x "${SVN_EXE-}" ]]; then
125+
elif [[ -x "${SVN_EXE-}" ]] && _bash-it-find-in-ancestor '.svn' > /dev/null; then
126126
SCM="${SCM_SVN?}"
127-
elif [[ -x "${GIT_EXE-}" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then
128-
SCM="${SCM_GIT?}"
129-
elif [[ -x "${HG_EXE-}" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then
130-
SCM="${SCM_HG?}"
131-
elif [[ -x "${SVN_EXE-}" ]] && [[ -n "$(svn info --show-item wc-root 2> /dev/null)" ]]; then
132-
SCM="${SCM_SVN?}"
133-
elif [[ -x "${P4_EXE-}" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then
127+
elif [[ -x "${P4_EXE-}" && -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then
134128
SCM="${SCM_P4?}"
135129
else
136130
SCM="${SCM_NONE-NONE}"
@@ -376,7 +370,7 @@ function hg_prompt_vars() {
376370
SCM_PREFIX="${HG_THEME_PROMPT_PREFIX:-${SCM_THEME_PROMPT_PREFIX-}}"
377371
SCM_SUFFIX="${HG_THEME_PROMPT_SUFFIX:-${SCM_THEME_PROMPT_SUFFIX-}}"
378372

379-
HG_ROOT=$(_bash-it-find-in-ancestor ".hg")
373+
HG_ROOT="$(_bash-it-find-in-ancestor ".hg")/.hg"
380374

381375
if [[ -f "$HG_ROOT/branch" ]]; then
382376
# Mercurial holds it's current branch in .hg/branch file

0 commit comments

Comments
 (0)