Skip to content

Commit 75e3283

Browse files
sunzhuoshidscho
andcommitted
Add config option "windows.appendatomically"
Atomic append on windows is only supported on local disk files, and it may cause errors in other situations, e.g. network file system. If that is the case, this config option should be used to turn atomic append off. Signed-off-by: sunzhuoshi <[email protected]> Co-Authored-By: Johannes Schindelin <[email protected]>
1 parent 9b2e006 commit 75e3283

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Documentation/config.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,4 +500,6 @@ include::config/versionsort.txt[]
500500

501501
include::config/web.txt[]
502502

503+
include::config/windows.txt[]
504+
503505
include::config/worktree.txt[]

Documentation/config/windows.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
windows.appendatomically::
2+
By default, append atomic API is used on windows. But it works only with
3+
local disk files, if you're working on a network file system, you should
4+
set it false to turn it off.

compat/mingw.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ static int is_local_named_pipe_path(const char *filename)
743743

744744
int mingw_open (const char *filename, int oflags, ...)
745745
{
746+
static int append_atomically = -1;
746747
typedef int (*open_fn_t)(wchar_t const *wfilename, int oflags, ...);
747748
va_list args;
748749
unsigned mode;
@@ -759,7 +760,13 @@ int mingw_open (const char *filename, int oflags, ...)
759760
return -1;
760761
}
761762

762-
if ((oflags & O_APPEND) && !is_local_named_pipe_path(filename))
763+
if (append_atomically < 0 &&
764+
(!the_repository || git_config_get_bool("windows.appendatomically",
765+
&append_atomically)))
766+
append_atomically = 1;
767+
768+
if (append_atomically && (oflags & O_APPEND) &&
769+
!is_local_named_pipe_path(filename))
763770
open_fn = mingw_open_append;
764771
else
765772
open_fn = _wopen;

0 commit comments

Comments
 (0)