Merge branch 'sb/push-options-via-transport'
authorJunio C Hamano <gitster@pobox.com>
Mon, 27 Mar 2017 17:59:27 +0000 (10:59 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Mar 2017 17:59:27 +0000 (10:59 -0700)
Recently we started passing the "--push-options" through the
external remote helper interface; now the "smart HTTP" remote
helper understands what to do with the passed information.

* sb/push-options-via-transport:
remote-curl: allow push options
send-pack: send push options correctly in stateless-rpc case

1  2 
send-pack.c
diff --combined send-pack.c
index d2d2a49a0231293e98ab8546945f8d3ef9fa205d,56cc5c3a746224bc3dc54880363b9625d0faed91..66e652f7ef79e43e5427364960da186b99b11686
@@@ -72,7 -72,6 +72,7 @@@ static int pack_objects(int fd, struct 
        struct child_process po = CHILD_PROCESS_INIT;
        FILE *po_in;
        int i;
 +      int rc;
  
        i = 4;
        if (args->use_thin_pack)
                po.out = -1;
        }
  
 -      if (finish_command(&po))
 +      rc = finish_command(&po);
 +      if (rc) {
 +              /*
 +               * For a normal non-zero exit, we assume pack-objects wrote
 +               * something useful to stderr. For death by signal, though,
 +               * we should mention it to the user. The exception is SIGPIPE
 +               * (141), because that's a normal occurence if the remote end
 +               * hangs up (and we'll report that by trying to read the unpack
 +               * status).
 +               */
 +              if (rc > 128 && rc != 141)
 +                      error("pack-objects died of signal %d", rc - 128);
                return -1;
 +      }
 +      return 0;
 +}
 +
 +static int receive_unpack_status(int in)
 +{
 +      const char *line = packet_read_line(in, NULL);
 +      if (!skip_prefix(line, "unpack ", &line))
 +              return error(_("unable to parse remote unpack status: %s"), line);
 +      if (strcmp(line, "ok"))
 +              return error(_("remote unpack failed: %s"), line);
        return 0;
  }
  
  static int receive_status(int in, struct ref *refs)
  {
        struct ref *hint;
 -      int ret = 0;
 -      char *line = packet_read_line(in, NULL);
 -      if (!starts_with(line, "unpack "))
 -              return error("did not receive remote status");
 -      if (strcmp(line, "unpack ok")) {
 -              error("unpack failed: %s", line + 7);
 -              ret = -1;
 -      }
 +      int ret;
 +
        hint = NULL;
 +      ret = receive_unpack_status(in);
        while (1) {
                char *refname;
                char *msg;
 -              line = packet_read_line(in, NULL);
 +              char *line = packet_read_line(in, NULL);
                if (!line)
                        break;
                if (!starts_with(line, "ok ") && !starts_with(line, "ng ")) {
@@@ -532,6 -514,14 +532,14 @@@ int send_pack(struct send_pack_args *ar
                }
        }
  
+       if (use_push_options) {
+               struct string_list_item *item;
+               packet_buf_flush(&req_buf);
+               for_each_string_list_item(item, args->push_options)
+                       packet_buf_write(&req_buf, "%s", item->string);
+       }
        if (args->stateless_rpc) {
                if (!args->dry_run && (cmds_sent || is_repository_shallow())) {
                        packet_buf_flush(&req_buf);
        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;
                                close(out);
                        if (git_connection_is_socket(conn))
                                shutdown(fd[0], SHUT_WR);
 +
 +                      /*
 +                       * Do not even bother with the return value; we know we
 +                       * are failing, and just want the error() side effects.
 +                       */
 +                      if (status_report)
 +                              receive_unpack_status(in);
 +
                        if (use_sideband) {
                                close(demux.out);
                                finish_async(&demux);