From 0dd276b8713a484496a2ef694b6c72b1ddbef08b Mon Sep 17 00:00:00 2001 From: Nick Hengeveld Date: Mon, 7 Nov 2005 11:39:37 -0800 Subject: Make http-push smarter about creating remote dirs Remember object directories known to exist in the remote repo and don't bother trying to create them. Signed-off-by: Nick Hengeveld Signed-off-by: Junio C Hamano --- http-push.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'http-push.c') diff --git a/http-push.c b/http-push.c index 89fda42efb..8e953a6759 100644 --- a/http-push.c +++ b/http-push.c @@ -47,6 +47,7 @@ static int active_requests = 0; static int data_received; static int pushing = 0; static int aborted = 0; +static char remote_dir_exists[256]; #ifdef USE_CURL_MULTI static int max_requests = -1; @@ -650,6 +651,7 @@ static void finish_request(struct transfer_request *request) if (request->http_code == 404) { request->state = NEED_PUSH; } else if (request->curl_result == CURLE_OK) { + remote_dir_exists[request->sha1[0]] = 1; request->state = COMPLETE; } else { fprintf(stderr, "HEAD %s failed, aborting (%d/%ld)\n", @@ -661,6 +663,7 @@ static void finish_request(struct transfer_request *request) } else if (request->state == RUN_MKCOL) { if (request->curl_result == CURLE_OK || request->http_code == 405) { + remote_dir_exists[request->sha1[0]] = 1; start_put(request); } else { fprintf(stderr, "MKCOL %s failed, aborting (%d/%ld)\n", @@ -767,7 +770,10 @@ void process_request_queue(void) start_check(request); curl_multi_perform(curlm, &num_transfers); } else if (pushing && request->state == NEED_PUSH) { - start_mkcol(request); + if (remote_dir_exists[request->sha1[0]]) + start_put(request); + else + start_mkcol(request); curl_multi_perform(curlm, &num_transfers); } request = request->next; @@ -1599,6 +1605,8 @@ int main(int argc, char **argv) break; } + memset(remote_dir_exists, 0, 256); + curl_global_init(CURL_GLOBAL_ALL); #ifdef USE_CURL_MULTI -- cgit v1.3-5-g9baa From 92e2eb9c0a868348dd2caf2b923fd6542ca7ceb7 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 7 Nov 2005 19:23:11 +0100 Subject: Small bugfixes for http-push.c This patch fixes three things: - older libexpat does not know about enum XML_Status - as in my patch for http-fetch, do not rely on a curl result in free()d data - calloc the new_lock structure Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- http-push.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'http-push.c') diff --git a/http-push.c b/http-push.c index 8e953a6759..0b90fb9ae3 100644 --- a/http-push.c +++ b/http-push.c @@ -28,6 +28,15 @@ static const char http_push_usage[] = #define NO_CURL_EASY_DUPHANDLE #endif +#ifndef XML_STATUS_OK +enum XML_Status { + XML_STATUS_OK = 1, + XML_STATUS_ERROR = 0 +}; +#define XML_STATUS_OK 1 +#define XML_STATUS_ERROR 0 +#endif + #define RANGE_HEADER_SIZE 30 /* DAV method names and request body templates */ @@ -731,11 +740,12 @@ void process_curl_messages(void) slot->curl != curl_message->easy_handle) slot = slot->next; if (slot != NULL) { + int curl_result = curl_message->data.result; curl_multi_remove_handle(curlm, slot->curl); active_requests--; slot->done = 1; slot->in_use = 0; - slot->curl_result = curl_message->data.result; + slot->curl_result = curl_result; curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CODE, &slot->http_code); @@ -1236,7 +1246,7 @@ struct active_lock *lock_remote(char *file, long timeout) in_buffer.posn = 0; in_buffer.buffer = in_data; - new_lock = xmalloc(sizeof(*new_lock)); + new_lock = xcalloc(1, sizeof(*new_lock)); new_lock->owner = NULL; new_lock->token = NULL; new_lock->timeout = -1; -- cgit v1.3-5-g9baa