http-push.c::remote_exists(): use the new http API

Signed-off-by: Mike Hommey <mh@glandium.org>
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Mike Hommey
2009-06-06 16:43:57 +08:00
committed by Junio C Hamano
parent 0d5896e1cc
commit 446b941a57

View File

@@ -2004,29 +2004,22 @@ static void update_remote_info_refs(struct remote_lock *lock)
static int remote_exists(const char *path) static int remote_exists(const char *path)
{ {
char *url = xmalloc(strlen(repo->url) + strlen(path) + 1); char *url = xmalloc(strlen(repo->url) + strlen(path) + 1);
struct active_request_slot *slot; int ret;
struct slot_results results;
int ret = -1;
sprintf(url, "%s%s", repo->url, path); sprintf(url, "%s%s", repo->url, path);
slot = get_active_slot(); switch (http_get_strbuf(url, NULL, 0)) {
slot->results = &results; case HTTP_OK:
curl_easy_setopt(slot->curl, CURLOPT_URL, url); ret = 1;
curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 1); break;
case HTTP_MISSING_TARGET:
if (start_active_slot(slot)) { ret = 0;
run_active_slot(slot); break;
if (results.http_code == 404) case HTTP_ERROR:
ret = 0; http_error(url, HTTP_ERROR);
else if (results.curl_result == CURLE_OK) default:
ret = 1; ret = -1;
else
fprintf(stderr, "HEAD HTTP error %ld\n", results.http_code);
} else {
fprintf(stderr, "Unable to start HEAD request\n");
} }
free(url); free(url);
return ret; return ret;
} }