From mboxrd@z Thu Jan 1 00:00:00 1970 From: Steffen Prohaska Subject: [PATCH 3/3] help (Windows): Display HTML in default browser using Windows' shell API Date: Fri, 11 Jul 2008 09:28:06 +0200 Message-ID: <1215761286-2489-3-git-send-email-prohaska@zib.de> References: <4668B2FF-2B2B-4221-8151-F0AEA681983C@zib.de> <1215761286-2489-1-git-send-email-prohaska@zib.de> <1215761286-2489-2-git-send-email-prohaska@zib.de> Cc: git@vger.kernel.org, Johannes Schindelin , Steffen Prohaska To: Junio C Hamano , Johannes Sixt X-From: git-owner@vger.kernel.org Fri Jul 11 09:29:34 2008 Return-path: Envelope-to: gcvg-git-2@gmane.org Received: from vger.kernel.org ([209.132.176.167]) by lo.gmane.org with esmtp (Exim 4.50) id 1KHD4O-00033Y-Jn for gcvg-git-2@gmane.org; Fri, 11 Jul 2008 09:29:33 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753669AbYGKH20 (ORCPT ); Fri, 11 Jul 2008 03:28:26 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753772AbYGKH20 (ORCPT ); Fri, 11 Jul 2008 03:28:26 -0400 Received: from mailer.zib.de ([130.73.108.11]:49543 "EHLO mailer.zib.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752545AbYGKH2Z (ORCPT ); Fri, 11 Jul 2008 03:28:25 -0400 Received: from mailsrv2.zib.de (sc2.zib.de [130.73.108.31]) by mailer.zib.de (8.13.7+Sun/8.13.7) with ESMTP id m6B7S76Y014457; Fri, 11 Jul 2008 09:28:12 +0200 (CEST) Received: from localhost.localdomain (vss6.zib.de [130.73.69.7]) by mailsrv2.zib.de (8.13.4/8.13.4) with ESMTP id m6B7S6CV029856; Fri, 11 Jul 2008 09:28:06 +0200 (MEST) X-Mailer: git-send-email 1.5.4.4 In-Reply-To: <1215761286-2489-2-git-send-email-prohaska@zib.de> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: 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 --- compat/mingw.c | 21 +++++++++++++++++++++ compat/mingw.h | 3 +++ help.c | 14 +++++++++++++- 3 files changed, 37 insertions(+), 1 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 3a05fe7..f7ef545 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1017,3 +1017,24 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler) timer_fn = handler; return old; } + +static const char *make_backslash_path(const char* path) { + 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; +} + +void mingw_open_html(const char *unixpath) +{ + const char *htmlpath = make_backslash_path(unixpath); + printf("Launching default browser to display HTML ...\n"); + ShellExecute(NULL, "open", htmlpath, NULL, "\\", 0); +} diff --git a/compat/mingw.h b/compat/mingw.h index 6bc049a..136361e 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -193,6 +193,9 @@ static inline unsigned int git_ntohl(unsigned int x) sig_handler_t mingw_signal(int sig, sig_handler_t handler); #define signal mingw_signal +void mingw_open_html(const char *path); +#define open_html mingw_open_html + /* * git specific compatibility */ diff --git a/help.c b/help.c index 0f055bf..18116f3 100644 --- a/help.c +++ b/help.c @@ -644,6 +644,18 @@ static void get_html_page_path(struct strbuf *page_path, const char *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); @@ -651,7 +663,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) -- 1.5.6.1.282.gd8a0d