changeset 30847:e12553cfd0a4 stable

pager: wrap _runcommand() no matter if stdout is redirected We've made chg utilize the common code path implemented in pager.py (by 815e1cefd082 and 493935e0327a), but the chg server does not always start with a tty. Because of this, uisetup() of the pager extension could be skipped on the chg server. Kudos given to Sean Farley for dogfooding new chg and spotting this problem.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 19 Jan 2017 23:01:32 +0900
parents dfc6663f97ca
children 7080652af6e6
files hgext/pager.py tests/test-chg.t tests/test-pager.t
diffstat 3 files changed, 38 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/pager.py	Thu Jan 19 09:48:40 2017 -0800
+++ b/hgext/pager.py	Thu Jan 19 23:01:32 2017 +0900
@@ -115,9 +115,6 @@
         pager.wait()
 
 def uisetup(ui):
-    if '--debugger' in sys.argv or not ui.formatted():
-        return
-
     class pagerui(ui.__class__):
         def _runpager(self, pagercmd):
             _runpager(self, pagercmd)
@@ -130,7 +127,7 @@
         always = util.parsebool(options['pager'])
         auto = options['pager'] == 'auto'
 
-        if not p:
+        if not p or '--debugger' in sys.argv or not ui.formatted():
             pass
         elif always:
             usepager = True
--- a/tests/test-chg.t	Thu Jan 19 09:48:40 2017 -0800
+++ b/tests/test-chg.t	Thu Jan 19 23:01:32 2017 +0900
@@ -32,6 +32,38 @@
 
   $ cd ..
 
+pager
+-----
+
+  $ cat >> fakepager.py <<EOF
+  > import sys
+  > for line in sys.stdin:
+  >     sys.stdout.write('paged! %r\n' % line)
+  > EOF
+
+enable pager extension globally, but spawns the master server with no tty:
+
+  $ chg init pager
+  $ cd pager
+  $ cat >> $HGRCPATH <<EOF
+  > [extensions]
+  > pager =
+  > [pager]
+  > pager = python $TESTTMP/fakepager.py
+  > EOF
+  $ chg version > /dev/null
+  $ touch foo
+  $ chg ci -qAm foo
+
+pager should be enabled if the attached client has a tty:
+
+  $ chg log -l1 -q --config ui.formatted=True
+  paged! '0:1f7b0de80e11\n'
+  $ chg log -l1 -q --config ui.formatted=False
+  0:1f7b0de80e11
+
+  $ cd ..
+
 server lifecycle
 ----------------
 
--- a/tests/test-pager.t	Thu Jan 19 09:48:40 2017 -0800
+++ b/tests/test-pager.t	Thu Jan 19 23:01:32 2017 +0900
@@ -152,6 +152,11 @@
   summary:     modify a 9
   
 
+Pager should not start if stdout is not a tty.
+
+  $ hg log -l1 -q --config ui.formatted=False
+  10:46106edeeb38
+
 Pager with color enabled allows colors to come through by default,
 even though stdout is no longer a tty.
   $ cat >> $HGRCPATH <<EOF