Re: [WIP Patch 04/12] Use the new http API in http_fetch_ref()
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jan 18, 2009, 15:10 UTC
- Message-ID
- <alpine.DEB.1.00.0901181607210.3586@pacific.mpi-cbg.de>
- In-Reply-To
- <1232265877-3649-5-git-send-email-mh@glandium.org>
Hi,
On Sun, 18 Jan 2009, Mike Hommey wrote:
Show 45 quoted lines
> diff --git a/http.c b/http.c
> index 82534cf..0c9504b 100644
> --- a/http.c
> +++ b/http.c
> @@ -604,34 +604,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");
> }Why not keep that error?
BTW I had to scratch my head for a few seconds why you do not need to set "else ret=1;" for the HTTP_OK case; you set ret = 1 in the beginning. I'd rather put that back for clarity.
Ciao, Dscho