diff --git a/cache.h b/cache.h index b7f57fdc2e..e87d0a350b 100644 --- a/cache.h +++ b/cache.h @@ -381,6 +381,9 @@ static inline int is_dev_null(const char *str) return !strcmp(str, "/dev/null"); } const char *make_absolute_path(const char *path); +/* Convert slashes in place. On Windows to backslashes. */ +char *make_native_separator(char *path); +const char *git_install_prefix(); /* 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 1c0946c649..e59b856d9f 100644 --- a/help.c +++ b/help.c @@ -165,34 +165,6 @@ 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; - } - } - } - /* Note, according to the msdn documentation we have a full path - if started through the shell and this error should never happen. */ - 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; @@ -210,20 +182,11 @@ static void show_man_page(const char *git_cmd) #ifdef __MINGW32__ { - 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; + const char *htmlpath = make_native_separator( + mkpath("%s/doc/git/html/%s.html" + , git_install_prefix() + , page) + ); printf("Launching default browser to display HTML help ...\n"); ShellExecute(NULL, "open", htmlpath, NULL, NULL, 0); } diff --git a/path.c b/path.c index 7a5ac5b067..e42b234fa1 100644 --- a/path.c +++ b/path.c @@ -370,3 +370,51 @@ const char *make_absolute_path(const char *path) return buf; } + +const char* git_install_prefix() +{ +#ifdef __MINGW32__ + static char* prefix; + + if (prefix) { + return prefix; + } + + char* p; + int pgm_len = strlen(_pgmptr); + prefix = xmalloc(pgm_len + 1); + strcpy(prefix, _pgmptr); + p = strrchr(prefix, '\\'); /* \bin\ <- p */ + if (p) { + *p = '\0'; + p = strrchr(prefix, '\\'); /* \ <- p */ + if (p) { + *p = '\0'; + for (p = prefix; *p; p++) + if (*p == '\\') + *p = '/'; + return prefix; + } + } + + /* Note, according to the msdn documentation we have a full path + if started through the shell and this error should never happen. */ + fprintf(stderr, "Fatal Error: failed to locate installation root.\n"); + exit(1); +#else + return ""; +#endif +} + +char *make_native_separator(char* path) { +#ifdef __MINGW32__ + char* c; + for (c = path; *c; c++) { + if (*c == '/') + *c = '\\'; + } + return path; +#else + return path; +#endif +}