git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] http-push: making HTTP push more robust and more user-friendly
@ 2008-01-13 19:02 Grégoire Barbier
  2008-01-13 19:02 ` [PATCH] http-push: fix webdav lock leak Grégoire Barbier
  2008-01-13 23:01 ` [PATCH] http-push: making HTTP push more robust and more user-friendly Junio C Hamano
  0 siblings, 2 replies; 28+ messages in thread
From: Grégoire Barbier @ 2008-01-13 19:02 UTC (permalink / raw)
  To: git; +Cc: gitster, Grégoire Barbier

Fail when info/refs exists and is already locked (avoiding strange behaviour
and errors, and maybe 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 before anyone can do a push on the repo).

Signed-off-by: Grégoire Barbier <gb@gbarbier.org>
---
 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 "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<D:propfind xmlns:D=\"DAV:\">\n<D:allprop/>\n</D:propfind>"
 #define LOCK_REQUEST "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<D:lockinfo xmlns:D=\"DAV:\">\n<D:lockscope><D:exclusive/></D:lockscope>\n<D:locktype><D:write/></D:locktype>\n<D:owner>\n<D:href>mailto:%s</D:href>\n</D:owner>\n</D:lockinfo>"
 
-#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.3.6

^ permalink raw reply related	[flat|nested] 28+ messages in thread
* [PATCH] http-push: fix webdav lock leak.
@ 2008-01-19 15:22 Grégoire Barbier
  2008-01-19 23:08 ` Johannes Schindelin
  0 siblings, 1 reply; 28+ messages in thread
From: Grégoire Barbier @ 2008-01-19 15:22 UTC (permalink / raw)
  To: git; +Cc: gitster, Grégoire Barbier

Releasing webdav lock even if push fails because of bad (or no) reference
on command line.

To reproduce the issue that this patch fixes, you need a test git repository
availlable over http+webdav, let's say at http://myhost/myrepo.git/
Then, you do this:
$ git clone http://myhost/myrepo.git/
$ cd myrepo
$ git push http
Fetching remote heads...
  refs/
  refs/heads/
  refs/tags/
No refs in common and none specified; doing nothing.
$ git push http
Fetching remote heads...
  refs/
  refs/heads/
  refs/tags/
No refs in common and none specified; doing nothing.
$

Finally, you look at the web server logs, and will find one LOCK query and no
UNLOCK query, of course the second one will be in 423 return code instead of
200:
1.2.3.4 - gb [19/Jan/2008:14:24:56 +0100] "LOCK /myrepo.git/info/refs HTTP/1.1" 200 465
(...)
1.2.3.4 - gb [19/Jan/2008:14:25:10 +0100] "LOCK /myrepo.git/info/refs HTTP/1.1" 423 363

With this patch, there would have be two UNLOCKs in addition of the LOCKs

From the user point of view:
- If you realize that you should have typed e.g. "git push http master"
instead of "git push http", you will have to wait for 10 minutes for the lock
to expire by its own.
- Furthermore, if somebody else is dumb enough to type "git push http" while
you need to push "master" branch, then you'll need too to wait for 10 minutes
too.

Signed-off-by: Grégoire Barbier <gb@gbarbier.org>
---
 http-push.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/http-push.c b/http-push.c
index eef7674..2c4e91d 100644
--- a/http-push.c
+++ b/http-push.c
@@ -2264,11 +2264,14 @@ int main(int argc, char **argv)
 	if (!remote_tail)
 		remote_tail = &remote_refs;
 	if (match_refs(local_refs, remote_refs, &remote_tail,
-		       nr_refspec, (const char **) refspec, push_all))
-		return -1;
+		       nr_refspec, (const char **) refspec, push_all)) {
+		rc = -1;
+		goto cleanup;
+	}
 	if (!remote_refs) {
 		fprintf(stderr, "No refs in common and none specified; doing nothing.\n");
-		return 0;
+		rc = 0;
+		goto cleanup;
 	}
 
 	new_refs = 0;
@@ -2399,10 +2402,10 @@ int main(int argc, char **argv)
 			fprintf(stderr, "Unable to update server info\n");
 		}
 	}
-	if (info_ref_lock)
-		unlock_remote(info_ref_lock);
 
  cleanup:
+	if (info_ref_lock)
+		unlock_remote(info_ref_lock);
 	free(remote);
 
 	curl_slist_free_all(no_pragma_header);
-- 
1.5.4.rc3.52.g9a5bd-dirty

^ permalink raw reply related	[flat|nested] 28+ messages in thread
* Allowing override of the default "origin" nickname
@ 2008-01-11  3:29 Mark Levedahl
  2008-01-11  3:29 ` [PATCH] Teach remote machinery about remotes.default config variable Mark Levedahl
  0 siblings, 1 reply; 28+ messages in thread
From: Mark Levedahl @ 2008-01-11  3:29 UTC (permalink / raw)
  To: gitster; +Cc: git

git's current support for remote nicknames other than
"origin" is restricted to tracking branches where
branch.<name>.remote is defined. This does not work on
detached heads, and thus does not work for managed
submodules as those are kept on detached heads. When working
with submodules, the remote must be called "origin."

As my project is distributed across multiple domains with
many firewalls and airgaps such that no single server is
available to all, we really need to use nicknames to refer
to different servers, and we need that to work well with
submodules.

So, this patch series:
1) defines a new "remotes.default" config variable per
repository to be the default remote used if no
branch.<name>.remote is found.

2) teaches clone to set remotes.default according to
the user's command (via -o).

3) teaches remote rm to unset remotes.default if deleting
that remote.

4) teaches git-submodule to propoagate the parent's default
branch to submoules during "init", IFF those modules are
defined using relative urls. (Modules using absolute urls
are likely from a different server, so this inheritence is
not likely the right thing in that case.)


This is working well for me, allowing

        git clone -o myserver <url> project
        cd project
        git submodule init
        git submoule update

to work as expected, with all submodules pointing to
"myserver" rather than "origin" and updating correctly despite
being on detached heads.

Mark Levedahl

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2008-01-22  2:14 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-13 19:02 [PATCH] http-push: making HTTP push more robust and more user-friendly Grégoire Barbier
2008-01-13 19:02 ` [PATCH] http-push: fix webdav lock leak Grégoire Barbier
2008-01-13 19:02   ` [PATCH] http-push: disable http-push without USE_CURL_MULTI Grégoire Barbier
2008-01-13 23:01 ` [PATCH] http-push: making HTTP push more robust and more user-friendly Junio C Hamano
2008-01-14 11:21   ` Johannes Schindelin
2008-01-14 19:35     ` Junio C Hamano
2008-01-14 20:22       ` Johannes Schindelin
2008-01-19 15:21   ` Grégoire Barbier
2008-01-19 23:18     ` Johannes Schindelin
2008-01-21 10:09   ` Grégoire Barbier
2008-01-21 10:20     ` Junio C Hamano
2008-01-21 10:27       ` Grégoire Barbier
2008-01-21 11:06         ` Junio C Hamano
2008-01-21 12:17           ` Johannes Schindelin
2008-01-21 20:18             ` Junio C Hamano
2008-01-21 20:29               ` Mike Hommey
2008-01-22  0:58                 ` Johannes Schindelin
2008-01-22  1:34                   ` Junio C Hamano
2008-01-22  1:38                     ` Johannes Schindelin
2008-01-22  2:04                       ` Junio C Hamano
2008-01-22  2:14                         ` Johannes Schindelin
2008-01-21 21:30               ` Daniel Barkalow
2008-01-21 22:05                 ` Junio C Hamano
2008-01-21 23:12                   ` Grégoire Barbier
  -- strict thread matches above, loose matches on Subject: below --
2008-01-19 15:22 [PATCH] http-push: fix webdav lock leak Grégoire Barbier
2008-01-19 23:08 ` Johannes Schindelin
2008-01-11  3:29 Allowing override of the default "origin" nickname Mark Levedahl
2008-01-11  3:29 ` [PATCH] Teach remote machinery about remotes.default config variable Mark Levedahl
2008-01-11  8:00   ` Junio C Hamano
2008-01-11 20:52     ` Mark Levedahl
2008-01-12  2:18       ` Junio C Hamano
2008-01-12  5:52         ` Mark Levedahl
2008-01-12  6:03           ` Junio C Hamano
2008-01-12  6:16             ` Mark Levedahl
2008-01-12  6:27               ` Junio C Hamano
2008-01-12 13:24                 ` Mark Levedahl
2008-01-12 18:46                   ` Junio C Hamano
2008-01-12 19:34                     ` Mark Levedahl
2008-01-12 20:26                       ` Junio C Hamano
2008-01-12 22:24                         ` Mark Levedahl
2008-01-12 22:48                           ` Junio C Hamano
2008-01-13 21:27                             ` Johannes Schindelin
2008-01-14  1:50                               ` Junio C Hamano
2008-01-18  9:41                                 ` What's not in 'master' but should be Junio C Hamano
2008-01-18 18:28                                   ` Johannes Schindelin
2008-01-19 15:21                                     ` [PATCH] http-push: fix webdav lock leak Grégoire Barbier
2008-01-19 23:38                                       ` Johannes Schindelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).