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

Re: [PATCH v3] completion: add new _GIT_complete helper

From
SZEDER Gábor <szeder@ira.uka.de>
Date
May 6, 2012, 11:36 UTC
Message-ID
<20120506113622.GL2164@goldbirke>
In-Reply-To
<20120506113021.GK2164@goldbirke>
On Sun, May 06, 2012 at 01:30:21PM +0200, SZEDER Gábor wrote:
Show 27 quoted lines
> On Sun, May 06, 2012 at 01:14:25PM +0200, SZEDER Gábor wrote:
> > On Sat, May 05, 2012 at 05:23:20PM +0200, Felipe Contreras wrote:
> > > This simplifies the completions, and makes it easier to define aliases:
> > > 
> > >  _GIT_complete gf git_fetch
> > 
> > So, 'gf' is an alias for 'git fetch', for which the user would like to
> > use the completion for 'git fetch', right?  But that completion
> > function is caled _git_fetch(), so the underscore prefix is missing
> > here.
> > 
> > Besides, this example won't work, because the completion for 'git
> > fetch' uses __git_complete_remote_or_refspec(), which in turn relies
> > on finding out the name of the git command from the word on the
> > command line, and it won't be able to do that from 'gf'.
> 
> I scanned the completion script for places where we iterate over the
> words on the command line, i.e. for the pattern 'while.*\$cword'.
> 
> It seems that with the exception of __git_complete_remote_or_refspec()
> all those places seem to be OK to be used with aliases.  They all
> start the iteration at the first word on the command line ('git' or
> 'gf' being the nullth) so they will iterate over all relevant words in
> case of aliases, too.  Perhaps this is a heritage of the dashed
> commands; back then the completion script had to deal with 'git cmd'
> and 'git-cmd', too.  __git_complete_remote_or_refspec() starts at the
> second word, so that must be changed.

There is one more odd case, though: __git_config_get_set_variables() iterates over the words on the command line backwards, i.e. starting at the index $cword until the index of the word is greater than 1. This means that the iteration will stop at the second word, so this must be adjusted, too, just in case someone wants an alias for 'git config'.

Previous: SZEDER GáborNext: SZEDER Gábor
Message 18 of 24 in “completion: add new _GIT_complete helper”
  1. completion: add new _GIT_complete helperFelipe Contreras, May 5, 2012
  2. Jonathan NiederMay 5, 2012
  3. Felipe ContrerasMay 5, 2012
  4. Jonathan NiederMay 5, 2012
  5. Jonathan NiederMay 5, 2012
  6. Felipe ContrerasMay 5, 2012
  7. Jonathan gives feedback --> flamewars inevitable? (Re: [PATCH v3] completion: add new _GIT_complete helper)Jonathan Nieder, May 5, 2012
  8. Felipe ContrerasMay 5, 2012
  9. Jonathan NiederMay 5, 2012
  10. Jonathan NiederMay 5, 2012
  11. Tay Ray ChuanMay 6, 2012
  12. Felipe ContrerasMay 14, 2012
  13. Jonathan NiederMay 5, 2012
  14. SZEDER GáborMay 6, 2012
  15. Jonathan NiederMay 6, 2012
  16. SZEDER GáborMay 6, 2012
  17. SZEDER GáborMay 6, 2012
  18. SZEDER GáborMay 6, 2012
  19. SZEDER GáborMay 6, 2012
  20. Felipe ContrerasMay 6, 2012
  21. Felipe ContrerasMay 6, 2012
  22. SZEDER GáborMay 6, 2012
  23. Felipe ContrerasMay 7, 2012
  24. SZEDER GáborMay 7, 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.