help: move column config discovery to help.c library

When a git_config() call was added in dbfae689690 (help: reuse print_columns() for help -a, 2012-04-13) to read the column config we'd always use the resulting "colopts" variable. Then in 63eae83f8f3 (help: add "-a --verbose" to list all commands with synopsis, 2018-05-20) we started only using the "colopts" config under "--all" if "--no-verbose" was also given, but the "git_config()" call was not moved inside the "verbose" branch of the code. This change effectively does that, we'll only call list_commands() under "--all --no-verbose", so let's have it look up the config it needs. See 26c7d067832 (help -a: improve and make --verbose default, 2018-09-29) for another case in help.c where we look up config. The get_colopts() function is named for consistency with the existing get_alias() function added in 26c7d067832. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Sep 22, 2021 at 00:40 UTC 06fa4db3f7e450deb0bb849b338d7a5453f0d183
3 files changed +16 -9
builtin/help.c
+1 -6
@@ -7,7 +7,6 @@
7 #include "exec-cmd.h"
8 #include "parse-options.h"
9 #include "run-command.h"
10 -#include "column.h"
10 #include "config-list.h"
11 #include "help.h"
12 #include "alias.h"
@@ -50,7 +49,6 @@ static enum help_action {
49
50 static const char *html_path;
51 static int verbose = 1;
53 -static unsigned int colopts;
52 static enum help_format help_format = HELP_FORMAT_NONE;
53 static int exclude_guides;
54 static struct option builtin_help_options[] = {
@@ -384,8 +382,6 @@ static int add_man_viewer_info(const char *var, const char *value)
382
383 static int git_help_config(const char *var, const char *value, void *cb)
384 {
387 - if (starts_with(var, "column."))
388 - return git_column_config(var, value, "help", &colopts);
385 if (!strcmp(var, "help.format")) {
386 if (!value)
387 return config_error_nonbool(var);
@@ -595,7 +591,6 @@ int cmd_help(int argc, const char **argv, const char *prefix)
591
592 switch (cmd_mode) {
593 case HELP_ACTION_ALL:
598 - git_config(git_help_config, NULL);
594 if (verbose) {
595 setup_pager();
596 list_all_cmds_help();
@@ -603,7 +598,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)
598 }
599 printf(_("usage: %s%s"), _(git_usage_string), "\n\n");
600 load_command_list("git-", &main_cmds, &other_cmds);
606 - list_commands(colopts, &main_cmds, &other_cmds);
601 + list_commands(&main_cmds, &other_cmds);
602 printf("%s\n", _(git_more_info_string));
603 break;
604 case HELP_ACTION_GUIDES:
help.c
+14 -2
@@ -293,9 +293,21 @@ void load_command_list(const char *prefix,
293 exclude_cmds(other_cmds, main_cmds);
294 }
295
296 -void list_commands(unsigned int colopts,
297 - struct cmdnames *main_cmds, struct cmdnames *other_cmds)
296 +static int get_colopts(const char *var, const char *value, void *data)
297 {
298 + unsigned int *colopts = data;
299 +
300 + if (starts_with(var, "column."))
301 + return git_column_config(var, value, "help", colopts);
302 +
303 + return 0;
304 +}
305 +
306 +void list_commands(struct cmdnames *main_cmds, struct cmdnames *other_cmds)
307 +{
308 + unsigned int colopts = 0;
309 + git_config(get_colopts, &colopts);
310 +
311 if (main_cmds->cnt) {
312 const char *exec_path = git_exec_path();
313 printf_ln(_("available git commands in '%s'"), exec_path);
help.h
+1 -1
@@ -37,7 +37,7 @@ void add_cmdname(struct cmdnames *cmds, const char *name, int len);
37 /* Here we require that excludes is a sorted list. */
38 void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes);
39 int is_in_cmdlist(struct cmdnames *cmds, const char *name);
40 -void list_commands(unsigned int colopts, struct cmdnames *main_cmds, struct cmdnames *other_cmds);
40 +void list_commands(struct cmdnames *main_cmds, struct cmdnames *other_cmds);
41 void get_version_info(struct strbuf *buf, int show_build_options);
42
43 /*