@matheusbsbs / matheus-bagliano / commits / 4804aabcdb
Fork 0

help (Windows): Display HTML in default browser using Windows' shell API

The system's default browser for displaying HTML help pages is now used directly on Windows, instead of launching git-web--browser, which requires a Unix shell. Avoiding MSYS' bash when possible is good because it avoids potential path translation issues. In this case it is not too hard to avoid launching a shell, so let's avoid it. The Windows-specific code is implemented in compat/mingw.c to avoid platform-specific code in the main code base. On Windows, open_html is provided as a define. If open_html is not defined, git-web--browse is used. This approach avoids platform-specific ifdefs by using per-function ifdefs. The "ifndef open_html" together with the introductory comment should sufficiently warn developers, so that they hopefully will not break this mechanism. Signed-off-by: Steffen Prohaska <prohaska@zib.de> Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Steffen Prohaska committed Jul 13, 2008 at 22:31 UTC 4804aabcdbffb41dba96825ca2693ea45830a108
3 files changed +38 -1
compat/mingw.c
+22
@@ -1017,3 +1017,25 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler)
1017 timer_fn = handler;
1018 return old;
1019 }
1020 +
1021 +static const char *make_backslash_path(const char *path)
1022 +{
1023 + static char buf[PATH_MAX + 1];
1024 + char *c;
1025 +
1026 + if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
1027 + die("Too long path: %.*s", 60, path);
1028 +
1029 + for (c = buf; *c; c++) {
1030 + if (*c == '/')
1031 + *c = '\\';
1032 + }
1033 + return buf;
1034 +}
1035 +
1036 +void mingw_open_html(const char *unixpath)
1037 +{
1038 + const char *htmlpath = make_backslash_path(unixpath);
1039 + printf("Launching default browser to display HTML ...\n");
1040 + ShellExecute(NULL, "open", htmlpath, NULL, "\\", 0);
1041 +}
compat/mingw.h
+3
@@ -202,6 +202,9 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler);
202 #define PATH_SEP ';'
203 #define PRIuMAX "I64u"
204
205 +void mingw_open_html(const char *path);
206 +#define open_html mingw_open_html
207 +
208 /*
209 * helpers
210 */
help.c
+13 -1
@@ -644,6 +644,18 @@ static void get_html_page_path(struct strbuf *page_path, const char *page)
644 strbuf_addf(page_path, "%s/%s.html", html_path, page);
645 }
646
647 +/*
648 + * If open_html is not defined in a platform-specific way (see for
649 + * example compat/mingw.h), we use the script web--browse to display
650 + * HTML.
651 + */
652 +#ifndef open_html
653 +void open_html(const char *path)
654 +{
655 + execl_git_cmd("web--browse", "-c", "help.browser", path, NULL);
656 +}
657 +#endif
658 +
659 static void show_html_page(const char *git_cmd)
660 {
661 const char *page = cmd_to_page(git_cmd);
@@ -651,7 +663,7 @@ static void show_html_page(const char *git_cmd)
663
664 get_html_page_path(&page_path, page);
665
654 - execl_git_cmd("web--browse", "-c", "help.browser", page_path.buf, NULL);
666 + open_html(page_path.buf);
667 }
668
669 void help_unknown_cmd(const char *cmd)