zsh-workers
 help / color / mirror / code / Atom feed
From: Aleksandr Mezin <mezin.alexander@gmail.com>
To: zsh-workers@zsh.org
Cc: Aleksandr Mezin <mezin.alexander@gmail.com>
Subject: [PATCH 3/3] vcs_info: choose the nearest repository
Date: Sun, 24 Nov 2019 04:14:43 +0600	[thread overview]
Message-ID: <20191123221443.279556-4-mezin.alexander@gmail.com> (raw)
In-Reply-To: <20191123221443.279556-1-mezin.alexander@gmail.com>

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


  parent reply	other threads:[~2019-11-24 22:52 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-23 22:14 [PATCH 0/3] vcs_info: handle nested repositories of different types Aleksandr Mezin
2019-11-23 22:14 ` [PATCH 1/3] vcs_info/git: set vcs_comm[basedir] in VCS_INFO_detect_git Aleksandr Mezin
2019-11-23 22:14 ` [PATCH 2/3] vcs_info/cvs: set vcs_comm[basedir] in VCS_INFO_detect_cvs Aleksandr Mezin
2019-11-25  4:35   ` Daniel Shahaf
2019-11-25  7:31     ` Aleksandr Mezin
2019-11-25  8:16       ` Daniel Shahaf
2019-11-26  1:26         ` Aleksandr Mezin
2019-11-26  1:28           ` Aleksandr Mezin
2019-11-26  4:52             ` Daniel Shahaf
2019-11-26 10:22               ` Aleksandr Mezin
2019-11-28 11:13                 ` Daniel Shahaf
2019-11-28 21:34                   ` Daniel Shahaf
2019-11-29 13:41                     ` Aleksandr Mezin
2019-11-29 15:25                       ` Mikael Magnusson
2019-11-29 19:55                         ` Daniel Shahaf
2019-11-29 20:30                       ` Daniel Shahaf
2019-11-29 20:52                         ` Daniel Shahaf
2019-11-25  9:13       ` Bart Schaefer
2019-11-25 18:22         ` Daniel Shahaf
2019-11-25 18:47           ` Bart Schaefer
2019-11-23 22:14 ` Aleksandr Mezin [this message]
2019-11-25  4:33   ` [PATCH 3/3] vcs_info: choose the nearest repository Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191123221443.279556-4-mezin.alexander@gmail.com \
    --to=mezin.alexander@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).