shithub: git9

Download patch

ref: 5f37a591ae54f65d64fb764cc826a078dbe41ea4
parent: 92718a91d63cefe61f9f631703c42702861ef8c5
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Aug 31 00:21:36 EDT 2020

git/{fetch,send}: fix lost direction, off-by-one

Make sure that we pass the direction of the pull and push
when we open the connection. Also, fix an off-by-one in
our grab() function.

--- a/fetch.c
+++ b/fetch.c
@@ -274,7 +274,7 @@
 	if((pfd = create(packtmp, ORDWR, 0644)) == -1)
 		sysfatal("could not create %s: %r", packtmp);
 
-	if(gitconnect(&c, argv[0]) == -1)
+	if(gitconnect(&c, argv[0], "upload") == -1)
 		sysfatal("could not dial %s: %r", argv[0]);
 	if(fetchpack(&c, pfd, packtmp) == -1)
 		sysfatal("fetch failed: %r");
--- a/git.h
+++ b/git.h
@@ -269,7 +269,7 @@
 int	writepkt(Conn*, char*, int);
 int	flushpkt(Conn*);
 void	initconn(Conn*, int, int);
-int	gitconnect(Conn *, char *);
+int	gitconnect(Conn *, char *, char*);
 int	readphase(Conn *);
 int	writephase(Conn *);
 void	closeconn(Conn *);
--- a/proto.c
+++ b/proto.c
@@ -83,8 +83,7 @@
 	if(l >= n)
 		sysfatal("overlong component");
 	memcpy(dst, p, l);
-	dst[l + 1] = 0;
-
+	dst[l] = 0;
 }
 
 static int
@@ -92,6 +91,7 @@
 {
 	char *s, *p, *q;
 	int n, hasport;
+	print("uri: \"%s\"\n", uri);
 
 	p = strstr(uri, "://");
 	if(!p){
@@ -258,7 +258,7 @@
 		dup(pfd[0], 1);
 		snprint(cmd, sizeof(cmd), "git-%s-pack", direction);
 		if(chattygit)
-			fprint(2, "exec ssh %s %s %s\n", host, cmd, path);
+			fprint(2, "exec ssh '%s' '%s' %s\n", host, cmd, path);
 		execl("/bin/ssh", "ssh", host, cmd, path, nil);
 	}else{
 		close(pfd[0]);
@@ -347,7 +347,7 @@
 }
 
 int
-gitconnect(Conn *c, char *uri)
+gitconnect(Conn *c, char *uri, char *direction)
 {
 	char proto[Nproto], host[Nhost], port[Nport];
 	char repo[Nrepo], path[Npath];
@@ -359,13 +359,13 @@
 
 	memset(c, 0, sizeof(Conn));
 	if(strcmp(proto, "ssh") == 0)
-		return dialssh(c, host, port, path, "receive");
+		return dialssh(c, host, port, path, direction);
 	else if(strcmp(proto, "git") == 0)
-		return dialgit(c, host, port, path, "receive");
+		return dialgit(c, host, port, path, direction);
 	else if(strcmp(proto, "hjgit") == 0)
-		return dialhjgit(c, host, port, path, "receive");
+		return dialhjgit(c, host, port, path, direction);
 	else if(strcmp(proto, "http") == 0 || strcmp(proto, "https") == 0)
-		return dialhttp(c, host, port, path, "receive");
+		return dialhttp(c, host, port, path, direction);
 	werrstr("unknown protocol %s", proto);
 	return -1;
 }
--- a/send.c
+++ b/send.c
@@ -451,7 +451,7 @@
 	gitinit();
 	if(argc != 1)
 		usage();
-	if(gitconnect(&c, argv[0]) == -1)
+	if(gitconnect(&c, argv[0], "receive") == -1)
 		sysfatal("git connect: %s: %r", argv[0]);
 	if(sendpack(&c) == -1)
 		sysfatal("send failed: %r");