Browse Source

receive-pack: feed report options to post-receive

When commands are fed to the "post-receive" hook, report options will
be parsed and the real old-oid, new-oid, reference name will feed to
the "post-receive" hook.

Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Jiang Xin 4 years ago committed by Junio C Hamano
parent
commit
195d6eaea3
  1. 30
      builtin/receive-pack.c
  2. 14
      t/t5411/test-0032-report-with-options.sh
  3. 14
      t/t5411/test-0033-report-with-options--porcelain.sh
  4. 11
      t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh
  5. 11
      t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh
  6. 2
      t/t5411/test-0038-report-mixed-refs.sh
  7. 2
      t/t5411/test-0039-report-mixed-refs--porcelain.sh

30
builtin/receive-pack.c

@ -694,6 +694,7 @@ static void prepare_push_cert_sha1(struct child_process *proc)


struct receive_hook_feed_state { struct receive_hook_feed_state {
struct command *cmd; struct command *cmd;
struct ref_push_report *report;
int skip_broken; int skip_broken;
struct strbuf buf; struct strbuf buf;
const struct string_list *push_options; const struct string_list *push_options;
@ -781,11 +782,31 @@ static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep)
cmd = cmd->next; cmd = cmd->next;
if (!cmd) if (!cmd)
return -1; /* EOF */ return -1; /* EOF */
if (!bufp)
return 0; /* OK, can feed something. */
strbuf_reset(&state->buf); strbuf_reset(&state->buf);
strbuf_addf(&state->buf, "%s %s %s\n", if (!state->report)
oid_to_hex(&cmd->old_oid), oid_to_hex(&cmd->new_oid), state->report = cmd->report;
cmd->ref_name); if (state->report) {
state->cmd = cmd->next; struct object_id *old_oid;
struct object_id *new_oid;
const char *ref_name;

old_oid = state->report->old_oid ? state->report->old_oid : &cmd->old_oid;
new_oid = state->report->new_oid ? state->report->new_oid : &cmd->new_oid;
ref_name = state->report->ref_name ? state->report->ref_name : cmd->ref_name;
strbuf_addf(&state->buf, "%s %s %s\n",
oid_to_hex(old_oid), oid_to_hex(new_oid),
ref_name);
state->report = state->report->next;
if (!state->report)
state->cmd = cmd->next;
} else {
strbuf_addf(&state->buf, "%s %s %s\n",
oid_to_hex(&cmd->old_oid), oid_to_hex(&cmd->new_oid),
cmd->ref_name);
state->cmd = cmd->next;
}
if (bufp) { if (bufp) {
*bufp = state->buf.buf; *bufp = state->buf.buf;
*sizep = state->buf.len; *sizep = state->buf.len;
@ -804,6 +825,7 @@ static int run_receive_hook(struct command *commands,
strbuf_init(&state.buf, 0); strbuf_init(&state.buf, 0);
state.cmd = commands; state.cmd = commands;
state.skip_broken = skip_broken; state.skip_broken = skip_broken;
state.report = NULL;
if (feed_receive_hook(&state, NULL, NULL)) if (feed_receive_hook(&state, NULL, NULL))
return 0; return 0;
state.cmd = commands; state.cmd = commands;

14
t/t5411/test-0032-report-with-options.sh

@ -54,7 +54,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL)" '
remote: proc-receive> ok refs/for/master/topic remote: proc-receive> ok refs/for/master/topic
remote: proc-receive> option refname refs/pull/123/head remote: proc-receive> option refname refs/pull/123/head
remote: # post-receive hook remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
To <URL/of/upstream.git> To <URL/of/upstream.git>
* [new reference] HEAD -> refs/for/master/topic * [new reference] HEAD -> refs/for/master/topic
EOF EOF
@ -87,7 +87,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO
remote: proc-receive> option refname refs/pull/123/head remote: proc-receive> option refname refs/pull/123/head
remote: proc-receive> option forced-update remote: proc-receive> option forced-update
remote: # post-receive hook remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
To <URL/of/upstream.git> To <URL/of/upstream.git>
* [new reference] HEAD -> refs/for/master/topic * [new reference] HEAD -> refs/for/master/topic
EOF EOF
@ -121,7 +121,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL)
remote: proc-receive> option refname refs/pull/123/head remote: proc-receive> option refname refs/pull/123/head
remote: proc-receive> option old-oid <COMMIT-B> remote: proc-receive> option old-oid <COMMIT-B>
remote: # post-receive hook remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head
To <URL/of/upstream.git> To <URL/of/upstream.git>
* [new reference] HEAD -> refs/for/master/topic * [new reference] HEAD -> refs/for/master/topic
EOF EOF
@ -153,7 +153,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL)" '
remote: proc-receive> ok refs/for/master/topic remote: proc-receive> ok refs/for/master/topic
remote: proc-receive> option old-oid <COMMIT-B> remote: proc-receive> option old-oid <COMMIT-B>
remote: # post-receive hook remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic
To <URL/of/upstream.git> To <URL/of/upstream.git>
* [new reference] HEAD -> refs/for/master/topic * [new reference] HEAD -> refs/for/master/topic
EOF EOF
@ -187,7 +187,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL)
remote: proc-receive> option old-oid <COMMIT-A> remote: proc-receive> option old-oid <COMMIT-A>
remote: proc-receive> option new-oid <COMMIT-B> remote: proc-receive> option new-oid <COMMIT-B>
remote: # post-receive hook remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
To <URL/of/upstream.git> To <URL/of/upstream.git>
* [new reference] HEAD -> refs/for/master/topic * [new reference] HEAD -> refs/for/master/topic
EOF EOF
@ -237,9 +237,9 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL)" '
remote: proc-receive> option forced-update remote: proc-receive> option forced-update
remote: proc-receive> option new-oid <COMMIT-A> remote: proc-receive> option new-oid <COMMIT-A>
remote: # post-receive hook remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head
To <URL/of/upstream.git> To <URL/of/upstream.git>
* [new reference] HEAD -> refs/for/next/topic * [new reference] HEAD -> refs/for/next/topic
* [new reference] HEAD -> refs/for/a/b/c/topic * [new reference] HEAD -> refs/for/a/b/c/topic

14
t/t5411/test-0033-report-with-options--porcelain.sh

@ -55,7 +55,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL/porcelain)"
remote: proc-receive> ok refs/for/master/topic remote: proc-receive> ok refs/for/master/topic
remote: proc-receive> option refname refs/pull/123/head remote: proc-receive> option refname refs/pull/123/head
remote: # post-receive hook remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
To <URL/of/upstream.git> To <URL/of/upstream.git>
* HEAD:refs/for/master/topic [new reference] * HEAD:refs/for/master/topic [new reference]
Done Done
@ -90,7 +90,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO
remote: proc-receive> option refname refs/pull/123/head remote: proc-receive> option refname refs/pull/123/head
remote: proc-receive> option forced-update remote: proc-receive> option forced-update
remote: # post-receive hook remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
To <URL/of/upstream.git> To <URL/of/upstream.git>
* HEAD:refs/for/master/topic [new reference] * HEAD:refs/for/master/topic [new reference]
Done Done
@ -125,7 +125,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL/
remote: proc-receive> option refname refs/pull/123/head remote: proc-receive> option refname refs/pull/123/head
remote: proc-receive> option old-oid <COMMIT-B> remote: proc-receive> option old-oid <COMMIT-B>
remote: # post-receive hook remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head
To <URL/of/upstream.git> To <URL/of/upstream.git>
* HEAD:refs/for/master/topic [new reference] * HEAD:refs/for/master/topic [new reference]
Done Done
@ -158,7 +158,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL/porcelain)"
remote: proc-receive> ok refs/for/master/topic remote: proc-receive> ok refs/for/master/topic
remote: proc-receive> option old-oid <COMMIT-B> remote: proc-receive> option old-oid <COMMIT-B>
remote: # post-receive hook remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic
To <URL/of/upstream.git> To <URL/of/upstream.git>
* HEAD:refs/for/master/topic [new reference] * HEAD:refs/for/master/topic [new reference]
Done Done
@ -193,7 +193,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL/
remote: proc-receive> option old-oid <COMMIT-A> remote: proc-receive> option old-oid <COMMIT-A>
remote: proc-receive> option new-oid <COMMIT-B> remote: proc-receive> option new-oid <COMMIT-B>
remote: # post-receive hook remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
To <URL/of/upstream.git> To <URL/of/upstream.git>
* HEAD:refs/for/master/topic [new reference] * HEAD:refs/for/master/topic [new reference]
Done Done
@ -245,9 +245,9 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL/porc
remote: proc-receive> option forced-update remote: proc-receive> option forced-update
remote: proc-receive> option new-oid <COMMIT-A> remote: proc-receive> option new-oid <COMMIT-A>
remote: # post-receive hook remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head
To <URL/of/upstream.git> To <URL/of/upstream.git>
* HEAD:refs/for/next/topic [new reference] * HEAD:refs/for/next/topic [new reference]
* HEAD:refs/for/a/b/c/topic [new reference] * HEAD:refs/for/a/b/c/topic [new reference]

11
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh

@ -41,7 +41,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
remote: proc-receive> option old-oid <COMMIT-A> remote: proc-receive> option old-oid <COMMIT-A>
remote: proc-receive> option new-oid <COMMIT-B> remote: proc-receive> option new-oid <COMMIT-B>
remote: # post-receive hook remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1
To <URL/of/upstream.git> To <URL/of/upstream.git>
* [new reference] HEAD -> refs/for/master/topic * [new reference] HEAD -> refs/for/master/topic
EOF EOF
@ -99,7 +101,9 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
remote: proc-receive> option new-oid <COMMIT-A> remote: proc-receive> option new-oid <COMMIT-A>
remote: proc-receive> option forced-update remote: proc-receive> option forced-update
remote: # post-receive hook remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1
To <URL/of/upstream.git> To <URL/of/upstream.git>
* [new reference] HEAD -> refs/for/master/topic * [new reference] HEAD -> refs/for/master/topic
EOF EOF
@ -145,7 +149,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
remote: proc-receive> option old-oid <COMMIT-A> remote: proc-receive> option old-oid <COMMIT-A>
remote: proc-receive> option new-oid <COMMIT-B> remote: proc-receive> option new-oid <COMMIT-B>
remote: # post-receive hook remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1
remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2
To <URL/of/upstream.git> To <URL/of/upstream.git>
* [new reference] HEAD -> refs/for/master/topic * [new reference] HEAD -> refs/for/master/topic
EOF EOF

11
t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh

@ -41,7 +41,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
remote: proc-receive> option old-oid <COMMIT-A> remote: proc-receive> option old-oid <COMMIT-A>
remote: proc-receive> option new-oid <COMMIT-B> remote: proc-receive> option new-oid <COMMIT-B>
remote: # post-receive hook remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1
To <URL/of/upstream.git> To <URL/of/upstream.git>
* HEAD:refs/for/master/topic [new reference] * HEAD:refs/for/master/topic [new reference]
Done Done
@ -100,7 +102,9 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
remote: proc-receive> option new-oid <COMMIT-A> remote: proc-receive> option new-oid <COMMIT-A>
remote: proc-receive> option forced-update remote: proc-receive> option forced-update
remote: # post-receive hook remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1
To <URL/of/upstream.git> To <URL/of/upstream.git>
* HEAD:refs/for/master/topic [new reference] * HEAD:refs/for/master/topic [new reference]
Done Done
@ -147,7 +151,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL/porc
remote: proc-receive> option old-oid <COMMIT-A> remote: proc-receive> option old-oid <COMMIT-A>
remote: proc-receive> option new-oid <COMMIT-B> remote: proc-receive> option new-oid <COMMIT-B>
remote: # post-receive hook remote: # post-receive hook
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1
remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2
To <URL/of/upstream.git> To <URL/of/upstream.git>
* HEAD:refs/for/master/topic [new reference] * HEAD:refs/for/master/topic [new reference]
Done Done

2
t/t5411/test-0038-report-mixed-refs.sh

@ -53,7 +53,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2 remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
To <URL/of/upstream.git> To <URL/of/upstream.git>
<OID-A>..<OID-B> <COMMIT-B> -> master <OID-A>..<OID-B> <COMMIT-B> -> master
* [new branch] HEAD -> bar * [new branch] HEAD -> bar

2
t/t5411/test-0039-report-mixed-refs--porcelain.sh

@ -53,7 +53,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2 remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
To <URL/of/upstream.git> To <URL/of/upstream.git>
<COMMIT-B>:refs/heads/master <OID-A>..<OID-B> <COMMIT-B>:refs/heads/master <OID-A>..<OID-B>
* HEAD:refs/heads/bar [new branch] * HEAD:refs/heads/bar [new branch]

Loading…
Cancel
Save