summaryrefslogtreecommitdiff
path: root/plugins/mercurial
diff options
context:
space:
mode:
authoranatolyrr <anatoly.rr@gmail.com>2019-06-16 16:50:11 +0300
committerMarc Cornellà <hello@mcornella.com>2021-12-13 10:50:17 +0100
commite52584c90195d0cc0979efec88b94271a31fe494 (patch)
tree746687c4359ec4910acafb7a09ebdbfd671551f7 /plugins/mercurial
parentdcf12ba8f3b31eead602c530a9fbfd5579c64630 (diff)
downloadzsh-e52584c90195d0cc0979efec88b94271a31fe494.tar.gz
zsh-e52584c90195d0cc0979efec88b94271a31fe494.tar.bz2
zsh-e52584c90195d0cc0979efec88b94271a31fe494.zip
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
Diffstat (limited to 'plugins/mercurial')
-rw-r--r--plugins/mercurial/mercurial.plugin.zsh27
1 files changed, 22 insertions, 5 deletions
diff --git a/plugins/mercurial/mercurial.plugin.zsh b/plugins/mercurial/mercurial.plugin.zsh
index 68a3d9a5c..f110507fd 100644
--- a/plugins/mercurial/mercurial.plugin.zsh
+++ b/plugins/mercurial/mercurial.plugin.zsh
@@ -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
+
+ 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
- unset _DISPLAY
+
+ 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 {