Merge branch 'sk/ftp'

* sk/ftp:
  Add ftp:// protocol support for git-http-fetch
  http-fetch.c: consolidate code to detect missing fetch target
This commit is contained in:
Junio C Hamano 2006-09-17 18:43:36 -07:00
commit 808239a7db

View File

@ -144,6 +144,19 @@ static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
return size; return size;
} }
static int missing__target(int code, int result)
{
return /* file:// URL -- do we ever use one??? */
(result == CURLE_FILE_COULDNT_READ_FILE) ||
/* http:// and https:// URL */
(code == 404 && result == CURLE_HTTP_RETURNED_ERROR) ||
/* ftp:// URL */
(code == 550 && result == CURLE_FTP_COULDNT_RETR_FILE)
;
}
#define missing_target(a) missing__target((a)->http_code, (a)->curl_result)
static void fetch_alternates(const char *base); static void fetch_alternates(const char *base);
static void process_object_response(void *callback_data); static void process_object_response(void *callback_data);
@ -323,8 +336,7 @@ static void process_object_response(void *callback_data)
obj_req->state = COMPLETE; obj_req->state = COMPLETE;
/* Use alternates if necessary */ /* Use alternates if necessary */
if (obj_req->http_code == 404 || if (missing_target(obj_req)) {
obj_req->curl_result == CURLE_FILE_COULDNT_READ_FILE) {
fetch_alternates(alt->base); fetch_alternates(alt->base);
if (obj_req->repo->next != NULL) { if (obj_req->repo->next != NULL) {
obj_req->repo = obj_req->repo =
@ -537,8 +549,7 @@ static void process_alternates_response(void *callback_data)
return; return;
} }
} else if (slot->curl_result != CURLE_OK) { } else if (slot->curl_result != CURLE_OK) {
if (slot->http_code != 404 && if (!missing_target(slot)) {
slot->curl_result != CURLE_FILE_COULDNT_READ_FILE) {
got_alternates = -1; got_alternates = -1;
return; return;
} }
@ -941,8 +952,7 @@ static int fetch_indices(struct alt_base *repo)
if (start_active_slot(slot)) { if (start_active_slot(slot)) {
run_active_slot(slot); run_active_slot(slot);
if (results.curl_result != CURLE_OK) { if (results.curl_result != CURLE_OK) {
if (results.http_code == 404 || if (missing_target(&results)) {
results.curl_result == CURLE_FILE_COULDNT_READ_FILE) {
repo->got_indices = 1; repo->got_indices = 1;
free(buffer.buffer); free(buffer.buffer);
return 0; return 0;
@ -1123,8 +1133,7 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1)
ret = error("Request for %s aborted", hex); ret = error("Request for %s aborted", hex);
} else if (obj_req->curl_result != CURLE_OK && } else if (obj_req->curl_result != CURLE_OK &&
obj_req->http_code != 416) { obj_req->http_code != 416) {
if (obj_req->http_code == 404 || if (missing_target(obj_req))
obj_req->curl_result == CURLE_FILE_COULDNT_READ_FILE)
ret = -1; /* Be silent, it is probably in a pack. */ ret = -1; /* Be silent, it is probably in a pack. */
else else
ret = error("%s (curl_result = %d, http_code = %ld, sha1 = %s)", ret = error("%s (curl_result = %d, http_code = %ld, sha1 = %s)",