Re: [PATCH v2 04/11] help: add --config to list all available config

2018-05-27 Thread Eric Sunshine
On Sat, May 26, 2018 at 9:55 AM, Nguyễn Thái Ngọc Duy  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.
>
> This is not the best way to collect the available config since it's
> not precise. Ideally we should have a centralized list of config in C
> code (pretty much like 'struct option'), but that's a lot more work.
> This will do for now.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy 
> ---
> diff --git a/help.c b/help.c
> @@ -409,6 +409,62 @@ void list_common_guides_help(void)
> +void list_config_help(void)
> +{
> +   for (p = config_name_list; *p; p++) {
> +   const char *var = *p;
> +   struct strbuf sb = STRBUF_INIT;
> +
> +   for (e = slot_expansions; e->prefix; e++) {
> +
> +   strbuf_reset();

Style nit: unwanted blank line

> +   strbuf_addf(, "%s.%s", e->prefix, e->placeholder);
> +   if (!strcasecmp(var, sb.buf)) {
> +   e->fn(, e->prefix);
> +   e->found++;
> +   break;
> +   }
> +   }
> +   strbuf_release();
> +   if (!e->prefix)
> +   string_list_append(, var);
> +   }


[PATCH v2 04/11] help: add --config to list all available config

2018-05-26 Thread Nguyễn Thái Ngọc Duy
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.

This is not the best way to collect the available config since it's
not precise. Ideally we should have a centralized list of config in C
code (pretty much like 'struct option'), but that's a lot more work.
This will do for now.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Documentation/git-help.txt |  5 
 advice.c   |  9 ++
 builtin/branch.c   |  3 ++
 builtin/clean.c|  3 ++
 builtin/commit.c   |  3 ++
 builtin/help.c |  9 ++
 diff.c |  3 ++
 fsck.c | 12 
 generate-cmdlist.sh| 19 +
 grep.c |  3 ++
 help.c | 56 ++
 help.h | 45 +-
 log-tree.c |  3 ++
 13 files changed, 172 insertions(+), 1 deletion(-)

diff --git a/Documentation/git-help.txt b/Documentation/git-help.txt
index a40fc38d8b..83d25d825a 100644
--- a/Documentation/git-help.txt
+++ b/Documentation/git-help.txt
@@ -45,6 +45,11 @@ OPTIONS
When used with `--verbose` print description for all recognized
commands.
 
+-c::
+--config::
+   List all available configuration variables. This is a short
+   summary of the list in linkgit:git-config[1].
+
 -g::
 --guides::
Prints a list of useful guides on the standard output. This
diff --git a/advice.c b/advice.c
index 370a56d054..cf6c673ed7 100644
--- a/advice.c
+++ b/advice.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "config.h"
 #include "color.h"
+#include "help.h"
 
 int advice_push_update_rejected = 1;
 int advice_push_non_ff_current = 1;
@@ -131,6 +132,14 @@ int git_default_advice_config(const char *var, const char 
*value)
return 0;
 }
 
+void list_config_advices(struct string_list *list, const char *prefix)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(advice_config); i++)
+   list_config_item(list, prefix, advice_config[i].name);
+}
+
 int error_resolve_conflict(const char *me)
 {
if (!strcmp(me, "cherry-pick"))
diff --git a/builtin/branch.c b/builtin/branch.c
index 09232576b6..ddc48ca931 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -22,6 +22,7 @@
 #include "wt-status.h"
 #include "ref-filter.h"
 #include "worktree.h"
+#include "help.h"
 
 static const char * const builtin_branch_usage[] = {
N_("git branch [] [-r | -a] [--merged | --no-merged]"),
@@ -67,6 +68,8 @@ static const char *color_branch_slots[] = {
 static struct string_list output = STRING_LIST_INIT_DUP;
 static unsigned int colopts;
 
+define_list_config_array(color_branch_slots);
+
 static int git_branch_config(const char *var, const char *value, void *cb)
 {
const char *slot_name;
diff --git a/builtin/clean.c b/builtin/clean.c
index 0ccd95e693..ab402c204c 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -16,6 +16,7 @@
 #include "column.h"
 #include "color.h"
 #include "pathspec.h"
+#include "help.h"
 
 static int force = -1; /* unset */
 static int interactive;
@@ -91,6 +92,8 @@ struct menu_stuff {
void *stuff;
 };
 
+define_list_config_array(color_interactive_slots);
+
 static int git_clean_config(const char *var, const char *value, void *cb)
 {
const char *slot_name;
diff --git a/builtin/commit.c b/builtin/commit.c
index 2b43a6c48a..9bcbb0c25c 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -32,6 +32,7 @@
 #include "column.h"
 #include "sequencer.h"
 #include "mailmap.h"
+#include "help.h"
 
 static const char * const builtin_commit_usage[] = {
N_("git commit [] [--] ..."),
@@ -1195,6 +1196,8 @@ static int dry_run_commit(int argc, const char **argv, 
const char *prefix,
return commitable ? 0 : 1;
 }
 
+define_list_config_array_extra(color_status_slots, {"added"});
+
 static int parse_status_slot(const char *slot)
 {
if (!strcasecmp(slot, "added"))
diff --git a/builtin/help.c b/builtin/help.c
index 58e0a5507f..ccb206e1d4 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -37,6 +37,7 @@ static const char *html_path;
 
 static int show_all = 0;
 static int show_guides = 0;
+static int show_config;
 static int verbose;
 static unsigned int colopts;
 static enum help_format help_format = HELP_FORMAT_NONE;
@@ -45,6 +46,7 @@ static struct option builtin_help_options[] = {
OPT_BOOL('a', "all", _all, N_("print all available commands")),
OPT_HIDDEN_BOOL(0, "exclude-guides", _guides, N_("exclude 
guides")),
OPT_BOOL('g', "guides", _guides, N_("print list of useful 
guides")),
+   OPT_BOOL('c', "config", _config, N_("print all configuration 
variable names")),
OPT_SET_INT('m', "man", _format, N_("show man page"), 
HELP_FORMAT_MAN),
OPT_SET_INT('w',