Skip to content

Commit d5659f8

Browse files
rybakgitster
authored andcommitted
help: convert git_cmd to page in one place
Depending on the chosen format of help pages, git-help uses function show_man_page, show_info_page, or show_html_page. The first thing all three functions do is to convert given `git_cmd` to a `page` using function cmd_to_page. Move the common part of these three functions to function cmd_help to avoid code duplication. Signed-off-by: Andrei Rybak <[email protected]> Reviewed-by: Felipe Contreras <[email protected]> Acked-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 670b81a commit d5659f8

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

builtin/help.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,9 @@ static void exec_viewer(const char *name, const char *page)
436436
warning(_("'%s': unknown man viewer."), name);
437437
}
438438

439-
static void show_man_page(const char *git_cmd)
439+
static void show_man_page(const char *page)
440440
{
441441
struct man_viewer_list *viewer;
442-
const char *page = cmd_to_page(git_cmd);
443442
const char *fallback = getenv("GIT_MAN_VIEWER");
444443

445444
setup_man_path();
@@ -453,9 +452,8 @@ static void show_man_page(const char *git_cmd)
453452
die(_("no man viewer handled the request"));
454453
}
455454

456-
static void show_info_page(const char *git_cmd)
455+
static void show_info_page(const char *page)
457456
{
458-
const char *page = cmd_to_page(git_cmd);
459457
setenv("INFOPATH", system_path(GIT_INFO_PATH), 1);
460458
execlp("info", "info", "gitman", page, (char *)NULL);
461459
die(_("no info viewer handled the request"));
@@ -486,9 +484,8 @@ static void open_html(const char *path)
486484
execl_git_cmd("web--browse", "-c", "help.browser", path, (char *)NULL);
487485
}
488486

489-
static void show_html_page(const char *git_cmd)
487+
static void show_html_page(const char *page)
490488
{
491-
const char *page = cmd_to_page(git_cmd);
492489
struct strbuf page_path; /* it leaks but we exec bellow */
493490

494491
get_html_page_path(&page_path, page);
@@ -548,6 +545,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)
548545
{
549546
int nongit;
550547
enum help_format parsed_help_format;
548+
const char *page;
551549

552550
argc = parse_options(argc, argv, prefix, builtin_help_options,
553551
builtin_help_usage, 0);
@@ -606,16 +604,17 @@ int cmd_help(int argc, const char **argv, const char *prefix)
606604

607605
argv[0] = check_git_cmd(argv[0]);
608606

607+
page = cmd_to_page(argv[0]);
609608
switch (help_format) {
610609
case HELP_FORMAT_NONE:
611610
case HELP_FORMAT_MAN:
612-
show_man_page(argv[0]);
611+
show_man_page(page);
613612
break;
614613
case HELP_FORMAT_INFO:
615-
show_info_page(argv[0]);
614+
show_info_page(page);
616615
break;
617616
case HELP_FORMAT_WEB:
618-
show_html_page(argv[0]);
617+
show_html_page(page);
619618
break;
620619
}
621620

0 commit comments

Comments
 (0)