Skip to content

Commit 06fa4db

Browse files
avargitster
authored andcommitted
help: move column config discovery to help.c library
When a git_config() call was added in dbfae68 (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 63eae83 (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 26c7d06 (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 26c7d06. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a9baccc commit 06fa4db

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

builtin/help.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "exec-cmd.h"
88
#include "parse-options.h"
99
#include "run-command.h"
10-
#include "column.h"
1110
#include "config-list.h"
1211
#include "help.h"
1312
#include "alias.h"
@@ -50,7 +49,6 @@ static enum help_action {
5049

5150
static const char *html_path;
5251
static int verbose = 1;
53-
static unsigned int colopts;
5452
static enum help_format help_format = HELP_FORMAT_NONE;
5553
static int exclude_guides;
5654
static struct option builtin_help_options[] = {
@@ -384,8 +382,6 @@ static int add_man_viewer_info(const char *var, const char *value)
384382

385383
static int git_help_config(const char *var, const char *value, void *cb)
386384
{
387-
if (starts_with(var, "column."))
388-
return git_column_config(var, value, "help", &colopts);
389385
if (!strcmp(var, "help.format")) {
390386
if (!value)
391387
return config_error_nonbool(var);
@@ -595,15 +591,14 @@ int cmd_help(int argc, const char **argv, const char *prefix)
595591

596592
switch (cmd_mode) {
597593
case HELP_ACTION_ALL:
598-
git_config(git_help_config, NULL);
599594
if (verbose) {
600595
setup_pager();
601596
list_all_cmds_help();
602597
return 0;
603598
}
604599
printf(_("usage: %s%s"), _(git_usage_string), "\n\n");
605600
load_command_list("git-", &main_cmds, &other_cmds);
606-
list_commands(colopts, &main_cmds, &other_cmds);
601+
list_commands(&main_cmds, &other_cmds);
607602
printf("%s\n", _(git_more_info_string));
608603
break;
609604
case HELP_ACTION_GUIDES:

help.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,21 @@ void load_command_list(const char *prefix,
293293
exclude_cmds(other_cmds, main_cmds);
294294
}
295295

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)
298297
{
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+
299311
if (main_cmds->cnt) {
300312
const char *exec_path = git_exec_path();
301313
printf_ln(_("available git commands in '%s'"), exec_path);

help.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void add_cmdname(struct cmdnames *cmds, const char *name, int len);
3737
/* Here we require that excludes is a sorted list. */
3838
void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes);
3939
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);
4141
void get_version_info(struct strbuf *buf, int show_build_options);
4242

4343
/*

0 commit comments

Comments
 (0)