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 <rybak.a.v@gmail.com> Reviewed-by: Felipe Contreras <felipe.contreras@gmail.com> Acked-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Andrei Rybak committed
Jul 4, 2021 at 17:39 UTC
d5659f856f3084d33d2379958dd3eefd8a24379f
1 file changed
+8
-9
builtin/help.c
+8
-9
@@ -436,10 +436,9 @@ static void exec_viewer(const char *name, const char *page)
436
warning(_("'%s': unknown man viewer."), name);
437
}
438
439
-static void show_man_page(const char *git_cmd)
439
+static void show_man_page(const char *page)
440
{
441
struct man_viewer_list *viewer;
442
- const char *page = cmd_to_page(git_cmd);
442
const char *fallback = getenv("GIT_MAN_VIEWER");
443
444
setup_man_path();
@@ -453,9 +452,8 @@ static void show_man_page(const char *git_cmd)
452
die(_("no man viewer handled the request"));
453
}
454
456
-static void show_info_page(const char *git_cmd)
455
+static void show_info_page(const char *page)
456
{
458
- const char *page = cmd_to_page(git_cmd);
457
setenv("INFOPATH", system_path(GIT_INFO_PATH), 1);
458
execlp("info", "info", "gitman", page, (char *)NULL);
459
die(_("no info viewer handled the request"));
@@ -486,9 +484,8 @@ static void open_html(const char *path)
484
execl_git_cmd("web--browse", "-c", "help.browser", path, (char *)NULL);
485
}
486
489
-static void show_html_page(const char *git_cmd)
487
+static void show_html_page(const char *page)
488
{
491
- const char *page = cmd_to_page(git_cmd);
489
struct strbuf page_path; /* it leaks but we exec bellow */
490
491
get_html_page_path(&page_path, page);
@@ -548,6 +545,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)
545
{
546
int nongit;
547
enum help_format parsed_help_format;
548
+ const char *page;
549
550
argc = parse_options(argc, argv, prefix, builtin_help_options,
551
builtin_help_usage, 0);
@@ -606,16 +604,17 @@ int cmd_help(int argc, const char **argv, const char *prefix)
604
605
argv[0] = check_git_cmd(argv[0]);
606
607
+ page = cmd_to_page(argv[0]);
608
switch (help_format) {
609
case HELP_FORMAT_NONE:
610
case HELP_FORMAT_MAN:
612
- show_man_page(argv[0]);
611
+ show_man_page(page);
612
break;
613
case HELP_FORMAT_INFO:
615
- show_info_page(argv[0]);
614
+ show_info_page(page);
615
break;
616
case HELP_FORMAT_WEB:
618
- show_html_page(argv[0]);
617
+ show_html_page(page);
618
break;
619
}
620