From: Andreas Ericsson Date: Tue, 01 Nov 2005 22:59:21 GMT Subject: [PATCH 1/4] Client side of user-relative paths, take two. Message-ID: <20051101225921.245595BF70@nox.op5.se> 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. Signed-off-by: Andreas Ericsson --- connect.c | 53 ++++++++++++++++++++++++++++++++++------------------- 1 files changed, 34 insertions(+), 19 deletions(-) applies-to: e39c96179f2cc5064a0255057b8e8a8863594536 22ca6db517baf2bb4824a971408543d9bd956209 diff --git a/connect.c b/connect.c index c2badc7..9150ad2 100644 --- a/connect.c +++ b/connect.c @@ -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