[PATCH 2/2] help (Windows): Display HTML in default browser using Win32 API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The Win32 API is now called directly to launch the system's default
browser for displaying HTML help pages instead of launching a shell to
execute git-web--browser.  Avoiding the 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.

This commit also adds make_native_separator() to convert slashes to
backslashes on Windows.

Signed-off-by: Steffen Prohaska <prohaska@xxxxxx>
---
 cache.h |    2 ++
 help.c  |   18 ++++++++++++++++++
 path.c  |   18 ++++++++++++++++++
 3 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/cache.h b/cache.h
index 35a9132..747581f 100644
--- a/cache.h
+++ b/cache.h
@@ -527,6 +527,8 @@ static inline int is_absolute_path(const char *path)
 const char *make_absolute_path(const char *path);
 const char *make_nonrelative_path(const char *path);
 const char *make_relative_path(const char *abs, const char *base);
+/* Convert slashes to backslashes on Windows.  no-op on other platforms. */
+const char *make_native_separator(const char *path);
 
 /* Read and unpack a sha1 file into memory, write memory to a sha1 file */
 extern int sha1_object_info(const unsigned char *, unsigned long *);
diff --git a/help.c b/help.c
index 5586e1d..8fcd644 100644
--- a/help.c
+++ b/help.c
@@ -9,6 +9,7 @@
 #include "common-cmds.h"
 #include "parse-options.h"
 #include "run-command.h"
+#include "dir.h"
 
 static struct man_viewer_list {
 	struct man_viewer_list *next;
@@ -650,6 +651,19 @@ static void get_html_page_path(struct strbuf *page_path, const char *page)
 	strbuf_addf(page_path, "%s/%s.html", html_path, page);
 }
 
+#ifdef __MINGW32__
+static void open_html_win(const char *unixpath)
+{
+	const char *htmlpath = make_native_separator(mkpath("%s",unixpath));
+	if (!file_exists(htmlpath)) {
+		fprintf(stderr, "HTML file '%s' does not exist.\n", htmlpath);
+		exit(1);
+	}
+	printf("Launching default browser to display HTML help ...\n");
+	ShellExecute(NULL, "open", htmlpath, NULL, "\\", 0);
+}
+#endif
+
 static void show_html_page(const char *git_cmd)
 {
 	const char *page = cmd_to_page(git_cmd);
@@ -657,7 +671,11 @@ static void show_html_page(const char *git_cmd)
 
 	get_html_page_path(&page_path, page);
 
+#ifdef __MINGW32__
+	open_html_win(page_path.buf);
+#else
 	execl_git_cmd("web--browse", "-c", "help.browser", page_path.buf, NULL);
+#endif
 }
 
 void help_unknown_cmd(const char *cmd)
diff --git a/path.c b/path.c
index 496123c..9f2bd91 100644
--- a/path.c
+++ b/path.c
@@ -343,3 +343,21 @@ const char *make_relative_path(const char *abs, const char *base)
 	strcpy(buf, abs + baselen);
 	return buf;
 }
+
+const char *make_native_separator(const char* path) {
+#ifdef __MINGW32__
+	static char buf[PATH_MAX + 1];
+	char* c;
+
+	if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
+		die ("Too long path: %.*s", 60, path);
+
+	for (c = buf; *c; c++) {
+		if (*c == '/')
+			*c = '\\';
+	}
+	return buf;
+#else
+	return path;
+#endif
+}
-- 
1.5.6.1.282.gd8a0d

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux