[PATCH 10 of 10] chg: limit reconnect attempts

Jun Wu quark at fb.com
Wed Mar 2 05:44:12 EST 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1456915378 0
#      Wed Mar 02 10:42:58 2016 +0000
# Node ID 4b0543c62bab85fc9b92ff26372c48491c2d195e
# Parent  f27ebf7ddfd12df9e4c087d419454504fc7f097a
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.

diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
--- a/contrib/chg/chg.c
+++ b/contrib/chg/chg.c
@@ -545,6 +545,7 @@
 	}
 
 	hgclient_t *hgc;
+	int retry = 0;
 	while (1) {
 		hgc = connectcmdserver(&opts);
 		if (!hgc)
@@ -553,6 +554,13 @@
 		const char **insts = hgc_validate(hgc, argv + 1, argc - 1);
 		if (insts == NULL)
 			break;
+		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());
 		runinstructions(&opts, insts);
 		hgc_close(hgc);
 		free(insts);


More information about the Mercurial-devel mailing list