filter_buffer_or_fd(): ignore EPIPE
authorJunio C Hamano <gitster@pobox.com>
Tue, 19 May 2015 18:08:23 +0000 (11:08 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 May 2015 17:19:12 +0000 (10:19 -0700)
We are explicitly ignoring SIGPIPE, as we fully expect that the
filter program may not read our output fully. Ignore EPIPE that
may come from writing to it as well.

A new test was stolen from Jeff's suggestion.

Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
convert.c
t/t0021-conversion.sh
index 9a5612e93da2058f64bcec20cfd474a8b6b2d223..f3bd3e93fb2ecf95413db3c53d7e686cd03d1e69 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -356,9 +356,14 @@ static int filter_buffer_or_fd(int in, int out, void *data)
        sigchain_push(SIGPIPE, SIG_IGN);
 
        if (params->src) {
-               write_err = (write_in_full(child_process.in, params->src, params->size) < 0);
+               write_err = (write_in_full(child_process.in,
+                                          params->src, params->size) < 0);
+               if (errno == EPIPE)
+                       write_err = 0;
        } else {
                write_err = copy_fd(params->fd, child_process.in);
+               if (write_err == COPY_WRITE_ERROR && errno == EPIPE)
+                       write_err = 0;
        }
 
        if (close(child_process.in))
index ca7d2a630a8442d8812b444708d6f28f2e45fb32..e0200b9f338f0478fd55029eab9c32c6b7956476 100755 (executable)
@@ -204,6 +204,16 @@ test_expect_success 'filtering large input to small output should use little mem
        GIT_MMAP_LIMIT=1m GIT_ALLOC_LIMIT=1m git add 30MB
 '
 
+test_expect_success 'filter that does not read is fine' '
+       test-genrandom foo $((128 * 1024 + 1)) >big &&
+       echo "big filter=epipe" >.gitattributes &&
+       git config filter.epipe.clean "echo xyzzy" &&
+       git add big &&
+       git cat-file blob :big >actual &&
+       echo xyzzy >expect &&
+       test_cmp expect actual
+'
+
 test_expect_success EXPENSIVE 'filter large file' '
        git config filter.largefile.smudge cat &&
        git config filter.largefile.clean cat &&