send-pack: send push options correctly in stateless-rpc case

"git send-pack --stateless-rpc" puts each request in a sequence of pkt-lines followed by a flush-pkt. The push option code forgot about this and sends push options and their terminating delimiter as ordinary pkt-lines that get their length header stripped off by remote-curl before being sent to the server. The result is multiple malformed requests, which the server rejects. Fortunately send-pack --stateless-rpc already is aware of this "pkt-line within pkt-line" framing for the update commands that precede push options. Handle push options the same way. Helped-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Brandon Williams <bmwill@google.com> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed Mar 22, 2017 at 15:21 UTC eb7b9749f2b7bc0d0e0ac2c68d98cf1b8f4a2761
1 file changed +8 -12
send-pack.c
+8 -12
@@ -514,6 +514,14 @@ int send_pack(struct send_pack_args *args,
514 }
515 }
516
517 + if (use_push_options) {
518 + struct string_list_item *item;
519 +
520 + packet_buf_flush(&req_buf);
521 + for_each_string_list_item(item, args->push_options)
522 + packet_buf_write(&req_buf, "%s", item->string);
523 + }
524 +
525 if (args->stateless_rpc) {
526 if (!args->dry_run && (cmds_sent || is_repository_shallow())) {
527 packet_buf_flush(&req_buf);
@@ -526,18 +534,6 @@ int send_pack(struct send_pack_args *args,
534 strbuf_release(&req_buf);
535 strbuf_release(&cap_buf);
536
529 - if (use_push_options) {
530 - struct string_list_item *item;
531 - struct strbuf sb = STRBUF_INIT;
532 -
533 - for_each_string_list_item(item, args->push_options)
534 - packet_buf_write(&sb, "%s", item->string);
535 -
536 - write_or_die(out, sb.buf, sb.len);
537 - packet_flush(out);
538 - strbuf_release(&sb);
539 - }
540 -
537 if (use_sideband && cmds_sent) {
538 memset(&demux, 0, sizeof(demux));
539 demux.proc = sideband_demux;