From: Junio C Hamano Date: Tue, 1 Nov 2011 22:45:16 +0000 (-0700) Subject: Merge branch 'sp/smart-http-failure' into maint X-Git-Tag: v1.7.7.2~8 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/7fa6c90c72fb8dc8277d7cae759d5036046a5164?hp=-c Merge branch 'sp/smart-http-failure' into maint * sp/smart-http-failure: remote-curl: Fix warning after HTTP failure --- 7fa6c90c72fb8dc8277d7cae759d5036046a5164 diff --combined remote-curl.c index b8cf45a7dd,d9abbf5f75..0aa4bfed30 --- a/remote-curl.c +++ b/remote-curl.c @@@ -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; @@@ -486,11 -488,11 +486,11 @@@ 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) @@@ -855,14 -862,7 +862,14 @@@ 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) @@@ -902,7 -902,6 +909,7 @@@ printf("\n"); fflush(stdout); } else { + fprintf(stderr, "Unknown command '%s'\n", buf.buf); return 1; } strbuf_reset(&buf);