]> git.ipfire.org Git - thirdparty/git.git/commitdiff
allow hooks to ignore their standard input stream
authorClemens Buchacher <clemens.buchacher@intel.com>
Mon, 16 Nov 2015 08:05:58 +0000 (09:05 +0100)
committerJeff King <peff@peff.net>
Mon, 16 Nov 2015 13:59:19 +0000 (08:59 -0500)
Since ec7dbd145 (receive-pack: allow hooks to ignore its
standard input stream) the pre-receive and post-receive
hooks ignore SIGPIPE. Do the same for the remaining hooks
pre-push and post-rewrite, which read from standard input.
The same arguments for ignoring SIGPIPE apply.

Include test by Jeff King which checks that SIGPIPE does not
cause pre-push hook failure. With the use of git update-ref
--stdin it is fast enough to be enabled by default.

Signed-off-by: Clemens Buchacher <clemens.buchacher@intel.com>
Signed-off-by: Jeff King <peff@peff.net>
builtin/commit.c
t/t5571-pre-push-hook.sh
transport.c

index dca09e2c3bd8a839b27e279c427ebba71e88966e..f2a8b78c7a7c5f52c46e03e644cf50413b643d3e 100644 (file)
@@ -32,6 +32,7 @@
 #include "sequencer.h"
 #include "notes-utils.h"
 #include "mailmap.h"
+#include "sigchain.h"
 
 static const char * const builtin_commit_usage[] = {
        N_("git commit [<options>] [--] <pathspec>..."),
@@ -1537,8 +1538,10 @@ static int run_rewrite_hook(const unsigned char *oldsha1,
                return code;
        n = snprintf(buf, sizeof(buf), "%s %s\n",
                     sha1_to_hex(oldsha1), sha1_to_hex(newsha1));
+       sigchain_push(SIGPIPE, SIG_IGN);
        write_in_full(proc.in, buf, n);
        close(proc.in);
+       sigchain_pop(SIGPIPE);
        return finish_command(&proc);
 }
 
index 6f9916a3901caa71b6a1994b6091b629a4397473..ba975bb3557b5e243deb2c40217dbe04ff4953ae 100755 (executable)
@@ -109,23 +109,20 @@ test_expect_success 'push to URL' '
        diff expected actual
 '
 
-# Test that filling pipe buffers doesn't cause failure
-# Too slow to leave enabled for general use
-if false
-then
-       printf 'parent1\nrepo1\n' >expected
-       nr=1000
-       while test $nr -lt 2000
-       do
-               nr=$(( $nr + 1 ))
-               git branch b/$nr $COMMIT3
-               echo "refs/heads/b/$nr $COMMIT3 refs/heads/b/$nr $_z40" >>expected
-       done
-
-       test_expect_success 'push many refs' '
-               git push parent1 "refs/heads/b/*:refs/heads/b/*" &&
-               diff expected actual
-       '
-fi
+test_expect_success 'set up many-ref tests' '
+       {
+               nr=1000
+               while test $nr -lt 2000
+               do
+                       nr=$(( $nr + 1 ))
+                       echo "create refs/heads/b/$nr $COMMIT3"
+               done
+       } | git update-ref --stdin
+'
+
+test_expect_success 'sigpipe does not cause pre-push hook failure' '
+       echo "exit 0" | write_script "$HOOK" &&
+       git push parent1 "refs/heads/b/*:refs/heads/b/*"
+'
 
 test_done
index 863eb524f9087302be6b99c89f071195dd1258b8..37e4f5e42cbe86d69221256ab63af609d02c7d07 100644 (file)
@@ -15,6 +15,7 @@
 #include "submodule.h"
 #include "string-list.h"
 #include "sha1-array.h"
+#include "sigchain.h"
 
 /* rsync support */
 
@@ -1126,6 +1127,8 @@ static int run_pre_push_hook(struct transport *transport,
                return -1;
        }
 
+       sigchain_push(SIGPIPE, SIG_IGN);
+
        strbuf_init(&buf, 256);
 
        for (r = remote_refs; r; r = r->next) {
@@ -1139,8 +1142,10 @@ static int run_pre_push_hook(struct transport *transport,
                         r->peer_ref->name, sha1_to_hex(r->new_sha1),
                         r->name, sha1_to_hex(r->old_sha1));
 
-               if (write_in_full(proc.in, buf.buf, buf.len) != buf.len) {
-                       ret = -1;
+               if (write_in_full(proc.in, buf.buf, buf.len) < 0) {
+                       /* We do not mind if a hook does not read all refs. */
+                       if (errno != EPIPE)
+                               ret = -1;
                        break;
                }
        }
@@ -1151,6 +1156,8 @@ static int run_pre_push_hook(struct transport *transport,
        if (!ret)
                ret = x;
 
+       sigchain_pop(SIGPIPE);
+
        x = finish_command(&proc);
        if (!ret)
                ret = x;