contrib/chg/chg.c
changeset 28237 a3d73e069f8d
parent 28196 87de4a22e8c2
child 28260 0a17cfbe5429
--- a/contrib/chg/chg.c	Wed Feb 24 23:00:33 2016 +0900
+++ b/contrib/chg/chg.c	Wed Feb 24 14:24:00 2016 +0000
@@ -190,13 +190,22 @@
 	opts->lockfd = -1;
 }
 
+static const char *gethgcmd(void)
+{
+	static const char *hgcmd = NULL;
+	if (!hgcmd) {
+		hgcmd = getenv("CHGHG");
+		if (!hgcmd || hgcmd[0] == '\0')
+			hgcmd = getenv("HG");
+		if (!hgcmd || hgcmd[0] == '\0')
+			hgcmd = "hg";
+	}
+	return hgcmd;
+}
+
 static void execcmdserver(const struct cmdserveropts *opts)
 {
-	const char *hgcmd = getenv("CHGHG");
-	if (!hgcmd || hgcmd[0] == '\0')
-		hgcmd = getenv("HG");
-	if (!hgcmd || hgcmd[0] == '\0')
-		hgcmd = "hg";
+	const char *hgcmd = gethgcmd();
 
 	const char *baseargv[] = {
 		hgcmd,