mirror of
https://github.com/git/git.git
synced 2026-03-14 10:53:25 +01:00
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 <prohaska@zib.de>
This commit is contained in:
60
help.c
60
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, '\\'); /* <gitroot>\bin\ <- p */
|
||||
if (p) {
|
||||
*p = '\0';
|
||||
p = strrchr(pgm, '\\'); /* <gitroot>\ <- 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
|
||||
|
||||
Reference in New Issue
Block a user