* RE: [PATCH] Completion must sort before using uniq [not found] ` <CAFj1UpEMKq9zH3nbLwYrNZRmd52_KEcN5BBrzGg2jxCzd+fsbA@mail.gmail.com> @ 2012-11-23 12:15 ` Joachim Schmitz 2012-11-23 12:26 ` Sascha Cunz 0 siblings, 1 reply; 6+ messages in thread From: Joachim Schmitz @ 2012-11-23 12:15 UTC (permalink / raw) To: 'Marc Khouzam', git; +Cc: szeder, felipe.contreras Re-adding git@vger... > From: Marc Khouzam [mailto:marc.khouzam@gmail.com] > Sent: Friday, November 23, 2012 11:51 AM > To: Joachim Schmitz > Cc: szeder@ira.uka.de; felipe.contreras@gmail.com > Subject: Re: [PATCH] Completion must sort before using uniq > > On Fri, Nov 23, 2012 at 3:10 AM, Joachim Schmitz > <jojo@schmitz-digital.de> wrote: > > Marc Khouzam wrote: > >> The uniq program only works with sorted input. The man page states > >> "uniq prints the unique lines in a sorted file". > > ... > >> --- 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 > > > > Is 'sort -u' not universally available and sufficient here? It is POSIX > > at least: > > http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sort.html > > "-u Unique: suppress all but one in each set of lines having equal > keys. If used with the -c option, check that there are no lines with > duplicate keys, in addition to checking that the input file is > sorted." > > What the code aims to do is to only show lines that are not > duplicated. 'sort -u' would still output one line for each duplicated > one. It seems 'sort -u' is the equivalent of 'sort | uniq' but won't > replace 'sort | uniq -u'. I can't see the difference and in fact don't understand uniq's -u option al all Linux man pages say: "only print unique lines", but that is what uniq does by default anyway?!? > Is 'sort | uniq -u' not POSIX? It is. It is one process more though. Bye, Jojo ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Completion must sort before using uniq 2012-11-23 12:15 ` [PATCH] Completion must sort before using uniq Joachim Schmitz @ 2012-11-23 12:26 ` Sascha Cunz 2012-11-23 12:36 ` Joachim Schmitz 0 siblings, 1 reply; 6+ messages in thread From: Sascha Cunz @ 2012-11-23 12:26 UTC (permalink / raw) To: Joachim Schmitz; +Cc: 'Marc Khouzam', git, szeder, felipe.contreras > I can't see the difference and in fact don't understand uniq's -u option al > all Linux man pages say: "only print unique lines", but that is what uniq > does by default anyway?!? >From the german translation of uniq's man-page, you can deduct that "only print unique lines" actually means: "print lines that are _not repeated_ in the input". A short test confirms that. i.e.: printf "a\nb\nb\nc\n" | uniq -u gives: a c Sascha ^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH] Completion must sort before using uniq 2012-11-23 12:26 ` Sascha Cunz @ 2012-11-23 12:36 ` Joachim Schmitz 0 siblings, 0 replies; 6+ messages in thread From: Joachim Schmitz @ 2012-11-23 12:36 UTC (permalink / raw) To: 'Sascha Cunz' Cc: 'Marc Khouzam', git, szeder, felipe.contreras > From: Sascha Cunz [mailto:sascha-ml@babbelbox.org] > Sent: Friday, November 23, 2012 1:26 PM > To: Joachim Schmitz > Cc: 'Marc Khouzam'; git@vger.kernel.org; szeder@ira.uka.de; felipe.contreras@gmail.com > Subject: Re: [PATCH] Completion must sort before using uniq > > > I can't see the difference and in fact don't understand uniq's -u option al > > all Linux man pages say: "only print unique lines", but that is what uniq > > does by default anyway?!? > > From the german translation of uniq's man-page, you can deduct that "only > print unique lines" actually means: "print lines that are _not repeated_ in > the input". > > A short test confirms that. i.e.: > > printf "a\nb\nb\nc\n" | uniq -u > > gives: > a > c Ah, OK, then I rest my case. Sorry for the noise. ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <1353557598-4820-1-git-send-email-marc.khouzam@gmail.com>]
* [PATCH] Completion must sort before using uniq [not found] <1353557598-4820-1-git-send-email-marc.khouzam@gmail.com> @ 2012-11-22 4:16 ` Marc Khouzam 2012-11-23 8:09 ` Joachim Schmitz 2012-11-23 8:21 ` Felipe Contreras 0 siblings, 2 replies; 6+ messages in thread From: Marc Khouzam @ 2012-11-22 4:16 UTC (permalink / raw) To: git; +Cc: SZEDER Gábor, Felipe Contreras 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 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Completion must sort before using uniq 2012-11-22 4:16 ` Marc Khouzam @ 2012-11-23 8:09 ` Joachim Schmitz 2012-11-23 8:21 ` Felipe Contreras 1 sibling, 0 replies; 6+ messages in thread From: Joachim Schmitz @ 2012-11-23 8:09 UTC (permalink / raw) To: git Marc Khouzam wrote: > The uniq program only works with sorted input. The man page states > "uniq prints the unique lines in a sorted file". ... > --- 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 Is 'sort -u' not universally available and sufficient here? It is POSIX at least: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sort.html Bye, Jojo ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Completion must sort before using uniq 2012-11-22 4:16 ` Marc Khouzam 2012-11-23 8:09 ` Joachim Schmitz @ 2012-11-23 8:21 ` Felipe Contreras 1 sibling, 0 replies; 6+ messages in thread From: Felipe Contreras @ 2012-11-23 8:21 UTC (permalink / raw) To: Marc Khouzam; +Cc: git, SZEDER Gábor On Thu, Nov 22, 2012 at 5:16 AM, Marc Khouzam <marc.khouzam@gmail.com> wrote: > 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'. The solution to what? This seems to be the right thing indeed, but you don't explain what is the actual problem that is being solved. What does the user experience? What would (s)he experience after the patch? -- Felipe Contreras ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-11-23 12:36 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <002201cdc952$00159c90$0040d5b0$@schmitz-digital.de> [not found] ` <CAFj1UpEMKq9zH3nbLwYrNZRmd52_KEcN5BBrzGg2jxCzd+fsbA@mail.gmail.com> 2012-11-23 12:15 ` [PATCH] Completion must sort before using uniq Joachim Schmitz 2012-11-23 12:26 ` Sascha Cunz 2012-11-23 12:36 ` Joachim Schmitz [not found] <1353557598-4820-1-git-send-email-marc.khouzam@gmail.com> 2012-11-22 4:16 ` Marc Khouzam 2012-11-23 8:09 ` Joachim Schmitz 2012-11-23 8:21 ` Felipe Contreras
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).