diff contrib/chg/chg.c @ 28535:aa082a8125da

chgserver: add an explicit "reconnect" instruction to validate In some rare cases (next patch), we may want validate to do "unlink" without forcing the client reconnect. This patch addes a new "reconnect" instruction and makes "unlink" not to reconnect by default.
author Jun Wu <quark@fb.com>
date Mon, 14 Mar 2016 13:48:33 +0000
parents 3bf2892f685f
children 1435a8e9b5fe
line wrap: on
line diff
--- a/contrib/chg/chg.c	Mon Mar 14 11:06:34 2016 +0000
+++ b/contrib/chg/chg.c	Mon Mar 14 13:48:33 2016 +0000
@@ -444,9 +444,14 @@
 	abortmsg("failed to prepare pager (errno = %d)", errno);
 }
 
-/* Run instructions sent from the server like unlink and set redirect path */
-static void runinstructions(struct cmdserveropts *opts, const char **insts)
+/* Run instructions sent from the server like unlink and set redirect path
+ * Return 1 if reconnect is needed, otherwise 0 */
+static int runinstructions(struct cmdserveropts *opts, const char **insts)
 {
+	int needreconnect = 0;
+	if (!insts)
+		return needreconnect;
+
 	assert(insts);
 	opts->redirectsockname[0] = '\0';
 	const char **pinst;
@@ -460,15 +465,19 @@
 					 "%s", *pinst + 9);
 			if (r < 0 || r >= (int)sizeof(opts->redirectsockname))
 				abortmsg("redirect path is too long (%d)", r);
+			needreconnect = 1;
 		} else if (strncmp(*pinst, "exit ", 5) == 0) {
 			int n = 0;
 			if (sscanf(*pinst + 5, "%d", &n) != 1)
 				abortmsg("cannot read the exit code");
 			exit(n);
+		} else if (strcmp(*pinst, "reconnect") == 0) {
+			needreconnect = 1;
 		} else {
 			abortmsg("unknown instruction: %s", *pinst);
 		}
 	}
+	return needreconnect;
 }
 
 /*
@@ -542,10 +551,10 @@
 			abortmsg("cannot open hg client");
 		hgc_setenv(hgc, envp);
 		const char **insts = hgc_validate(hgc, argv + 1, argc - 1);
-		if (insts == NULL)
+		int needreconnect = runinstructions(&opts, insts);
+		free(insts);
+		if (!needreconnect)
 			break;
-		runinstructions(&opts, insts);
-		free(insts);
 		hgc_close(hgc);
 		if (++retry > 10)
 			abortmsg("too many redirections.\n"