Skip to contentSkip to conversation

http.c::http_fetch_ref(): use the new http API

PATCH In review Tay Ray Chuan 2 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 17/23 http.c::http_fetch_ref(): use the new http API

From: Mike Hommey <[email protected]>
Subject: [WIP Patch 04/12] Use the new http API in http_fetch_ref()
Date: Sun, 18 Jan 2009 09:04:29 +0100

The error message ("Unable to start request") has been removed, since the http API already prints it.

---
 http.c |   33 ++++++++-------------------------
 1 files changed, 8 insertions(+), 25 deletions(-)
http.c +8 -25
index df22180..2a49372 100644
@@ -773,34 +773,17 @@ int http_fetch_ref(const char *base, struct ref *ref)
 {
 	char *url;
 	struct strbuf buffer = STRBUF_INIT;
-	struct active_request_slot *slot;
-	struct slot_results results;
-	int ret;
+	int ret = -1;
 
 	url = quote_ref_url(base, ref->name);
-	slot = get_active_slot();
-	slot->results = &results;
-	curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
-	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
-	curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL);
-	curl_easy_setopt(slot->curl, CURLOPT_URL, url);
-	if (start_active_slot(slot)) {
-		run_active_slot(slot);
-		if (results.curl_result == CURLE_OK) {
-			strbuf_rtrim(&buffer);
-			if (buffer.len == 40)
-				ret = get_sha1_hex(buffer.buf, ref->old_sha1);
-			else if (!prefixcmp(buffer.buf, "ref: ")) {
-				ref->symref = xstrdup(buffer.buf + 5);
-				ret = 0;
-			} else
-				ret = 1;
-		} else {
-			ret = error("Couldn't get %s for %s\n%s",
-				    url, ref->name, curl_errorstr);
+	if (http_get_strbuf(url, &buffer, HTTP_NO_CACHE) == HTTP_OK) {
+		strbuf_rtrim(&buffer);
+		if (buffer.len == 40)
+			ret = get_sha1_hex(buffer.buf, ref->old_sha1);
+		else if (!prefixcmp(buffer.buf, "ref: ")) {
+			ref->symref = xstrdup(buffer.buf + 5);
+			ret = 0;
 		}
-	} else {
-		ret = error("Unable to start request");
 	}
 
 	strbuf_release(&buffer);

--
1.6.3.1

#1 lore raw
Quoted 2 lines · Tay Ray Chuan

From: Mike Hommey <[email protected]>
Subject: [WIP Patch 04/12] Use the new http API in http_fetch_ref()

What is the subject of this patch:
"http.c::http_fetch_ref(): use the new http API"
or
"Use the new http API in http_fetch_ref()"

Perhaps this and previous patch should be squashed?

Quoted 61 lines

Date: Sun, 18 Jan 2009 09:04:29 +0100

The error message ("Unable to start request") has been removed, since the http API already prints it.

---
 http.c |   33 ++++++++-------------------------
 1 files changed, 8 insertions(+), 25 deletions(-)
http.c +8 -26
index df22180..2a49372 100644
@@ -773,34 +773,17 @@ int http_fetch_ref(const char *base, struct ref *ref)
 {
 	char *url;
 	struct strbuf buffer = STRBUF_INIT;
-	struct active_request_slot *slot;
-	struct slot_results results;
-	int ret;
+	int ret = -1;
 
 	url = quote_ref_url(base, ref->name);
-	slot = get_active_slot();
-	slot->results = &results;
-	curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
-	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
-	curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL);
-	curl_easy_setopt(slot->curl, CURLOPT_URL, url);
-	if (start_active_slot(slot)) {
-		run_active_slot(slot);
-		if (results.curl_result == CURLE_OK) {
-			strbuf_rtrim(&buffer);
-			if (buffer.len == 40)
-				ret = get_sha1_hex(buffer.buf, ref->old_sha1);
-			else if (!prefixcmp(buffer.buf, "ref: ")) {
-				ref->symref = xstrdup(buffer.buf + 5);
-				ret = 0;
-			} else
-				ret = 1;
-		} else {
-			ret = error("Couldn't get %s for %s\n%s",
-				    url, ref->name, curl_errorstr);
+	if (http_get_strbuf(url, &buffer, HTTP_NO_CACHE) == HTTP_OK) {
+		strbuf_rtrim(&buffer);
+		if (buffer.len == 40)
+			ret = get_sha1_hex(buffer.buf, ref->old_sha1);
+		else if (!prefixcmp(buffer.buf, "ref: ")) {
+			ref->symref = xstrdup(buffer.buf + 5);
+			ret = 0;
 		}
-	} else {
-		ret = error("Unable to start request");
 	}
 
 	strbuf_release(&buffer);
--

1.6.3.1

Signature · 3 lines
Jakub Narebski
Poland
ShadeHawk on #git
#2 lore raw

Hi,

Quoted 7 lines · Jakub Narebski
Quoted 2 lines

From: Mike Hommey <[email protected]>
Subject: [WIP Patch 04/12] Use the new http API in http_fetch_ref()

What is the subject of this patch:
 "http.c::http_fetch_ref(): use the new http API"
or
 "Use the new http API in http_fetch_ref()"

See my reply for patch #12.

Quoted 1 line

Perhaps this and previous patch should be squashed?

Why should this and patch #16 (for get_refs_via_curl()) be squashed? Are you perhaps suggesting that all the use-the-new-http-API patches should be squashed?

Signature · 2 lines
Cheers,
Ray Chuan
#3 lore raw
Quoted 1 line · Tay Ray Chuan

On Sat, Jun 6, 2009 at 4:50 AM, Jakub Narebski<[email protected]> wrote:

[...]

Quoted 5 lines
Quoted 1 line

Perhaps this and previous patch should be squashed?

Why should this and patch #16 (for get_refs_via_curl()) be squashed? Are you perhaps suggesting that all the use-the-new-http-API patches should be squashed?

I'm sorry this was before I noticed that there are a few more patches which are about using newly introduced API. Please disregard this part of message.

Signature · 2 lines
Jakub Narebski
Poland