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

Re: [PATCH 4/9] help: add --config to list all available config

From
Eric Sunshine <sunshine@sunshineco.com>
Date
May 11, 2018, 22:39 UTC
Message-ID
<CAPig+cR63S-cpihwHYOadK_SbNRoCVjOOQH87Ry7fdCwxdbOxg@mail.gmail.com>
In-Reply-To
<20180510141927.23590-5-pclouds@gmail.com>

On Thu, May 10, 2018 at 10:20 AM Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:

> Sometimes it helps to list all available config vars so the user can
> search for something they want. The config man page can also be used
> but it's harder to search if you want to focus on the variable name,
> for example.
Show 5 quoted lines
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> diff --git a/builtin/help.c b/builtin/help.c
> @@ -44,6 +45,7 @@ static struct option builtin_help_options[] = {
>          OPT_BOOL('g', "guides", &show_guides, N_("print list of useful
guides")),
> +       OPT_BOOL('c', "config", &show_config, N_("print list recognized
config variables")),
s/list/& of/
Though, simpler might be better: "print all configuration variable names"
Show 9 quoted lines
> diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh
> @@ -76,6 +76,24 @@ print_command_list () {
> +print_config_list() {
> +       cat <<EOF
> +static const char *config_name_list[] = {
> +EOF
> +       grep '^[a-zA-Z].*\..*::$' Documentation/config.txt |
> +       grep -v deprecated |
> +       sed 's/::$//; s/,  */\n/g' |
Nit: "grep -v" and "sed" could be combined:
     sed '/deprecated/d; s/::$//; s/,  */\n/g' |
Show 21 quoted lines
> +       sort |
> +       while read line
> +       do
> +               echo "  \"$line\","
> +       done
> +       cat <<EOF
> +       NULL,
> +};
> +EOF
> diff --git a/help.c b/help.c
> @@ -409,6 +409,54 @@ void list_common_guides_help(void)
> +void list_config_help(void)
> +{
> +       [...]
> +       for (p = config_name_list; *p; p++) {
> +               const char *var = *p;
> +
> +               for (e = slot_expansions; e->prefix; e++) {
> +                       struct strbuf sb = STRBUF_INIT;
> +
> +                       strbuf_addf(&sb, "%s.%s", e->prefix,
e->placeholder);
> +                       if (strcasecmp(var, sb.buf))
> +                               continue;

Isn't this "continue" leaking the strbuf? It seems that it would be easier to declare the strbuf once outside the loop, strbuf_reset() it at the top of the loop, and finally strbuf_release() it after the loop exits.

Show 8 quoted lines
> +                       e->fn(e->prefix);
> +                       strbuf_release(&sb);
> +                       e->found++;
> +                       break;
> +               }
> +               if (!e->prefix)
> +                       puts(var);
> +       }
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 17 of 36 in “completion: avoid hard coding config var list”
  1. 0/9 completion: avoid hard coding config var listNguyễn Thái Ngọc Duy, May 10, 2018
  2. 1/9 Add and use generic name->id mapping code for color slot parsingNguyễn Thái Ngọc Duy, May 10, 2018
  3. Stefan BellerMay 10, 2018
  4. Duy NguyenMay 11, 2018
  5. 3/9 fsck: factor out msg_id_info[] lazy initialization codeNguyễn Thái Ngọc Duy, May 10, 2018
  6. Eric SunshineMay 11, 2018
  7. 2/9 grep: keep all colors in an arrayNguyễn Thái Ngọc Duy, May 10, 2018
  8. 8/9 completion: support case-insensitive config vars just a bitNguyễn Thái Ngọc Duy, May 10, 2018
  9. SZEDER GáborMay 20, 2018
  10. 7/9 completion: drop the hard coded list of config varsNguyễn Thái Ngọc Duy, May 10, 2018
  11. Eric SunshineMay 11, 2018
  12. SZEDER GáborMay 20, 2018
  13. 6/9 am: move advice.amWorkDir parsing back to advice.cNguyễn Thái Ngọc Duy, May 10, 2018
  14. Eric SunshineMay 11, 2018
  15. 9/9 log-tree: allow to customize 'grafted' colorNguyễn Thái Ngọc Duy, May 10, 2018
  16. 4/9 help: add --config to list all available configNguyễn Thái Ngọc Duy, May 10, 2018
  17. Eric SunshineMay 11, 2018
  18. 5/9 advice: keep config name in camelCase in advice_config[]Nguyễn Thái Ngọc Duy, May 10, 2018
  19. Duy NguyenMay 10, 2018
  20. Junio C HamanoMay 11, 2018
  21. Duy NguyenMay 11, 2018
  22. 00/11 completion: avoid hard coding config var listNguyễn Thái Ngọc Duy, May 26, 2018
  23. 01/11 Add and use generic name->id mapping code for color slot parsingNguyễn Thái Ngọc Duy, May 26, 2018
  24. Stefan BellerMay 29, 2018
  25. 04/11 help: add --config to list all available configNguyễn Thái Ngọc Duy, May 26, 2018
  26. Eric SunshineMay 27, 2018
  27. 09/11 completion: keep other config var completion in camelCaseNguyễn Thái Ngọc Duy, May 26, 2018
  28. 07/11 am: move advice.amWorkDir parsing back to advice.cNguyễn Thái Ngọc Duy, May 26, 2018
  29. 11/11 log-tree: allow to customize 'grafted' colorNguyễn Thái Ngọc Duy, May 26, 2018
  30. 12/11 completion: complete general config vars in two stepsNguyễn Thái Ngọc Duy, May 27, 2018
  31. 10/11 completion: support case-insensitive config varsNguyễn Thái Ngọc Duy, May 26, 2018
  32. 03/11 fsck: factor out msg_id_info[] lazy initialization codeNguyễn Thái Ngọc Duy, May 26, 2018
  33. 08/11 completion: drop the hard coded list of config varsNguyễn Thái Ngọc Duy, May 26, 2018
  34. 02/11 grep: keep all colors in an arrayNguyễn Thái Ngọc Duy, May 26, 2018
  35. 06/11 advice: keep config name in camelCase in advice_config[]Nguyễn Thái Ngọc Duy, May 26, 2018
  36. 05/11 fsck: produce camelCase config key namesNguyễn Thái Ngọc Duy, May 26, 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.