Skip to content

Commit

Permalink
lib/theme: improve performance of scm()
Browse files Browse the repository at this point in the history
- 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()`.
  • Loading branch information
gaelicWizard committed Feb 18, 2022
1 parent 2a419cc commit afe9142
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions themes/base.theme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,13 @@ _bash_it_library_finalize_hook+=('_bash_it_appearance_scm_init')
function scm() {
if [[ "${SCM_CHECK:-true}" == "false" ]]; then
SCM="${SCM_NONE-NONE}"
elif [[ -f .git/HEAD ]] && [[ -x "${GIT_EXE-}" ]]; then
elif [[ -x "${GIT_EXE-}" ]] && _bash-it-find-in-ancestor '.git' > /dev/null; then
SCM="${SCM_GIT?}"
elif [[ -d .hg ]] && [[ -x "${HG_EXE-}" ]]; then
elif [[ -x "${HG_EXE-}" ]] && _bash-it-find-in-ancestor '.hg' > /dev/null; then
SCM="${SCM_HG?}"
elif [[ -d .svn ]] && [[ -x "${SVN_EXE-}" ]]; then
elif [[ -x "${SVN_EXE-}" ]] && _bash-it-find-in-ancestor '.svn' > /dev/null; then
SCM="${SCM_SVN?}"
elif [[ -x "${GIT_EXE-}" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then
SCM="${SCM_GIT?}"
elif [[ -x "${HG_EXE-}" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then
SCM="${SCM_HG?}"
elif [[ -x "${SVN_EXE-}" ]] && [[ -n "$(svn info --show-item wc-root 2> /dev/null)" ]]; then
SCM="${SCM_SVN?}"
elif [[ -x "${P4_EXE-}" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then
elif [[ -x "${P4_EXE-}" && -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then
SCM="${SCM_P4?}"
else
SCM="${SCM_NONE-NONE}"
Expand Down Expand Up @@ -376,7 +370,7 @@ function hg_prompt_vars() {
SCM_PREFIX="${HG_THEME_PROMPT_PREFIX:-${SCM_THEME_PROMPT_PREFIX-}}"
SCM_SUFFIX="${HG_THEME_PROMPT_SUFFIX:-${SCM_THEME_PROMPT_SUFFIX-}}"

HG_ROOT=$(_bash-it-find-in-ancestor ".hg")
HG_ROOT="$(_bash-it-find-in-ancestor ".hg")/.hg"

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

0 comments on commit afe9142

Please sign in to comment.