Define is_dir_sep conditionally in compat/mingw.h and git-compat-util.h.

By doing it there we can reduce yet another bunch of conditionals from
setup.c.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
This commit is contained in:
Johannes Sixt
2008-03-13 13:12:18 +01:00
parent 1881ab8876
commit a76ef1f443
3 changed files with 14 additions and 24 deletions

View File

@@ -193,6 +193,7 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler);
*/
#define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':')
#define is_dir_sep(c) ((c) == '/' || (c) == '\\')
#define PATH_SEP ';'
#define PRIuMAX "I64u"

View File

@@ -117,6 +117,10 @@
#define has_dos_drive_prefix(path) 0
#endif
#ifndef is_dir_sep
#define is_dir_sep(c) ((c) == '/')
#endif
#ifdef __GNUC__
#define NORETURN __attribute__((__noreturn__))
#else

33
setup.c
View File

@@ -4,23 +4,16 @@
static int inside_git_dir = -1;
static int inside_work_tree = -1;
#ifdef __MINGW32__
static inline int is_dir_sep(char c) { return c == '/' || c == '\\'; }
#else
static inline int is_dir_sep(char c) { return c == '/'; }
#endif
static int sanitary_path_copy(char *dst, const char *src)
{
char *dst0 = dst;
char *dst0;
#ifdef __MINGW32__
if (isalpha(*src) && src[1] == ':') {
if (has_dos_drive_prefix(src)) {
*dst++ = *src++;
*dst++ = *src++;
dst0 = dst;
}
#endif
dst0 = dst;
if (is_dir_sep(*src)) {
*dst++ = '/';
while (is_dir_sep(*src))
@@ -39,30 +32,22 @@ static int sanitary_path_copy(char *dst, const char *src)
* (4) "../" -- strip one, eat slash and continue.
*/
if (c == '.') {
switch (src[1]) {
case '\0':
if (!src[1]) {
/* (1) */
src++;
break;
case '/':
#ifdef __MINGW32__
case '\\':
#endif
} else if (is_dir_sep(src[1])) {
/* (2) */
src += 2;
while (is_dir_sep(*src))
src++;
continue;
case '.':
switch (src[2]) {
case '\0':
} else if (src[1] == '.') {
if (!src[2]) {
/* (3) */
src += 2;
goto up_one;
case '/':
#ifdef __MINGW32__
case '\\':
#endif
} else if (is_dir_sep(src[2])) {
/* (4) */
src += 3;
while (is_dir_sep(*src))