Skip to contentSkip to conversation

Client side of user-relative paths, take two.

PATCH In review Andreas Ericsson 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 Client side of user-relative paths, take two.

See this discussion, "[RFC] GIT paths", on the git-list:
http://www.gelato.unsw.edu.au/archives/git/0510/10924.html

In particular, the client side now passes identical paths for these two:

	ssh://host.xz/~junio/repo
	host.xz:~junio/repo

A friendly error message is produced if no path is specified.

---

 connect.c |   53 ++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 34 insertions(+), 19 deletions(-)

applies-to: e39c96179f2cc5064a0255057b8e8a8863594536 22ca6db517baf2bb4824a971408543d9bd956209

connect.c +34 -19
index c2badc7..9150ad2 100644
@@ -460,26 +460,41 @@ int git_connect(int fd[2], char *url, co
 	pid_t pid;
 	enum protocol protocol;
 
-	host = NULL;
-	path = url;
-	colon = strchr(url, ':');
-	protocol = PROTO_LOCAL;
-	if (colon) {
-		*colon = 0;
+	protocol = PROTO_SSH;
+	host = strstr(url, "://");
+	if(host) {
+		*host = '\0';
+		protocol = get_protocol(url);
+		host += 3;
+	}
+	else
 		host = url;
-		path = colon+1;
-		protocol = PROTO_SSH;
-		if (!memcmp(path, "//", 2)) {
-			char *slash = strchr(path + 2, '/');
-			if (slash) {
-				int nr = slash - path - 2;
-				memmove(path, path+2, nr);
-				path[nr] = 0;
-				protocol = get_protocol(url);
-				host = path;
-				path = slash;
-			}
-		}
+
+	path = strchr(host, '/');
+	colon = strchr(host, ':');
+
+	/* We keep server-side code simple by handling the difference
+	 * between these two on the client side:
+	 *    ssh://host.xz/~user/repo
+	 *    host.xz:~repo
+	 */
+	if (protocol == PROTO_SSH && colon && (!path || colon < path)) {
+		*colon = 0;
+		path = colon + 1;
+	}
+
+	if(!path || !*path)
+		die("No path specified. Try '%s%s/path/to/repo'", url, colon ? ":" : "");
+
+	/* null-terminate host part and point path to ~ for URL's like this:
+	 *    ssh://host.xz/~user/repo
+	 */
+	if(!colon && *(path + 1) == '~')
+		*path++ = '\0';
+	else {
+		colon = path;
+		path = strdup(path);
+		*colon = '\0';
 	}
 
 	if (protocol == PROTO_GIT)

---
0.99.9.GIT

#1 lore raw

connect.c int git_connect(int fd[2], char *url, co · line 484

Quoted 4 lines · Andreas Ericsson
connect.c +4 -0
+	if (protocol == PROTO_SSH && colon && (!path || colon < path)) {
+		*colon = 0;
+		path = colon + 1;
+	}

I think "colon < path" is to cover "git://host.xz/foo/bar:baz" case (i.e. funny directory name with an embedded colon); I think you should reset colon to NULL if you do things differently later depending on colon is set or not, like this part:

Quoted 9 lines
connect.c +9 -0
+	/* null-terminate host part and point path to ~ for URL's like this:
+	 *    ssh://host.xz/~user/repo
+	 */
+	if(!colon && *(path + 1) == '~')
+		*path++ = '\0';
+	else {
+		colon = path;
+		path = strdup(path);
+		*colon = '\0';
#2 lore raw
Quoted 15 lines · Junio C Hamano

connect.c int git_connect(int fd[2], char *url, co · line 484

Quoted 4 lines · Andreas Ericsson
connect.c +4 -0
+	if (protocol == PROTO_SSH && colon && (!path || colon < path)) {
+		*colon = 0;
+		path = colon + 1;
+	}

I think "colon < path" is to cover "git://host.xz/foo/bar:baz" case (i.e. funny directory name with an embedded colon); I think you should reset colon to NULL if you do things differently later depending on colon is set or not, like this part:

Quoted 11 lines

connect.c int git_connect(int fd[2], char *url, co · line 497

Quoted 9 lines
connect.c +9 -0
+	/* null-terminate host part and point path to ~ for URL's like this:
+	 *    ssh://host.xz/~user/repo
+	 */
+	if(!colon && *(path + 1) == '~')
+		*path++ = '\0';
+	else {
+		colon = path;
+		path = strdup(path);
+		*colon = '\0';

True. Should I update this patch or submit a new one fixing only this specific issue?

Signature · 3 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231