From 732eb0a8d9b5d3a217421ec61e2b2335fc5a1e36 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Fri, 10 Jun 2011 13:54:25 +0200 Subject: [PATCH 1/5] Add some missing MSVC compatibility defines --- src/msvc-compat.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/msvc-compat.h b/src/msvc-compat.h index 6f38e482d..2343ea849 100644 --- a/src/msvc-compat.h +++ b/src/msvc-compat.h @@ -12,14 +12,17 @@ # define stat _stat64 # define fstat _fstat64 -#define _S_IFLNK 0120000 - /* stat: file mode type testing macros */ +# define _S_IFLNK 0120000 +# define S_IFLNK _S_IFLNK + # define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) # define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO) # define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) +# define MAXPATHLEN MAX_PATH + /* case-insensitive string comparison */ # define strcasecmp _stricmp # define strncasecmp _strnicmp From 535ff384e2afe029147b89b95c9fb812c955cd7b Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Fri, 10 Jun 2011 13:54:47 +0200 Subject: [PATCH 2/5] Prefer to use S_IFLNK instead of _S_IFLNK for consistency --- src/fileops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fileops.c b/src/fileops.c index 98fc53a50..54f6d9387 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -627,7 +627,7 @@ static int do_lstat(const char *file_name, struct stat *buf) fMode |= S_IWRITE; if (fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) - fMode |= _S_IFLNK; + fMode |= S_IFLNK; buf->st_ino = 0; buf->st_gid = 0; From c1802641ff398d11396d6187a3972622b2ff8ba6 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Fri, 10 Jun 2011 13:56:24 +0200 Subject: [PATCH 3/5] Prefer to use file mode defines instead of raw numbers --- src/index.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.c b/src/index.c index 60b65848d..08e24906c 100644 --- a/src/index.c +++ b/src/index.c @@ -142,8 +142,8 @@ unsigned int index_create_mode(unsigned int mode) { if (S_ISLNK(mode)) return S_IFLNK; - if (S_ISDIR(mode) || (mode & S_IFMT) == 0160000) - return 0160000; + if (S_ISDIR(mode) || (mode & S_IFMT) == (S_IFLNK | S_IFDIR)) + return (S_IFLNK | S_IFDIR); return S_IFREG | ((mode & 0100) ? 0755 : 0644); } From 3f66c202029ab9911b3c4ce0d01eaf0a98111aba Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Fri, 10 Jun 2011 13:57:01 +0200 Subject: [PATCH 4/5] Use "__inline" instead of "inline" with MSVC MSVC supports "inline" only in C++ code, not in C code. --- src/fileops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fileops.c b/src/fileops.c index 54f6d9387..2a78764c6 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -603,7 +603,7 @@ int gitfo_getcwd(char *buffer_out, size_t size) } #ifdef GIT_WIN32 -static inline time_t filetime_to_time_t(const FILETIME *ft) +GIT_INLINE(time_t) filetime_to_time_t(const FILETIME *ft) { long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime; winTime -= 116444736000000000LL; /* Windows to Unix Epoch conversion */ From e6480970b400b38c041ffedd611632eea2d720ea Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Fri, 10 Jun 2011 14:00:54 +0200 Subject: [PATCH 5/5] Add missing function declarations to avoid MSVC compiler warnings The better solution would probably be to turn the gitfo_lstat / gitfo_readlink macros into real functions that wrap either lstat or gitfo_lstat__w32 (and readlink or gitfo_readlink__w32). However, that would introduce an indirection unless inlined. For now, this is the less intrusive change. --- src/fileops.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fileops.h b/src/fileops.h index 4e6007ad4..ae8932bd3 100644 --- a/src/fileops.h +++ b/src/fileops.h @@ -98,6 +98,9 @@ extern int gitfo_mv_force(const char *from, const char *to); #ifdef GIT_WIN32 # define gitfo_lstat(p,b) gitfo_lstat__w32(p,b) # define gitfo_readlink(a, b, c) gitfo_readlink__w32(a, b, c) + + extern int gitfo_lstat__w32(const char *file_name, struct stat *buf); + extern int gitfo_readlink__w32(const char *link, char *target, size_t target_len); #else # define gitfo_lstat(p,b) lstat(p,b) # define gitfo_readlink(a, b, c) readlink(a, b, c)