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

Re: [PATCH] completion: add option completion for most builtin commands

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 21, 2018, 20:59 UTC
Message-ID
<xmqqd0zxno0j.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20180321193039.19779-1-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
Show 14 quoted lines
> These commands can take options and use parse-options so it's quite
> easy to allow option completion. This does not pollute the command
> name completion though. "git <tab>" will show you the same set as
> before. This only kicks in when you type the correct command name.
>
> Some other builtin commands are not still added because either they
> don't use parse-options, or they are deprecated, or they are those
> -helper commands that are used to move some logic back in C for
> sh-based commands.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  contrib/completion/git-completion.bash | 276 +++++++++++++++++++++++++
>  1 file changed, 276 insertions(+)

Wow, just wow. It however looks a lot of boilerplates, e.g. looking at these, we notice ...

Show 27 quoted lines
> +_git_blame() {
> +	case "$cur" in
> +	--*)
> +		__gitcomp_builtin blame
> +		return
> +		;;
> +	esac
> +}
> +
>  
> +_git_cat_file() {
> +	case "$cur" in
> +	--*)
> +		__gitcomp_builtin cat-file
> +		return
> +		;;
> +	esac
> +}
> +
> +_git_check_attr() {
> +	case "$cur" in
> +	--*)
> +		__gitcomp_builtin check-attr
> +		return
> +		;;
> +	esac
> +}

... the only thing we need for the above three is a table that says "use blame for blame, cat-file for cat_file, and check-attr for check_attr".

And that pattern repeats throughout the patch. I wonder if we can express the same a lot more concisely by updating the caller that calls these command specific helpers?

Previous: Nguyễn Thái Ngọc DuyNext: Duy Nguyen
Message 2 of 18 in “completion: add option completion for most builtin commands”
  1. completion: add option completion for most builtin commandsNguyễn Thái Ngọc Duy, Mar 21, 2018
  2. Junio C HamanoMar 21, 2018
  3. Duy NguyenMar 22, 2018
  4. Junio C HamanoMar 22, 2018
  5. Duy NguyenMar 22, 2018
  6. Junio C HamanoMar 22, 2018
  7. Duy NguyenMar 22, 2018
  8. Duy NguyenMar 24, 2018
  9. 0/8 completion: add option completion for most builtin commandsNguyễn Thái Ngọc Duy, Mar 24, 2018
  10. 1/8 git.c: move cmd_struct declaration upNguyễn Thái Ngọc Duy, Mar 24, 2018
  11. 2/8 git.c: add hidden option --list-parseopt-builtinsNguyễn Thái Ngọc Duy, Mar 24, 2018
  12. 8/8 completion: use __gitcomp_builtin in _git_cherryNguyễn Thái Ngọc Duy, Mar 24, 2018
  13. 4/8 completion: factor out _git_xxx calling codeNguyễn Thái Ngọc Duy, Mar 24, 2018
  14. 7/8 completion: use __gitcomp_builtin in _git_ls_treeNguyễn Thái Ngọc Duy, Mar 24, 2018
  15. 3/8 completion: mention the oldest version we need to supportNguyễn Thái Ngọc Duy, Mar 24, 2018
  16. 6/8 completion: delete option-only completion commandsNguyễn Thái Ngọc Duy, Mar 24, 2018
  17. 5/8 completion: add --option completion for most builtin commandsNguyễn Thái Ngọc Duy, Mar 24, 2018
  18. Eric SunshineMar 25, 2018

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.