Skip to content

Commit 30defec

Browse files
vtbassmattdscho
authored andcommitted
clean/smudge: allow clean filters to process extremely large files
The filter system allows for alterations to file contents when they're moved between the database and the worktree. We already made sure that it is possible for smudge filters to produce contents that are larger than `unsigned long` can represent (which matters on systems where `unsigned long` is narrower than `size_t`, most notably 64-bit Windows). Now we make sure that clean filters can _consume_ contents that are larger than that. Note that this commit only allows clean filters' _input_ to be larger than can be represented by `unsigned long`. This change makes only a very minute dent into the much larger project to teach Git to use `size_t` instead of `unsigned long` wherever appropriate. Helped-by: Johannes Schindelin <[email protected]> Signed-off-by: Matt Cooper <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 1e03c75 commit 30defec

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

convert.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ static int crlf_to_worktree(const char *src, size_t len, struct strbuf *buf,
613613

614614
struct filter_params {
615615
const char *src;
616-
unsigned long size;
616+
size_t size;
617617
int fd;
618618
const char *cmd;
619619
const char *path;

t/t1051-large-conversion.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,15 @@ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
9797
test "$size" -ge $((5 * 1024 * 1024 * 1024))
9898
'
9999

100+
# This clean filter writes down the size of input it receives. By checking against
101+
# the actual size, we ensure that cleaning doesn't mangle large files on 64-bit Windows.
102+
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
103+
'files over 4GB convert on input' '
104+
test-tool genzeros $((5*1024*1024*1024)) >big &&
105+
test_config filter.checklarge.clean "wc -c >big.size" &&
106+
echo "big filter=checklarge" >.gitattributes &&
107+
git add big &&
108+
test $(test_file_size big) -eq $(cat big.size)
109+
'
110+
100111
test_done

0 commit comments

Comments
 (0)