git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Completion must sort before using uniq

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Nov 23, 2012, 08:21 UTC
Message-ID
<CAMP44s3qpr11JXi-znddAH2BWYbM_kp+nZnTa8CQgCzrBmfzmA@mail.gmail.com>
In-Reply-To
<CAFj1UpF2wh0imcqW7Ez_J14R_07a_A1-YWESaGrHRNa7Nsv-xg@mail.gmail.com>
On Thu, Nov 22, 2012 at 5:16 AM, Marc Khouzam <marc.khouzam@gmail.com> wrote:
Show 35 quoted lines
> 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
Previous: Joachim SchmitzNext: Marc Khouzam
Message 3 of 8 in “Completion must sort before using uniq”
  1. Completion must sort before using uniqMarc Khouzam, Nov 22, 2012
  2. Joachim SchmitzNov 23, 2012
  3. Felipe ContrerasNov 23, 2012
  4. Completion must sort before using uniqMarc Khouzam, Nov 23, 2012
  5. Felipe ContrerasNov 23, 2012
  6. Completion must sort before using uniqMarc Khouzam, Nov 23, 2012
  7. Felipe ContrerasNov 23, 2012
  8. Junio C HamanoNov 25, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.