chg: allows default hg path to be overridden
authorJun Wu <quark@fb.com>
Sun, 20 Mar 2016 15:43:20 -0700
changeset 28605 baa073200ba2
parent 28604 d4d8a3c89e6d
child 28606 8cc51c5a9365
chg: allows default hg path to be overridden Before this patch, chg will fall back to "hg" if neither CHGHG nor HG are set. This may have trouble if the "hg" in PATH is not compatible with chg, which can happen, for example, an old hg is installed in a virtualenv. Since it's very hard to do a quick hg version check from chg, after discussion in IRC with smf and marmoute, the quickest solution is to build a package with a hardcoded absolute hg path in chg. This patch makes it possible by adding a C macro HGPATH.
contrib/chg/Makefile
contrib/chg/chg.c
--- a/contrib/chg/Makefile	Sun Mar 20 15:25:25 2016 -0700
+++ b/contrib/chg/Makefile	Sun Mar 20 15:43:20 2016 -0700
@@ -7,6 +7,9 @@
 CFLAGS ?= -O2 -Wall -Wextra -pedantic -g
 CPPFLAGS ?= -D_FORTIFY_SOURCE=2
 override CFLAGS += -std=gnu99
+ifdef HGPATH
+override CPPFLAGS += -DHGPATH=\"$(HGPATH)\"
+endif
 
 DESTDIR =
 PREFIX = /usr/local
--- a/contrib/chg/chg.c	Sun Mar 20 15:25:25 2016 -0700
+++ b/contrib/chg/chg.c	Sun Mar 20 15:43:20 2016 -0700
@@ -194,7 +194,11 @@
 		if (!hgcmd || hgcmd[0] == '\0')
 			hgcmd = getenv("HG");
 		if (!hgcmd || hgcmd[0] == '\0')
+#ifdef HGPATH
+			hgcmd = (HGPATH);
+#else
 			hgcmd = "hg";
+#endif
 	}
 	return hgcmd;
 }