};
static const char * const builtin_help_usage[] = {
- "git-help [--all] [--man|--web|--info] [command]",
+ "git help [--all] [--man|--web|--info] [command]",
NULL
};
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;
add_cmdname(cmds, de->d_name + prefix_len, entlen);
}
closedir(dir);
+ strbuf_release(&buf);
return longest;
}
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);
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)