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

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

From
Duy Nguyen <pclouds@gmail.com>
Date
Mar 22, 2018, 05:12 UTC
Message-ID
<CACsJy8CWWSixQpXDh+q108j4xF8vpm5gsj2u3gJEgW=2bnXQHA@mail.gmail.com>
In-Reply-To
<xmqqd0zxno0j.fsf@gitster-ct.c.googlers.com>
On Wed, Mar 21, 2018 at 9:59 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 56 quoted lines
> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
>
>> 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 ...
>
>> +_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?
>

Yeah. I almost went to just generate and eval these functions. But we still need to keep a list of "bultin with --git-completion-helper" support somewhere, and people may want to complete arguments without double dashes (e.g. read-tree should take a ref...) which can't be helped by --git-completion-helper.

-- 
Duy
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 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.