changeset 30738:a45c0f42271f

chg: handle pager request client-side This patch implements the simple S-channel pager handling at chg client-side. Note: It does not deal with environ and cwd currently for simplicity, which will be fixed later.
author Jun Wu <quark@fb.com>
date Tue, 10 Jan 2017 06:59:03 +0800
parents 2957409449ac
children 815e1cefd082
files contrib/chg/Makefile contrib/chg/hgclient.c
diffstat 2 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/chg/Makefile	Tue Jan 10 06:58:51 2017 +0800
+++ b/contrib/chg/Makefile	Tue Jan 10 06:59:03 2017 +0800
@@ -25,7 +25,7 @@
 	$(CC) $(LDFLAGS) -o $@ $(OBJS)
 
 chg.o: hgclient.h procutil.h util.h
-hgclient.o: hgclient.h util.h
+hgclient.o: hgclient.h procutil.h util.h
 procutil.o: procutil.h util.h
 util.o: util.h
 
--- a/contrib/chg/hgclient.c	Tue Jan 10 06:58:51 2017 +0800
+++ b/contrib/chg/hgclient.c	Tue Jan 10 06:59:03 2017 +0800
@@ -23,6 +23,7 @@
 #include <unistd.h>
 
 #include "hgclient.h"
+#include "procutil.h"
 #include "util.h"
 
 enum {
@@ -71,6 +72,8 @@
 
 static const size_t defaultdatasize = 4096;
 
+static void attachio(hgclient_t *hgc);
+
 static void initcontext(context_t *ctx)
 {
 	ctx->ch = '\0';
@@ -248,6 +251,13 @@
 		memcpy(ctx->data, &r_n, sizeof(r_n));
 		ctx->datasize = sizeof(r_n);
 		writeblock(hgc);
+	} else if (strcmp(args[0], "pager") == 0) {
+		setuppager(args[1]);
+		if (hgc->capflags & CAP_ATTACHIO)
+			attachio(hgc);
+		/* unblock the server */
+		static const char emptycmd[] = "\n";
+		sendall(hgc->sockfd, emptycmd, sizeof(emptycmd) - 1);
 	} else {
 		abortmsg("unknown type in system request: %s", args[0]);
 	}