Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH 3/3] vcs_info: choose the nearest repository
- X-seq: zsh-workers 44921
- From: Aleksandr Mezin <mezin.alexander@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [PATCH 3/3] vcs_info: choose the nearest repository
- Date: Sun, 24 Nov 2019 04:14:43 +0600
- Cc: Aleksandr Mezin <mezin.alexander@xxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OfU3DXQOw3fXg2wNN/8pZARMjYiCIp0stIonzj15eQg=; b=D7XQ6qW+ysZ620cW5Yy2vbq8E0OPSKkMxDKwu3u8WKzuuS2jflZjKWUn8njiptGfbf dcnkdCO9X25LtlNzfyI8d+tN2dQWIAC22dY992npW91PLmtKhNSQupSPYbsDn3GVdoPj x2ZiXFoitWmQe+pqCaMJRr4VgiKhkKUp9GdS5X+4g7MM+cTR9LlyuvkNJBjiQEe+P9xD t/EhaRi1qH0RRh7CyIAPMfVvc7fYbt4mCd7bHUQon54u85AfjXFuSst9zLzxR/tw5nql 3rflUfGQ+mjYyxzlbu9EdMtWyy6V1qp4dHCIJSedE59lkC0W8SmJ9SBYqeQP+DOo8oMN 8pJQ==
- In-reply-to: <20191123221443.279556-1-mezin.alexander@gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author