@matheusbsbs / matheus-bagliano / commits / 466ddf90c2
Fork 0

http-push: when making directories, have a trailing slash in the path name

The function lock_remote() sends MKCOL requests to make leading directories; However, if it does not put a forward slash '/' at the end of the path, the server sends a 301 redirect. By leaving the '/' in place, we can avoid this additional step. Incidentally, at least one version of Curl (7.16.3) does not resend credentials when it follows a 301 redirect, so this commit also fixes a bug. Original patch by Tay Ray Chuan <rctay89@gmail.com>. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jan 17, 2009 at 16:11 UTC 466ddf90c2f270b973d141f20e912f743743331c
3 files changed +11 -2
http-push.c
+3 -2
@@ -1201,7 +1201,8 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
1201 /* Make sure leading directories exist for the remote ref */
1202 ep = strchr(url + strlen(remote->url) + 1, '/');
1203 while (ep) {
1204 - *ep = 0;
1204 + char saved_character = ep[1];
1205 + ep[1] = '\0';
1206 slot = get_active_slot();
1207 slot->results = &results;
1208 curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
@@ -1223,7 +1224,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
1224 free(url);
1225 return NULL;
1226 }
1226 - *ep = '/';
1227 + ep[1] = saved_character;
1228 ep = strchr(ep + 1, '/');
1229 }
1230
t/lib-httpd/apache.conf
+2
@@ -1,6 +1,8 @@
1 ServerName dummy
2 PidFile httpd.pid
3 DocumentRoot www
4 +LogFormat "%h %l %u %t \"%r\" %>s %b" common
5 +CustomLog access.log common
6 ErrorLog error.log
7
8 <IfDefine SSL>
t/t5540-http-push.sh
+6
@@ -76,6 +76,12 @@ test_expect_failure 'create and delete remote branch' '
76 test_must_fail git show-ref --verify refs/remotes/origin/dev
77 '
78
79 +test_expect_success 'MKCOL sends directory names with trailing slashes' '
80 +
81 + ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log
82 +
83 +'
84 +
85 stop_httpd
86
87 test_done