Merge branch 'js/remote-curl-i18n'
authorJunio C Hamano <gitster@pobox.com>
Tue, 16 Apr 2019 10:28:05 +0000 (19:28 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 16 Apr 2019 10:28:05 +0000 (19:28 +0900)
Error messages given from the http transport have been updated so
that they can be localized.

* js/remote-curl-i18n:
remote-curl: mark all error messages for translation

1  2 
remote-curl.c
diff --cc remote-curl.c
index 78f340f004e36bdfd84687f1ee803254b8fb8d43,06f091d86217765dbdaca10180e9e877b8a7c77c..8bba57270b00b72c7e70fe749880a29c1ddfea1f
@@@ -332,63 -331,9 +332,63 @@@ static int get_protocol_http_header(enu
        return 0;
  }
  
-               die("invalid server response; expected service, got flush packet");
 +static void check_smart_http(struct discovery *d, const char *service,
 +                           struct strbuf *type)
 +{
 +      const char *p;
 +      struct packet_reader reader;
 +
 +      /*
 +       * If we don't see x-$service-advertisement, then it's not smart-http.
 +       * But once we do, we commit to it and assume any other protocol
 +       * violations are hard errors.
 +       */
 +      if (!skip_prefix(type->buf, "application/x-", &p) ||
 +          !skip_prefix(p, service, &p) ||
 +          strcmp(p, "-advertisement"))
 +              return;
 +
 +      packet_reader_init(&reader, -1, d->buf, d->len,
 +                         PACKET_READ_CHOMP_NEWLINE |
 +                         PACKET_READ_DIE_ON_ERR_PACKET);
 +      if (packet_reader_read(&reader) != PACKET_READ_NORMAL)
-               die("invalid server response; got '%s'", reader.line);
++              die(_("invalid server response; expected service, got flush packet"));
 +
 +      if (skip_prefix(reader.line, "# service=", &p) && !strcmp(p, service)) {
 +              /*
 +               * The header can include additional metadata lines, up
 +               * until a packet flush marker.  Ignore these now, but
 +               * in the future we might start to scan them.
 +               */
 +              for (;;) {
 +                      packet_reader_read(&reader);
 +                      if (reader.pktlen <= 0) {
 +                              break;
 +                      }
 +              }
 +
 +              /*
 +               * v0 smart http; callers expect us to soak up the
 +               * service and header packets
 +               */
 +              d->buf = reader.src_buffer;
 +              d->len = reader.src_len;
 +              d->proto_git = 1;
 +
 +      } else if (!strcmp(reader.line, "version 2")) {
 +              /*
 +               * v2 smart http; do not consume version packet, which will
 +               * be handled elsewhere.
 +               */
 +              d->proto_git = 1;
 +
 +      } else {
++              die(_("invalid server response; got '%s'"), reader.line);
 +      }
 +}
 +
  static struct discovery *discover_refs(const char *service, int for_push)
  {
 -      struct strbuf exp = STRBUF_INIT;
        struct strbuf type = STRBUF_INIT;
        struct strbuf charset = STRBUF_INIT;
        struct strbuf buffer = STRBUF_INIT;
@@@ -523,81 -502,11 +523,81 @@@ struct rpc_state 
        int in;
        int out;
        int any_written;
 -      struct strbuf result;
        unsigned gzip_request : 1;
        unsigned initial_buffer : 1;
 +
 +      /*
 +       * Whenever a pkt-line is read into buf, append the 4 characters
 +       * denoting its length before appending the payload.
 +       */
 +      unsigned write_line_lengths : 1;
 +
 +      /*
 +       * Used by rpc_out; initialize to 0. This is true if a flush has been
 +       * read, but the corresponding line length (if write_line_lengths is
 +       * true) and EOF have not been sent to libcurl. Since each flush marks
 +       * the end of a request, each flush must be completely sent before any
 +       * further reading occurs.
 +       */
 +      unsigned flush_read_but_not_sent : 1;
  };
  
-                               die("shouldn't have EOF when not gentle on EOF");
 +/*
 + * Appends the result of reading from rpc->out to the string represented by
 + * rpc->buf and rpc->len if there is enough space. Returns 1 if there was
 + * enough space, 0 otherwise.
 + *
 + * If rpc->write_line_lengths is true, appends the line length as a 4-byte
 + * hexadecimal string before appending the result described above.
 + *
 + * Writes the total number of bytes appended into appended.
 + */
 +static int rpc_read_from_out(struct rpc_state *rpc, int options,
 +                           size_t *appended,
 +                           enum packet_read_status *status) {
 +      size_t left;
 +      char *buf;
 +      int pktlen_raw;
 +
 +      if (rpc->write_line_lengths) {
 +              left = rpc->alloc - rpc->len - 4;
 +              buf = rpc->buf + rpc->len + 4;
 +      } else {
 +              left = rpc->alloc - rpc->len;
 +              buf = rpc->buf + rpc->len;
 +      }
 +
 +      if (left < LARGE_PACKET_MAX)
 +              return 0;
 +
 +      *status = packet_read_with_status(rpc->out, NULL, NULL, buf,
 +                      left, &pktlen_raw, options);
 +      if (*status != PACKET_READ_EOF) {
 +              *appended = pktlen_raw + (rpc->write_line_lengths ? 4 : 0);
 +              rpc->len += *appended;
 +      }
 +
 +      if (rpc->write_line_lengths) {
 +              switch (*status) {
 +              case PACKET_READ_EOF:
 +                      if (!(options & PACKET_READ_GENTLE_ON_EOF))
++                              die(_("shouldn't have EOF when not gentle on EOF"));
 +                      break;
 +              case PACKET_READ_NORMAL:
 +                      set_packet_header(buf - 4, *appended);
 +                      break;
 +              case PACKET_READ_DELIM:
 +                      memcpy(buf - 4, "0001", 4);
 +                      break;
 +              case PACKET_READ_FLUSH:
 +                      memcpy(buf - 4, "0000", 4);
 +                      break;
 +              }
 +      }
 +
 +      return 1;
 +}
 +
  static size_t rpc_out(void *ptr, size_t eltsize,
                size_t nmemb, void *buffer_)
  {
@@@ -757,19 -624,13 +757,19 @@@ static int probe_rpc(struct rpc_state *
        return err;
  }
  
 -static curl_off_t xcurl_off_t(ssize_t len) {
 -      if (len > maximum_signed_value_of_type(curl_off_t))
 +static curl_off_t xcurl_off_t(size_t len)
 +{
 +      uintmax_t size = len;
 +      if (size > maximum_signed_value_of_type(curl_off_t))
-               die("cannot handle pushes this big");
+               die(_("cannot handle pushes this big"));
 -      return (curl_off_t) len;
 +      return (curl_off_t)size;
  }
  
 -static int post_rpc(struct rpc_state *rpc)
 +/*
 + * If flush_received is true, do not attempt to read any more; just use what's
 + * in rpc->buf.
 + */
 +static int post_rpc(struct rpc_state *rpc, int flush_received)
  {
        struct active_request_slot *slot;
        struct curl_slist *headers = http_copy_default_headers();