Patchwork [5,of,5,V2] chg: limit reconnect attempts

login
register
mail settings
Submitter Jun Wu
Date March 4, 2016, 1:28 p.m.
Message ID <02c370d356044409c1ec.1457098138@x1c>
Download mbox | patch
Permalink /patch/13593/
State Superseded
Commit ffd3ac07b1d79dda7f57bd826208fdaf92a76717
Delegated to: Yuya Nishihara
Headers show

Comments

Jun Wu - March 4, 2016, 1:28 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1456915378 0
#      Wed Mar 02 10:42:58 2016 +0000
# Node ID 02c370d356044409c1ecab1abb79716c2bf611e6
# Parent  6a5b979dd315c60b0eb0f3c3e87fcaf1c892e6e1
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.

Patch

diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
--- a/contrib/chg/chg.c
+++ b/contrib/chg/chg.c
@@ -557,6 +557,7 @@ 
 	}
 
 	hgclient_t *hgc;
+	size_t retry = 0;
 	while (1) {
 		hgc = connectcmdserver(&opts);
 		if (!hgc)
@@ -567,6 +568,13 @@ 
 			break;
 		runinstructions(hgc, &opts, instsize);
 		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));