summaryrefslogtreecommitdiff
path: root/http.c
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-07-11 20:51:30 +0000
committerJunio C Hamano <gitster@pobox.com>2016-07-12 15:17:42 -0700
commit17966c0a63d25b1cc2dd1e98d30873e643bd581f (patch)
tree865db4ee901c1aef4befa2860e20173475006829 /http.c
parent43b8bba6b60aa644456d7682b99357dd4778e8d6 (diff)
downloadgit-17966c0a63d25b1cc2dd1e98d30873e643bd581f.tar.gz
http: avoid disconnecting on 404s for loose objects
404s are common when fetching loose objects on static HTTP servers, and reestablishing a connection for every single 404 adds additional latency. Signed-off-by: Eric Wong <e@80x24.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'http.c')
-rw-r--r--http.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/http.c b/http.c
index df6dd01594..6f12661a14 100644
--- a/http.c
+++ b/http.c
@@ -1855,8 +1855,19 @@ static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb,
unsigned char expn[4096];
size_t size = eltsize * nmemb;
int posn = 0;
- struct http_object_request *freq =
- (struct http_object_request *)data;
+ struct http_object_request *freq = data;
+ struct active_request_slot *slot = freq->slot;
+
+ if (slot) {
+ CURLcode c = curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CODE,
+ &slot->http_code);
+ if (c != CURLE_OK)
+ die("BUG: curl_easy_getinfo for HTTP code failed: %s",
+ curl_easy_strerror(c));
+ if (slot->http_code >= 400)
+ return size;
+ }
+
do {
ssize_t retval = xwrite(freq->localfile,
(char *) ptr + posn, size - posn);
@@ -1977,6 +1988,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
freq->slot = get_active_slot();
curl_easy_setopt(freq->slot->curl, CURLOPT_FILE, freq);
+ curl_easy_setopt(freq->slot->curl, CURLOPT_FAILONERROR, 0);
curl_easy_setopt(freq->slot->curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file);
curl_easy_setopt(freq->slot->curl, CURLOPT_ERRORBUFFER, freq->errorstr);
curl_easy_setopt(freq->slot->curl, CURLOPT_URL, freq->url);