Skip to content

Commit 8d89e40

Browse files
authored
Merge pull request libgit2#4192 from libgit2/ethomson/win32_posix
Refactor some of the win32 POSIX emulation
2 parents f9d3b0d + 86536c7 commit 8d89e40

File tree

9 files changed

+407
-111
lines changed

9 files changed

+407
-111
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ v0.25 + 1
99

1010
### API additions
1111

12+
* You can now set the default share mode on Windows for opening files using
13+
`GIT_OPT_SET_WINDOWS_SHAREMODE` option with `git_libgit2_opts()`.
14+
You can query the current share mode with `GIT_OPT_GET_WINDOWS_SHAREMODE`.
15+
1216
### API removals
1317

1418
### Breaking API changes

include/git2/common.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ typedef enum {
180180
GIT_OPT_GET_USER_AGENT,
181181
GIT_OPT_ENABLE_OFS_DELTA,
182182
GIT_OPT_ENABLE_SYNCHRONOUS_OBJECT_CREATION,
183+
GIT_OPT_GET_WINDOWS_SHAREMODE,
184+
GIT_OPT_SET_WINDOWS_SHAREMODE,
183185
} git_libgit2_opt_t;
184186

185187
/**
@@ -284,6 +286,17 @@ typedef enum {
284286
* > - `user_agent` is the value that will be delivered as the
285287
* > User-Agent header on HTTP requests.
286288
*
289+
* * opts(GIT_OPT_SET_WINDOWS_SHAREMODE, unsigned long value)
290+
*
291+
* > Set the share mode used when opening files on Windows.
292+
* > For more information, see the documentation for CreateFile.
293+
* > The default is: FILE_SHARE_READ | FILE_SHARE_WRITE. This is
294+
* > ignored and unused on non-Windows platforms.
295+
*
296+
* * opts(GIT_OPT_GET_WINDOWS_SHAREMODE, unsigned long *value)
297+
*
298+
* > Get the share mode used when opening files on Windows.
299+
*
287300
* * opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, int enabled)
288301
*
289302
* > Enable strict input validation when creating new objects

include/git2/errors.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ typedef enum {
5353

5454
GIT_PASSTHROUGH = -30, /**< Internal only */
5555
GIT_ITEROVER = -31, /**< Signals end of iteration with iterator */
56+
GIT_RETRY = -32, /**< Internal only */
5657
} git_error_code;
5758

5859
/**

src/posix.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#define _S_IFLNK S_IFLNK
2525
#endif
2626

27+
#ifndef S_IWUSR
28+
#define S_IWUSR 00200
29+
#endif
30+
2731
#ifndef S_IXUSR
2832
#define S_IXUSR 00100
2933
#endif

src/settings.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,18 @@ int git_libgit2_opts(int key, ...)
231231
git_object__synchronous_writing = (va_arg(ap, int) != 0);
232232
break;
233233

234+
case GIT_OPT_GET_WINDOWS_SHAREMODE:
235+
#ifdef GIT_WIN32
236+
*(va_arg(ap, unsigned long *)) = git_win32__createfile_sharemode;
237+
#endif
238+
break;
239+
240+
case GIT_OPT_SET_WINDOWS_SHAREMODE:
241+
#ifdef GIT_WIN32
242+
git_win32__createfile_sharemode = va_arg(ap, unsigned long);
243+
#endif
244+
break;
245+
234246
default:
235247
giterr_set(GITERR_INVALID, "invalid option key");
236248
error = -1;

src/win32/posix.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#include "utf-conv.h"
1515
#include "dir.h"
1616

17+
extern unsigned long git_win32__createfile_sharemode;
18+
extern int git_win32__retries;
19+
1720
typedef SOCKET GIT_SOCKET;
1821

1922
#define p_lseek(f,n,w) _lseeki64(f, n, w)

0 commit comments

Comments
 (0)