From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 55f7a48b for ; Sun, 24 Nov 2019 22:52:20 +0000 (UTC) Received: (qmail 11153 invoked by alias); 23 Nov 2019 22:15:45 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 44921 Received: (qmail 17273 invoked by uid 1010); 23 Nov 2019 22:15:44 -0000 X-Qmail-Scanner-Diagnostics: from mail-lf1-f66.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.0/25635. spamassassin: 3.4.2. Clear:RC:0(209.85.167.66):SA:0(-2.0/5.0):. Processed in 4.860271 secs); 23 Nov 2019 22:15:44 -0000 X-Envelope-From: mezin.alexander@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.167.66 as permitted sender) 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OfU3DXQOw3fXg2wNN/8pZARMjYiCIp0stIonzj15eQg=; b=gQ1xz7Iq5sZu64Y08LAkSAju2gs6pvf2AiQ2t89K8gx7B7LqKlJzDz9v6I/E/awsp0 Y2Pt/Y7Hblr/5u5tdqlY7fV/xa6inr4PivJxul9njj79+ZAgWNx5tTjb/jWICYe0YJDd wRPAYvF18U09U5cu6G6A38JwP81ZS4xK6ecuvu38VEbC5lwGHvkPO/VOWrwWwzsM6z6l VmX+G5BYO6AQw98ptA3SLImpodojqG6xKanR9sRTq4KG0y6PHcLeq2zHmQO9GLMgx1bD qxt3xxKpBQSFKF1j12oK1H3GTYJ4+NdfmOkrM3nlYuaYGKGLOa47vFyz0j4PDiQbJzym Ta3A== X-Gm-Message-State: APjAAAW1kXrdPEQG4ruHbBydBMDlzM7UzlxmVyX2N/6eX8McIwp89gOd GKB0ti8Dvr22O9QED2PqFu8mw3+QExdYoQ== X-Google-Smtp-Source: APXvYqwtcYzMW3dI6gcACN66Z6xkIFY3w2ewmqbAc3ufx7qP3+ZQKezKSjnt3WN3WzZYNO8ZOHLjJw== X-Received: by 2002:ac2:4919:: with SMTP id n25mr15692995lfi.58.1574547305933; Sat, 23 Nov 2019 14:15:05 -0800 (PST) From: Aleksandr Mezin To: zsh-workers@zsh.org Cc: Aleksandr Mezin Subject: [PATCH 3/3] vcs_info: choose the nearest repository Date: Sun, 24 Nov 2019 04:14:43 +0600 Message-Id: <20191123221443.279556-4-mezin.alexander@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191123221443.279556-1-mezin.alexander@gmail.com> References: <20191123221443.279556-1-mezin.alexander@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Qmail-Scanner-2.11: added fake Content-Type header Content-Type: text/plain 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