From: Junio C Hamano Date: Mon, 21 Jul 2014 18:18:40 +0000 (-0700) Subject: Merge branch 'jk/remote-curl-squelch-extra-errors' X-Git-Tag: v2.1.0-rc0~21 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/0ac744305f5885207bf96fc5488fcc59782ffa96?ds=inline;hp=-c Merge branch 'jk/remote-curl-squelch-extra-errors' * jk/remote-curl-squelch-extra-errors: remote-curl: mark helper-protocol errors more clearly remote-curl: use error instead of fprintf(stderr) remote-curl: do not complain on EOF from parent git --- 0ac744305f5885207bf96fc5488fcc59782ffa96 diff --combined remote-curl.c index cdcca2903b,449c24defa..0fcf2ce5ff --- a/remote-curl.c +++ b/remote-curl.c @@@ -194,19 -194,19 +194,19 @@@ static void free_discovery(struct disco } } -static int show_http_message(struct strbuf *type, struct strbuf *msg) +static int show_http_message(struct strbuf *type, struct strbuf *charset, + struct strbuf *msg) { const char *p, *eol; /* * We only show text/plain parts, as other types are likely * to be ugly to look at on the user's terminal. - * - * TODO should handle "; charset=XXX", and re-encode into - * logoutputencoding */ - if (strcasecmp(type->buf, "text/plain")) + if (strcmp(type->buf, "text/plain")) return -1; + if (charset->len) + strbuf_reencode(msg, charset->buf, get_log_output_encoding()); strbuf_trim(msg); if (!msg->len) @@@ -225,7 -225,6 +225,7 @@@ static struct discovery* discover_refs( { struct strbuf exp = STRBUF_INIT; struct strbuf type = STRBUF_INIT; + struct strbuf charset = STRBUF_INIT; struct strbuf buffer = STRBUF_INIT; struct strbuf refs_url = STRBUF_INIT; struct strbuf effective_url = STRBUF_INIT; @@@ -250,7 -249,6 +250,7 @@@ memset(&options, 0, sizeof(options)); options.content_type = &type; + options.charset = &charset; options.effective_url = &effective_url; options.base_url = &url; options.no_cache = 1; @@@ -261,13 -259,13 +261,13 @@@ case HTTP_OK: break; case HTTP_MISSING_TARGET: - show_http_message(&type, &buffer); + show_http_message(&type, &charset, &buffer); die("repository '%s' not found", url.buf); case HTTP_NOAUTH: - show_http_message(&type, &buffer); + show_http_message(&type, &charset, &buffer); die("Authentication failed for '%s'", url.buf); default: - show_http_message(&type, &buffer); + show_http_message(&type, &charset, &buffer); die("unable to access '%s': %s", url.buf, curl_errorstr); } @@@ -312,7 -310,6 +312,7 @@@ strbuf_release(&refs_url); strbuf_release(&exp); strbuf_release(&type); + strbuf_release(&charset); strbuf_release(&effective_url); strbuf_release(&buffer); last_discovery = last; @@@ -399,7 -396,7 +399,7 @@@ static curlioerr rpc_ioctl(CURL *handle rpc->pos = 0; return CURLIOE_OK; } - fprintf(stderr, "Unable to rewind rpc post data - try increasing http.postBuffer\n"); + error("unable to rewind rpc post data - try increasing http.postBuffer"); return CURLIOE_FAILRESTART; default: @@@ -426,8 -423,11 +426,8 @@@ static int run_slot(struct active_reque if (!results) results = &results_buf; - slot->results = results; - slot->curl_result = curl_easy_perform(slot->curl); - finish_active_slot(slot); + err = run_one_slot(slot, results); - err = handle_curl_result(results); if (err != HTTP_OK && err != HTTP_REAUTH) { error("RPC failed; result=%d, HTTP code = %ld", results->curl_result, results->http_code); @@@ -709,7 -709,7 +709,7 @@@ static int fetch_dumb(int nr_heads, str free(targets[i]); free(targets); - return ret ? error("Fetch failed.") : 0; + return ret ? error("fetch failed.") : 0; } static int fetch_git(struct discovery *heads, @@@ -791,9 -791,9 +791,9 @@@ static void parse_fetch(struct strbuf * int alloc_heads = 0, nr_heads = 0; do { - if (starts_with(buf->buf, "fetch ")) { - char *p = buf->buf + strlen("fetch "); - char *name; + const char *p; + if (skip_prefix(buf->buf, "fetch ", &p)) { + const char *name; struct ref *ref; unsigned char old_sha1[20]; @@@ -949,7 -949,7 +949,7 @@@ int main(int argc, const char **argv git_extract_argv0_path(argv[0]); setup_git_directory_gently(&nongit); if (argc < 2) { - fprintf(stderr, "Remote needed\n"); + error("remote-curl: usage: git remote-curl []"); return 1; } @@@ -968,20 -968,16 +968,18 @@@ http_init(remote, url.buf, 0); do { + const char *arg; + 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"); + error("remote-curl: error reading command stream from git"); return 1; } if (buf.len == 0) break; if (starts_with(buf.buf, "fetch ")) { if (nongit) - die("Fetch attempted without a local repo"); + die("remote-curl: fetch attempted without a local repo"); parse_fetch(&buf); } else if (!strcmp(buf.buf, "list") || starts_with(buf.buf, "list ")) { @@@ -991,8 -987,9 +989,8 @@@ } else if (starts_with(buf.buf, "push ")) { parse_push(&buf); - } else if (starts_with(buf.buf, "option ")) { - char *name = buf.buf + strlen("option "); - char *value = strchr(name, ' '); + } else if (skip_prefix(buf.buf, "option ", &arg)) { + char *value = strchr(arg, ' '); int result; if (value) @@@ -1000,7 -997,7 +998,7 @@@ else value = "true"; - result = set_option(name, value); + result = set_option(arg, value); if (!result) printf("ok\n"); else if (result < 0) @@@ -1017,7 -1014,7 +1015,7 @@@ printf("\n"); fflush(stdout); } else { - fprintf(stderr, "Unknown command '%s'\n", buf.buf); + error("remote-curl: unknown command '%s' from git", buf.buf); return 1; } strbuf_reset(&buf);