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>
This commit is contained in:
Jeff King
2013-04-05 18:21:34 -04:00
committed by Junio C Hamano
parent d5ccbe4dfb
commit 67d2a7b5c5
4 changed files with 8 additions and 12 deletions

11
http.c
View File

@ -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 @@ cleanup:
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)