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

RE: [PATCH] parse-options: don't complete option aliases by default

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Jul 15, 2021, 17:04 UTC
Message-ID
<60f06a8a8e611_4b68208a9@natae.notmuch>
In-Reply-To
<pull.996.git.1626353925051.gitgitgadget@gmail.com>
Philippe Blain via GitGitGadget wrote:
Show 19 quoted lines
> From: Philippe Blain <levraiphilippeblain@gmail.com>
> 
> Since 'OPT_ALIAS' was created in 5c387428f1 (parse-options: don't emit
> "ambiguous option" for aliases, 2019-04-29), 'git clone
> --git-completion-helper', which is used by the Bash completion script to
> list options accepted by clone (via '__gitcomp_builtin'), lists both
> '--recurse-submodules' and its alias '--recursive', which was not the
> case before since '--recursive' had the PARSE_OPT_HIDDEN flag set, and
> options with this flag are skipped by 'parse-options.c::show_gitcomp',
> which implements 'git <cmd> --git-completion-helper'.
> 
> At the point where 'show_gitcomp' is called in 'parse_options_step',
> 'preprocess_options' was already called in 'parse_options', so any
> aliases are now copies of the original options with a modified help text
> indicating they are aliases.
> 
> Helpfully, since 64cc539fd2 (parse-options: don't leak alias help
> messages, 2021-03-21) these copies have the PARSE_OPT_FROM_ALIAS flag
> set, so check that flag early in 'show_gitcomp' and do not print them,

Makes sense but I don't think what the patch is doing should be buried here. I think a separate paragraph explaining what you are trying to do will be better.

Show 15 quoted lines
> unless the user explicitely requested that *all* completion be shown (by
> setting 'GIT_COMPLETION_SHOW_ALL'). After all, if we want to encourage
> the use of '--recurse-submodules' over '--recursive', we'd better just
> suggest the former.
> 
> The only other options alias is 'log' and friends' '--mailmap', which is
> an alias for '--use-mailmap', but the Bash completion helpers for these
> commands do not use '__gitcomp_builtin', and thus are unnaffected by
> this change.
> 
> Test the new behaviour in t9902-completion.sh. As a side effect, this
> also tests the correct behaviour of GIT_COMPLETION_SHOW_ALL, which was
> not tested before. Note that since '__gitcomp_builtin' caches the
> options it shows, we need to re-source the completion script to clear
> that cache for the second test.
I agree this is better, and the patch itself looks obviously correct.
Reviewed-by: Felipe Contreras <felipe.contreras@gmail.com>
-- 
Felipe Contreras
Previous: Philippe BlainNext: Philippe Blain
Message 7 of 9 in “parse-options: don't complete option aliases by default”
  1. parse-options: don't complete option aliases by defaultPhilippe Blain via GitGitGadget, Jul 15, 2021
  2. Ævar Arnfjörð BjarmasonJul 15, 2021
  3. Felipe ContrerasJul 15, 2021
  4. Junio C HamanoJul 15, 2021
  5. Philippe BlainJul 16, 2021
  6. Philippe BlainJul 16, 2021
  7. Felipe ContrerasJul 15, 2021
  8. Philippe BlainJul 16, 2021
  9. parse-options: don't complete option aliases by defaultPhilippe Blain via GitGitGadget, Jul 16, 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.