Code

do not force write of packed refs
[git.git] / help.c
diff --git a/help.c b/help.c
index ca9632b6c58267776086f48e87e2236ff1f6053f..dc0786d8002ef633cae4485eb5b25cdb6cf17df4 100644 (file)
--- a/help.c
+++ b/help.c
@@ -40,7 +40,7 @@ static struct option builtin_help_options[] = {
 };
 
 static const char * const builtin_help_usage[] = {
-       "git-help [--all] [--man|--web|--info] [command]",
+       "git help [--all] [--man|--web|--info] [command]",
        NULL
 };
 
@@ -425,17 +425,24 @@ static unsigned int list_commands_in_dir(struct cmdnames *cmds,
        int prefix_len = strlen(prefix);
        DIR *dir = opendir(path);
        struct dirent *de;
+       struct strbuf buf = STRBUF_INIT;
+       int len;
 
-       if (!dir || chdir(path))
+       if (!dir)
                return 0;
 
+       strbuf_addf(&buf, "%s/", path);
+       len = buf.len;
+
        while ((de = readdir(dir)) != NULL) {
                int entlen;
 
                if (prefixcmp(de->d_name, prefix))
                        continue;
 
-               if (!is_executable(de->d_name))
+               strbuf_setlen(&buf, len);
+               strbuf_addstr(&buf, de->d_name);
+               if (!is_executable(buf.buf))
                        continue;
 
                entlen = strlen(de->d_name) - prefix_len;
@@ -448,6 +455,7 @@ static unsigned int list_commands_in_dir(struct cmdnames *cmds,
                add_cmdname(cmds, de->d_name + prefix_len, entlen);
        }
        closedir(dir);
+       strbuf_release(&buf);
 
        return longest;
 }
@@ -547,7 +555,8 @@ static int is_git_command(const char *s)
 {
        load_command_list();
        return is_in_cmdlist(&main_cmds, s) ||
-               is_in_cmdlist(&other_cmds, s);
+               is_in_cmdlist(&other_cmds, s) ||
+               !strcmp(s, "help");
 }
 
 static const char *prepend(const char *prefix, const char *cmd)
@@ -633,15 +642,29 @@ static void show_info_page(const char *git_cmd)
 static void get_html_page_path(struct strbuf *page_path, const char *page)
 {
        struct stat st;
+       const char *html_path = system_path(GIT_HTML_PATH);
 
        /* Check that we have a git documentation directory. */
-       if (stat(GIT_HTML_PATH "/git.html", &st) || !S_ISREG(st.st_mode))
-               die("'%s': not a documentation directory.", GIT_HTML_PATH);
+       if (stat(mkpath("%s/git.html", html_path), &st)
+           || !S_ISREG(st.st_mode))
+               die("'%s': not a documentation directory.", html_path);
 
        strbuf_init(page_path, 0);
-       strbuf_addf(page_path, GIT_HTML_PATH "/%s.html", page);
+       strbuf_addf(page_path, "%s/%s.html", html_path, page);
 }
 
+/*
+ * If open_html is not defined in a platform-specific way (see for
+ * example compat/mingw.h), we use the script web--browse to display
+ * HTML.
+ */
+#ifndef open_html
+void open_html(const char *path)
+{
+       execl_git_cmd("web--browse", "-c", "help.browser", path, NULL);
+}
+#endif
+
 static void show_html_page(const char *git_cmd)
 {
        const char *page = cmd_to_page(git_cmd);
@@ -649,7 +672,7 @@ static void show_html_page(const char *git_cmd)
 
        get_html_page_path(&page_path, page);
 
-       execl_git_cmd("web--browse", "-c", "help.browser", page_path.buf, NULL);
+       open_html(page_path.buf);
 }
 
 void help_unknown_cmd(const char *cmd)