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

[PATCH] vcs_info: Use ‘command’ prefix to call version control programs



Bart Schaefer wrote:
> On Oct 22,  6:24am, Manfred Lotz wrote:
[...]
> } VCS_INFO_get_data_svn:31: bad set of key/value pairs for associative
> } array
[...]
> I suppose VCS_INFO_get_data_svn ought to use "command ${vcs_comm[cmd]}"
> instead to bypass any such wrapper functions.  There are around three
> dozen places in Functions/VCS_Info/Backends/* that could similarly use
> the "command" prefix if we want to support Manfred's style of use.

This patch implements Bart's suggestion.
---

    I think this is reasonable. I hope, people don't count on
    wrapper functions to work to achieve some sort of sinister
    hack. :)

 Functions/VCS_Info/Backends/VCS_INFO_detect_git      |  4 ++--
 Functions/VCS_Info/Backends/VCS_INFO_detect_p4       |  4 ++--
 Functions/VCS_Info/Backends/VCS_INFO_detect_tla      |  2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr    |  8 ++++----
 Functions/VCS_Info/Backends/VCS_INFO_get_data_fossil |  2 +-
 Functions/VCS_Info/Backends/VCS_INFO_get_data_git    | 18 +++++++++---------
 Functions/VCS_Info/Backends/VCS_INFO_get_data_hg     |  2 +-
 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    |  8 ++++----
 Functions/VCS_Info/Backends/VCS_INFO_get_data_tla    |  2 +-
 Functions/VCS_Info/VCS_INFO_quilt                    |  2 +-
 12 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_git b/Functions/VCS_Info/Backends/VCS_INFO_detect_git
index 61bc483..5db0a1d 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 ${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 VCS_INFO_check_com ${vcs_comm[cmd]} && command ${vcs_comm[cmd]} rev-parse --is-inside-work-tree &> /dev/null ; then
+    vcs_comm[gitdir]="$(command ${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_p4 b/Functions/VCS_Info/Backends/VCS_INFO_detect_p4
index 377453f..fdf3543 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)"$(${vcs_comm[cmd]} set)"})
+  settings=(${(f)"$(command ${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="$(${vcs_comm[cmd]} where 2>&1)"; then
+    if p4where="$(command ${vcs_comm[cmd]} where 2>&1)"; then
       return 0
     fi
     if [[ $p4where = *"Connect to server failed"* ]]; then
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_tla b/Functions/VCS_Info/Backends/VCS_INFO_detect_tla
index ac4dbd7..2d50ff1 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_detect_tla
+++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_tla
@@ -7,5 +7,5 @@ setopt localoptions NO_shwordsplit
 [[ $1 == '--flavours' ]] && return 1
 
 VCS_INFO_check_com ${vcs_comm[cmd]} || return 1
-vcs_comm[basedir]="$(${vcs_comm[cmd]} tree-root 2> /dev/null)" && return 0
+vcs_comm[basedir]="$(command ${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 cae1a3b..1767fff 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr
@@ -9,7 +9,7 @@ local -a bzrinfo
 local -xA hook_com bzr_info
 
 VCS_INFO_bzr_get_info() {
-    bzrinfo=( ${(s.:.)$( ${vcs_comm[cmd]} version-info --custom \
+    bzrinfo=( ${(s.:.)$( command ${vcs_comm[cmd]} version-info --custom \
         --template="{revno}:{branch_nick}:{clean}")} )
     if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-changes"
     then
@@ -22,7 +22,7 @@ VCS_INFO_bzr_get_info() {
 
 VCS_INFO_bzr_get_info_restricted() {
     # we are forbidden from fetching info on bound branch from remote repository
-    bzrinfo=( $(${vcs_comm[cmd]} revno) ${bzrbase:t} )
+    bzrinfo=( $(command ${vcs_comm[cmd]} revno) ${bzrbase:t} )
     if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-changes" && \
        [[ ! $bzr_type == lightweigth ]]
     then
@@ -34,7 +34,7 @@ VCS_INFO_bzr_get_changes() {
     local -A counts
     local line flag
     bzr_changes=$(
-        ${vcs_comm[cmd]} stat -SV | while read flag line
+        command ${vcs_comm[cmd]} stat -SV | while read flag line
         do
             counts[${flag}]=$(( ${counts[${flag}]:-0} + 1 ))
         done
@@ -55,7 +55,7 @@ if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "use-simple" ; then
     fi
 else
     # Parse the output of 'bzr info' into associative array bzr_info
-    ${vcs_comm[cmd]} info | {
+    command ${vcs_comm[cmd]} info | {
         local line key value dirtype
         read dirtype
         grep '^[ a-zA-Z0-9]\+: ' | while read line
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_fossil b/Functions/VCS_Info/Backends/VCS_INFO_get_data_fossil
index fd0f838..ed9a9c7 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_fossil
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_fossil
@@ -7,7 +7,7 @@ local a b
 local -A fsinfo
 local fshash fsbranch changed merging action
 
-${vcs_comm[cmd]} status |
+command ${vcs_comm[cmd]} status |
    while IFS=: read a b; do
       fsinfo[${a//-/_}]="${b## #}"
    done
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index 48d552f..d859781 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -72,7 +72,7 @@ VCS_INFO_git_getaction () {
 
 VCS_INFO_git_getbranch () {
     local gitdir=$1 tmp actiondir
-    local gitsymref="${vcs_comm[cmd]} symbolic-ref HEAD"
+    local gitsymref="command ${vcs_comm[cmd]} symbolic-ref HEAD"
 
     actiondir=''
     for tmp in "${gitdir}/rebase-apply" \
@@ -102,7 +102,7 @@ VCS_INFO_git_getbranch () {
         gitbranch="$(${(z)gitsymref} 2> /dev/null)"
 
         if [[ $? -ne 0 ]] ; then
-            gitbranch="refs/tags/$(${vcs_comm[cmd]} describe --all --exact-match HEAD 2>/dev/null)"
+            gitbranch="refs/tags/$(command ${vcs_comm[cmd]} describe --all --exact-match HEAD 2>/dev/null)"
 
             if [[ $? -ne 0 ]] ; then
                 gitbranch="${${"$(< $gitdir/HEAD)"}[1,7]}..."
@@ -153,10 +153,10 @@ VCS_INFO_git_handle_patches () {
 
 gitdir=${vcs_comm[gitdir]}
 VCS_INFO_git_getbranch ${gitdir}
-gitbase=$( ${vcs_comm[cmd]} rev-parse --show-toplevel )
+gitbase=$( command ${vcs_comm[cmd]} rev-parse --show-toplevel )
 rrn=${gitbase:t}
 if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then
-    gitsha1=$(${vcs_comm[cmd]} rev-parse --quiet --verify HEAD)
+    gitsha1=$(command ${vcs_comm[cmd]} rev-parse --quiet --verify HEAD)
 else
     gitsha1=''
 fi
@@ -173,20 +173,20 @@ elif zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-staged-change
     querystaged=1
 fi
 if (( querystaged || queryunstaged )) && \
-   [[ "$(${vcs_comm[cmd]} rev-parse --is-inside-work-tree 2> /dev/null)" == 'true' ]] ; then
+   [[ "$(command ${vcs_comm[cmd]} rev-parse --is-inside-work-tree 2> /dev/null)" == 'true' ]] ; then
     # Default: off - these are potentially expensive on big repositories
     if (( queryunstaged )) ; then
-        ${vcs_comm[cmd]} diff --no-ext-diff --ignore-submodules=dirty --quiet --exit-code ||
+        command ${vcs_comm[cmd]} diff --no-ext-diff --ignore-submodules=dirty --quiet --exit-code ||
             gitunstaged=1
     fi
     if (( querystaged )) ; then
-        if ${vcs_comm[cmd]} rev-parse --quiet --verify HEAD &> /dev/null ; then
-            ${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules=dirty HEAD 2> /dev/null
+        if command ${vcs_comm[cmd]} rev-parse --quiet --verify HEAD &> /dev/null ; then
+            command ${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules=dirty HEAD 2> /dev/null
             (( $? && $? != 128 )) && gitstaged=1
         else
             # empty repository (no commits yet)
             # 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is the git empty tree.
-            ${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules=dirty 4b825dc642cb6eb9a060e54bf8d69288fbee4904 2>/dev/null
+            command ${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules=dirty 4b825dc642cb6eb9a060e54bf8d69288fbee4904 2>/dev/null
             (( $? && $? != 128 )) && gitstaged=1
         fi
     fi
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
index cedaf56..13046e1 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
@@ -53,7 +53,7 @@ if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then
             "check-for-changes" || hgid_args+=( -r. )
 
         local HGRCPATH
-        HGRCPATH="/dev/null" ${vcs_comm[cmd]} ${(z)hgid_args} 2> /dev/null \
+        HGRCPATH="/dev/null" command ${vcs_comm[cmd]} ${(z)hgid_args} 2> /dev/null \
             | read -r r_csetid r_lrev r_branch
     fi
 fi
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_mtn b/Functions/VCS_Info/Backends/VCS_INFO_get_data_mtn
index 0a8064c..197540c 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)"$( ${vcs_comm[cmd]} status )"}:#(#s)Current branch:*}/*: /}
+mtnbranch=${${(M)${(f)"$( command ${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 430cfa6..e2a54d1 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4
@@ -8,7 +8,7 @@ local p4base a b
 local -A p4info
 local -xA hook_com
 
-${vcs_comm[cmd]} info | while IFS=: read a b; do p4info[${a// /_}]="${b## #}"; done
+command ${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.
@@ -16,7 +16,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="${${$(${vcs_comm[cmd]} changes -m 1 ...\#have)##Change }%% *}"
+change="${${$(command ${vcs_comm[cmd]} changes -m 1 ...\#have)##Change }%% *}"
 zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat p4branch || p4branch="%b:%r"
 hook_com=( branch "${p4info[Client_name]}" revision "${change}" )
 if VCS_INFO_hook 'set-branch-format' "${p4branch}"; then
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
index e56afee..a37d240 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
@@ -16,11 +16,11 @@ svninfo=()
 # resolved, here is a workaround that will get things done, without using it.
 # Clumsily, but that's life.
 local -a dat
-dat=( ${(f)"$(${vcs_comm[cmd]} info --non-interactive 2>&1)"} )
+dat=( ${(f)"$(command ${vcs_comm[cmd]} info --non-interactive 2>&1)"} )
 rc=$?
 (( rc != 0 )) && return 1
 # The following line is the real code, the following is the workaround.
-#${vcs_comm[cmd]} info --non-interactive \
+#command ${vcs_comm[cmd]} info --non-interactive \
 print -l "${dat[@]}" \
 |& while IFS=: read a b; do
     svninfo[${a// /_}]="${b## #}"
@@ -34,12 +34,12 @@ cwdinfo=(${(kv)svninfo})
 if (( ${+svninfo[Working_Copy_Root_Path]} )); then
   # svn 1.7+
   svnbase=${svninfo[Working_Copy_Root_Path]}
-  ${vcs_comm[cmd]} info --non-interactive -- "${svnbase}" | while IFS=: read a b; do svninfo[${a// /_}]="${b## #}"; done
+  command ${vcs_comm[cmd]} info --non-interactive -- "${svnbase}" | while IFS=: read a b; do svninfo[${a// /_}]="${b## #}"; done
 else
   # svn 1.0-1.6
   while [[ -d "${svnbase}/../.svn" ]]; do
       parentinfo=()
-      ${vcs_comm[cmd]} info --non-interactive -- "${svnbase}/.." | while IFS=: read a b; do parentinfo[${a// /_}]="${b## #}"; done
+      command ${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 f015e0c..9bdfd6a 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=${${"$( ${vcs_comm[cmd]} tree-id )"}/*\//}
+tlabranch=${${"$( command ${vcs_comm[cmd]} tree-id )"}/*\//}
 VCS_INFO_formats '' "${tlabranch}" "${tlabase}" '' '' '' ''
 return 0
diff --git a/Functions/VCS_Info/VCS_INFO_quilt b/Functions/VCS_Info/VCS_INFO_quilt
index db15dda..cca1393 100644
--- a/Functions/VCS_Info/VCS_INFO_quilt
+++ b/Functions/VCS_Info/VCS_INFO_quilt
@@ -134,7 +134,7 @@ function VCS_INFO_quilt() {
         # This zstyle call needs to be moved further up if `quilt' needs
         # to be run in more places than this one.
         zstyle -s "${context}" quiltcommand quiltcommand || quiltcommand='quilt'
-        unapplied=( ${(f)"$(QUILT_PATCHES=$patches $quiltcommand --quiltrc /dev/null unapplied 2> /dev/null)"} )
+        unapplied=( ${(f)"$(QUILT_PATCHES=$patches command $quiltcommand --quiltrc /dev/null unapplied 2> /dev/null)"} )
         unapplied=( ${unapplied:#} )
     else
         unapplied=()
-- 
2.1.0.60.g85f0837



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