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

[PATCH 3/3] vcs_info: choose the nearest repository



Previously vcs_info didn't handle nested repositories of different types
correctly: for example, when in a hg repository, that is cloned inside of a git
working tree (not as a submodule), it was still showing git branch.

Choose the repository that's nearest to the current working directory. And
since base directories are always parents of the current directory - just
choose the longest path.

However, this logic may not work correctly for symlinked repositories, if
VCS_INFO_detect_* functions will continue to use :P modifier for the basedir.
Is there a reason why :P is used for basedir instead of :a?
---
 Functions/VCS_Info/vcs_info | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/Functions/VCS_Info/vcs_info b/Functions/VCS_Info/vcs_info
index d67ae6bf5..640fd1a79 100644
--- a/Functions/VCS_Info/vcs_info
+++ b/Functions/VCS_Info/vcs_info
@@ -53,13 +53,13 @@ vcs_info () {
     [[ -r . ]] || return 0
 
     local pat
-    local -i found retval
+    local -i retval
     local -a enabled disabled dps
-    local usercontext vcs rrn quiltmode
+    local usercontext vcs nearest_vcs rrn quiltmode
     local -x LC_MESSAGES
     local -i maxexports
     local -a msgs
-    local -A vcs_comm hook_com backend_misc user_data
+    local -A vcs_comm nearest_vcs_comm hook_com backend_misc nearest_backend_misc user_data
 
     LC_MESSAGES=C
     if [[ -n ${LC_ALL} ]]; then
@@ -107,7 +107,6 @@ vcs_info () {
 
     VCS_INFO_maxexports
 
-    (( found = 0 ))
     for vcs in ${enabled} ; do
         [[ -n ${(M)disabled:#${vcs}} ]] && continue
         if (( ${+functions[VCS_INFO_detect_${vcs}]} == 0 )) ; then
@@ -117,15 +116,25 @@ vcs_info () {
         fi
         vcs_comm=()
         VCS_INFO_get_cmd
-        VCS_INFO_detect_${vcs} && (( found = 1 )) && break
+        if VCS_INFO_detect_${vcs}; then
+            if (( ${#vcs_comm[basedir]:a} > ${#nearest_vcs_comm[basedir]:a} )); then
+                nearest_vcs_comm=("${(kv)vcs_comm[@]}")
+                nearest_vcs="${vcs}"
+                nearest_backend_misc=("${(kv)backend_misc[@]}")
+            fi
+        fi
     done
 
-    (( found == 0 )) && {
+    [ -z "${nearest_vcs}" ] && {
         vcs='-quilt-'; quiltmode='standalone'
         VCS_INFO_quilt standalone || VCS_INFO_set --nvcs
         return 0
     }
 
+    vcs_comm=("${(kv)nearest_vcs_comm[@]}")
+    vcs="${nearest_vcs}"
+    backend_misc=("${(kv)nearest_backend_misc[@]}")
+
     VCS_INFO_hook "pre-get-data"
     retval=$?
     if (( retval == 1 )); then
-- 
2.24.0



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