Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: completion: git: --fixup: problem with _describe -2V and duplicate commit subjects
- X-seq: zsh-workers 34814
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Daniel Hahler <genml+zsh-workers@xxxxxxxxxx>
- Subject: Re: completion: git: --fixup: problem with _describe -2V and duplicate commit subjects
- Date: Sun, 29 Mar 2015 05:47:53 +0000
- Cc: Zsh Hackers' List <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:subject:to:x-sasl-enc:x-sasl-enc; s= mesmtp; bh=n8uGHo5MEf5UOu5t6GgeEcbIbRE=; b=wgW4onhJtpQL4JRIDWv/L vuGCoeydcZt6kEVvUOfvpfOHQYlaUVXJbNb7/Hv90kLqlqN6YAuCa/idEAihf6z9 gfpLPxO580rjJSX35PTaLJVdJtVLDNM6z6Ll+7u/hh/XBO1qTK0ELa5/SiEj7ctN +h1fEP6b5SgQYrwMiTZH+s=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:subject:to:x-sasl-enc:x-sasl-enc; s= smtpout; bh=n8uGHo5MEf5UOu5t6GgeEcbIbRE=; b=QmGOwkJRmUMLSfNTKEZx kSrsjYSO3VeMiK72ToYzqZNghXk5IdOZX5tHuP7IdEJ8l6C9+jMqIfcpsXJz3W7B nD3jD2Utw24OTAivQ8ArR4S+2C3iL8Qejp66DI5WOpFYw570qHa8eWRr9kxmQQ9e 1kMulxc2FIz7mSmrVaqYobo=
- In-reply-to: <5510AAD4.8040807@thequod.de>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
[ compdescribe question inside ]
On Tue, Mar 24, 2015 at 01:07:48AM +0100, Daniel Hahler wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
Inline PGP and inline patches don't go well together (inline PGP
corrupts lines with a '-' on the first column.). It would be slightly
easier to process your patches if you either attached them, or used MIME
PGP rather than inline PGP. Thanks.
> On 23.03.2015 23:05, I wrote:
>
> > I've noticed that with duplicate descriptions for different commits,
> > the new completion for --fixup (__git_recent_commits) does not behave
> > properly, triggered by the "-2V" used with _describe.
> >
> > When completing "git commit --fixup=" in a repo with two commits having
> > "init" as its subject:
> >
> > Without "-2V":
> >
> > -- commit object name --
> > b1fc0ca 05a98c0 -- init
> >
This one behaves correctly, though of course it no longer sorts
completions most recent first (since -V did that).
> > With "-2V":
> >
> > -- commit object name --
> > -- init
> > -- commit object name --
> > b1fc0ca 05a98c0
> >
Yes, I see that. Here's a more minimal reproducer:
[[[
$ zsh -f
% autoload compinit
% compinit
% a=(alice:foo bob:foo)
% compdef '_describe -2Vx person a' f
% zstyle ':completion:*:descriptions' format '%B> %U%d%u%b'
% zstyle ':completion:*' group-name ''
% f <TAB>
> person
-- foo
> person
alice bob
% zstyle ':completion:*' completer _all_matches _complete _ignored
% f <TAB>
> person
-- foo
> person
alice bob
> all matches
alice bob
]]]
I've tracked this down a little. It has to do with the C implementation of
compdescribe passing "-E1" to compadd, here:
[in Src/Zle/computil.c]
737 case CRT_EXPL:
738 {
739 /* add columns as safety margin */
740 VARARR(char, dbuf, cd_state.suf + cd_state.slen +
741 zterm_columns);
742 char buf[20], *p, *pp, *d;
743 int i = run->count, remw, w, l;
744
745 sprintf(buf, "-E%d", i);
This also explains the space in front of "alice" in the "all matches"
line: "compadd -E1" adds an empty match.
So, in essence, compadd sees an empty match with description 'foo' and
two matches, 'alice' and 'bob', with no descriptions; which causes it to
print
[[[
-- foo
alice bob
]]]
when descriptions are disabled. I'm not sure what should be done
instead. One option is to disable the 'group by description' step for
the 'git commit --fixup=' use case, and just let the list of matches to
include two lines with the same description text. Or perhaps the "one
empty match with a description and two real matches without
descriptions" trick should be changed. Thoughts?
> > This does not only affect the duplicate commits, but will move all
> > hashes to a separate "commit object name" section, leaving the
> > descriptions without them.
> >
> > This was added in 236da69, where the options are passed on to next_label.
>
> As a workaround I could imagine also adding the date, which is useful
> by itself:
...
> - - local i j k
> + local i j k l
...
> It would be nice if this could be shortened, e.g. by removing the timezone offset and
> removing the current year, month etc.
>
I suppose you could use %ct to get the seconds-since-epoch value and
strftime it yourself. However, I believe this code has to work even if
the strftime builtin is not available, so it'd have to be something like
"use %ci & strftime if strftime(1) is available, else fallback to %cd".
> There's a "relative date" option ("%cr"), but that might produce duplicates again.
> If this can be fixed, it might be a good alternative to "%cd".
>
Actually, I'm tempted to deduplicate it by throwing the hash into the
description:
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 5524cb0..87ec986 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -5651,7 +5651,7 @@ __git_recent_commits () {
__git_command_successful $pipestatus || return 1
for i j k in "$commits[@]" ; do
- descr+=($i:$k)
+ descr+=("$i:[$i] $k")
j=${${j# \(}%\)} # strip leading ' (' and trailing ')'
for j in ${(s:, :)j}; do
if [[ $j == 'tag: '* ]] ; then
The hash will ensure descriptions are unique (git prints more hash
digits than requested if the amount requested would be ambiguous), which
works around the problem; and in the common case the [$i] prefix would
be the same width in every line, making it easier to visually skip it.
So I'm inclined to use the above, and fix _describe separately.
We can of course add the date still, as you suggested; I just think if
we add the date it should be because the date is useful, not because it
uniquifies, since adding the hash is a better uniquifier.
WDYT?
Thanks,
Daniel
P.S. Sorry for the delayed reply, I was offline last week.
>
> I've noticed btw that with `zsh -f` this is not the same, but commits are not grouped
> together and appear to get sorted. Therefore some zstyle might be involved here.
>
>
> Regards,
> Daniel.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author