git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] http-push: append slash if possible for directories

From
Ray Chuan <rctay89@gmail.com>
Date
Jan 17, 2009, 02:53 UTC
Message-ID
<be6fef0d0901161853y6784310dgf94dadb2218001a1@mail.gmail.com>

the lock_remote currently sends MKCOL requests to leading directories to make sure they exist; however, it doesn't put a forward slash '/' behind the path, so if the path is a directory, the server sends a 301 redirect.

by appending a '/' we can save the server this additional step.

in addition, it seems that curl doesn't re-send the authentication credentials when it follows a 301 redirect, so skipping (unnecessary) redirects can also be seen as a workaround for this issue. (i'm using 7.16.3)

Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---
 src/git-1.6.1/http-push.c |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/src/git-1.6.1/http-push.c b/src/git-1.6.1/http-push.c
index 7c64609..25b655d 100644
--- a/src/git-1.6.1/http-push.c
+++ b/src/git-1.6.1/http-push.c
@@ -1189,6 +1189,7 @@ static struct remote_lock *lock_remote(const
char *path, long timeout)
 	struct strbuf in_buffer = STRBUF_INIT;
 	char *url;
 	char *ep;
+	char ep_old;
 	char timeout_header[25];
 	struct remote_lock *lock = NULL;
 	struct curl_slist *dav_headers = NULL;
@@ -1198,9 +1199,18 @@ static struct remote_lock *lock_remote(const
char *path, long timeout)
 	sprintf(url, "%s%s", remote->url, path);

 	/* Make sure leading directories exist for the remote ref */
-	ep = strchr(url + strlen(remote->url) + 1, '/');
-	while (ep) {
-		*ep = 0;
+	ep = url + strlen(remote->url) + 1;
+	int has_fs = 0;
+	while (1) {
+		ep = strchr(ep + 1, '/');
+		if(ep) {
+			ep++;
+			ep_old=*ep;
+			*ep = 0;
+			has_fs = 1;
+		} else {
+			break;
+		}
 		slot = get_active_slot();
 		slot->results = &results;
 		curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
@@ -1222,8 +1232,9 @@ static struct remote_lock *lock_remote(const
char *path, long timeout)
 			free(url);
 			return NULL;
 		}
-		*ep = '/';
-		ep = strchr(ep + 1, '/');
+		if(has_fs) {
+			*ep = ep_old;
+		}
 	}

 	strbuf_addf(&out_buffer.buf, LOCK_REQUEST, git_default_email);
-- 
1.6.0.4
Next: Johannes Schindelin
Message 1 of 5 in “http-push: append slash if possible for directories”
  1. 1/3 http-push: append slash if possible for directoriesRay Chuan, Jan 17, 2009
  2. Johannes SchindelinJan 17, 2009
  3. Johannes SchindelinJan 17, 2009
  4. Ray ChuanJan 17, 2009
  5. http-push: when making directories, have a trailing slash in the path nameJohannes Schindelin, Jan 17, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.