Skip to contentSkip to conversation

upload-pack/fetch-pack: support side-band communication

PATCH In review Junio C Hamano 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 4/4 upload-pack/fetch-pack: support side-band communication

This implements a protocol extension between fetch-pack and upload-pack to allow stderr stream from upload-pack (primarily used for the progress bar display) to be passed back.

---

* With this, fetching and cloning over git+ssh:// and git://
does not discard the progress bar and error messages that upload-pack emits on its standard output. They are sent to the downloader and shown to the user.

Somehow this does not work when connecting to git daemon that runs under inetd. Fixes appreciated.

 cache.h       |    4 ++-
 fetch-clone.c |   71 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 fetch-pack.c  |   22 +++++++++++++-----
 pkt-line.c    |    4 ++-
 pkt-line.h    |    1 +
 upload-pack.c |   60 +++++++++++++++++++++++++++++++++++++++++-------
 6 files changed, 139 insertions(+), 23 deletions(-)
cache.h +2 -2
index eaa5c0c..efeafea 100644
@@ -374,8 +374,8 @@ extern char git_commit_encoding[MAX_ENCO
 extern int copy_fd(int ifd, int ofd);
 
 /* Finish off pack transfer receiving end */
-extern int receive_unpack_pack(int fd[2], const char *me, int quiet);
-extern int receive_keep_pack(int fd[2], const char *me, int quiet);
+extern int receive_unpack_pack(int fd[2], const char *me, int quiet, int);
+extern int receive_keep_pack(int fd[2], const char *me, int quiet, int);
 
 /* pager.c */
 extern void setup_pager(void);
fetch-clone.c +66 -5

105 lines not on this page · raw message

fetch-pack.c +16 -6
index 7d23a80..f2c51eb 100644
@@ -25,7 +25,7 @@ #define POPPED		(1U << 4)
 #define MAX_IN_VAIN 256
 
 static struct commit_list *rev_list = NULL;
-static int non_common_revs = 0, multi_ack = 0, use_thin_pack = 0;
+static int non_common_revs = 0, multi_ack = 0, use_thin_pack = 0, use_sideband;
 
 static void rev_list_push(struct commit *commit, int mark)
 {
@@ -165,9 +165,14 @@ static int find_common(int fd[2], unsign
 			continue;
 		}
 
-		packet_write(fd[1], "want %s%s%s\n", sha1_to_hex(remote),
-			     (multi_ack ? " multi_ack" : ""),
-			     (use_thin_pack ? " thin-pack" : ""));
+		if (!fetching)
+			packet_write(fd[1], "want %s%s%s%s\n",
+				     sha1_to_hex(remote),
+				     (multi_ack ? " multi_ack" : ""),
+				     (use_sideband ? " side-band" : ""),
+				     (use_thin_pack ? " thin-pack" : ""));
+		else
+			packet_write(fd[1], "want %s\n", sha1_to_hex(remote));
 		fetching++;
 	}
 	packet_flush(fd[1]);
@@ -421,6 +426,11 @@ static int fetch_pack(int fd[2], int nr_
 			fprintf(stderr, "Server supports multi_ack\n");
 		multi_ack = 1;
 	}
+	if (server_supports("side-band")) {
+		if (verbose)
+			fprintf(stderr, "Server supports side-band\n");
+		use_sideband = 1;
+	}
 	if (!ref) {
 		packet_flush(fd[1]);
 		die("no matching remote head");
@@ -437,9 +447,9 @@ static int fetch_pack(int fd[2], int nr_
 			fprintf(stderr, "warning: no common commits\n");
 
 	if (keep_pack)
-		status = receive_keep_pack(fd, "git-fetch-pack", quiet);
+		status = receive_keep_pack(fd, "git-fetch-pack", quiet, use_sideband);
 	else
-		status = receive_unpack_pack(fd, "git-fetch-pack", quiet);
+		status = receive_unpack_pack(fd, "git-fetch-pack", quiet, use_sideband);
 
 	if (status)
 		die("git-fetch-pack: fetch failed.");
pkt-line.c +3 -1
index bb3bab0..3d724ac 100644
@@ -16,8 +16,9 @@ #include "pkt-line.h"
  * The writing side could use stdio, but since the reading
  * side can't, we stay with pure read/write interfaces.
  */
-static void safe_write(int fd, const void *buf, unsigned n)
+ssize_t safe_write(int fd, const void *buf, ssize_t n)
 {
+	ssize_t nn = n;
 	while (n) {
 		int ret = xwrite(fd, buf, n);
 		if (ret > 0) {
@@ -29,6 +30,7 @@ static void safe_write(int fd, const voi
 			die("write error (disk full?)");
 		die("write error (%s)", strerror(errno));
 	}
+	return nn;
 }
 
 /*
pkt-line.h +1 -0
index 51d0cbe..9abef24 100644
@@ -8,5 +8,6 @@ void packet_flush(int fd);
 void packet_write(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
 
 int packet_read_line(int fd, char *buffer, unsigned size);
+ssize_t safe_write(int, const void *, ssize_t);
 
 #endif
upload-pack.c +51 -9

126 lines not on this page · raw message

Signature · 1 line
1.4.0.g160a
#1 lore raw
Quoted 7 lines · Junio C Hamano

This implements a protocol extension between fetch-pack and upload-pack to allow stderr stream from upload-pack (primarily used for the progress bar display) to be passed back.

---

Quoted 7 lines

* With this, fetching and cloning over git+ssh:// and git://
does not discard the progress bar and error messages that upload-pack emits on its standard output. They are sent to the downloader and shown to the user.

Somehow this does not work when connecting to git daemon that runs under inetd. Fixes appreciated.

This seems to fix it.

-- >8 --
Subject: [PATCH] daemon: send stderr to /dev/null instead of closing.

---
 daemon.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
daemon.c +1 -1
index bdfe80d..0747ce2 100644
@@ -757,7 +757,7 @@ int main(int argc, char **argv)
 		struct sockaddr *peer = (struct sockaddr *)&ss;
 		socklen_t slen = sizeof(ss);
 
-		fclose(stderr); //FIXME: workaround
+		freopen("/dev/null", "w", stderr);
 
 		if (getpeername(0, peer, &slen))
 			peer = NULL;
Signature · 1 line
1.4.0.g7883
#2 lore raw

daemon.c int main(int argc, char **argv) · line 760

Quoted 8 lines · Junio C Hamano
Quoted 2 lines

Somehow this does not work when connecting to git daemon that runs under inetd. Fixes appreciated.

This seems to fix it.

daemon.c +1 -1
-		fclose(stderr); //FIXME: workaround
+		freopen("/dev/null", "w", stderr);

Sweet. Thanks!

jdl