Skip to content

Commit 67d2a7b

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d5ccbe4 commit 67d2a7b

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

http-push.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@ static int remote_exists(const char *path)
15511551
ret = 0;
15521552
break;
15531553
case HTTP_ERROR:
1554-
http_error(url, HTTP_ERROR);
1554+
http_error(url);
15551555
default:
15561556
ret = -1;
15571557
}

http.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,8 @@ static int http_request(const char *url, struct strbuf *type,
857857
run_active_slot(slot);
858858
ret = handle_curl_result(&results);
859859
} else {
860-
error("Unable to start HTTP request for %s", url);
860+
snprintf(curl_errorstr, sizeof(curl_errorstr),
861+
"failed to start HTTP request");
861862
ret = HTTP_START_FAILED;
862863
}
863864

@@ -940,13 +941,9 @@ static int http_get_file(const char *url, const char *filename, int options)
940941
return ret;
941942
}
942943

943-
int http_error(const char *url, int ret)
944+
void http_error(const char *url)
944945
{
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);
950947
}
951948

952949
int http_fetch_ref(const char *base, struct ref *ref)

http.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,9 @@ extern char *get_remote_object_url(const char *url, const char *hex,
136136
int http_get_strbuf(const char *url, struct strbuf *content_type, struct strbuf *result, int options);
137137

138138
/*
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.
141140
*/
142-
int http_error(const char *url, int ret);
141+
void http_error(const char *url);
143142

144143
extern int http_fetch_ref(const char *base, struct ref *ref);
145144

remote-curl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static struct discovery* discover_refs(const char *service, int for_push)
216216
die("Authentication failed for '%s'", url);
217217
default:
218218
show_http_message(&type, &buffer);
219-
http_error(url, http_ret);
219+
http_error(url);
220220
die("HTTP request failed");
221221
}
222222

0 commit comments

Comments
 (0)