Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] vcs_info: add 'find-deepest' zstyle
- X-seq: zsh-workers 47486
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Aleksandr Mezin <mezin.alexander@xxxxxxxxx>
- Subject: Re: [PATCH] vcs_info: add 'find-deepest' zstyle
- Date: Fri, 23 Oct 2020 23:48:55 +0000
- Archived-at: <https://zsh.org/workers/47486>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2020-10/20201023234855.5a0c6290%40tarpaulin.shahaf.local2>
- Authentication-results: zsh.org; iprev=pass (out5-smtp.messagingengine.com) smtp.remote-ip=66.111.4.29; dkim=pass header.d=daniel.shahaf.name header.s=fm1 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:cc:subject:message-id :in-reply-to:references:mime-version:content-type :content-transfer-encoding; s=fm1; bh=QOJsSm/oRyoIhhU80N8Eaw2gck wINYj0gC3y+hlNBts=; b=utaWMRPgM2pVqS0gWDIXIenfE1T382yKiAMqAg3R2Y bee5CLwpfkufD3l7bA0i2UgzJ8xfbSXGptPP9Ru6mbMfMpsssM7hEKdGcvt8Xhy8 MYfVqAbM+WTGVj8INeVEWuZUA/+uzXPXEnVw0qmYUgeSHtwRgoegd33+FpRgTJpe bd6QJvr4m+3vAKKWEjT5IXh0gt+FbN3t4GiTKWCivgt8F0x54cG+WYkL9IuMNjqI rG3d1U/v6i2ced1P8WWyg5tw9zCh7mi184F9vR8q5avHVa6ZRdcmnkjJpQXie3ar wb+BMQSLQsIhllT57xuYzhl/xXR7KY5dQWwKeLvUXmiA==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=QOJsSm/oRyoIhhU80N8Eaw2gckwINYj0gC3y+hlNB ts=; b=b0O0EweRSBxA72vVb+VuaXQ+gZJ1sewfu4QHYWan78f/Xdv3xafa5uwdH hVqX6d4OaCaK2UkJ+pgyP0Iiv9BVO1SC32g6ZRVfb7Pu+VknEP4k2Qo5rSg60RLf /M7ZhzqEhzNmrcyukLtGl5qiZ+mNOsZ3zufx7BZuPHKZTYgFp74wQD8yTZ+5jkgS MV7ASxmKQ06ABpLkV8Oli9FGsj/QE1HxgZ3kT8qjZ3jM9wykAtEpohYajS4dh3DT 4pYArvSvAjprM0lRCqzcSA9cLSofwgd66f4BRzkYVq18yvqDHwvbKoMFcllOU5ke iLgAFCzzXsv/SFdJwxlWI7ko+Z20Q==
- In-reply-to: <20201023083444.1565608-1-mezin.alexander@gmail.com>
- List-archive: <http://www.zsh.org/sympa/arc/zsh-workers>
- List-help: <mailto:sympa@zsh.org?subject=help>
- List-id: <zsh-workers.zsh.org>
- List-owner: <mailto:zsh-workers-request@zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-subscribe: <mailto:sympa@zsh.org?subject=subscribe%20zsh-workers>
- List-unsubscribe: <mailto:sympa@zsh.org?subject=unsubscribe%20zsh-workers>
- References: <20201023083444.1565608-1-mezin.alexander@gmail.com>
- Sender: zsh-workers-request@xxxxxxx
Aleksandr Mezin wrote on Fri, 23 Oct 2020 14:34 +0600:
> 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.
I suppose that's the Right thing to do in most cases: e.g., it's
context-sensitive whereas the 'enable' style's value doesn't usually
depend on the current directory.
(Separately, in your example it might be nice to indicate that there's
an "outside" Git repository, but that'd be a separate feature request.)
> Because some people, apparently, want the old behavior of vcs_info,
What's those people's argument? The default behaviour should be decided
on on this list, not simply announced to this list as a _fait accompli_.
> 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
>
I'd probably set this in my dotfiles: in the rare cases that I nest
repositories, I don't add files in the deeper repository to the
shallower repository.
> 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).
Would you clarify the last sentence (not the parenthetical but the part
before it)?
> 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.
Thanks. I don't recall if there's "How to write a backend"
documentation, but so long as all existing backends get it right, we're
probably covered well enough in practice. Going forward, we could
heavily comment one of the backends and declare it documentation, as
with Test/B01cd.ztst.
> Signed-off-by: Aleksandr Mezin <mezin.alexander@xxxxxxxxx>
> ---
> 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 ++++++++++++++++---
Please update _zstyle.
> 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
Multiple tweaks here. How about:
By default, tt(vcs_info) tries backends in the order given by the tt(enable) style, and
operates on the repository detected by the first backend to successfully detect a repository.
When this style (tt(find-deepest)) is set to tt(true), tt(vcs_info) will try all enabled backends,
and will operate on [...]
Wordier, yes, but "the output of a backend" didn't parse for me.
> +returns the deepest tt(basedir) path.
"basedir" is an implementation term; readers won't know what it means.
Keeping it would be like having zshparam(1) document $? as "The value
of tt(lastval)".
If /foo/.${vcs} and /foo/bar/.${vcs} both exist (same value of ${vcs} in
both) the style is set, the latter should be used. However, you don't
seem to be handling this case in any way. I guess that if this patch is
to be accepted, we'll have to go through all backends and verify that
they prefer /foo/bar/.${vcs} to /foo/.${vcs} when both exist and the
style is set appropriately. It's probably best if you go through
backends you can install via your distro and ask -workers@ volunteers to
go through any others. (Some backends will probably be left over, but
we can cross that bridge when we come to it.)
When /foo/.${vcs} and /foo/bar/.${vcs} both exist and «find-deepest» is
set to _«false»_, might someone expect /foo/.${vcs} to be used? (After
all, one might reasonably presume flipping the style's value would
_somehow_ affect vcs_info's behaviour.) Perhaps we can name the style
more unambiguously? How about changing it from boolean to enum, as in:
.
zstyle ':vcs_info:*' detection-algorithm enablement-order
zstyle ':vcs_info:*' detection-algorithm deepest-.vcs-dir
.
That'd also be more extensible.
Separately, as implemented the style doesn't quite go by the _deepest_
basedir path. Rather, it goes by the one that _has more path
components_.¹ That's not the same thing, at least if you take "X is
deeper than Y" to imply "X is a (possibly nested) subdirectory of Y",
which, I think, would be the appropriate semantics here. For instance,
given the pair of repository root paths {/foo/bar/baz, /lorem/ipsum},
the patch will prefer /foo/bar/baz, even though it's not "deeper than"
/lorem/ipsum. I don't think setting find-deepest should affect the
relative precedence of /foo/bar/baz and /lorem/ipsum…
… unless either of the two directories happens to be an ancestor of cwd,
in which case there's an argument to be made that that directory should
be preferred. (I hope we don't have to worry about symlinks here.)
Moreover, the above description wasn't entirely accurate. The patch
doesn't count path components; it counts slashes. That's not
equivalent, because of things like «/foo/bar», «/foo/bar/»,
«/foo/./bar», «/foo//bar», and «bar» (the last one depends on cwd, of
course). For instance, «/foo///bar» will be considered deeper than
«/foo/bar/baz».
I think a reasonable next step would be to nail down what repository
should be chosen, given $PWD and a set of existing .${vcs} dirs
(possibly more than one of those per value of ${vcs}). For instance:
1. The .${vcs} dir whose parent is an ancestor of ${PWD}; if there's
more than one of these, the closest ancestor; if there's more than
one of _these_, the first enabled.
2. If there's no such .${vcs} dir, then a .${vcs} dir from the first
backend in enablement order. If there's more than one of these,
then XXX. (TODO: What if the first backend in enablement order
identifies two repository directories, and one of them is an
ancestor of the other? Which one will be used?)
> +Usually it will be the repository closest to the current directory.
Documentation shouldn't say "usually" without also explaining what
happens in the _unusual_ case.
> +++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_cvs
> @@ -7,5 +7,5 @@ setopt localoptions NO_shwordsplit
> -[[ -d "./CVS" ]] && [[ -r "./CVS/Repository" ]] && return 0
> +[[ -d "./CVS" ]] && [[ -r "./CVS/Repository" ]] && vcs_comm[basedir]=.(:P) && return 0
«.(:P)» won't be expanded here.
Cheers,
Daniel
Messages sorted by:
Reverse Date,
Date,
Thread,
Author