Update libgit2 to 0.25.1
[TortoiseGit.git] / ext / libgit2-0008-Allow-to-configure-default-file-share-mode-for-openi.patch
blobf9817ff30f00c182ac02074e1f9e9ea408c3ad38
1 From 005d051ce8dc252c7b0cac70b7f72e96cda57134 Mon Sep 17 00:00:00 2001
2 From: Sven Strickroth <email@cs-ware.de>
3 Date: Sat, 14 Jan 2017 18:39:32 +0100
4 Subject: [PATCH 4/4] Allow to configure default file share mode for opening
5 files
7 This can prevent FILE_SHARED_VIOLATIONS when used in tools such as TortoiseGit TGitCache and FILE_SHARE_DELETE, because files can be opened w/o being locked any more.
9 Signed-off-by: Sven Strickroth <email@cs-ware.de>
10 ---
11 CHANGELOG.md | 4 ++++
12 include/git2/common.h | 12 ++++++++++++
13 src/settings.c | 18 ++++++++++++++++++
14 src/win32/posix.h | 2 ++
15 src/win32/posix_w32.c | 4 +++-
16 5 files changed, 39 insertions(+), 1 deletion(-)
18 diff --git a/CHANGELOG.md b/CHANGELOG.md
19 index 6137efd71..060d8f7e3 100644
20 --- a/CHANGELOG.md
21 +++ b/CHANGELOG.md
22 @@ -52,6 +52,10 @@ v0.25
24 ### API additions
26 +* You can now set the default share modes on Windows for opening files using
27 + `GIT_OPT_SET_WINDOWS_SHAREMODE` option with `git_libgit2_opts()`.
28 + It is the counterpart to `GIT_OPT_GET_WINDOWS_SHAREMODE`.
30 * You can now get the user-agent used by libgit2 using the
31 `GIT_OPT_GET_USER_AGENT` option with `git_libgit2_opts()`.
32 It is the counterpart to `GIT_OPT_SET_USER_AGENT`.
33 diff --git a/include/git2/common.h b/include/git2/common.h
34 index 99c99812b..f7ba89a33 100644
35 --- a/include/git2/common.h
36 +++ b/include/git2/common.h
37 @@ -177,6 +177,8 @@ typedef enum {
38 GIT_OPT_ENABLE_STRICT_OBJECT_CREATION,
39 GIT_OPT_SET_SSL_CIPHERS,
40 GIT_OPT_GET_USER_AGENT,
41 + GIT_OPT_GET_WINDOWS_SHAREMODE,
42 + GIT_OPT_SET_WINDOWS_SHAREMODE,
43 } git_libgit2_opt_t;
45 /**
46 @@ -281,6 +283,16 @@ typedef enum {
47 * > - `user_agent` is the value that will be delivered as the
48 * > User-Agent header on HTTP requests.
50 + * * opts(GIT_OPT_SET_WINDOWS_SHAREMODE, DWORD value)
51 + *
52 + * > Set the default share modes on Windows for opening files.
53 + * > This can be used to add FILE_SHARE_DELETE.
54 + * > The Windows default is: FILE_SHARE_READ | FILE_SHARE_WRITE.
55 + *
56 + * * opts(GIT_OPT_GET_WINDOWS_SHAREMODE, DWORD *value)
57 + *
58 + * > Get the default share modes on Windows for opening files.
59 + *
60 * * opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, int enabled)
62 * > Enable strict input validation when creating new objects
63 diff --git a/src/settings.c b/src/settings.c
64 index 980233d88..3fa4bae8b 100644
65 --- a/src/settings.c
66 +++ b/src/settings.c
67 @@ -217,6 +217,24 @@ int git_libgit2_opts(int key, ...)
69 break;
71 + case GIT_OPT_GET_WINDOWS_SHAREMODE:
72 +#ifdef GIT_WIN32
73 + *(va_arg(ap, DWORD *)) = git_posix_w32__windows_sharemode;
74 +#else
75 + giterr_set(GITERR_INVALID, "cannot set windows share mode on non Windows builds");
76 + error = -1;
77 +#endif
78 + break;
80 + case GIT_OPT_SET_WINDOWS_SHAREMODE:
81 +#ifdef GIT_WIN32
82 + git_posix_w32__windows_sharemode = (va_arg(ap, DWORD) & (FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE));
83 +#else
84 + giterr_set(GITERR_INVALID, "cannot set windows share mode on non Windows builds");
85 + error = -1;
86 +#endif
87 + break;
89 default:
90 giterr_set(GITERR_INVALID, "invalid option key");
91 error = -1;
92 diff --git a/src/win32/posix.h b/src/win32/posix.h
93 index 73705fb2b..89d543b73 100644
94 --- a/src/win32/posix.h
95 +++ b/src/win32/posix.h
96 @@ -14,6 +14,8 @@
97 #include "utf-conv.h"
98 #include "dir.h"
100 +extern DWORD git_posix_w32__windows_sharemode;
102 typedef SOCKET GIT_SOCKET;
104 #define p_lseek(f,n,w) _lseeki64(f, n, w)
105 diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
106 index a20ae9b2f..3f4fa7d25 100644
107 --- a/src/win32/posix_w32.c
108 +++ b/src/win32/posix_w32.c
109 @@ -18,6 +18,8 @@
110 #include <fcntl.h>
111 #include <ws2tcpip.h>
113 +DWORD git_posix_w32__windows_sharemode = FILE_SHARE_READ | FILE_SHARE_WRITE;
115 #ifndef FILE_NAME_NORMALIZED
116 # define FILE_NAME_NORMALIZED 0
117 #endif
118 @@ -356,7 +358,7 @@ int p_open(const char *path, int flags, ...)
119 return -1;
122 - handle = CreateFileW(buf, desired_access, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, creation_disposition, flags_and_attributes, 0);
123 + handle = CreateFileW(buf, desired_access, git_posix_w32__windows_sharemode, NULL, creation_disposition, flags_and_attributes, 0);
124 if (handle == INVALID_HANDLE_VALUE)
126 _dosmaperr(GetLastError());
128 2.11.0.windows.1