Patchwork [2,of,2] chg: respect environment variables for pager

login
register
mail settings
Submitter Jun Wu
Date April 12, 2017, 11:51 p.m.
Message ID <5972f38edf036bab36f4.1492041066@x1c>
Download mbox | patch
Permalink /patch/20153/
State Accepted
Headers show

Comments

Jun Wu - April 12, 2017, 11:51 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1492041023 25200
#      Wed Apr 12 16:50:23 2017 -0700
# Node ID 5972f38edf036bab36f41cb0835d21c3cf1ab5e5
# Parent  c8f21c8e1a9a8b5ca97bb87916ede5770d6f7021
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 5972f38edf03
chg: respect environment variables for pager

Previously chg runs the pager command without respecting its environment
variables being told to use. This patch makes it so.
Yuya Nishihara - April 13, 2017, 11:58 a.m.
On Wed, 12 Apr 2017 16:51:06 -0700, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1492041023 25200
> #      Wed Apr 12 16:50:23 2017 -0700
> # Node ID 5972f38edf036bab36f41cb0835d21c3cf1ab5e5
> # Parent  c8f21c8e1a9a8b5ca97bb87916ede5770d6f7021
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r 5972f38edf03
> chg: respect environment variables for pager

Queued this, thanks.

Patch

diff --git a/contrib/chg/hgclient.c b/contrib/chg/hgclient.c
--- a/contrib/chg/hgclient.c
+++ b/contrib/chg/hgclient.c
@@ -253,5 +253,5 @@  static void handlesystemrequest(hgclient
 		writeblock(hgc);
 	} else if (strcmp(args[0], "pager") == 0) {
-		setuppager(args[1]);
+		setuppager(args[1], args + 3);
 		if (hgc->capflags & CAP_ATTACHIO)
 			attachio(hgc);
diff --git a/contrib/chg/procutil.c b/contrib/chg/procutil.c
--- a/contrib/chg/procutil.c
+++ b/contrib/chg/procutil.c
@@ -178,5 +178,5 @@  error:
 /* This implementation is based on hgext/pager.py (post 369741ef7253)
  * Return 0 if pager is not started, or pid of the pager */
-pid_t setuppager(const char *pagercmd)
+pid_t setuppager(const char *pagercmd, const char *envp[])
 {
 	assert(pagerpid == 0);
@@ -206,5 +206,6 @@  pid_t setuppager(const char *pagercmd)
 		close(pipefds[1]);
 
-		int r = execlp("/bin/sh", "/bin/sh", "-c", pagercmd, NULL);
+		int r = execle("/bin/sh", "/bin/sh", "-c", pagercmd, NULL,
+				envp);
 		if (r < 0) {
 			abortmsgerrno("cannot start pager '%s'", pagercmd);
diff --git a/contrib/chg/procutil.h b/contrib/chg/procutil.h
--- a/contrib/chg/procutil.h
+++ b/contrib/chg/procutil.h
@@ -16,5 +16,5 @@  void restoresignalhandler(void);
 void setupsignalhandler(pid_t pid, pid_t pgid);
 
-pid_t setuppager(const char *pagercmd);
+pid_t setuppager(const char *pagercmd, const char *envp[]);
 void waitpager(void);