From 65230e232c91527c16724a665e5d5f2ea670f9b6 Mon Sep 17 00:00:00 2001 From: Steffen Prohaska Date: Mon, 1 Oct 2007 22:56:45 +0200 Subject: [PATCH] help (msysgit): fix locating html help for paths with spaces Derive the git installation dir from the executable path and directly use the Win32 API to open the HTML file. This avoids the mingw layer and command line escaping problems, which caused the previous implementation to fail if spaces were contained in the path to git. Signed-off-by: Steffen Prohaska --- help.c | 60 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/help.c b/help.c index 98d00cc4d9..a5ada18c76 100644 --- a/help.c +++ b/help.c @@ -165,6 +165,32 @@ static void list_common_cmds_help(void) puts("(use 'git help -a' to get a list of all installed git commands)"); } +#ifdef __MINGW32__ +char* get_install_dir() +{ + static char* pgm = 0; + if (pgm) { + return pgm; + } else { + char* p; + int pgm_len = strlen(_pgmptr); + pgm = xmalloc(pgm_len + 1); + strcpy(pgm, _pgmptr); + p = strrchr(pgm, '\\'); /* \bin\ <- p */ + if (p) { + *p = '\0'; + p = strrchr(pgm, '\\'); /* \ <- p */ + if (p) { + *p = '\0'; + return pgm; + } + } + } + fprintf(stderr, "Fatal Error: failed to locate installation root.\n"); + exit(1); +} +#endif + static void show_man_page(const char *git_cmd) { const char *page; @@ -181,22 +207,24 @@ static void show_man_page(const char *git_cmd) } #ifdef __MINGW32__ - { - char* prefix = "/doc/git/html/"; - int prefix_len = strlen (prefix); - char* suffix = ".html"; - int suffix_len = strlen (suffix); - int page_len = strlen (page); - int htmlpath_len = prefix_len + page_len + suffix_len; - char* htmlpath = xmalloc (htmlpath_len + 1); - strcpy (htmlpath, prefix); - strcpy (htmlpath + prefix_len, page); - strcpy (htmlpath + prefix_len + page_len, suffix); - htmlpath[htmlpath_len] = 0; - printf("Launching default browser to display html help...\n"); - /* We need sh here to run shell script /bin/start. */ - execlp("sh", "start", "/bin/start", htmlpath, NULL ); - } + { + char* install_dir = get_install_dir(); + int install_dir_len = strlen(install_dir); + char* html_dir = "\\doc\\git\\html\\"; + int html_dir_len = strlen(html_dir); + char* suffix = ".html"; + int suffix_len = strlen(suffix); + int page_len = strlen(page); + int htmlpath_len = install_dir_len + html_dir_len + page_len + suffix_len; + char* htmlpath = xmalloc(htmlpath_len + 1); + strcpy (htmlpath, install_dir); + strcpy (htmlpath + install_dir_len, html_dir); + strcpy (htmlpath + install_dir_len + html_dir_len, page); + strcpy (htmlpath + install_dir_len + html_dir_len + page_len, suffix); + htmlpath[htmlpath_len] = 0; + printf("Launching default browser to display html help...\n"); + ShellExecute(NULL, "open", htmlpath, NULL, NULL, 0); + } #else execlp("man", "man", page, NULL); #endif