Merge branch 'jn/maint-http-error-message'
authorJunio C Hamano <gitster@pobox.com>
Mon, 10 Oct 2011 22:56:17 +0000 (15:56 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Oct 2011 22:56:17 +0000 (15:56 -0700)
* jn/maint-http-error-message:
http: avoid empty error messages for some curl errors
http: remove extra newline in error message

1  2 
http.c
diff --combined http.c
index a59cac45d7a6c159e740cab9b20bb63ab91f7c48,61a90896ecb154089ef77756c1cfa8b03f524170..fb3465f50c95ab9cb3e6fae1d1e594f6ae0b9c42
--- 1/http.c
--- 2/http.c
+++ b/http.c
@@@ -41,7 -41,6 +41,7 @@@ static long curl_low_speed_limit = -1
  static long curl_low_speed_time = -1;
  static int curl_ftp_no_epsv;
  static const char *curl_http_proxy;
 +static const char *curl_cookie_file;
  static char *user_name, *user_pass;
  static const char *user_agent;
  
@@@ -192,9 -191,6 +192,9 @@@ static int http_options(const char *var
        if (!strcmp("http.proxy", var))
                return git_config_string(&curl_http_proxy, var, value);
  
 +      if (!strcmp("http.cookiefile", var))
 +              return git_config_string(&curl_cookie_file, var, value);
 +
        if (!strcmp("http.postbuffer", var)) {
                http_post_buffer = git_config_int(var, value);
                if (http_post_buffer < LARGE_PACKET_MAX)
@@@ -535,7 -531,6 +535,7 @@@ struct active_request_slot *get_active_
        slot->finished = NULL;
        slot->callback_data = NULL;
        slot->callback_func = NULL;
 +      curl_easy_setopt(slot->curl, CURLOPT_COOKIEFILE, curl_cookie_file);
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, pragma_header);
        curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, curl_errorstr);
        curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, NULL);
@@@ -851,8 -846,13 +851,13 @@@ static int http_request(const char *url
                                init_curl_http_auth(slot->curl);
                                ret = HTTP_REAUTH;
                        }
-               } else
+               } else {
+                       if (!curl_errorstr[0])
+                               strlcpy(curl_errorstr,
+                                       curl_easy_strerror(results.curl_result),
+                                       sizeof(curl_errorstr));
                        ret = HTTP_ERROR;
+               }
        } else {
                error("Unable to start HTTP request for %s", url);
                ret = HTTP_START_FAILED;
@@@ -908,7 -908,7 +913,7 @@@ int http_error(const char *url, int ret
  {
        /* http_request has already handled HTTP_START_FAILED. */
        if (ret != HTTP_START_FAILED)
-               error("%s while accessing %s\n", curl_errorstr, url);
+               error("%s while accessing %s", curl_errorstr, url);
  
        return ret;
  }
@@@ -1121,8 -1121,9 +1126,8 @@@ struct http_pack_request *new_http_pack
        struct strbuf buf = STRBUF_INIT;
        struct http_pack_request *preq;
  
 -      preq = xmalloc(sizeof(*preq));
 +      preq = xcalloc(1, sizeof(*preq));
        preq->target = target;
 -      preq->range_header = NULL;
  
        end_url_with_slash(&buf, base_url);
        strbuf_addf(&buf, "objects/pack/pack-%s.pack",
@@@ -1214,7 -1215,7 +1219,7 @@@ struct http_object_request *new_http_ob
        struct curl_slist *range_header = NULL;
        struct http_object_request *freq;
  
 -      freq = xmalloc(sizeof(*freq));
 +      freq = xcalloc(1, sizeof(*freq));
        hashcpy(freq->sha1, sha1);
        freq->localfile = -1;
  
                goto abort;
        }
  
 -      memset(&freq->stream, 0, sizeof(freq->stream));
 -
        git_inflate_init(&freq->stream);
  
        git_SHA1_Init(&freq->c);
        return freq;
  
  abort:
 -      free(filename);
        free(freq->url);
        free(freq);
        return NULL;