ref: 30af66e87cd2b47d9834ba95812c2952d01a5478
parent: c791a397417e779e8a31b3d950a58057b3955932
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Mar 3 21:44:23 EST 2026
git: dont' mangle '/' in repo urls when cloning a repo like gits://foo/bar/baz.git//, the trailing slashes may have semantic meaning; don't strip them out, and don't try to parse them in the url parser.
--- a/sys/src/cmd/git/clone
+++ b/sys/src/cmd/git/clone
@@ -7,13 +7,13 @@
if(~ $debug 1)
debug=(-d)
-remote=`{echo $1 | sed 's@/*$@@'}+remote=$1
local=$2
if(~ $#remote 0)
exec aux/usage
if(~ $#local 0)
- local=`{basename $remote .git}+ local=`$nl{basename `$nl{echo $remote | sed 's@.*/([^/]+)/*$@\1@'} .git}if(~ $#branch 1)
branchflag=(-b $branch)
--- a/sys/src/cmd/git/proto.c
+++ b/sys/src/cmd/git/proto.c
@@ -13,7 +13,6 @@
Nport = 16,
Nhost = 256,
Npath = 128,
- Nrepo = 64,
Nbranch = 32,
};
@@ -172,10 +171,11 @@
}
static int
-parseuri(char *uri, char *proto, char *host, char *port, char *path, char *repo)
+parseuri(char *uri, char *proto, char *host, char *port, char *path)
{char *s, *p, *q;
- int n, hasport;
+ int hasport;
+
print("uri: \"%s\"\n", uri);p = strstr(uri, "://");
@@ -220,18 +220,8 @@
}else{grab(host, Nhost, s, p);
}
-
+
snprint(path, Npath, "%s", p);
- if((q = strrchr(p, '/')) != nil)
- p = q + 1;
- if(strlen(p) == 0){- werrstr("missing repository in uri");- return -1;
- }
- n = strlen(p);
- if(hassuffix(p, ".git"))
- n -= 4;
- grab(repo, Nrepo, p, p + n);
return 0;
}
@@ -312,19 +302,24 @@
static int
dialhttp(Conn *c, char *host, char *port, char *path, char *direction)
{- char *geturl, *suff, *hsep, *psep;
+ char *geturl, *suff, *hsep, *psep, *isep;
suff = "";
hsep = "";
psep = "";
+ isep = "";
if(port && strlen(port) != 0)
hsep = ":";
if(path && path[0] != '/')
psep = "/";
+ if(path && path[0] && path[strlen(path)-1] != '/')
+ isep = "/";
memset(c, 0, sizeof(*c));
- geturl = smprint("https://%s%s%s%s%s%s/info/refs?service=git-%s-pack", host, hsep, port, psep, path, suff, direction);+ geturl = smprint("https://%s%s%s%s%s%s%sinfo/refs?service=git-%s-pack",+ host, hsep, port, psep, path, suff, isep, direction);
c->type = ConnHttp;
- c->url = smprint("https://%s%s%s%s%s%s/git-%s-pack", host, hsep, port, psep, path, suff, direction);+ c->url = smprint("https://%s%s%s%s%s%s%sgit-%s-pack",+ host, hsep, port, psep, path, suff, isep, direction);
c->cfd = webclone(c, geturl);
free(geturl);
if(c->cfd == -1)
@@ -484,8 +479,7 @@
int
gitconnect(Conn *c, char *uri, char *direction)
{- char proto[Nproto], host[Nhost], port[Nport];
- char repo[Nrepo], path[Npath];
+ char proto[Nproto], host[Nhost], port[Nport], path[Npath];
memset(c, 0, sizeof(Conn));
c->rfd = c->wfd = c->cfd = -1;
@@ -493,7 +487,7 @@
if(localrepo(uri, path, sizeof(path)) == 0)
return servelocal(c, path, direction);
- if(parseuri(uri, proto, host, port, path, repo) == -1){+ if(parseuri(uri, proto, host, port, path) == -1){ werrstr("bad uri %s", uri);return -1;
}
--
⑨