1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-18 03:40:08 +00:00

perf(mercurial): improve performance of hg_prompt_info (#7929)

Replaced two different calls of hg with one `hg --id --branch` for retrieving
information whether we're in a repo (will be empty if not), whether the repo is
dirty (revision id will contain "+" if there are uncommitted changed), and the
branch name.

Closes #6197
Closes #7929
This commit is contained in:
anatolyrr 2019-06-16 16:50:11 +03:00 committed by Marc Cornellà
parent dcf12ba8f3
commit e52584c901
No known key found for this signature in database
GPG key ID: 0314585E776A9C1B

View file

@ -35,12 +35,29 @@ function hg_get_branch_name() {
}
function hg_prompt_info {
_DISPLAY=`hg branch 2>/dev/null`
if [ $? -eq 0 ]; then
echo "$ZSH_PROMPT_BASE_COLOR$ZSH_THEME_HG_PROMPT_PREFIX\
$ZSH_THEME_REPO_NAME_COLOR$_DISPLAY$ZSH_PROMPT_BASE_COLOR$ZSH_PROMPT_BASE_COLOR$(hg_dirty)$ZSH_THEME_HG_PROMPT_SUFFIX$ZSH_PROMPT_BASE_COLOR"
local info rev branch dirty
if ! info=$(hg id --id --branch 2>/dev/null); then
return
fi
unset _DISPLAY
rev="${info[(w)1]}"
branch="${${info[(w)2]}:gs/%/%%}"
if [[ "$rev" = *+ ]]; then
dirty="$ZSH_THEME_HG_PROMPT_DIRTY"
else
dirty="$ZSH_THEME_HG_PROMPT_CLEAN"
fi
echo "${ZSH_PROMPT_BASE_COLOR}\
${ZSH_THEME_HG_PROMPT_PREFIX}\
${ZSH_THEME_REPO_NAME_COLOR}\
${branch}\
${ZSH_PROMPT_BASE_COLOR}\
${dirty}\
${ZSH_THEME_HG_PROMPT_SUFFIX}\
${ZSH_PROMPT_BASE_COLOR}"
}
function hg_dirty_choose {