chg: limit reconnect attempts
authorJun Wu <quark@fb.com>
Wed, 02 Mar 2016 10:42:58 +0000
changeset 28358 ffd3ac07b1d7
parent 28357 2f0f352d4196
child 28359 f6b5b041c6c9
chg: limit reconnect attempts Some users may have hg as a wrapper script which sets sensitive environment variables (like setting up virtualenv). This will make chg redirect forever because the environment variables are never considered up to date. This patch adds a limit (10) for reconnect attempts and warn the user with a possible solution if the limit is exceeded.
contrib/chg/chg.c
--- a/contrib/chg/chg.c	Sun Mar 06 14:22:37 2016 +0000
+++ b/contrib/chg/chg.c	Wed Mar 02 10:42:58 2016 +0000
@@ -549,6 +549,7 @@
 	}
 
 	hgclient_t *hgc;
+	size_t retry = 0;
 	while (1) {
 		hgc = connectcmdserver(&opts);
 		if (!hgc)
@@ -560,6 +561,13 @@
 		runinstructions(&opts, insts);
 		free(insts);
 		hgc_close(hgc);
+		if (++retry > 10)
+			abortmsg("too many redirections.\n"
+				 "Please make sure %s is not a wrapper which "
+				 "changes sensitive environment variables "
+				 "before executing hg. If you have to use a "
+				 "wrapper, wrap chg instead of hg.",
+				 gethgcmd());
 	}
 
 	setupsignalhandler(hgc_peerpid(hgc));