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.
--- 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,