Code

Merge branch 'jc/maint-limit-note-output'
[git.git] / builtin-help.c
index f076efa9211ddcffdc81ffd7c0c56fdb197a11b0..3182a2bec466c50a9a1db1e91888bad3335414b1 100644 (file)
@@ -23,13 +23,14 @@ static struct man_viewer_info_list {
 } *man_viewer_info_list;
 
 enum help_format {
+       HELP_FORMAT_NONE,
        HELP_FORMAT_MAN,
        HELP_FORMAT_INFO,
        HELP_FORMAT_WEB,
 };
 
 static int show_all = 0;
-static enum help_format help_format = HELP_FORMAT_MAN;
+static enum help_format help_format = HELP_FORMAT_NONE;
 static struct option builtin_help_options[] = {
        OPT_BOOLEAN('a', "all", &show_all, "print all available commands"),
        OPT_SET_INT('m', "man", &help_format, "show man page", HELP_FORMAT_MAN),
@@ -80,10 +81,9 @@ static int check_emacsclient_version(void)
        ec_process.argv = argv_ec;
        ec_process.err = -1;
        ec_process.stdout_to_stderr = 1;
-       if (start_command(&ec_process)) {
-               fprintf(stderr, "Failed to start emacsclient.\n");
-               return -1;
-       }
+       if (start_command(&ec_process))
+               return error("Failed to start emacsclient.");
+
        strbuf_read(&buffer, ec_process.err, 20);
        close(ec_process.err);
 
@@ -94,27 +94,24 @@ static int check_emacsclient_version(void)
        finish_command(&ec_process);
 
        if (prefixcmp(buffer.buf, "emacsclient")) {
-               fprintf(stderr, "Failed to parse emacsclient version.\n");
                strbuf_release(&buffer);
-               return -1;
+               return error("Failed to parse emacsclient version.");
        }
 
        strbuf_remove(&buffer, 0, strlen("emacsclient"));
        version = atoi(buffer.buf);
 
        if (version < 22) {
-               fprintf(stderr,
-                       "emacsclient version '%d' too old (< 22).\n",
-                       version);
                strbuf_release(&buffer);
-               return -1;
+               return error("emacsclient version '%d' too old (< 22).",
+                       version);
        }
 
        strbuf_release(&buffer);
        return 0;
 }
 
-static void exec_woman_emacs(const charpath, const char *page)
+static void exec_woman_emacs(const char *path, const char *page)
 {
        if (!check_emacsclient_version()) {
                /* This works only with emacsclient version >= 22. */
@@ -128,7 +125,7 @@ static void exec_woman_emacs(const char* path, const char *page)
        }
 }
 
-static void exec_man_konqueror(const charpath, const char *page)
+static void exec_man_konqueror(const char *path, const char *page)
 {
        const char *display = getenv("DISPLAY");
        if (display && *display) {
@@ -156,7 +153,7 @@ static void exec_man_konqueror(const char* path, const char *page)
        }
 }
 
-static void exec_man_man(const charpath, const char *page)
+static void exec_man_man(const char *path, const char *page)
 {
        if (!path)
                path = "man";
@@ -236,7 +233,7 @@ static int add_man_viewer_info(const char *var, const char *value)
        const char *subkey = strrchr(name, '.');
 
        if (!subkey)
-               return error("Config with no key for man viewer: %s", name);
+               return 0;
 
        if (!strcmp(subkey, ".path")) {
                if (!value)
@@ -249,7 +246,6 @@ static int add_man_viewer_info(const char *var, const char *value)
                return add_man_viewer_cmd(name, subkey - name, value);
        }
 
-       warning("'%s': unsupported man viewer sub key.", subkey);
        return 0;
 }
 
@@ -329,7 +325,7 @@ static void setup_man_path(void)
         * old_path, the ':' at the end will let 'man' to try
         * system-wide paths after ours to find the manual page. If
         * there is old_path, we need ':' as delimiter. */
-       strbuf_addstr(&new_path, GIT_MAN_PATH);
+       strbuf_addstr(&new_path, system_path(GIT_MAN_PATH));
        strbuf_addch(&new_path, ':');
        if (old_path)
                strbuf_addstr(&new_path, old_path);
@@ -375,8 +371,9 @@ static void show_man_page(const char *git_cmd)
 static void show_info_page(const char *git_cmd)
 {
        const char *page = cmd_to_page(git_cmd);
-       setenv("INFOPATH", GIT_INFO_PATH, 1);
+       setenv("INFOPATH", system_path(GIT_INFO_PATH), 1);
        execlp("info", "info", "gitman", page, NULL);
+       die("no info viewer handled the request");
 }
 
 static void get_html_page_path(struct strbuf *page_path, const char *page)
@@ -399,7 +396,7 @@ static void get_html_page_path(struct strbuf *page_path, const char *page)
  * HTML.
  */
 #ifndef open_html
-void open_html(const char *path)
+static void open_html(const char *path)
 {
        execl_git_cmd("web--browse", "-c", "help.browser", path, NULL);
 }
@@ -419,13 +416,12 @@ int cmd_help(int argc, const char **argv, const char *prefix)
 {
        int nongit;
        const char *alias;
+       enum help_format parsed_help_format;
        load_command_list("git-", &main_cmds, &other_cmds);
 
-       setup_git_directory_gently(&nongit);
-       git_config(git_help_config, NULL);
-
-       argc = parse_options(argc, argv, builtin_help_options,
+       argc = parse_options(argc, argv, prefix, builtin_help_options,
                        builtin_help_usage, 0);
+       parsed_help_format = help_format;
 
        if (show_all) {
                printf("usage: %s\n\n", git_usage_string);
@@ -441,6 +437,12 @@ int cmd_help(int argc, const char **argv, const char *prefix)
                return 0;
        }
 
+       setup_git_directory_gently(&nongit);
+       git_config(git_help_config, NULL);
+
+       if (parsed_help_format != HELP_FORMAT_NONE)
+               help_format = parsed_help_format;
+
        alias = alias_lookup(argv[0]);
        if (alias && !is_git_command(argv[0])) {
                printf("`git %s' is aliased to `%s'\n", argv[0], alias);
@@ -448,6 +450,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)
        }
 
        switch (help_format) {
+       case HELP_FORMAT_NONE:
        case HELP_FORMAT_MAN:
                show_man_page(argv[0]);
                break;