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

Re: [PATCH 2/5] git-completion.bash: rename to $__git_cmd_idx

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Apr 20, 2021, 21:14 UTC
Message-ID
<20210420211432.GA3842406@szeder.dev>
In-Reply-To
<xmqqr1j44r5g.fsf@gitster.g>
On Tue, Apr 20, 2021 at 01:50:19PM -0700, Junio C Hamano wrote:
Show 21 quoted lines
> Denton Liu <liu.denton@gmail.com> writes:
> 
> > In e94fb44042 (git-completion.bash: pass $__git_subcommand_idx from
> > __git_main(), 2021-03-24), the $__git_subcommand_idx variable was
> > introduced. Naming it after the index of the subcommand is flat-out
> > wrong as this variable really holds the index of the git comand (e.g.
> 
> comand -> command
> 
> > "stash").
> >
> > Rename this variable so that it's obvious it's about git commands. While
> > we're at it, shorten up its name so that it's still readable without
> > being a handful to type.
> 
> As the patch has already written, I won't complain too much, but to
> many people "git" is a command and "add", "commit" etc. are
> subcommands of "git", so I do not see git_subcommand_idx so wrong
> that it needs to be renamed.  I do understand that it is a bit too
> long and it may be easier to type if renamed to say git_cmd_idx,
> though ;-)

The completion functions for git commands having subcommands usually start like this:

    _git_remote ()
    {
        local subcommands="
                add rename remove set-head set-branches
                get-url set-url show prune update
                "
        local subcommand="$(__git_find_on_cmdline "$subcommands")"
        if [ -z "$subcommand" ]; then

__git_subcommand_idx holds the index of the word "remote", not the index of "add/rename/etc.", so in the context of the completion script that name is misleading.

Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 18 in “git-completion.bash: fixes on top of 'dl/complete-stash'”
  1. 0/5 git-completion.bash: fixes on top of 'dl/complete-stash'Denton Liu, Apr 20, 2021
  2. 1/5 git-completion.bash: separate some commands onto their own lineDenton Liu, Apr 20, 2021
  3. 2/5 git-completion.bash: rename to $__git_cmd_idxDenton Liu, Apr 20, 2021
  4. Junio C HamanoApr 20, 2021
  5. SZEDER GáborApr 20, 2021
  6. Junio C HamanoApr 20, 2021
  7. 3/5 git-completion.bash: use $__git_cmd_idx in more placesDenton Liu, Apr 20, 2021
  8. 4/5 git-completion.bash: consolidate cases in _git_stash()Denton Liu, Apr 20, 2021
  9. Ævar Arnfjörð BjarmasonApr 20, 2021
  10. Denton LiuApr 21, 2021
  11. 5/5 git-completion.bash: consolidate no-subcommand case for _git_stash()Denton Liu, Apr 20, 2021
  12. Junio C HamanoApr 20, 2021
  13. Denton LiuApr 21, 2021
  14. 0/4 git-completion.bash: fixes on top of 'dl/complete-stash'Denton Liu, Apr 22, 2021
  15. 1/4 git-completion.bash: separate some commands onto their own lineDenton Liu, Apr 22, 2021
  16. 2/4 git-completion.bash: rename to $__git_cmd_idxDenton Liu, Apr 22, 2021
  17. 4/4 git-completion.bash: consolidate cases in _git_stash()Denton Liu, Apr 22, 2021
  18. 3/4 git-completion.bash: use $__git_cmd_idx in more placesDenton Liu, Apr 22, 2021

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.