From: Felipe Contreras <felipe.contreras@gmail.com>
To: Marc Khouzam <marc.khouzam@gmail.com>
Cc: "Junio C Hamano" <gitster@pobox.com>,
git@vger.kernel.org, "SZEDER Gábor" <szeder@ira.uka.de>
Subject: Re: [PATCH v3] Completion must sort before using uniq
Date: Fri, 23 Nov 2012 20:21:15 +0100 [thread overview]
Message-ID: <CAMP44s2ZgbZkjnrNA0ry-koZbTtqRgO5JrJtk-UtDuvdR0k0PA@mail.gmail.com> (raw)
In-Reply-To: <CAFj1UpH8h6c7xHuRG6F+pLy5YMvsJ0QdXsotCpLKnht0PsdiNw@mail.gmail.com>
On Fri, Nov 23, 2012 at 3:02 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:
> The user can be presented with invalid completion results
> when trying to complete a 'git checkout' command. This can happen
> when using a branch name prefix that matches multiple remote branches.
>
> For example, if available branches are:
> master
> remotes/GitHub/maint
> remotes/GitHub/master
> remotes/origin/maint
> remotes/origin/master
>
> When performing completion on 'git checkout ma' the user will be
> given the choices:
> maint
> master
>
> However, 'git checkout maint' will fail in this case, although
> completion previously said 'maint' was valid. Furthermore, when
> performing completion on 'git checkout mai', no choices will be
> suggested. So, the user is first told that the branch name
> 'maint' is valid, but when trying to complete 'mai' into 'maint',
> that completion is no longer valid.
>
> The completion results should never propose 'maint' as a valid
> branch name, since 'git checkout' will refuse it.
>
> The reason for this bug is that the uniq program only
> works with sorted input. The man page states
> "uniq prints the unique lines in a sorted file".
>
> When __git_refs uses the guess heuristic employed by checkout for
> tracking branches it wants to consider remote branches but only if
> the branch name is unique. To do that, it calls 'uniq -u'. However
> the input given to 'uniq -u' is not sorted.
>
> Therefore, in the above example, when dealing with 'git checkout ma',
> "__git_refs '' 1" will find the following list:
> master
> maint
> master
> maint
> master
>
> which, when passed to 'uniq -u' will remain the same. Therefore
> 'maint' will be wrongly suggested as a valid option.
>
> When dealing with 'git checkout mai', the list will be:
> maint
> maint
>
> which happens to be sorted and will be emptied by 'uniq -u',
> properly ignoring 'maint'.
>
> A solution for preventing the completion script from suggesting
> such invalid branch names is to first call 'sort' and then 'uniq -u'.
>
> Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>
Looks good. Reviewed-by: Felipe Contreras <felipe.contreras@gmail.com>
--
Felipe Contreras
next prev parent reply other threads:[~2012-11-23 19:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1353557598-4820-1-git-send-email-marc.khouzam@gmail.com>
2012-11-22 4:16 ` [PATCH] Completion must sort before using uniq Marc Khouzam
2012-11-23 8:09 ` Joachim Schmitz
2012-11-23 8:21 ` Felipe Contreras
2012-11-23 11:17 ` [PATCH v2] " Marc Khouzam
2012-11-23 11:34 ` Felipe Contreras
2012-11-23 14:02 ` [PATCH v3] " Marc Khouzam
2012-11-23 19:21 ` Felipe Contreras [this message]
2012-11-25 6:32 ` Junio C Hamano
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAMP44s2ZgbZkjnrNA0ry-koZbTtqRgO5JrJtk-UtDuvdR0k0PA@mail.gmail.com \
--to=felipe.contreras@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=marc.khouzam@gmail.com \
--cc=szeder@ira.uka.de \
/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://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).