summaryrefslogtreecommitdiff
path: root/compat/mingw.c
diff options
context:
space:
mode:
authorJeff Hostetler <jeffhost@microsoft.com>2020-08-17 10:37:02 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-08-17 18:27:16 (GMT)
commit680e0b4524482c4bb679030188f6ae8db4caff06 (patch)
tree88b5f31084a0bd74597d96a64d76e7c5c4bbd271 /compat/mingw.c
parent47ae905ffb98cc4d4fd90083da6bc8dab55d9ecc (diff)
downloadgit-680e0b4524482c4bb679030188f6ae8db4caff06.zip
git-680e0b4524482c4bb679030188f6ae8db4caff06.tar.gz
git-680e0b4524482c4bb679030188f6ae8db4caff06.tar.bz2
mingw: improve performance of mingw_unlink()
Update mingw_unlink() to first try to delete the file with existing permissions before trying to force it. Windows throws an error when trying to delete a read-only file. The mingw_unlink() compatibility wrapper always tries to _wchmod(666) the file before calling _wunlink() to avoid that error. However, since most files in the worktree are already writable, this is usually wasted effort. Update mingw_unlink() to just call DeleteFileW() directly and if that succeeds return. If that fails, fall back into the existing code path to update the permissions and use _wunlink() to get the existing error code mapping. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat/mingw.c')
-rw-r--r--compat/mingw.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/compat/mingw.c b/compat/mingw.c
index 8ee0b64..f18636c 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -290,6 +290,9 @@ int mingw_unlink(const char *pathname)
if (xutftowcs_path(wpathname, pathname) < 0)
return -1;
+ if (DeleteFileW(wpathname))
+ return 0;
+
/* read-only files cannot be removed */
_wchmod(wpathname, 0666);
while ((ret = _wunlink(wpathname)) == -1 && tries < ARRAY_SIZE(delay)) {