Merge branch 'sp/smart-http-failure'
authorJunio C Hamano <gitster@pobox.com>
Wed, 12 Oct 2011 19:34:27 +0000 (12:34 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 12 Oct 2011 19:34:27 +0000 (12:34 -0700)
* sp/smart-http-failure:
remote-curl: Fix warning after HTTP failure

1  2 
remote-curl.c
diff --combined remote-curl.c
index b8cf45a7dd439b83c80bcf7a397e1b8e34c70f67,d9abbf5f7596a7d8ba359d79827e433a452f24cf..0aa4bfed309d6c439fac4ff2a0df6a468307e7bf
@@@ -227,8 -227,6 +227,8 @@@ static struct ref *parse_info_refs(stru
                if (data[i] == '\t')
                        mid = &data[i];
                if (data[i] == '\n') {
 +                      if (mid - start != 40)
 +                              die("%sinfo/refs not valid: is this a git repository?", url);
                        data[i] = 0;
                        ref_name = mid + 1;
                        ref = xmalloc(sizeof(struct ref) +
@@@ -349,7 -347,7 +349,7 @@@ static curlioerr rpc_ioctl(CURL *handle
  }
  #endif
  
 -static size_t rpc_in(const void *ptr, size_t eltsize,
 +static size_t rpc_in(char *ptr, size_t eltsize,
                size_t nmemb, void *buffer_)
  {
        size_t size = eltsize * nmemb;
@@@ -473,12 -471,16 +473,12 @@@ static int post_rpc(struct rpc_state *r
                 * the transfer time.
                 */
                size_t size;
 -              z_stream stream;
 +              git_zstream stream;
                int ret;
  
                memset(&stream, 0, sizeof(stream));
 -              ret = deflateInit2(&stream, Z_BEST_COMPRESSION,
 -                              Z_DEFLATED, (15 + 16),
 -                              8, Z_DEFAULT_STRATEGY);
 -              if (ret != Z_OK)
 -                      die("cannot deflate request; zlib init error %d", ret);
 -              size = deflateBound(&stream, rpc->len);
 +              git_deflate_init_gzip(&stream, Z_BEST_COMPRESSION);
 +              size = git_deflate_bound(&stream, rpc->len);
                gzip_body = xmalloc(size);
  
                stream.next_in = (unsigned char *)rpc->buf;
                stream.next_out = (unsigned char *)gzip_body;
                stream.avail_out = size;
  
 -              ret = deflate(&stream, Z_FINISH);
 +              ret = git_deflate(&stream, Z_FINISH);
                if (ret != Z_STREAM_END)
                        die("cannot deflate request; zlib deflate error %d", ret);
  
 -              ret = deflateEnd(&stream);
 +              ret = git_deflate_end_gently(&stream);
                if (ret != Z_OK)
                        die("cannot deflate request; zlib end error %d", ret);
  
@@@ -573,7 -575,14 +573,14 @@@ static int rpc_service(struct rpc_stat
  
        close(client.in);
        client.in = -1;
-       strbuf_read(&rpc->result, client.out, 0);
+       if (!err) {
+               strbuf_read(&rpc->result, client.out, 0);
+       } else {
+               char buf[4096];
+               for (;;)
+                       if (xread(client.out, buf, sizeof(buf)) <= 0)
+                               break;
+       }
  
        close(client.out);
        client.out = -1;
@@@ -809,21 -818,19 +816,21 @@@ static void parse_push(struct strbuf *b
  
                strbuf_reset(buf);
                if (strbuf_getline(buf, stdin, '\n') == EOF)
 -                      return;
 +                      goto free_specs;
                if (!*buf->buf)
                        break;
        } while (1);
  
        if (push(nr_spec, specs))
                exit(128); /* error already reported */
 -      for (i = 0; i < nr_spec; i++)
 -              free(specs[i]);
 -      free(specs);
  
        printf("\n");
        fflush(stdout);
 +
 + free_specs:
 +      for (i = 0; i < nr_spec; i++)
 +              free(specs[i]);
 +      free(specs);
  }
  
  int main(int argc, const char **argv)
        http_init(remote);
  
        do {
 -              if (strbuf_getline(&buf, stdin, '\n') == EOF)
 +              if (strbuf_getline(&buf, stdin, '\n') == EOF) {
 +                      if (ferror(stdin))
 +                              fprintf(stderr, "Error reading command stream\n");
 +                      else
 +                              fprintf(stderr, "Unexpected end of command stream\n");
 +                      return 1;
 +              }
 +              if (buf.len == 0)
                        break;
                if (!prefixcmp(buf.buf, "fetch ")) {
                        if (nongit)
                        printf("\n");
                        fflush(stdout);
                } else {
 +                      fprintf(stderr, "Unknown command '%s'\n", buf.buf);
                        return 1;
                }
                strbuf_reset(&buf);