Anonymous avatar Anonymous committed 0772b9a

Support remote references with slashes in their names

Support remote references with slashes in their names

Signed-off-by: Nick Hengeveld <nickh@reactrix.com>;
Signed-off-by: Junio C Hamano <junkio@cox.net>;

Comments (0)

Files changed (1)

 	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);
 	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");
 
 
 	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);
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.