From f6a4e61fbb647928d615a0befaec163a5d2bf4af Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 14 Jul 2016 14:49:47 -0700 Subject: push: accept push options This implements everything that is required on the client side to make use of push options from the porcelain push command. Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- send-pack.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'send-pack.c') diff --git a/send-pack.c b/send-pack.c index 299d30384..3a842ac2d 100644 --- a/send-pack.c +++ b/send-pack.c @@ -260,6 +260,7 @@ static int generate_push_cert(struct strbuf *req_buf, const char *push_cert_nonce) { const struct ref *ref; + struct string_list_item *item; char *signing_key = xstrdup(get_signing_key()); const char *cp, *np; struct strbuf cert = STRBUF_INIT; @@ -276,6 +277,9 @@ static int generate_push_cert(struct strbuf *req_buf, } if (push_cert_nonce[0]) strbuf_addf(&cert, "nonce %s\n", push_cert_nonce); + if (args->push_options) + for_each_string_list_item(item, args->push_options) + strbuf_addf(&cert, "push-option %s\n", item->string); strbuf_addstr(&cert, "\n"); for (ref = remote_refs; ref; ref = ref->next) { @@ -370,6 +374,8 @@ int send_pack(struct send_pack_args *args, int agent_supported = 0; int use_atomic = 0; int atomic_supported = 0; + int use_push_options = 0; + int push_options_supported = 0; unsigned cmds_sent = 0; int ret; struct async demux; @@ -392,6 +398,8 @@ int send_pack(struct send_pack_args *args, args->use_thin_pack = 0; if (server_supports("atomic")) atomic_supported = 1; + if (server_supports("push-options")) + push_options_supported = 1; if (args->push_cert != SEND_PACK_PUSH_CERT_NEVER) { int len; @@ -418,6 +426,11 @@ int send_pack(struct send_pack_args *args, use_atomic = atomic_supported && args->atomic; + if (args->push_options && !push_options_supported) + die(_("the receiving end does not support push options")); + + use_push_options = push_options_supported && args->push_options; + if (status_report) strbuf_addstr(&cap_buf, " report-status"); if (use_sideband) @@ -426,6 +439,8 @@ int send_pack(struct send_pack_args *args, strbuf_addstr(&cap_buf, " quiet"); if (use_atomic) strbuf_addstr(&cap_buf, " atomic"); + if (use_push_options) + strbuf_addstr(&cap_buf, " push-options"); if (agent_supported) strbuf_addf(&cap_buf, " agent=%s", git_user_agent_sanitized()); @@ -512,6 +527,18 @@ int send_pack(struct send_pack_args *args, strbuf_release(&req_buf); strbuf_release(&cap_buf); + if (use_push_options) { + struct string_list_item *item; + struct strbuf sb = STRBUF_INIT; + + for_each_string_list_item(item, args->push_options) + packet_buf_write(&sb, "%s", item->string); + + write_or_die(out, sb.buf, sb.len); + packet_flush(out); + strbuf_release(&sb); + } + if (use_sideband && cmds_sent) { memset(&demux, 0, sizeof(demux)); demux.proc = sideband_demux; -- cgit v1.2.1