Merge branch 'jk/remote-curl-squelch-extra-errors'
authorJunio C Hamano <gitster@pobox.com>
Mon, 21 Jul 2014 18:18:40 +0000 (11:18 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 21 Jul 2014 18:18:41 +0000 (11:18 -0700)
* 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

1  2 
remote-curl.c
diff --combined remote-curl.c
index cdcca2903b100c775d4e004312086581f5839ad4,449c24defa1485d972467d55633b79107af5f6ae..0fcf2ce5ff20cc7c6f1bdf6257c94cf8fa21b35a
@@@ -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;
  
        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;
        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);
        }
  
        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 <remote> [<url>]");
                return 1;
        }
  
        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 ")) {
                } 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)
                        else
                                value = "true";
  
 -                      result = set_option(name, value);
 +                      result = set_option(arg, value);
                        if (!result)
                                printf("ok\n");
                        else if (result < 0)
                        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);