zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: m0viefreak <m0viefreak.cm@googlemail.com>
Cc: dana <dana@dana.is>, Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [RFC] Case-insensitive path completion in _git
Date: Sat, 27 Mar 2021 21:08:26 +0000	[thread overview]
Message-ID: <20210327210826.GJ18178@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <c7ece4f3-86e4-36d8-527a-e99f8a8f11d1@googlemail.com>

m0viefreak wrote on Sun, Dec 13, 2020 at 14:55:55 +0100:
> 
> 
> On 13.12.2020 05:40, dana wrote:
> > _git has issues completing files case-insensitively (if you have matcher-list
> > 'm:{a-zA-Z}={A-Za-z}' or whatever). Looking into it, i found that __git_files
> > is trying to pass a glob pattern to `git ls-files`, and this fails if there's
> > not an exact case match, since ls-files is always case-sensitive.
> 
> > There is a fall-back to `git ls-files` with no path, but this doesn't always
> > work either, because it defaults to the CWD, and the file you're trying to
> > complete may not be under the CWD. Even when the fall-back succeeds, it's not
> > ideal, because it'll pass every single file in the tree to _multi_parts, which
> > can be slow.
> > 
> > The following hack solves the problem for me, but it might be too silly to
> > commit. Can anyone think of a more proper fix? If not, would the hack be
> > viable (probably gated behind a style)?
> > 
> > dana
> > 
> > ...
> > +  pref=${pref//(#m)[[:alpha:]]/\[${(U)MATCH}${(L)MATCH}\]}
> > ...
> 
> This solution only handles simple upper-lower-case conversion matcher-list styles,
> but it will not work for more complicated styles like 'r:|[._-]=* r:|=*'.
> That's probably fine for most use-cases.

What about the default use-case — no matchspec and case-sensitive
matching?  The patch transforms a plain string to a list of character
classes, and it's not clear to me what costs that might incur on large
trees.

@Lawrence Thanks for fishing these out of the archives ☺

Cheers,

Daniel

> I have been running with the following patch applied locally for quite some time:
> 
> 
> diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
> index 81a060e4d..1a6619e31 100644
> --- a/Completion/Unix/Command/_git
> +++ b/Completion/Unix/Command/_git
> @@ -7153,7 +7153,7 @@ __git_files () {
>    # TODO: --directory should probably be added to $opts when --others is given.
> 
>    local pref=${(Q)${~PREFIX}}
> -  [[ $pref[1] == '/' ]] || pref=$gittoplevel$gitprefix$pref
> +  [[ $pref[1] == '/' ]] || pref=$gittoplevel$gitprefix
> 
>    # First allow ls-files to pattern-match in case of remote repository
>    files=(${(0)"$(_call_program files git ls-files -z --exclude-standard ${(q)opts} -- ${(q)${pref:+$pref\*}:-.} 2>/dev/null)"})
> 
> 
> It just lets _multi_parts do the matching.
> Performance-wise, it's obviously worse than than your proposed solution, but
> still better than the fallback, since it still passes $gitprefix to ls-files,
> which should also avoid the CWD problem.
> 
> The trigger of the fallback is broken anyways, isn't it?
> 
> >  # If ls-files succeeded but returned nothing, try again with no pattern
> >  if [[ -z "$files" && -n "$pref" ]]; then
> 
> It just considers the case where no match was found at all, but it does not
> handle the case where *some* matches were found, but not all.
> 
> 


  parent reply	other threads:[~2021-03-27 21:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-13  4:40 dana
2020-12-13 13:55 ` m0viefreak
2020-12-14 10:25   ` dana
2021-03-27 21:08   ` Daniel Shahaf [this message]
2021-03-28  5:07     ` dana
2021-03-28  8:08       ` Oliver Kiddle
2021-03-30  5:59         ` dana
2021-04-10 20:43           ` Lawrence Velázquez
2021-04-10 20:56             ` dana
2021-03-27 20:06 ` Lawrence Velázquez

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=20210327210826.GJ18178@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=dana@dana.is \
    --cc=m0viefreak.cm@googlemail.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).