From: Marc Khouzam <marc.khouzam@gmail.com>
To: git@vger.kernel.org
Cc: "SZEDER Gábor" <szeder@ira.uka.de>,
"Felipe Contreras" <felipe.contreras@gmail.com>
Subject: [PATCH] Completion must sort before using uniq
Date: Wed, 21 Nov 2012 23:16:09 -0500 [thread overview]
Message-ID: <CAFj1UpF2wh0imcqW7Ez_J14R_07a_A1-YWESaGrHRNa7Nsv-xg@mail.gmail.com> (raw)
In-Reply-To: <1353557598-4820-1-git-send-email-marc.khouzam@gmail.com>
The uniq program only works with sorted input. The man page states
"uniq prints the unique lines in a sorted file".
When __git_refs use 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.
For example if all available branches are:
master
remotes/GitHub/maint
remotes/GitHub/master
remotes/origin/maint
remotes/origin/master
When performing completion on 'git checkout ma' the choices given are
maint
master
but when performing completion on 'git checkout mai', no choices
appear, which is obviously contradictory.
The reason is that, 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.
But when dealing with 'git checkout mai', the list will be:
maint
maint
which happens to be sorted and will be emptied by 'uniq -u'.
The solution is to first call 'sort' and then 'uniq -u'.
Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>
---
I ran into this by fluke when testing the tcsh completion.
Thanks for considering the fix.
Marc
contrib/completion/git-completion.bash | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/contrib/completion/git-completion.bash
b/contrib/completion/git-completion.bash
index bc0657a..85ae419 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -321,7 +321,7 @@ __git_refs ()
if [[ "$ref" == "$cur"* ]]; then
echo "$ref"
fi
- done | uniq -u
+ done | sort | uniq -u
fi
return
fi
--
1.8.0.1.g9fe2839
next parent reply other threads:[~2012-11-22 19:47 UTC|newest]
Thread overview: 11+ 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 ` Marc Khouzam [this message]
2012-11-23 8:09 ` [PATCH] Completion must sort before using uniq 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
2012-11-25 6:32 ` Junio C Hamano
[not found] <002201cdc952$00159c90$0040d5b0$@schmitz-digital.de>
[not found] ` <CAFj1UpEMKq9zH3nbLwYrNZRmd52_KEcN5BBrzGg2jxCzd+fsbA@mail.gmail.com>
2012-11-23 12:15 ` [PATCH] " Joachim Schmitz
2012-11-23 12:26 ` Sascha Cunz
2012-11-23 12:36 ` Joachim Schmitz
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=CAFj1UpF2wh0imcqW7Ez_J14R_07a_A1-YWESaGrHRNa7Nsv-xg@mail.gmail.com \
--to=marc.khouzam@gmail.com \
--cc=felipe.contreras@gmail.com \
--cc=git@vger.kernel.org \
--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).