Skip to content

Commit 596b5e7

Browse files
vtbassmattgitster
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]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d6a09e7 commit 596b5e7

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
@@ -98,4 +98,15 @@ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
9898
test "$size" -eq $((5 * 1024 * 1024 * 1024 + $small_size))
9999
'
100100

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

0 commit comments

Comments
 (0)