Client side support for user-relative paths.
With this patch, the client side passes identical paths for these two: ssh://host.xz/~junio/repo host.xz:~junio/repo Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Junio C Hamano <junkio@cox.net>
Andreas Ericsson committed
Nov 17, 2005 at 20:37 UTC
faea9ccbadf75128a9e394dca80ed9454e19c7a9
1 file changed
+33
-22
connect.c
+33
-22
@@ -454,34 +454,45 @@ static int git_tcp_connect(int fd[2], const char *prog, char *host, char *path)
454
int git_connect(int fd[2], char *url, const char *prog)
455
{
456
char command[1024];
457
- char *host, *path;
458
- char *colon;
457
+ char *host, *path = url;
458
+ char *colon = NULL;
459
int pipefd[2][2];
460
pid_t pid;
461
- enum protocol protocol;
462
-
463
- host = NULL;
464
- path = url;
465
- colon = strchr(url, ':');
466
- protocol = PROTO_LOCAL;
467
- if (colon) {
468
- *colon = 0;
461
+ enum protocol protocol = PROTO_LOCAL;
462
+
463
+ host = strstr(url, "://");
464
+ if(host) {
465
+ *host = '\0';
466
+ protocol = get_protocol(url);
467
+ host += 3;
468
+ path = strchr(host, '/');
469
+ }
470
+ else {
471
host = url;
470
- path = colon+1;
471
- protocol = PROTO_SSH;
472
- if (!memcmp(path, "//", 2)) {
473
- char *slash = strchr(path + 2, '/');
474
- if (slash) {
475
- int nr = slash - path - 2;
476
- memmove(path, path+2, nr);
477
- path[nr] = 0;
478
- protocol = get_protocol(url);
479
- host = path;
480
- path = slash;
481
- }
472
+ if ((colon = strchr(host, ':'))) {
473
+ protocol = PROTO_SSH;
474
+ *colon = '\0';
475
+ path = colon + 1;
476
}
477
}
478
479
+ if (!path || !*path)
480
+ die("No path specified. See 'man git-pull' for valid url syntax");
481
+
482
+ /*
483
+ * null-terminate hostname and point path to ~ for URL's like this:
484
+ * ssh://host.xz/~user/repo
485
+ */
486
+ if (protocol != PROTO_LOCAL && host != url) {
487
+ char *ptr = path;
488
+ if (path[1] == '~')
489
+ path++;
490
+ else
491
+ path = strdup(ptr);
492
+
493
+ *ptr = '\0';
494
+ }
495
+
496
if (protocol == PROTO_GIT)
497
return git_tcp_connect(fd, prog, host, path);
498