e52584c90195d0cc0979efec88b94271a31fe494

Author
anatolyrr <anatoly.rr@gmail.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

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

Diff

 1diff --git a/plugins/mercurial/mercurial.plugin.zsh b/plugins/mercurial/mercurial.plugin.zsh
 2index 68a3d9a5c1721b48d7fdce139288fa3f82d701aa..f110507fdec651f028ec3b4b25ba7ee5f2704413 100644
 3--- a/plugins/mercurial/mercurial.plugin.zsh
 4+++ b/plugins/mercurial/mercurial.plugin.zsh
 5@@ -35,12 +35,29 @@ function hg_get_branch_name() {
 6 }
 7 
 8 function hg_prompt_info {
 9-  _DISPLAY=`hg branch 2>/dev/null`
10-  if [ $? -eq 0 ]; then
11-    echo "$ZSH_PROMPT_BASE_COLOR$ZSH_THEME_HG_PROMPT_PREFIX\
12-$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"
13+  local info rev branch dirty
14+
15+  if ! info=$(hg id --id --branch 2>/dev/null); then
16+    return
17+  fi
18+
19+  rev="${info[(w)1]}"
20+  branch="${${info[(w)2]}:gs/%/%%}"
21+
22+  if [[ "$rev" = *+ ]]; then
23+    dirty="$ZSH_THEME_HG_PROMPT_DIRTY"
24+  else
25+    dirty="$ZSH_THEME_HG_PROMPT_CLEAN"
26   fi
27-  unset _DISPLAY
28+
29+  echo "${ZSH_PROMPT_BASE_COLOR}\
30+${ZSH_THEME_HG_PROMPT_PREFIX}\
31+${ZSH_THEME_REPO_NAME_COLOR}\
32+${branch}\
33+${ZSH_PROMPT_BASE_COLOR}\
34+${dirty}\
35+${ZSH_THEME_HG_PROMPT_SUFFIX}\
36+${ZSH_PROMPT_BASE_COLOR}"
37 }
38 
39 function hg_dirty_choose {