Merge branch 'mc/clean-smudge-with-llp64'
The clean/smudge conversion code path has been prepared to better work on platforms where ulong is narrower than size_t. * mc/clean-smudge-with-llp64: clean/smudge: allow clean filters to process extremely large files odb: guard against data loss checking out a huge file git-compat-util: introduce more size_t helpers odb: teach read_blob_entry to use size_t t1051: introduce a smudge filter test for extremely large files test-lib: add prerequisite for 64-bit platforms test-tool genzeros: generate large amounts of data more efficiently test-genzeros: allow more than 2G zeros in Windows
This commit is contained in:
@ -3,18 +3,31 @@
|
||||
|
||||
int cmd__genzeros(int argc, const char **argv)
|
||||
{
|
||||
long count;
|
||||
/* static, so that it is NUL-initialized */
|
||||
static const char zeros[256 * 1024];
|
||||
intmax_t count;
|
||||
ssize_t n;
|
||||
|
||||
if (argc > 2) {
|
||||
fprintf(stderr, "usage: %s [<count>]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
count = argc > 1 ? strtol(argv[1], NULL, 0) : -1L;
|
||||
count = argc > 1 ? strtoimax(argv[1], NULL, 0) : -1;
|
||||
|
||||
while (count < 0 || count--) {
|
||||
if (putchar(0) == EOF)
|
||||
/* Writing out individual NUL bytes is slow... */
|
||||
while (count < 0)
|
||||
if (write(1, zeros, ARRAY_SIZE(zeros)) < 0)
|
||||
return -1;
|
||||
|
||||
while (count > 0) {
|
||||
n = write(1, zeros, count < ARRAY_SIZE(zeros) ?
|
||||
count : ARRAY_SIZE(zeros));
|
||||
|
||||
if (n < 0)
|
||||
return -1;
|
||||
|
||||
count -= n;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -83,4 +83,30 @@ test_expect_success 'ident converts on output' '
|
||||
test_cmp small.clean large.clean
|
||||
'
|
||||
|
||||
# This smudge filter prepends 5GB of zeros to the file it checks out. This
|
||||
# ensures that smudging doesn't mangle large files on 64-bit Windows.
|
||||
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
|
||||
'files over 4GB convert on output' '
|
||||
test_commit test small "a small file" &&
|
||||
small_size=$(test_file_size small) &&
|
||||
test_config filter.makelarge.smudge \
|
||||
"test-tool genzeros $((5*1024*1024*1024)) && cat" &&
|
||||
echo "small filter=makelarge" >.gitattributes &&
|
||||
rm small &&
|
||||
git checkout -- small &&
|
||||
size=$(test_file_size small) &&
|
||||
test "$size" -eq $((5 * 1024 * 1024 * 1024 + $small_size))
|
||||
'
|
||||
|
||||
# This clean filter writes down the size of input it receives. By checking against
|
||||
# the actual size, we ensure that cleaning doesn't mangle large files on 64-bit Windows.
|
||||
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
|
||||
'files over 4GB convert on input' '
|
||||
test-tool genzeros $((5*1024*1024*1024)) >big &&
|
||||
test_config filter.checklarge.clean "wc -c >big.size" &&
|
||||
echo "big filter=checklarge" >.gitattributes &&
|
||||
git add big &&
|
||||
test $(test_file_size big) -eq $(cat big.size)
|
||||
'
|
||||
|
||||
test_done
|
||||
|
@ -1734,6 +1734,10 @@ build_option () {
|
||||
sed -ne "s/^$1: //p"
|
||||
}
|
||||
|
||||
test_lazy_prereq SIZE_T_IS_64BIT '
|
||||
test 8 -eq "$(build_option sizeof-size_t)"
|
||||
'
|
||||
|
||||
test_lazy_prereq LONG_IS_64BIT '
|
||||
test 8 -le "$(build_option sizeof-long)"
|
||||
'
|
||||
|
Reference in New Issue
Block a user