From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 2290 invoked from network); 23 Oct 2020 08:39:27 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 23 Oct 2020 08:39:27 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1603442367; b=wVPMg2UkZtmTq3lmDQ66aKmEvQ/3duhFIe8sRVJf+ZmA1igU0K9/vZik5TBGBsFJtFrTPwBtTl Ms5wpBcdQxtsGeI09gs2jYt+LPWuyJEYYTMsSNq/3rVLTHI62yRin/6yZ4NrmawE/rho0V3GSS Li3tHcjuWZZOLzWVzB7WLIla+nYuX8TVrmYdgyaIlxC0TBKGNagb+sMrUP6vunO5o3VIqRGF3c TInqosWKz10X9oXYeWMuM0n6B9spQhEb3c5Ls1UX+5soQe2pC5Ub6V685mkT2YZqBjoBNBGRwg Y9nTxf6TF/ZgRWsa4ZO8SRjiPS4POwSZQIhAVDDt8gTCbg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f68.google.com) smtp.remote-ip=209.85.167.68; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1603442367; bh=JWGYW4JWkqIDOWcmIWDYMIeaToTsy+DOiuv2UD9nM18=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:MIME-Version:Message-ID:Date: Subject:Cc:To:From:DKIM-Signature:DKIM-Signature; b=WAY7BPftjq4LSNP3k5QKSHKdUqP54fx5BwLE4DczjbUU4D2owmQxUGKXvRJHKKhBcUJfF3w7nM ltkfTHHn4TVdEQAWpZKW8LsTz2ESMY0/q/oewPQkM07LeX4dSNEUm47jxYE6q5tYjESHasfNAl PC/qIHiBa3FtZpMi5CmOJZtUxAh2BFsg9oVV4UYIK7ozzPC9P6I3PN5rXLdnyRUJgC6j0hn3bU dEektPA1xJG4AHr8rvUBwWIXucgoeYnjctkZzo+4wbzrIjmGzuZp1K3n5QBoDnWjYrO8qyFT28 /ADZTjlpHpTgN7XP0ncTKTv9wf/S7tdwrQ+ZVRpfg0RbNQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=0hJRZx6vNxtoZbPWhgiWHE9idp6UFHifKGgw87TBThs=; b=Xi8PwncKyVxu7ujQWeFxKefkbM PO8c4oF80SiSrybeEVX1kFCGtmScXiAwZDxaUmNHh1DOl3Bkz28nsIiQGaBhZEmca20u9z8Gt/AXw z9gXGS8RVZyYny0f6wMaZ7L3SIMAQvlMNG2JGpcqimbbMvQnj8c79yP1ZjF9klESo2c7OJdWzQCjC RDPmX+yY0IG9CTvPiUCg6NdIdjr3f5nmYCaofPv+g3pcmIlbUjGLlTdYOxzpbiIrHtXFCbWAEU+FG MJFXQ0+T8D4tVwps3oZryOw5/FH/UnhcOUpSdkpLGXX+bwvTu+n+CnIc4SuISMIhFD2uCgIl3P9A4 elGgrTtA==; Received: from authenticated user by zero.zsh.org with local id 1kVsbe-000JZu-KS; Fri, 23 Oct 2020 08:39:26 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f68.google.com) smtp.remote-ip=209.85.167.68; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lf1-f68.google.com ([209.85.167.68]:44333) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1kVsbK-000JPm-S1; Fri, 23 Oct 2020 08:39:07 +0000 Received: by mail-lf1-f68.google.com with SMTP id b1so1087264lfp.11 for ; Fri, 23 Oct 2020 01:39:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0hJRZx6vNxtoZbPWhgiWHE9idp6UFHifKGgw87TBThs=; b=tCD4nj+qPYX5CXp4Ot49rJOaM4JkHre8qe/09q4b9aIAZjUQFHYf3xL2qMNGsVmmve Fg3kimfSoEKaw58456HVABPa2SzVUCQzrazekhLQvxBkoHC08Uwuf/SSPlRkFri0shR9 Kl09aEz3YhzzMI1YdX7PWwOaiCHzjnmWnAynE/dMsMeN3NsC4/zx6zCdNWN2WO5YHrpu lnucWzOBjKKcd+n2TNBImW8kHaPzE0xaaV6ZpqxjcSUcDHnnG+ebAKpQ5TWOuROYW9N8 B2Fba9mgYjnuZH3K8hagZPQyGQdfL14DYr1S+t8AgW7dCxWyGueQzBKhhPcV9Fv0TnM2 kanA== 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:mime-version :content-transfer-encoding; bh=0hJRZx6vNxtoZbPWhgiWHE9idp6UFHifKGgw87TBThs=; b=Z+mGIBea4exInYGAenAWZKYTLNFkYMvsTqoHz8E4LCF70YAbWBxiCklR9bMVuRl6y+ eE1xsb+zsgsPkZK6gxFRMJeI24BkM0bmLQ9mxwhiHSOnqt4fD5w68T+wUG6srXEv/TZX rQLfWKzKlVaM3fdyYFBedDcMJlkVmVj/4FUQjRnc1zY8ubvt+PbBfSAlvmC00tbrrKdY Ol5jAOFEQxPML9JGOXos3Dn4WiBoWBdLczCWAwDvTCRhzUrf8U6/ZKuXzKPV5p/i1eGZ ymZvUpxMzHWqAofS2RphtRcWvneQ4YUzHj5X39i6QDvGqdIL0HqFbni/SzIHjYm8f+74 IdSA== X-Gm-Message-State: AOAM533zHmTegTeMZgvdS5D+eRHkjw8QQdKml7eMw3yuqJJRBdyybX49 ejPyTbEnV26hzXKTuJFvvZCDW0t0qrIqmw== X-Google-Smtp-Source: ABdhPJyZ0p9uiV4okfsT2I1s1JKIOWExlQiskRvTJu2h9T6EMhMHluRXU3ODcBSYGw5FcGUkRZFRTA== X-Received: by 2002:a19:cc8f:: with SMTP id c137mr401519lfg.476.1603442345498; Fri, 23 Oct 2020 01:39:05 -0700 (PDT) Received: from trx40.lan ([2a02:2698:542a:1500:6b4a:8267:1413:7b63]) by smtp.gmail.com with ESMTPSA id w10sm92957ljm.56.2020.10.23.01.39.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Oct 2020 01:39:04 -0700 (PDT) From: Aleksandr Mezin To: zsh-workers@zsh.org Cc: Aleksandr Mezin Subject: [PATCH] vcs_info: add 'find-deepest' zstyle Date: Fri, 23 Oct 2020 14:34:44 +0600 Message-Id: <20201023083444.1565608-1-mezin.alexander@gmail.com> X-Mailer: git-send-email 2.29.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Seq: 47481 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: Currently, vcs_info iterates over enabled VCS backends and outputs repository status from the first backend that works (i.e. first backend that can find a repository). But I prefer a different behavior: I want to see the status of the repository closest to the current working directory. For example: if there is a Mercurial repository inside a Git repository, and I 'cd' into the Mercurial repository, I want to see the status of Mercurial repo, even if 'git' comes before 'hg' in the 'enable' list. Because some people, apparently, want the old behavior of vcs_info, I made it configurable, and, by default, old behavior is kept. To enable new behavior, enable 'find-deepest' zstyle: zstyle ':vcs_info:*' find-deepest yes After this change, vcs_info will try all enabled backends, and choose the one that returns the deepest basedir path. Usually it will be the repository closest to the current directory - if all basedirs are ancestors of the current directory. I do not care about cases when a basedir isn't an ancestor (for example, if GIT_WORK_TREE is pointing to an unrelated directory). Also, this patch adjusts VCS_INFO_detect_git and VCS_INFO_detect_cvs to make them set vcs_comm[basedir]. They were the only VCS_INFO_detect_* functions not setting it. Signed-off-by: Aleksandr Mezin --- Doc/Zsh/contrib.yo | 9 +++++++ .../VCS_Info/Backends/VCS_INFO_detect_cvs | 2 +- .../VCS_Info/Backends/VCS_INFO_detect_git | 1 + .../VCS_Info/Backends/VCS_INFO_get_data_git | 2 +- Functions/VCS_Info/vcs_info | 25 ++++++++++++++++--- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 00f693664..88d00c0ac 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -1238,6 +1238,14 @@ of unapplied patches (for example with Mercurial Queue patches). Used by the tt(quilt), tt(hg), and tt(git) backends. ) +kindex(find-deepest) +item(tt(find-deepest))( +By default, tt(vcs_info) tries backends in the order of 'enable' list, and +returns the output of the first backend that can find a repository. When +tt(find-deepest) is set to tt(true), tt(vcs_info) will try all enabled backends, +and will choose the one that returns the deepest tt(basedir) path. Usually it +will be the repository closest to the current directory. +) enditem() The default values for these styles in all contexts are: @@ -1272,6 +1280,7 @@ sitem(tt(quiltcommand))(quilt) sitem(tt(patch-format))(var(backend dependent)) sitem(tt(nopatch-format))(var(backend dependent)) sitem(tt(get-unapplied))(false) +sitem(tt(find-deepest))(false) endsitem() In normal tt(formats) and tt(actionformats) the following replacements are diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_cvs b/Functions/VCS_Info/Backends/VCS_INFO_detect_cvs index 7a5ee1eef..491219c16 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_detect_cvs +++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_cvs @@ -7,5 +7,5 @@ setopt localoptions NO_shwordsplit [[ $1 == '--flavours' ]] && return 1 VCS_INFO_check_com ${vcs_comm[cmd]} || return 1 -[[ -d "./CVS" ]] && [[ -r "./CVS/Repository" ]] && return 0 +[[ -d "./CVS" ]] && [[ -r "./CVS/Repository" ]] && vcs_comm[basedir]=.(:P) && return 0 return 1 diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_git b/Functions/VCS_Info/Backends/VCS_INFO_detect_git index e4191f474..b7955de38 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_detect_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_git @@ -7,6 +7,7 @@ setopt localoptions NO_shwordsplit [[ $1 == '--flavours' ]] && { print -l git-p4 git-svn; return 0 } if VCS_INFO_check_com ${vcs_comm[cmd]} && vcs_comm[gitdir]="$(${vcs_comm[cmd]} rev-parse --git-dir 2> /dev/null)" ; then + vcs_comm[basedir]="$( ${vcs_comm[cmd]} rev-parse --show-toplevel 2> /dev/null )" if [[ -d ${vcs_comm[gitdir]}/svn ]] ; then vcs_comm[overwrite_name]='git-svn' elif [[ -d ${vcs_comm[gitdir]}/refs/remotes/p4 ]] ; then vcs_comm[overwrite_name]='git-p4' ; fi return 0 diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index 79429c8e0..eb04d4b41 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -138,7 +138,7 @@ VCS_INFO_git_handle_patches () { gitdir=${vcs_comm[gitdir]} VCS_INFO_git_getbranch ${gitdir} -gitbase=$( ${vcs_comm[cmd]} rev-parse --show-toplevel 2> /dev/null ) +gitbase=${vcs_comm[basedir]} if [[ -z ${gitbase} ]]; then # Bare repository gitbase=${gitdir:P} diff --git a/Functions/VCS_Info/vcs_info b/Functions/VCS_Info/vcs_info index 786b61918..53e0f9416 100644 --- a/Functions/VCS_Info/vcs_info +++ b/Functions/VCS_Info/vcs_info @@ -54,7 +54,7 @@ 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 -x LC_MESSAGES @@ -114,7 +114,9 @@ vcs_info () { VCS_INFO_maxexports - (( found = 0 )) + local -A deepest_vcs_comm deepest_backend_misc + local deepest_vcs find_first + for vcs in ${enabled} ; do [[ -n ${(M)disabled:#${vcs}} ]] && continue if (( ${+functions[VCS_INFO_detect_${vcs}]} == 0 )) ; then @@ -124,10 +126,25 @@ vcs_info () { fi vcs_comm=() VCS_INFO_get_cmd - VCS_INFO_detect_${vcs} && (( found = 1 )) && break + if VCS_INFO_detect_${vcs}; then + zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" find-deepest + find_first=$? + + if (( find_first )) || (( ${#vcs_comm[basedir]//[!\/]} > ${#deepest_vcs_comm[basedir]//[!\/]} )) ; then + deepest_vcs="${vcs}" + deepest_vcs_comm=("${(kv)vcs_comm[@]}") + deepest_backend_misc=("${(kv)backend_misc[@]}") + + (( find_first )) && break + fi + fi done - (( found == 0 )) && { + vcs="${deepest_vcs}" + vcs_comm=("${(kv)deepest_vcs_comm[@]}") + backend_misc=("${(kv)deepest_backend_misc[@]}") + + [ -z "${vcs}" ] && { vcs='-quilt-'; quiltmode='standalone' VCS_INFO_quilt standalone || VCS_INFO_set --nvcs return 0 -- 2.29.0