Skip to content

Commit c8b2964

Browse files
René Scharfegitster
authored andcommitted
Fix checkout of large files to network shares on Windows XP
Bigger writes to network drives on Windows XP fail. Cap them at 31MB to allow them to succeed. Callers need to be prepared for write() calls that do less work than requested anyway. On local drives, write() calls are translated to WriteFile() calls with a cap of 64KB on Windows XP and 256KB on Vista. Thus a cap of 31MB won't affect the number of WriteFile() calls which do the actual work. There's still room for some other version of Windows to use a chunk size of 1MB without increasing the number of system calls. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fc012c2 commit c8b2964

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

compat/mingw.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,23 @@ int mingw_open (const char *filename, int oflags, ...)
140140
return fd;
141141
}
142142

143+
#undef write
144+
ssize_t mingw_write(int fd, const void *buf, size_t count)
145+
{
146+
/*
147+
* While write() calls to a file on a local disk are translated
148+
* into WriteFile() calls with a maximum size of 64KB on Windows
149+
* XP and 256KB on Vista, no such cap is placed on writes to
150+
* files over the network on Windows XP. Unfortunately, there
151+
* seems to be a limit of 32MB-28KB on X64 and 64MB-32KB on x86;
152+
* bigger writes fail on Windows XP.
153+
* So we cap to a nice 31MB here to avoid write failures over
154+
* the net without changing the number of WriteFile() calls in
155+
* the local case.
156+
*/
157+
return write(fd, buf, min(count, 31 * 1024 * 1024));
158+
}
159+
143160
#undef fopen
144161
FILE *mingw_fopen (const char *filename, const char *otype)
145162
{

compat/mingw.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ int link(const char *oldpath, const char *newpath);
170170
int mingw_open (const char *filename, int oflags, ...);
171171
#define open mingw_open
172172

173+
ssize_t mingw_write(int fd, const void *buf, size_t count);
174+
#define write mingw_write
175+
173176
FILE *mingw_fopen (const char *filename, const char *otype);
174177
#define fopen mingw_fopen
175178

t/t5705-clone-2gb.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test_expect_success 'setup' '
1212
1313
git config pack.compression 0 &&
1414
git config pack.depth 0 &&
15-
blobsize=$((20*1024*1024)) &&
15+
blobsize=$((100*1024*1024)) &&
1616
blobcount=$((2*1024*1024*1024/$blobsize+1)) &&
1717
i=1 &&
1818
(while test $i -le $blobcount
@@ -36,9 +36,15 @@ test_expect_success 'setup' '
3636
3737
'
3838

39-
test_expect_success 'clone' '
39+
test_expect_success 'clone - bare' '
4040
41-
git clone --bare --no-hardlinks . clone
41+
git clone --bare --no-hardlinks . clone-bare
42+
43+
'
44+
45+
test_expect_success 'clone - with worktree, file:// protocol' '
46+
47+
git clone file://. clone-wt
4248
4349
'
4450

0 commit comments

Comments
 (0)