mirror of
https://github.com/git/git.git
synced 2026-03-13 18:33:25 +01:00
refactor help.c to git_install_prefix() and make_native_separator()
git_install_prefix() returns the install prefix of msysgit. For all other architectures it returns "". The path returned contains slashes. make_native_separator() takes a unix path (slashes) and converts the separators in place. On Windows slashes are converted to backslashes. All the code was available in help.c and is now moved to path.c. The new function will be used to located the templates and /etc/gitconfig. Signed-off-by: Steffen Prohaska <prohaska@zib.de>
This commit is contained in:
3
cache.h
3
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 *);
|
||||
|
||||
47
help.c
47
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, '\\'); /* <gitroot>\bin\ <- p */
|
||||
if (p) {
|
||||
*p = '\0';
|
||||
p = strrchr(pgm, '\\'); /* <gitroot>\ <- 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);
|
||||
}
|
||||
|
||||
48
path.c
48
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, '\\'); /* <gitroot>\bin\ <- p */
|
||||
if (p) {
|
||||
*p = '\0';
|
||||
p = strrchr(prefix, '\\'); /* <gitroot>\ <- 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user