Merge branch 'cb/hook-sigpipe' into maint

We now consistently allow all hooks to ignore their standard input,
rather than having git complain of SIGPIPE.

* cb/hook-sigpipe:
  allow hooks to ignore their standard input stream
This commit is contained in:
Jeff King 2015-12-01 17:19:52 -05:00
commit 347acea06a
3 changed files with 26 additions and 19 deletions

View File

@ -32,6 +32,7 @@
#include "sequencer.h" #include "sequencer.h"
#include "notes-utils.h" #include "notes-utils.h"
#include "mailmap.h" #include "mailmap.h"
#include "sigchain.h"
static const char * const builtin_commit_usage[] = { static const char * const builtin_commit_usage[] = {
N_("git commit [<options>] [--] <pathspec>..."), N_("git commit [<options>] [--] <pathspec>..."),
@ -1537,8 +1538,10 @@ static int run_rewrite_hook(const unsigned char *oldsha1,
return code; return code;
n = snprintf(buf, sizeof(buf), "%s %s\n", n = snprintf(buf, sizeof(buf), "%s %s\n",
sha1_to_hex(oldsha1), sha1_to_hex(newsha1)); sha1_to_hex(oldsha1), sha1_to_hex(newsha1));
sigchain_push(SIGPIPE, SIG_IGN);
write_in_full(proc.in, buf, n); write_in_full(proc.in, buf, n);
close(proc.in); close(proc.in);
sigchain_pop(SIGPIPE);
return finish_command(&proc); return finish_command(&proc);
} }

View File

@ -109,23 +109,20 @@ test_expect_success 'push to URL' '
diff expected actual diff expected actual
' '
# Test that filling pipe buffers doesn't cause failure test_expect_success 'set up many-ref tests' '
# Too slow to leave enabled for general use {
if false nr=1000
then while test $nr -lt 2000
printf 'parent1\nrepo1\n' >expected do
nr=1000 nr=$(( $nr + 1 ))
while test $nr -lt 2000 echo "create refs/heads/b/$nr $COMMIT3"
do done
nr=$(( $nr + 1 )) } | git update-ref --stdin
git branch b/$nr $COMMIT3 '
echo "refs/heads/b/$nr $COMMIT3 refs/heads/b/$nr $_z40" >>expected
done
test_expect_success 'push many refs' ' test_expect_success 'sigpipe does not cause pre-push hook failure' '
git push parent1 "refs/heads/b/*:refs/heads/b/*" && echo "exit 0" | write_script "$HOOK" &&
diff expected actual git push parent1 "refs/heads/b/*:refs/heads/b/*"
' '
fi
test_done test_done

View File

@ -15,6 +15,7 @@
#include "submodule.h" #include "submodule.h"
#include "string-list.h" #include "string-list.h"
#include "sha1-array.h" #include "sha1-array.h"
#include "sigchain.h"
/* rsync support */ /* rsync support */
@ -1126,6 +1127,8 @@ static int run_pre_push_hook(struct transport *transport,
return -1; return -1;
} }
sigchain_push(SIGPIPE, SIG_IGN);
strbuf_init(&buf, 256); strbuf_init(&buf, 256);
for (r = remote_refs; r; r = r->next) { 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->peer_ref->name, sha1_to_hex(r->new_sha1),
r->name, sha1_to_hex(r->old_sha1)); r->name, sha1_to_hex(r->old_sha1));
if (write_in_full(proc.in, buf.buf, buf.len) != buf.len) { if (write_in_full(proc.in, buf.buf, buf.len) < 0) {
ret = -1; /* We do not mind if a hook does not read all refs. */
if (errno != EPIPE)
ret = -1;
break; break;
} }
} }
@ -1151,6 +1156,8 @@ static int run_pre_push_hook(struct transport *transport,
if (!ret) if (!ret)
ret = x; ret = x;
sigchain_pop(SIGPIPE);
x = finish_command(&proc); x = finish_command(&proc);
if (!ret) if (!ret)
ret = x; ret = x;