# HG changeset patch # User Jun Wu # Date 2016-02-24 14:24:00 # Node ID a3d73e069f8d2a9ff6a9aca219c17eee4b9c283e # Parent e333cea7474179b69f2bd0f03a0663ca394731f5 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. diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c --- a/contrib/chg/chg.c +++ b/contrib/chg/chg.c @@ -190,13 +190,22 @@ static void unlockcmdserver(struct cmdse 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,