>From 70226905d8f1dd6ed7d953285a6ee693f1e87b65 Mon Sep 17 00:00:00 2001 From: Gregoire Barbier, gb at gbarbier dot org Date: Sun, 30 Dec 2007 17:48:07 +0100 Subject: [PATCH] Making HTTP push more robust and more user-friendly: - fail when info/refs exists and is already locked (avoiding some repository corruption) - warn if the URL does not end with '/' (since 302 is not yet handled) - more explicit error message when the URL or password is not set correctly (instead of "no DAV locking support") - DAV locking time of 1 minute instead of 10 minutes (avoid waiting 10 minutes for a orphan lock to expire) --- http-push.c | 17 ++++++++++++++++- http.c | 25 +++++++++++++++++++++++++ http.h | 1 + 3 files changed, 42 insertions(+), 1 deletions(-) diff --git a/http-push.c b/http-push.c index 55d0c94..c005903 100644 --- a/http-push.c +++ b/http-push.c @@ -57,7 +57,7 @@ enum XML_Status { #define PROPFIND_ALL_REQUEST "\n\n\n" #define LOCK_REQUEST "\n\n\n\n\nmailto:%s\n\n" -#define LOCK_TIME 600 +#define LOCK_TIME 60 #define LOCK_REFRESH 30 /* bits #0-15 in revision.h */ @@ -2224,6 +2224,16 @@ int main(int argc, char **argv) no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:"); + /* Verify connexion string (agains bad URLs or password errors) */ + if (remote->url && remote->url[strlen(remote->url)-1] != '/') { + fprintf(stderr, "Warning: remote URL does not end with a '/' which often leads to problems\n"); + } + if (!http_test_connection(remote->url)) { + fprintf(stderr, "Error: cannot access to remote URL (maybe malformed URL, network error or bad credentials)\n"); + rc = 1; + goto cleanup; + } + /* Verify DAV compliance/lock support */ if (!locking_available()) { fprintf(stderr, "Error: no DAV locking support on remote repo %s\n", remote->url); @@ -2239,6 +2249,11 @@ int main(int argc, char **argv) info_ref_lock = lock_remote("info/refs", LOCK_TIME); if (info_ref_lock) remote->can_update_info_refs = 1; + else { + fprintf(stderr, "Error: cannot lock existing info/refs\n"); + rc = 1; + goto cleanup; + } } if (remote->has_info_packs) fetch_indices(); diff --git a/http.c b/http.c index d2c11ae..8b04ae9 100644 --- a/http.c +++ b/http.c @@ -634,3 +634,28 @@ int http_fetch_ref(const char *base, const char *ref, unsigned char *sha1) free(url); return ret; } + +int http_test_connection(const char *url) +{ + struct strbuf buffer = STRBUF_INIT; + struct active_request_slot *slot; + struct slot_results results; + int ret = 0; + + 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) + ret = -1; + else + error("Cannot access to URL %s, return code %d", url, results.curl_result); + } else + error("Unable to start request"); + strbuf_release(&buffer); + return ret; +} diff --git a/http.h b/http.h index aeba930..b353007 100644 --- a/http.h +++ b/http.h @@ -77,6 +77,7 @@ extern void step_active_slots(void); extern void http_init(void); extern void http_cleanup(void); +extern int http_test_connection(const char *url); extern int data_received; extern int active_requests; -- 1.5.4.rc2.4.gcef60-dirty