Thread (72 messages) flat view 72 messages, 20 authors, 2016-06-15
STALE3719d

[PATCH 05/12] Windows(msysgit): Per default, display help as HTML in default browser

From: Steffen Prohaska <hidden>
Date: 2016-06-15 22:44:52
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)

The implementation directly calls the Win32 API to launch the browser.
Note that the specific directory layout of msysgit is required.

Signed-off-by: Steffen Prohaska <redacted>
---
 cache.h |    2 ++
 help.c  |   28 ++++++++++++++++++++++++++++
 path.c  |   13 +++++++++++++
 3 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/cache.h b/cache.h
index 0d8edda..958d257 100644
--- a/cache.h
+++ b/cache.h
@@ -529,6 +529,8 @@ const char *make_nonrelative_path(const char *path);
 const char *make_relative_path(const char *abs, const char *base);
 int normalize_absolute_path(char *buf, const char *path);
 int longest_ancestor_length(const char *path, const char *prefix_list);
+/* Convert slashes to backslashes on Windows. */
+char *make_native_separator(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 ca9632b..811f8db 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;
@@ -28,7 +29,11 @@ enum help_format {
 };
 
 static int show_all = 0;
+#ifdef __MINGW32__
+static enum help_format help_format = HELP_FORMAT_WEB;
+#else
 static enum help_format help_format = HELP_FORMAT_MAN;
+#endif
 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),
@@ -644,12 +649,35 @@ static void get_html_page_path(struct strbuf *page_path, const char *page)
 
 static void show_html_page(const char *git_cmd)
 {
+#ifdef __MINGW32__
+	const char* exec_path = git_exec_path();
+	char *htmlpath = make_native_separator(
+			   mkpath("%s/../doc/git/html/%s.html"
+				  , exec_path
+				  , git_cmd)
+			 );
+	if (!file_exists(htmlpath)) {
+		htmlpath = make_native_separator(
+			      mkpath("%s/../doc/git/html/git-%s.html"
+				     , exec_path
+				     , git_cmd)
+			   );
+		if (!file_exists(htmlpath)) {
+			fprintf(stderr, "Can't find HTML help for '%s'.\n"
+				, git_cmd);
+			exit(1);
+		}
+	}
+	printf("Launching default browser to display HTML help ...\n");
+	ShellExecute(NULL, "open", htmlpath, NULL, "\\", 0);
+#else
 	const char *page = cmd_to_page(git_cmd);
 	struct strbuf page_path; /* it leaks but we exec bellow */
 
 	get_html_page_path(&page_path, page);
 
 	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 5983255..2a4a76a 100644
--- a/path.c
+++ b/path.c
@@ -439,3 +439,16 @@ int longest_ancestor_length(const char *path, const char *prefix_list)
 
 	return max_len;
 }
+
+char *make_native_separator(char* path) {
+#ifdef __MINGW32__
+	char* c;
+	for (c = path; *c; c++) {
+		if (*c == '/')
+			*c = '\\';
+	}
+	return path;
+#else
+	return path;
+#endif
+}
-- 
1.5.6.1.255.g32571
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help