Patchwork [3,of,5] chg: decouple hgclient from setuppager

login
register
mail settings
Submitter Jun Wu
Date Jan. 2, 2017, 3:09 p.m.
Message ID <b2a4d87a091c27186872.1483369765@x1c>
Download mbox | patch
Permalink /patch/18065/
State Accepted
Headers show

Comments

Jun Wu - Jan. 2, 2017, 3:09 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1483366232 0
#      Mon Jan 02 14:10:32 2017 +0000
# Node ID b2a4d87a091c271868720be8cc51bb2b5988d1c2
# Parent  a8f21835ad4f31aa1c34f7f3eadb0f2a147af6bd
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r b2a4d87a091c
chg: decouple hgclient from setuppager

procutil should not depend on hgclient. This patch makes the pager handling
part independent from hgclient.

Patch

diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
--- a/contrib/chg/chg.c
+++ b/contrib/chg/chg.c
@@ -431,5 +431,8 @@  int main(int argc, const char *argv[], c
 
 	setupsignalhandler(hgc_peerpid(hgc), hgc_peerpgid(hgc));
-	pagerpid = setuppager(hgc, argv + 1, argc - 1);
+	const char *pagercmd = hgc_getpager(hgc, argv + 1, argc - 1);
+	pagerpid = setuppager(pagercmd);
+	if (pagerpid)
+		hgc_attachio(hgc);  /* reattach to pager */
 	int exitcode = hgc_runcommand(hgc, argv + 1, argc - 1);
 	restoresignalhandler();
diff --git a/contrib/chg/procutil.c b/contrib/chg/procutil.c
--- a/contrib/chg/procutil.c
+++ b/contrib/chg/procutil.c
@@ -158,8 +158,6 @@  error:
 /* This implementation is based on hgext/pager.py (post 369741ef7253)
  * Return 0 if pager is not started, or pid of the pager */
-static pid_t setuppager(hgclient_t *hgc, const char *const args[],
-		       size_t argsize)
+static pid_t setuppager(const char *pagercmd)
 {
-	const char *pagercmd = hgc_getpager(hgc, args, argsize);
 	if (!pagercmd)
 		return 0;
@@ -180,5 +178,4 @@  static pid_t setuppager(hgclient_t *hgc,
 		}
 		close(pipefds[1]);
-		hgc_attachio(hgc);  /* reattach to pager */
 		return pid;
 	} else {