changeset 28237:a3d73e069f8d

chg: extract gethgcmd logic to a function gethgcmd is to get original hg (not chg) binary name. This patch extracts the logic from execcmdserver to make it available for the following patch.
author Jun Wu <quark@fb.com>
date Wed, 24 Feb 2016 14:24:00 +0000
parents e333cea74741
children b57d45ec33b2
files contrib/chg/chg.c
diffstat 1 files changed, 14 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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,