[PATCH 7 of 8 STABLE] pager: unify handling of 'ui.pager' and '--pager'

Pierre-Yves David pierre-yves.david at ens-lyon.org
Mon May 1 12:12:49 EDT 2017


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1493651095 -7200
#      Mon May 01 17:04:55 2017 +0200
# Branch stable
# Node ID 2605f6e2ed168e6915fba6df575d80b962418ec6
# Parent  bdd42fa505b60739fa337e683a0f64b8dc1c4707
# EXP-Topic pager
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 2605f6e2ed16
pager: unify handling of 'ui.pager' and '--pager'

This is similar to what we do with 'ui.color' and '--color'. Both now takes the
same possible values. The config option act as a default for the global command
line flag.

In practice, this means 'ui.color' can now accept 'auto' as a value.

diff --git a/hgext/pager.py b/hgext/pager.py
--- a/hgext/pager.py
+++ b/hgext/pager.py
@@ -39,7 +39,10 @@ testedwith = 'ships-with-hg-core'
 def uisetup(ui):
 
     def pagecmd(orig, ui, options, cmd, cmdfunc):
-        auto = options['pager'] == 'auto'
+        pageropt = options.get('pager')
+        if not pageropt:
+            pageropt = ui.config('ui', 'pager', 'auto')
+        auto = pageropt == 'auto'
         if auto and not ui.pageractive:
             usepager = False
             attend = ui.configlist('pager', 'attend', attended)
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -99,7 +99,7 @@ globalopts = [
     ('', 'version', None, _('output version information and exit')),
     ('h', 'help', None, _('display help and exit')),
     ('', 'hidden', False, _('consider hidden changesets')),
-    ('', 'pager', 'auto',
+    ('', 'pager', '',
      _("when to paginate (boolean, always, auto, or never)"), _('TYPE')),
 ]
 
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -833,9 +833,13 @@ def _dispatch(req):
             for ui_ in uis:
                 ui_.setconfig('ui', 'interactive', 'off', '-y')
 
-        if util.parsebool(options['pager']):
+        pageropt = options.get('pager')
+        if not pageropt:
+            pageropt = ui.config('ui', 'pager', 'auto')
+
+        if util.parsebool(pageropt):
             ui.pager('internal-always-' + cmd)
-        elif options['pager'] != 'auto':
+        elif pageropt != 'auto':
             ui.disablepager()
 
         if cmdoptions.get('insecure', False):
diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -1963,8 +1963,8 @@ User interface controls.
     not a directory, one will be created.
 
 ``pager``
-  Control the pagination of command output (default: True). See :hg:`help pager`
-  for details.
+  Control the pagination of command output. Possible values are: on, auto, off
+  (defaul: auto).  See :hg:`help pager` for details.
 
 ``patch``
     An optional external tool that ``hg import`` and some extensions
diff --git a/mercurial/help/pager.txt b/mercurial/help/pager.txt
--- a/mercurial/help/pager.txt
+++ b/mercurial/help/pager.txt
@@ -27,9 +27,8 @@ you can use --pager=<value>:
   - suppress the pager: `no` or `off` (any unrecognized value
     will also work).
 
-To globally turn off all attempts to use a pager, set::
+You can use the `ui.pager` option to set a different default. For example, to
+globally turn off all attempts to use a pager, set::
 
   [ui]
-  pager = false
-
-which will prevent the pager from running.
+  pager = off
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -846,7 +846,6 @@ class ui(object):
         if (self._disablepager
             or self.pageractive
             or command in self.configlist('pager', 'ignore')
-            or not self.configbool('ui', 'pager', True)
             or not self.configbool('pager', 'attend-' + command, True)
             # TODO: if we want to allow HGPLAINEXCEPT=pager,
             # formatted() will need some adjustment.
diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -546,7 +546,6 @@ hide outer repo
    -h --help              display help and exit
       --hidden            consider hidden changesets
       --pager TYPE        when to paginate (boolean, always, auto, or never)
-                          (default: auto)
 
 
 
@@ -585,7 +584,6 @@ hide outer repo
    -h --help              display help and exit
       --hidden            consider hidden changesets
       --pager TYPE        when to paginate (boolean, always, auto, or never)
-                          (default: auto)
 
 
 
@@ -867,7 +865,6 @@ extension help itself
    -h --help              display help and exit
       --hidden            consider hidden changesets
       --pager TYPE        when to paginate (boolean, always, auto, or never)
-                          (default: auto)
 
 Make sure that single '-v' option shows help and built-ins only for 'dodo' command
   $ hg help -v dodo
@@ -904,7 +901,6 @@ Make sure that single '-v' option shows 
    -h --help              display help and exit
       --hidden            consider hidden changesets
       --pager TYPE        when to paginate (boolean, always, auto, or never)
-                          (default: auto)
 
 In case when extension name doesn't match any of its commands,
 help message should ask for '-v' to get list of built-in aliases
@@ -979,7 +975,6 @@ help options '-v' and '-v -e' should be 
    -h --help              display help and exit
       --hidden            consider hidden changesets
       --pager TYPE        when to paginate (boolean, always, auto, or never)
-                          (default: auto)
 
   $ hg help -v -e dudu
   dudu extension -
@@ -1015,7 +1010,6 @@ help options '-v' and '-v -e' should be 
    -h --help              display help and exit
       --hidden            consider hidden changesets
       --pager TYPE        when to paginate (boolean, always, auto, or never)
-                          (default: auto)
 
 Disabled extension commands:
 
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -333,7 +333,6 @@ Test short command list with verbose opt
    -h --help              display help and exit
       --hidden            consider hidden changesets
       --pager TYPE        when to paginate (boolean, always, auto, or never)
-                          (default: auto)
   
   (use 'hg help' for the full list of commands)
 
@@ -433,7 +432,6 @@ Verbose help for add
    -h --help              display help and exit
       --hidden            consider hidden changesets
       --pager TYPE        when to paginate (boolean, always, auto, or never)
-                          (default: auto)
 
 Test the textwidth config option
 
@@ -2626,7 +2624,7 @@ Dish up an empty repo; serve it cold.
   <td>consider hidden changesets</td></tr>
   <tr><td></td>
   <td>--pager TYPE</td>
-  <td>when to paginate (boolean, always, auto, or never) (default: auto)</td></tr>
+  <td>when to paginate (boolean, always, auto, or never)</td></tr>
   </table>
   
   </div>
@@ -2827,7 +2825,7 @@ Dish up an empty repo; serve it cold.
   <td>consider hidden changesets</td></tr>
   <tr><td></td>
   <td>--pager TYPE</td>
-  <td>when to paginate (boolean, always, auto, or never) (default: auto)</td></tr>
+  <td>when to paginate (boolean, always, auto, or never)</td></tr>
   </table>
   
   </div>
diff --git a/tests/test-pager.t b/tests/test-pager.t
--- a/tests/test-pager.t
+++ b/tests/test-pager.t
@@ -68,6 +68,13 @@ We can control the pager from the config
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     modify a 10
   
+  $ hg log --limit 1 --config 'ui.pager=off'
+  changeset:   10:46106edeeb38
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     modify a 10
+  
   $ hg log --limit 1 --config 'ui.pager=1'
   paged! 'changeset:   10:46106edeeb38\n'
   paged! 'tag:         tip\n'
@@ -75,6 +82,37 @@ We can control the pager from the config
   paged! 'date:        Thu Jan 01 00:00:00 1970 +0000\n'
   paged! 'summary:     modify a 10\n'
   paged! '\n'
+  $ hg log --limit 1 --config 'ui.pager=on'
+  paged! 'changeset:   10:46106edeeb38\n'
+  paged! 'tag:         tip\n'
+  paged! 'user:        test\n'
+  paged! 'date:        Thu Jan 01 00:00:00 1970 +0000\n'
+  paged! 'summary:     modify a 10\n'
+  paged! '\n'
+  $ hg log --limit 1 --config 'ui.pager=auto'
+  paged! 'changeset:   10:46106edeeb38\n'
+  paged! 'tag:         tip\n'
+  paged! 'user:        test\n'
+  paged! 'date:        Thu Jan 01 00:00:00 1970 +0000\n'
+  paged! 'summary:     modify a 10\n'
+  paged! '\n'
+
+The --pager option is stronger than the config
+
+  $ hg log --limit 1 --config 'ui.pager=off' --pager=on
+  paged! 'changeset:   10:46106edeeb38\n'
+  paged! 'tag:         tip\n'
+  paged! 'user:        test\n'
+  paged! 'date:        Thu Jan 01 00:00:00 1970 +0000\n'
+  paged! 'summary:     modify a 10\n'
+  paged! '\n'
+  $ hg log --limit 1 --config 'ui.pager=on' --pager=off
+  changeset:   10:46106edeeb38
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     modify a 10
+  
 
 We can enable the pager on id:
 


More information about the Mercurial-devel mailing list