From a76ef1f443951642616cf313926c6ebd3d7172a7 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Thu, 13 Mar 2008 13:12:18 +0100 Subject: [PATCH] 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 --- compat/mingw.h | 1 + git-compat-util.h | 4 ++++ setup.c | 33 +++++++++------------------------ 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/compat/mingw.h b/compat/mingw.h index bf3843272b..abac3f2caf 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -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" diff --git a/git-compat-util.h b/git-compat-util.h index 08f764ef9e..2889146e89 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -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 diff --git a/setup.c b/setup.c index 0ee0ae4f31..eea103807f 100644 --- a/setup.c +++ b/setup.c @@ -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)) -- 2.11.4.GIT