zsh-workers
 help / color / mirror / code / Atom feed
* PATCH simpler conditional vcs_info
@ 2015-07-24 22:00 Jakub Turski
  0 siblings, 0 replies; only message in thread
From: Jakub Turski @ 2015-07-24 22:00 UTC (permalink / raw)
  To: zsh-workers


[-- Attachment #1.1: Type: text/plain, Size: 426 bytes --]

Hello there,

I've recently found vcs_info being rather slow - and lo and behold, found a
nice recipe to make execution of git/hg optional in Misc/vcs_info-examples.
I've started using it, and I've rewritten it a bit to make it simpler (less
code is good, right? :). Included patch shows my changes (including
removing the obvious things, like autoloading vcs_info, etc).

I hope you'll find the included patch useful :)

KT.

[-- Attachment #1.2: Type: text/html, Size: 536 bytes --]

[-- Attachment #2: 0001-Update-vcs_info-misc-information.patch --]
[-- Type: application/octet-stream, Size: 3971 bytes --]

From f5c8d0c8ba7a83ebfceac0f40016c1350017021d Mon Sep 17 00:00:00 2001
From: Jakub Turski <yacoob@gmail.com>
Date: Fri, 24 Jul 2015 20:19:01 +0100
Subject: [PATCH] Update vcs_info misc information.

---
 Misc/vcs_info-examples | 88 ++++++++++++++++----------------------------------
 1 file changed, 27 insertions(+), 61 deletions(-)

diff --git a/Misc/vcs_info-examples b/Misc/vcs_info-examples
index 766eb82..bfcb805 100644
--- a/Misc/vcs_info-examples
+++ b/Misc/vcs_info-examples
@@ -253,28 +253,6 @@ function +vi-hg-branchhead() {
 # staged and unstaged changes in the vcs_info prompt and prevents running
 # it too often for speed reasons.
 
-
-# Allow substitutions and expansions in the prompt, necessary for
-# using a single-quoted $vcs_info_msg_0_ in PS1, RPOMPT (as used here) and
-# similar. Other ways of using the information are described above.
-setopt promptsubst
-# Load vcs_info to display information about version control repositories.
-autoload -Uz vcs_info
-
-# Check the repository for changes so they can be used in %u/%c (see
-# below). This comes with a speed penalty for bigger repositories.
-zstyle ':vcs_info:*' check-for-changes true
-zstyle ':vcs_info:*' get-revision true
-
-# Alternatively, the following would set only %c, but is faster:
-#zstyle ':vcs_info:*' check-for-changes false
-#zstyle ':vcs_info:*' check-for-staged-changes true
-
-
-# Default to running vcs_info. If possible we prevent running it later for
-# speed reasons. If set to a non empty value vcs_info is run.
-FORCE_RUN_VCS_INFO=1
-
 # Only run vcs_info when necessary to speed up the prompt and make using
 # check-for-changes bearable in bigger repositories. This setup was
 # inspired by Bart Trojanowski
@@ -288,48 +266,36 @@ FORCE_RUN_VCS_INFO=1
 # the VCS commands update the case check below.
 zstyle ':vcs_info:*+pre-get-data:*' hooks pre-get-data
 +vi-pre-get-data() {
-    # Only Git and Mercurial support and need caching. Abort if any other
-    # VCS is used.
-    [[ "$vcs" != git && "$vcs" != hg ]] && return
-
-    # If the shell just started up or we changed directories (or for other
-    # custom reasons) we must run vcs_info.
-    if [[ -n $FORCE_RUN_VCS_INFO ]]; then
-        FORCE_RUN_VCS_INFO=
-        return
-    fi
-
-    # If we got to this point, running vcs_info was not forced, so now we
-    # default to not running it and selectively choose when we want to run
-    # it (ret=0 means run it, ret=1 means don't).
-    ret=1
-    # If a git/hg command was run then run vcs_info as the status might
-    # need to be updated.
-    case "$(fc -ln $(($HISTCMD-1)))" in
-        git*)
-            ret=0
-            ;;
-        hg*)
-            ret=0
-            ;;
-    esac
-}
-
-# Call vcs_info as precmd before every prompt.
-prompt_precmd() {
-    vcs_info
+  # Don't handle VCSs other than git or hg.
+  [[ "$vcs" != git && "$vcs" != hg ]] && return
+
+  # Allow vcs_info to run if sentinel variable is set, prohibit it from running
+  # otherwise.
+  if [[ ${__FORCE_RUN_VCS_INFO-1} == 1 ]]; then
+      __FORCE_RUN_VCS_INFO=0
+      ret=0
+  else
+      ret=1
+  fi
 }
-add-zsh-hook precmd prompt_precmd
 
-# Must run vcs_info when changing directories.
-prompt_chpwd() {
-    FORCE_RUN_VCS_INFO=1
+# The name of this function is silly; vcs_info forces '+vi-' prefix for hook
+# function names.
+preexec_vcs_info() {
+  # Force vcs_info run if we're about to execute a git/hg command.
+  case "$1" in
+    git*|hg*)
+      __FORCE_RUN_VCS_INFO=1
+    ;;
+  esac
+autoload -Uz add-zsh-hook
+add-zsh-hook preexec preexec_vcs_info
+
+chpwd_vcs_info() {
+  # Force vcs_info run after cwd change.
+  __FORCE_RUN_VCS_INFO=1
 }
-add-zsh-hook chpwd prompt_chpwd
-
-# Display the VCS information in the right prompt. The {..:- } is a
-# workaround for Zsh below 4.3.9.
-RPROMPT='${vcs_info_msg_0_:- }'
+add-zsh-hook chpwd chpwd_vcs_info
 
 
 ### Quilt support ############################################################
-- 
2.4.6


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-07-24 22:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-24 22:00 PATCH simpler conditional vcs_info Jakub Turski

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).