Re: [PATCH v2] Allow git mv FileA fILEa on case ignore file systems
From: Erik Faye-Lund <hidden>
Date: 2016-06-15 22:50:49
2011/3/19 Torsten Bögershausen [off-list ref]:
quoted hunk ↗ jump to hunk
diff --git a/compat/win32/same-file.c b/compat/win32/same-file.c new file mode 100644 index 0000000..bb1a791 --- /dev/null +++ b/compat/win32/same-file.c@@ -0,0 +1,26 @@ +#include "../../git-compat-util.h" +#include "../win32.h" + +int win_is_same_file(const char *a, const char *b)
The compat/win32-folder is usually used to provide implementations of POSIX APIs lacking on Windows. I don't think this is appropriate functionality to be put there...
+{
+ BY_HANDLE_FILE_INFORMATION hia, hib;
+ HANDLE h;
+
+ h = CreateFile(a, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
+ if (INVALID_HANDLE_VALUE == h)
+ return 0;
+ if (!(GetFileInformationByHandle(h,&hia)))
+ return 0;
+ CloseHandle(h);Indentation-slip?
+ + h = CreateFile(b, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + if (INVALID_HANDLE_VALUE == h) + return 0; + if (!(GetFileInformationByHandle(h,&hib))) + return 0; + CloseHandle(h); +
Same as above...?
+#if defined (WIN32) || defined(__CYGWIN__)
+/* MinGW or MSVC or cygwin */
+int win_is_same_file(const char *a, const char *b);
+#define is_same_file(a,b) win_is_same_file((a),(b))
+#else
+static inline int is_same_file(const char *a, const char *b)
+{
+ struct stat sta, stb;
+ if (lstat(a, &sta) ||
+ lstat(b, &stb))
+ return 0;
+ return sta.st_ino && sta.st_dev == stb.st_dev && sta.st_ino == stb.st_ino;
+}
+#endifThis isn't how we usually do things like this. We usually define stuff in compat/mingw.h (which should really be called compat/win32.h instead, since it's used by our MSVC builds as well. But that's a different discussion), and check if it's defined near the bottom of git-compat-util.h.