http: simplify http_error helper function

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>

Jeff King committed Apr 5, 2013 at 18:21 UTC 67d2a7b5c502496b0c5acd25a5e0ffa766b61745
4 files changed +8 -12
http-push.c
+1 -1
@@ -1551,7 +1551,7 @@ static int remote_exists(const char *path)
1551 ret = 0;
1552 break;
1553 case HTTP_ERROR:
1554 - http_error(url, HTTP_ERROR);
1554 + http_error(url);
1555 default:
1556 ret = -1;
1557 }
http.c
+4 -7
@@ -857,7 +857,8 @@ static int http_request(const char *url, struct strbuf *type,
857 run_active_slot(slot);
858 ret = handle_curl_result(&results);
859 } else {
860 - error("Unable to start HTTP request for %s", url);
860 + snprintf(curl_errorstr, sizeof(curl_errorstr),
861 + "failed to start HTTP request");
862 ret = HTTP_START_FAILED;
863 }
864
@@ -940,13 +941,9 @@ cleanup:
941 return ret;
942 }
943
943 -int http_error(const char *url, int ret)
944 +void http_error(const char *url)
945 {
945 - /* http_request has already handled HTTP_START_FAILED. */
946 - if (ret != HTTP_START_FAILED)
947 - error("%s while accessing %s", curl_errorstr, url);
948 -
949 - return ret;
946 + error("%s while accessing %s", curl_errorstr, url);
947 }
948
949 int http_fetch_ref(const char *base, struct ref *ref)
http.h
+2 -3
@@ -136,10 +136,9 @@ extern char *get_remote_object_url(const char *url, const char *hex,
136 int http_get_strbuf(const char *url, struct strbuf *content_type, struct strbuf *result, int options);
137
138 /*
139 - * Prints an error message using error() containing url and curl_errorstr,
140 - * and returns ret.
139 + * Prints an error message using error() containing url and curl_errorstr.
140 */
142 -int http_error(const char *url, int ret);
141 +void http_error(const char *url);
142
143 extern int http_fetch_ref(const char *base, struct ref *ref);
144
remote-curl.c
+1 -1
@@ -216,7 +216,7 @@ static struct discovery* discover_refs(const char *service, int for_push)
216 die("Authentication failed for '%s'", url);
217 default:
218 show_http_message(&type, &buffer);
219 - http_error(url, http_ret);
219 + http_error(url);
220 die("HTTP request failed");
221 }
222