diff --git a/cache.h b/cache.h index e17bb6f4f5..53b4e44873 100644 --- a/cache.h +++ b/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); diff --git a/compat/mingw.c b/compat/mingw.c index 0888288b5c..6733727380 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -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; } diff --git a/connect.c b/connect.c index 92a2829f04..8d600c9ddf 100644 --- a/connect.c +++ b/connect.c @@ -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'; diff --git a/git-compat-util.h b/git-compat-util.h index 4a8df8e038..e9fcffd125 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -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 diff --git a/setup.c b/setup.c index e2e2e21d15..d184d4d5e5 100644 --- a/setup.c +++ b/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): diff --git a/sha1_file.c b/sha1_file.c index 0c608492c7..9a7fac9d5b 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -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 == '/'; }