[PATCH 2 of 2] pager: do not try to run an empty pager command

Yuya Nishihara yuya at tcha.org
Thu Feb 23 08:06:55 EST 2017


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1487852845 -32400
#      Thu Feb 23 21:27:25 2017 +0900
# Node ID 84acad766a0fdd0591c68783ff02ce688e45968b
# Parent  32900a2dc4c5d2fd51b8e1238deac712a5a0e177
pager: do not try to run an empty pager command

If pagercmd is explicitly set to '', the pager process would exit silently
and the output would be lost. We'd better disable the pager in such case.

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -868,7 +868,6 @@ class ui(object):
             # interactive, the user didn't say HGPLAIN or
             # HGPLAINEXCEPT=pager, and the user didn't specify --debug.
             return
-        self.debug('starting pager for command %r\n' % command)
 
         # TODO: add a "system defaults" config section so this default
         # of more(1) can be easily replaced with a global
@@ -878,6 +877,10 @@ class ui(object):
         # default editor command similar treatment.
         envpager = encoding.environ.get('PAGER', 'more')
         pagercmd = self.config('pager', 'pager', envpager)
+        if not pagercmd:
+            return
+
+        self.debug('starting pager for command %r\n' % command)
         self.pageractive = True
         # Preserve the formatted-ness of the UI. This is important
         # because we mess with stdout, which might confuse
diff --git a/tests/test-pager.t b/tests/test-pager.t
--- a/tests/test-pager.t
+++ b/tests/test-pager.t
@@ -89,6 +89,12 @@ Pager should not start if stdout is not 
   $ hg log -l1 -q --config ui.formatted=False
   10:46106edeeb38
 
+Pager should be disabled if pager.pager is empty (otherwise the output would
+be silently lost.)
+
+  $ hg log -l1 -q --config pager.pager=
+  10:46106edeeb38
+
 Pager with color enabled allows colors to come through by default,
 even though stdout is no longer a tty.
   $ cat >> $HGRCPATH <<EOF


More information about the Mercurial-devel mailing list