From e52584c90195d0cc0979efec88b94271a31fe494 Mon Sep 17 00:00:00 2001 From: anatolyrr Date: Sun, 16 Jun 2019 16:50:11 +0300 Subject: [PATCH] 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 --- plugins/mercurial/mercurial.plugin.zsh | 27 +++++++++++++++++++++----- 1 file 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 - 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 {