http: simplify http_error helper function
authorJeff King <peff@peff.net>
Fri, 5 Apr 2013 22:21:34 +0000 (18:21 -0400)
committerJunio C Hamano <gitster@pobox.com>
Sun, 7 Apr 2013 01:56:44 +0000 (18:56 -0700)
This helper function should really be a one-liner that
prints an error message, but it has ended up unnecessarily
complicated:

1. We call error() directly when we fail to start the curl
request, so we must later avoid printing a duplicate
error in http_error().

It would be much simpler in this case to just stuff the
error message into our usual curl_errorstr buffer
rather than printing it ourselves. This means that
http_error does not even have to care about curl's exit
value (the interesting part is in the errorstr buffer
already).

2. We return the "ret" value passed in to us, but none of
the callers actually cares about our return value. We
can just drop this entirely.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
http-push.c
http.c
http.h
remote-curl.c
index bd66f6ab6edd24946d2bc84e117a2b97417b1503..439a555a72e81d54e2cd453eae07e24e5ab61e66 100644 (file)
@@ -1551,7 +1551,7 @@ static int remote_exists(const char *path)
                ret = 0;
                break;
        case HTTP_ERROR:
-               http_error(url, HTTP_ERROR);
+               http_error(url);
        default:
                ret = -1;
        }
diff --git a/http.c b/http.c
index 45cc7c70105291f1f660f610c8acf2ae33a3a749..5e6f67d0049f2dd18f8e861cf3949e9f8b4a30b6 100644 (file)
--- a/http.c
+++ b/http.c
@@ -857,7 +857,8 @@ static int http_request(const char *url, struct strbuf *type,
                run_active_slot(slot);
                ret = handle_curl_result(&results);
        } else {
-               error("Unable to start HTTP request for %s", url);
+               snprintf(curl_errorstr, sizeof(curl_errorstr),
+                        "failed to start HTTP request");
                ret = HTTP_START_FAILED;
        }
 
@@ -940,13 +941,9 @@ static int http_get_file(const char *url, const char *filename, int options)
        return ret;
 }
 
-int http_error(const char *url, int ret)
+void http_error(const char *url)
 {
-       /* http_request has already handled HTTP_START_FAILED. */
-       if (ret != HTTP_START_FAILED)
-               error("%s while accessing %s", curl_errorstr, url);
-
-       return ret;
+       error("%s while accessing %s", curl_errorstr, url);
 }
 
 int http_fetch_ref(const char *base, struct ref *ref)
diff --git a/http.h b/http.h
index 0fe54f413121100edab133baa1ef99f2f38600b6..fa65128f9e0e2712bc7f4e58bec4eeb2c2e9ce35 100644 (file)
--- a/http.h
+++ b/http.h
@@ -136,10 +136,9 @@ extern char *get_remote_object_url(const char *url, const char *hex,
 int http_get_strbuf(const char *url, struct strbuf *content_type, struct strbuf *result, int options);
 
 /*
- * Prints an error message using error() containing url and curl_errorstr,
- * and returns ret.
+ * Prints an error message using error() containing url and curl_errorstr.
  */
-int http_error(const char *url, int ret);
+void http_error(const char *url);
 
 extern int http_fetch_ref(const char *base, struct ref *ref);
 
index 6c6714b00a13c9d3393493be6bfad3c131875c24..9abe4b71162d9b718c9c4af10637836714a14be4 100644 (file)
@@ -216,7 +216,7 @@ static struct discovery* discover_refs(const char *service, int for_push)
                die("Authentication failed for '%s'", url);
        default:
                show_http_message(&type, &buffer);
-               http_error(url, http_ret);
+               http_error(url);
                die("HTTP request failed");
        }