All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nick Hengeveld <nickh@reactrix.com>
To: git@vger.kernel.org
Subject: [PATCH 2/4] Support remote references with slashes in their names
Date: Fri, 4 Nov 2005 14:22:25 -0800	[thread overview]
Message-ID: <20051104222225.GE3001@reactrix.com> (raw)

Support remote references with slashes in their names

Signed-off-by: Nick Hengeveld <nickh@reactrix.com>


---

 http-push.c |   42 +++++++++++++++++++++++++++++++++++++++---
 1 files changed, 39 insertions(+), 3 deletions(-)

applies-to: 54e1d462248523bfac7d7c4b42e3b1ce1270fbd9
33cd543dfe656dce9c5722e4fe6af22fa5a80e7e
diff --git a/http-push.c b/http-push.c
index 134d405..6a241aa 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1066,12 +1066,44 @@ char *lock_remote(char *file, int timeou
 	struct buffer out_buffer;
 	char *out_data;
 	char *url;
+	char *ep;
 	char timeout_header[25];
 	struct curl_slist *dav_headers = NULL;
 
 	if (lock_token != NULL)
 		free(lock_token);
 
+	url = xmalloc(strlen(remote->url) + strlen(file) + 1);
+	sprintf(url, "%s%s", remote->url, file);
+
+	/* Make sure leading directories exist for the remote ref */
+	ep = strchr(url + strlen(remote->url) + 11, '/');
+	while (ep) {
+		*ep = 0;
+		slot = get_active_slot();
+		curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
+		curl_easy_setopt(slot->curl, CURLOPT_URL, url);
+		curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_MKCOL);
+		curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
+		if (start_active_slot(slot)) {
+			run_active_slot(slot);
+			if (slot->curl_result != CURLE_OK &&
+			    slot->http_code != 405) {
+				fprintf(stderr,
+					"Unable to create branch path %s\n",
+					url);
+				free(url);
+				return NULL;
+			}
+		} else {
+			fprintf(stderr, "Unable to start request\n");
+			free(url);
+			return NULL;
+		}
+		*ep = '/';
+		ep = strchr(ep + 1, '/');
+	}
+
 	out_buffer.size = strlen(LOCK_REQUEST) + strlen(git_default_email) - 2;
 	out_data = xmalloc(out_buffer.size + 1);
 	snprintf(out_data, out_buffer.size + 1, LOCK_REQUEST, git_default_email);
@@ -1079,8 +1111,6 @@ char *lock_remote(char *file, int timeou
 	out_buffer.buffer = out_data;
 
 	sprintf(timeout_header, "Timeout: Second-%d", timeout);
-	url = xmalloc(strlen(remote->url) + strlen(file) + 1);
-	sprintf(url, "%s%s", remote->url, file);
 	dav_headers = curl_slist_append(dav_headers, timeout_header);
 	dav_headers = curl_slist_append(dav_headers, "Content-Type: text/xml");
 
@@ -1098,16 +1128,22 @@ char *lock_remote(char *file, int timeou
 
 	if (start_active_slot(slot)) {
 		run_active_slot(slot);
-		free(out_data);
 		if (slot->curl_result != CURLE_OK) {
 			fprintf(stderr, "Got HTTP error %ld\n", slot->http_code);
+			free(url);
+			free(out_data);
 			return NULL;
 		}
 	} else {
+		free(url);
 		free(out_data);
 		fprintf(stderr, "Unable to start request\n");
+		return NULL;
 	}
 
+	free(url);
+	free(out_data);
+
 	return strdup(lock_token);
 }
 
---
0.99.9.GIT

                 reply	other threads:[~2005-11-04 22:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20051104222225.GE3001@reactrix.com \
    --to=nickh@reactrix.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.