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

[PATCH] VCS_Info: Replace VCS_Info_realpath() by :P



Some of the VCS stuff could stand to be modernised. Here's an easy one: Remove
VCS_Info_realpath() and replace it by the :P expansion modifier. This reduces
the time it takes VCS_INFO_bydir_detect() to walk up five directories on my Mac
from 40 ms (!) to 1 ms. The latter function is called at every single prompt for
each of the back-ends you have enabled (except git, luckily), so it can add up.

I thought about leaving the VCS_INFO_realpath() function itself, in case someone
has a custom back-end lying around that relies on it, but it's not part of the
public API (per the contrib documentation), so... too bad.

(Plus, it's hard to imagine many people in the world running a more obscure VCS
than some of the stuff this ships with. I can't find a single result on Google
suggesting that anyone even knows about the cdv, mtn, svk, or tla back-ends...)

dana


diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr b/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr
index e8c8e81de..705db65a7 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr
@@ -81,7 +81,7 @@ else
             bzrbase=${bzr_info[branch_root]} ;;
     esac
 
-    bzrbase="$(VCS_INFO_realpath ${bzrbase})"
+    bzrbase=${bzrbase:P}
 
     if [ -n "${bzr_info[checkout_of_branch]}" ] && \
        zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "use-server"
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_cvs b/Functions/VCS_Info/Backends/VCS_INFO_get_data_cvs
index ed738b98f..e9d172052 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_cvs
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_cvs
@@ -9,7 +9,7 @@ cvsbase="."
 while [[ -d "${cvsbase}/../CVS" ]]; do
     cvsbase="${cvsbase}/.."
 done
-cvsbase="$(VCS_INFO_realpath ${cvsbase})"
+cvsbase=${cvsbase:P}
 cvsbranch=$(< ./CVS/Repository)
 rrn=${cvsbase:t}
 cvsbranch=${cvsbranch##${rrn}/}
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
index e1334f661..a773a727d 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
@@ -46,7 +46,7 @@ else
   done
 fi
 
-svnbase="$(VCS_INFO_realpath ${svnbase})"
+svnbase=${svnbase:P}
 
 rrn=${svnbase:t}
 zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat svnbranch || svnbranch="%b:%r"
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_tla b/Functions/VCS_Info/Backends/VCS_INFO_get_data_tla
index f015e0cce..4e9cee8b9 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_tla
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_tla
@@ -5,7 +5,7 @@
 setopt localoptions extendedglob NO_shwordsplit
 local tlabase tlabranch
 
-tlabase="$(VCS_INFO_realpath ${vcs_comm[basedir]})"
+tlabase=${vcs_comm[basedir]:P}
 rrn=${tlabase:t}
 # tree-id gives us something like 'foo@xxxxxxxxxxx/demo--1.0--patch-4', so:
 tlabranch=${${"$( ${vcs_comm[cmd]} tree-id )"}/*\//}
diff --git a/Functions/VCS_Info/VCS_INFO_bydir_detect b/Functions/VCS_Info/VCS_INFO_bydir_detect
index 70b0fb6fa..b20c05c9c 100644
--- a/Functions/VCS_Info/VCS_INFO_bydir_detect
+++ b/Functions/VCS_Info/VCS_INFO_bydir_detect
@@ -4,11 +4,11 @@
 
 setopt localoptions NO_shwordsplit
 local dirname=$1
-local basedir="." realbasedir file
+local basedir="." file
 
-realbasedir="$(VCS_INFO_realpath ${basedir})"
-while [[ ${realbasedir} != '/' ]]; do
-    [[ -r ${realbasedir} ]] || return 1
+basedir=${basedir:P}
+while [[ ${basedir} != '/' ]]; do
+    [[ -r ${basedir} ]] || return 1
     if [[ -n ${vcs_comm[detect_need_file]} ]] ; then
         [[ -d ${basedir}/${dirname} ]] && {
             for file in ${(s: :)${vcs_comm[detect_need_file]}}; do
@@ -19,10 +19,9 @@ while [[ ${realbasedir} != '/' ]]; do
         [[ -d ${basedir}/${dirname} ]] && break
     fi
 
-    basedir=${basedir}/..
-    realbasedir="$(VCS_INFO_realpath ${basedir})"
+    basedir=${basedir:h}
 done
 
-[[ ${realbasedir} == "/" ]] && return 1
-vcs_comm[basedir]=${realbasedir}
+[[ ${basedir} == "/" ]] && return 1
+vcs_comm[basedir]=${basedir}
 return 0
diff --git a/Functions/VCS_Info/VCS_INFO_realpath b/Functions/VCS_Info/VCS_INFO_realpath
deleted file mode 100644
index ce4a69402..000000000
--- a/Functions/VCS_Info/VCS_INFO_realpath
+++ /dev/null
@@ -1,7 +0,0 @@
-## vim:ft=zsh
-## Written by Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx>
-## Distributed under the same BSD-ish license as zsh itself.
-
-setopt localoptions NO_shwordsplit chaselinks
-# -q to avoid chpwd() invocations
-( builtin cd -q $1 2>/dev/null && pwd; )
diff --git a/Functions/VCS_Info/vcs_info b/Functions/VCS_Info/vcs_info
index 4e9ac6c6a..d67ae6bf5 100644
--- a/Functions/VCS_Info/vcs_info
+++ b/Functions/VCS_Info/vcs_info
@@ -26,7 +26,6 @@ static_functions=(
     VCS_INFO_nvcsformats
     VCS_INFO_patch2subject
     VCS_INFO_quilt
-    VCS_INFO_realpath
     VCS_INFO_reposub
     VCS_INFO_set
 



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