Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: User-definable binaries in vcs_info



Someone on IRC asked for this, because for him the default svn binary is
too old to handle his repositories.

This adds a style that looks up other binary-names if set.

This has been tested for git and svn, but should work for all other
subsystems, too, if I didn't screw up. :-)

Doc update included.

I created the patch from in a git-import of zsh's cvs repository,
because it adds a new file (VCS_INFO_get_cmd) and I couldn't get cvs to
include it in a patch. I hope that's okay (patch 2.5.9 seems to handle the
patch just fine).

---
 Doc/Zsh/contrib.yo                                |   20 ++++++++++++++++++++
 Functions/VCS_Info/Backends/VCS_INFO_detect_cdv   |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_detect_cvs   |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_detect_darcs |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_detect_git   |    4 ++--
 Functions/VCS_Info/Backends/VCS_INFO_detect_hg    |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_detect_mtn   |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_detect_p4    |    6 +++---
 Functions/VCS_Info/Backends/VCS_INFO_detect_svk   |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_detect_svn   |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_detect_tla   |    4 ++--
 Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr |    4 ++--
 Functions/VCS_Info/Backends/VCS_INFO_get_data_git |    6 +++---
 Functions/VCS_Info/Backends/VCS_INFO_get_data_mtn |    2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_p4  |    4 ++--
 Functions/VCS_Info/Backends/VCS_INFO_get_data_svn |    4 ++--
 Functions/VCS_Info/Backends/VCS_INFO_get_data_tla |    2 +-
 Functions/VCS_Info/VCS_INFO_check_com             |    9 ++++++++-
 Functions/VCS_Info/VCS_INFO_get_cmd               |    6 ++++++
 Functions/VCS_Info/vcs_info                       |    2 ++
 20 files changed, 61 insertions(+), 26 deletions(-)
 create mode 100644 Functions/VCS_Info/VCS_INFO_get_cmd

diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index 4c2c7ab..c393d28 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -506,6 +506,25 @@ A list of VCSs, you don't want var(vcs_info) to test for
 repositories (checked in the var(-init-) context, too). Only used if
 tt(enable) contains tt(ALL).
 )
+kindex(command)
+item(tt(command))(
+This style causes var(vcs_info) to use the supplied string as the command
+to use as the vcs's binary. Note, that setting this in ':vcs_info:*' is
+not a good idea.
+
+If the value of this style is empty (which is the default), the used binary
+name is the name of the backend in use (e.g. var(svn) is used in a var(svn)
+repository).
+
+The var(repo-root-name) part in the context is always the default tt(-all-)
+when this style is looked up.
+
+For example, this style can be used to use binaries from non-default
+installation directories. Assume, var(git) is installed in /usr/bin, but
+your sysadmin installed a newer version in /usr/bin/local. Now, instead of
+changing the order of your tt($PATH) parameter, you can do this:
+example(zstyle ':vcs_info:git:*:-all-' command /usr/local/bin/git)
+)
 kindex(use-server)
 item(tt(use-server))(
 This is used by the Perforce backend (tt(p4)) to decide if it should
@@ -547,6 +566,7 @@ sitem(tt(nvcsformats))("")
 sitem(tt(max-exports))(2)
 sitem(tt(enable))(ALL)
 sitem(tt(disable))((empty list))
+sitem(tt(command))((empty string))
 sitem(tt(use-simple))(false)
 sitem(tt(use-prompt-escapes))(true)
 endsitem()
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_cdv b/Functions/VCS_Info/Backends/VCS_INFO_detect_cdv
index 356bd06..a032453 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_detect_cdv
+++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_cdv
@@ -6,7 +6,7 @@ setopt localoptions NO_shwordsplit
 
 [[ $1 == '--flavours' ]] && return 1
 
-VCS_INFO_check_com cdv || return 1
+VCS_INFO_check_com ${vcs_comm[cmd]} || return 1
 vcs_comm[detect_need_file]=format
 VCS_INFO_bydir_detect '.cdv'
 return $?
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_cvs b/Functions/VCS_Info/Backends/VCS_INFO_detect_cvs
index 61b43cc..7a5ee1e 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_detect_cvs
+++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_cvs
@@ -6,6 +6,6 @@ setopt localoptions NO_shwordsplit
 
 [[ $1 == '--flavours' ]] && return 1
 
-VCS_INFO_check_com svn || return 1
+VCS_INFO_check_com ${vcs_comm[cmd]} || return 1
 [[ -d "./CVS" ]] && [[ -r "./CVS/Repository" ]] && return 0
 return 1
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_darcs b/Functions/VCS_Info/Backends/VCS_INFO_detect_darcs
index 942d8af..1e3f547 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_detect_darcs
+++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_darcs
@@ -6,7 +6,7 @@ setopt localoptions NO_shwordsplit
 
 [[ $1 == '--flavours' ]] && return 1
 
-VCS_INFO_check_com darcs || return 1
+VCS_INFO_check_com ${vcs_comm[cmd]} || return 1
 vcs_comm[detect_need_file]=format
 VCS_INFO_bydir_detect '_darcs'
 return $?
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_git b/Functions/VCS_Info/Backends/VCS_INFO_detect_git
index 627b8cf..61bc483 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_detect_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_git
@@ -6,8 +6,8 @@ setopt localoptions NO_shwordsplit
 
 [[ $1 == '--flavours' ]] && { print -l git-p4 git-svn; return 0 }
 
-if VCS_INFO_check_com git && git rev-parse --is-inside-work-tree &> /dev/null ; then
-    vcs_comm[gitdir]="$(git rev-parse --git-dir 2> /dev/null)" || return 1
+if VCS_INFO_check_com ${vcs_comm[cmd]} && ${vcs_comm[cmd]} rev-parse --is-inside-work-tree &> /dev/null ; then
+    vcs_comm[gitdir]="$(${vcs_comm[cmd]} rev-parse --git-dir 2> /dev/null)" || return 1
     if   [[ -d ${vcs_comm[gitdir]}/svn ]]             ; then vcs_comm[overwrite_name]='git-svn'
     elif [[ -d ${vcs_comm[gitdir]}/refs/remotes/p4 ]] ; then vcs_comm[overwrite_name]='git-p4' ; fi
     return 0
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_hg b/Functions/VCS_Info/Backends/VCS_INFO_detect_hg
index 8a6c0c8..41fcc4b 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_detect_hg
+++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_hg
@@ -6,7 +6,7 @@ setopt localoptions NO_shwordsplit
 
 [[ $1 == '--flavours' ]] && return 1
 
-VCS_INFO_check_com hg || return 1
+VCS_INFO_check_com ${vcs_comm[cmd]} || return 1
 vcs_comm[detect_need_file]=branch
 VCS_INFO_bydir_detect '.hg'
 return $?
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_mtn b/Functions/VCS_Info/Backends/VCS_INFO_detect_mtn
index cb0fec1..3f88ba2 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_detect_mtn
+++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_mtn
@@ -6,7 +6,7 @@ setopt localoptions NO_shwordsplit
 
 [[ $1 == '--flavours' ]] && return 1
 
-VCS_INFO_check_com mtn || return 1
+VCS_INFO_check_com ${vcs_comm[cmd]} || return 1
 vcs_comm[detect_need_file]=revision
 VCS_INFO_bydir_detect '_MTN'
 return $?
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_p4 b/Functions/VCS_Info/Backends/VCS_INFO_detect_p4
index d9475fa..377453f 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_detect_p4
+++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_p4
@@ -21,7 +21,7 @@ VCS_INFO_p4_get_server() {
   setopt extendedglob
 
   local -a settings
-  settings=(${(f)"$(p4 set)"})
+  settings=(${(f)"$(${vcs_comm[cmd]} set)"})
   serverport=${${settings[(r)P4PORT=*]##P4PORT=}%% *}
   case $serverport in
     (''|:)
@@ -54,7 +54,7 @@ VCS_INFO_detect_p4() {
       VCS_INFO_p4_get_server
       [[ -n $vcs_info_p4_dead_servers[$serverport] ]] && return 1
     fi
-    if p4where="$(p4 where 2>&1)"; then
+    if p4where="$(${vcs_comm[cmd]} where 2>&1)"; then
       return 0
     fi
     if [[ $p4where = *"Connect to server failed"* ]]; then
@@ -67,7 +67,7 @@ VCS_INFO_detect_p4() {
     return 1
   else
     [[ -n ${P4CONFIG} ]] || return 1
-    VCS_INFO_check_com p4 || return 1
+    VCS_INFO_check_com ${vcs_comm[cmd]} || return 1
     vcs_comm[detect_need_file]="${P4CONFIG}"
     VCS_INFO_bydir_detect .
     return $?
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_svk b/Functions/VCS_Info/Backends/VCS_INFO_detect_svk
index 476b591..e21b2dd 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_detect_svk
+++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_svk
@@ -17,7 +17,7 @@ setopt localoptions noksharrays extendedglob
 local -i fhash
 fhash=0
 
-VCS_INFO_check_com svk || return 1
+VCS_INFO_check_com ${vcs_comm[cmd]} || return 1
 [[ -f ~/.svk/config ]] || return 1
 
 while IFS= read -r line ; do
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_svn b/Functions/VCS_Info/Backends/VCS_INFO_detect_svn
index f22c34e..bb9d083 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_detect_svn
+++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_svn
@@ -6,6 +6,6 @@ setopt localoptions NO_shwordsplit
 
 [[ $1 == '--flavours' ]] && return 1
 
-VCS_INFO_check_com svn || return 1
+VCS_INFO_check_com ${vcs_comm[cmd]} || return 1
 [[ -d ".svn" ]] && return 0
 return 1
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_tla b/Functions/VCS_Info/Backends/VCS_INFO_detect_tla
index 3b20428..ac4dbd7 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_detect_tla
+++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_tla
@@ -6,6 +6,6 @@ setopt localoptions NO_shwordsplit
 
 [[ $1 == '--flavours' ]] && return 1
 
-VCS_INFO_check_com tla || return 1
-vcs_comm[basedir]="$(tla tree-root 2> /dev/null)" && return 0
+VCS_INFO_check_com ${vcs_comm[cmd]} || return 1
+vcs_comm[basedir]="$(${vcs_comm[cmd]} tree-root 2> /dev/null)" && return 0
 return 1
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr b/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr
index 995b2ad..31618d3 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr
@@ -14,8 +14,8 @@ if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "use-simple" ; then
         bzrinfo[1]=${${bzrinfo[1]}%% *}
     fi
 else
-    bzrbase=${${(M)${(f)"$( bzr info )"}:# ##branch\ root:*}/*: ##/}
-    bzrinfo=( ${${${(M)${(f)"$( bzr version-info )"}:#(#s)(revno|branch-nick)*}/*: /}/*\//} )
+    bzrbase=${${(M)${(f)"$( ${vcs_comm[cmd]} info )"}:# ##branch\ root:*}/*: ##/}
+    bzrinfo=( ${${${(M)${(f)"$( ${vcs_comm[cmd]} version-info )"}:#(#s)(revno|branch-nick)*}/*: /}/*\//} )
     bzrbase="$(VCS_INFO_realpath ${bzrbase})"
 fi
 
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index 0d8a4f9..23545e5 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -55,7 +55,7 @@ VCS_INFO_git_getaction () {
 
 VCS_INFO_git_getbranch () {
     local gitbranch gitdir=$1
-    local gitsymref='git symbolic-ref HEAD'
+    local gitsymref="${vcs_comm[cmd]} symbolic-ref HEAD"
 
     if    [[ -d "${gitdir}/rebase-apply" ]] \
        || [[ -d "${gitdir}/rebase" ]]       \
@@ -77,7 +77,7 @@ VCS_INFO_git_getbranch () {
         gitbranch="$(${(z)gitsymref} 2> /dev/null)"
 
         if [[ $? -ne 0 ]] ; then
-            gitbranch="$(git describe --exact-match HEAD 2>/dev/null)"
+            gitbranch="$(${vcs_comm[cmd]} describe --exact-match HEAD 2>/dev/null)"
 
             if [[ $? -ne 0 ]] ; then
                 gitbranch="${${"$(< $gitdir/HEAD)"}[1,7]}..."
@@ -98,7 +98,7 @@ fi
 
 VCS_INFO_adjust
 gitaction="$(VCS_INFO_git_getaction ${gitdir})"
-gitbase=${PWD%/${$( git rev-parse --show-prefix )%/##}}
+gitbase=${PWD%/${$( ${vcs_comm[cmd]} rev-parse --show-prefix )%/##}}
 rrn=${gitbase:t}
 VCS_INFO_formats "${gitaction}" "${gitbranch}" "${gitbase}"
 return 0
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_mtn b/Functions/VCS_Info/Backends/VCS_INFO_get_data_mtn
index 5974df8..688c85e 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_mtn
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_mtn
@@ -7,6 +7,6 @@ local mtnbranch mtnbase
 
 mtnbase=${vcs_comm[basedir]}
 rrn=${mtnbase:t}
-mtnbranch=${${(M)${(f)"$( mtn status )"}:#(#s)Current branch:*}/*: /}
+mtnbranch=${${(M)${(f)"$( ${vcs_comm[cmd]} status )"}:#(#s)Current branch:*}/*: /}
 VCS_INFO_formats '' "${mtnbranch}" "${mtnbase}"
 return 0
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4 b/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4
index 077306a..dccd9d3 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4
@@ -7,7 +7,7 @@ setopt localoptions extendedglob
 local p4base a b
 local -A p4info
 
-p4 info | while IFS=: read a b; do p4info[${a// /_}]="${b## #}"; done
+${vcs_comm[cmd]} info | while IFS=: read a b; do p4info[${a// /_}]="${b## #}"; done
 p4base=${vcs_comm[basedir]}
 
 # We'll use the client name as the branch; close enough.
@@ -15,7 +15,7 @@ local p4branch change
 # We'll use the latest change number to which the hierarchy from
 # here down is synced as the revision.
 # I suppose the following might be slow on a tortuous client view.
-change="${${$(p4 changes -m 1 ...\#have)##Change }%% *}"
+change="${${$(${vcs_comm[cmd]} changes -m 1 ...\#have)##Change }%% *}"
 zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat p4branch ||
 p4branch="%b:%r"
 zformat -f p4branch "${p4branch}" "b:${p4info[Client_name]}" \
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
index 7a23419..57ff5d8 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
@@ -10,10 +10,10 @@ local -A svninfo parentinfo
 
 svnbase=".";
 svninfo=()
-svn info --non-interactive | while IFS=: read a b; do svninfo[${a// /_}]="${b## #}"; done
+${vcs_comm[cmd]} info --non-interactive | while IFS=: read a b; do svninfo[${a// /_}]="${b## #}"; done
 while [[ -d "${svnbase}/../.svn" ]]; do
     parentinfo=()
-    svn info --non-interactive "${svnbase}/.." | while IFS=: read a b; do parentinfo[${a// /_}]="${b## #}"; done
+    ${vcs_comm[cmd]} info --non-interactive "${svnbase}/.." | while IFS=: read a b; do parentinfo[${a// /_}]="${b## #}"; done
     [[ ${parentinfo[Repository_UUID]} != ${svninfo[Repository_UUID]} ]] && break
     svninfo=(${(kv)parentinfo})
     svnbase="${svnbase}/.."
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_tla b/Functions/VCS_Info/Backends/VCS_INFO_get_data_tla
index e192172..cbc48c0 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_tla
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_tla
@@ -8,6 +8,6 @@ local tlabase tlabranch
 tlabase="$(VCS_INFO_realpath ${vcs_comm[basedir]})"
 rrn=${tlabase:t}
 # tree-id gives us something like 'foo@xxxxxxxxxxx/demo--1.0--patch-4', so:
-tlabranch=${${"$( tla tree-id )"}/*\//}
+tlabranch=${${"$( ${vcs_comm[cmd]} tree-id )"}/*\//}
 VCS_INFO_formats '' "${tlabranch}" "${tlabase}"
 return 0
diff --git a/Functions/VCS_Info/VCS_INFO_check_com b/Functions/VCS_Info/VCS_INFO_check_com
index 6d65360..d9f7a13 100644
--- a/Functions/VCS_Info/VCS_INFO_check_com
+++ b/Functions/VCS_Info/VCS_INFO_check_com
@@ -4,5 +4,12 @@
 
 setopt localoptions NO_shwordsplit
 
-(( ${+commands[$1]} )) && [[ -x ${commands[$1]} ]] && return 0
+case $1 in
+    (/*)
+        [[ -x $1 ]] && return 0
+        ;;
+    (*)
+        (( ${+commands[$1]} )) && [[ -x ${commands[$1]} ]] && return 0
+esac
+
 return 1
diff --git a/Functions/VCS_Info/VCS_INFO_get_cmd b/Functions/VCS_Info/VCS_INFO_get_cmd
new file mode 100644
index 0000000..26046f1
--- /dev/null
+++ b/Functions/VCS_Info/VCS_INFO_get_cmd
@@ -0,0 +1,6 @@
+## vim:ft=zsh
+# find out if the user wants us to use a special binary.
+# the default command name is the same as the backend name.
+local cmd
+zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" "command" cmd
+vcs_comm[cmd]=${cmd:-$vcs}
diff --git a/Functions/VCS_Info/vcs_info b/Functions/VCS_Info/vcs_info
index fb87e6a..7ecd122 100644
--- a/Functions/VCS_Info/vcs_info
+++ b/Functions/VCS_Info/vcs_info
@@ -17,6 +17,7 @@ static_functions=(
     VCS_INFO_bydir_detect
     VCS_INFO_check_com
     VCS_INFO_formats
+    VCS_INFO_get_cmd
     VCS_INFO_maxexports
     VCS_INFO_nvcsformats
     VCS_INFO_realpath
@@ -74,6 +75,7 @@ vcs_info () {
             continue
         fi
         vcs_comm=()
+        VCS_INFO_get_cmd
         VCS_INFO_detect_${vcs} && (( found = 1 )) && break
     done
 
-- 
1.6.0.2.307.gc4275



Messages sorted by: Reverse Date, Date, Thread, Author