mirror of
https://github.com/git/git.git
synced 2026-03-13 10:23:30 +01:00
Introduce has_dos_drive_prefix() and use it.
This function tests whether there is a C: style prefix in the argument. It returns always 0 on Unix. With this functions a number of conditionals #ifdef __MINGW32__/#endif can be removed. The getcwd() replacement was simplified: It tried to elide the translation of backslashes to slashes if there was no drive prfix, but this optimization is wrong: We could be looking at an UNC path, which we also want to translate. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
This commit is contained in:
6
cache.h
6
cache.h
@@ -484,11 +484,7 @@ int safe_create_leading_directories(char *path);
|
||||
char *enter_repo(char *path, int strict);
|
||||
static inline int is_absolute_path(const char *path)
|
||||
{
|
||||
#ifndef __MINGW32__
|
||||
return path[0] == '/';
|
||||
#else
|
||||
return path[0] == '/' || (path[0] && path[1] == ':');
|
||||
#endif
|
||||
return path[0] == '/' || has_dos_drive_prefix(path);
|
||||
}
|
||||
const char *make_absolute_path(const char *path);
|
||||
|
||||
|
||||
@@ -330,16 +330,13 @@ struct tm *localtime_r(const time_t *timep, struct tm *result)
|
||||
#undef getcwd
|
||||
char *mingw_getcwd(char *pointer, int len)
|
||||
{
|
||||
int i;
|
||||
char *ret = getcwd(pointer, len);
|
||||
if (!ret)
|
||||
return ret;
|
||||
if (pointer[0] != 0 && pointer[1] == ':') {
|
||||
int i;
|
||||
for (i = 2; pointer[i]; i++)
|
||||
/* Thanks, Bill. You'll burn in hell for that. */
|
||||
if (pointer[i] == '\\')
|
||||
pointer[i] = '/';
|
||||
}
|
||||
for (i = 0; pointer[i]; i++)
|
||||
if (pointer[i] == '\\')
|
||||
pointer[i] = '/';
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -528,13 +528,7 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
|
||||
end = host;
|
||||
|
||||
path = strchr(end, c);
|
||||
#ifdef __MINGW32__
|
||||
/* host must have at least 2 chars to catch DOS C:/path */
|
||||
if (path && path - end > 1)
|
||||
#else
|
||||
if (path)
|
||||
#endif
|
||||
{
|
||||
if (path && !has_dos_drive_prefix(end)) {
|
||||
if (c == ':') {
|
||||
protocol = PROTO_SSH;
|
||||
*path++ = '\0';
|
||||
|
||||
@@ -650,6 +650,18 @@ char **copy_environ(void);
|
||||
void free_environ(char **env);
|
||||
char **env_setenv(char **env, const char *name);
|
||||
|
||||
static inline int has_dos_drive_prefix(const char *path)
|
||||
{
|
||||
return isalpha(*path) && path[1] == ':';
|
||||
}
|
||||
|
||||
#else /* __MINGW32__ */
|
||||
|
||||
static inline int has_dos_drive_prefix(const char *path)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* __MINGW32__ */
|
||||
|
||||
#endif
|
||||
|
||||
4
setup.c
4
setup.c
@@ -397,10 +397,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
|
||||
|
||||
if (!getcwd(cwd, sizeof(cwd)-1))
|
||||
die("Unable to read current working directory");
|
||||
#ifdef __MINGW32__
|
||||
if (cwd[1] == ':')
|
||||
if (has_dos_drive_prefix(cwd))
|
||||
minoffset = 2;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Test in the following order (relative to the cwd):
|
||||
|
||||
@@ -85,10 +85,8 @@ int get_sha1_hex(const char *hex, unsigned char *sha1)
|
||||
|
||||
static inline int offset_1st_component(const char *path)
|
||||
{
|
||||
#ifdef __MINGW32__
|
||||
if (isalpha(path[0]) && path[1] == ':')
|
||||
if (has_dos_drive_prefix(path))
|
||||
return 2 + (path[2] == '/');
|
||||
#endif
|
||||
return *path == '/';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user