threads / patch / 32177

patchRE: [PATCH] Completion must sort before using uniq

Subject: RE: [PATCH] Completion must sort before using uniq

## tl;dr

3 messages between Nov 23, 2012 and Nov 23, 2012. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Joachim Schmitz· Nov 23, 2012, 12:15 UTC · lore
Re-adding git@vger...
Show 34 quoted lines
> 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
Sascha Cunz· Nov 23, 2012, 12:26 UTC · re: Joachim Schmitz · lore

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
Sascha
Joachim Schmitz· Nov 23, 2012, 12:36 UTC · re: Sascha Cunz · lore
Show 21 quoted lines
> 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.

← back to recent threads