Patchwork [2,of,2] chg: allows default hg path to be overrided

login
register
mail settings
Submitter Jun Wu
Date March 20, 2016, 10:55 p.m.
Message ID <95197bd663b214584480.1458514550@x1c>
Download mbox | patch
Permalink /patch/13991/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Jun Wu - March 20, 2016, 10:55 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1458513800 25200
#      Sun Mar 20 15:43:20 2016 -0700
# Node ID 95197bd663b214584480e844eac49c0620514f8f
# Parent  cab48617a18dbccb5286ed8f90bfa608fe1d9f90
chg: allows default hg path to be overrided

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.
Yuya Nishihara - March 21, 2016, 12:53 a.m.
On Sun, 20 Mar 2016 15:55:50 -0700, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1458513800 25200
> #      Sun Mar 20 15:43:20 2016 -0700
> # Node ID 95197bd663b214584480e844eac49c0620514f8f
> # Parent  cab48617a18dbccb5286ed8f90bfa608fe1d9f90
> chg: allows default hg path to be overrided

Queued these, thanks.

> diff --git a/contrib/chg/Makefile b/contrib/chg/Makefile
> --- a/contrib/chg/Makefile
> +++ b/contrib/chg/Makefile
> @@ -7,6 +7,9 @@
>  CFLAGS ?= -O2 -Wall -Wextra -pedantic -g
>  CPPFLAGS ?= -D_FORTIFY_SOURCE=2
>  override CFLAGS += -std=gnu99
> +ifdef HGPATH
> +override CFLAGS += -DHGPATH=\"$(HGPATH)\"
> +endif

I've changed it to be passed to CPPFLAGS as -D is a flag for cpp, not cc.

Patch

diff --git a/contrib/chg/Makefile b/contrib/chg/Makefile
--- a/contrib/chg/Makefile
+++ b/contrib/chg/Makefile
@@ -7,6 +7,9 @@ 
 CFLAGS ?= -O2 -Wall -Wextra -pedantic -g
 CPPFLAGS ?= -D_FORTIFY_SOURCE=2
 override CFLAGS += -std=gnu99
+ifdef HGPATH
+override CFLAGS += -DHGPATH=\"$(HGPATH)\"
+endif
 
 DESTDIR =
 PREFIX = /usr/local
diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
--- a/contrib/chg/chg.c
+++ b/contrib/chg/chg.c
@@ -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;
 }