configwizard: prompt to enable and configure pager (bug 1279596); r?glob draft
authorGregory Szorc <gps@mozilla.com>
Fri, 10 Jun 2016 13:37:33 -0700
changeset 8538 6579aee1a6b19e7f54171ae2ecf293f831e16d69
parent 8537 e57a547d5c5200f5d56ee921442c4b58ba1416c5
child 8539 3ee8ae8bb7a027374011d9ebe46a9d2904e9fce3
child 8540 365f8e35bb5f527ff67afb8dad3a718c3b815d85
push id922
push userbmo:gps@mozilla.com
push dateFri, 10 Jun 2016 20:53:16 +0000
reviewersglob
bugs1279596
configwizard: prompt to enable and configure pager (bug 1279596); r?glob Lack of pager is IMO one of the most annoying things in a default Mercurial config. Enabling the pager extension gets a partially useful pager. But I feel you have to configure it a bit more, namely enabling it on other commands and defining a custom `less` invocation to make it behave better. `less` without -F in particular is quite annoying because you have to exit the pager for every command, even if it prints a single line of output! The config added in this commit mostly matches my local config. I think it is a good starting point. MozReview-Commit-ID: 4WTStWybmfr
hgext/configwizard/__init__.py
hgext/configwizard/tests/test-pager.t
hgext/configwizard/tests/test-wip.t
--- a/hgext/configwizard/__init__.py
+++ b/hgext/configwizard/__init__.py
@@ -74,16 +74,30 @@ acceptable.
 '''.lstrip()
 
 BAD_DIFF_SETTINGS = '''
 Mercurial is not configured to produce diffs in a more readable format.
 
 Would you like to change this (Yn)? $$ &Yes $$ &No
 '''.strip()
 
+PAGER_INFO = '''
+The "pager" extension transparently redirects command output to a pager
+program (like "less") so command output can be more easily consumed
+(e.g. output longer than the terminal can be scrolled).
+
+Please select one of the following for configuring pager:
+
+  1. Enable pager and configure with recommended settings (preferred)
+  2. Enable pager with default configuration
+  3. Don't enable pager
+
+Which option would you like? $$ &1 $$ &2 $$ &3
+'''.strip()
+
 FSMONITOR_INFO = '''
 The fsmonitor extension integrates the watchman filesystem watching tool
 with Mercurial. Commands like `hg status`, `hg diff`, and `hg commit`
 (which need to examine filesystem state) can query watchman to obtain
 this state, allowing these commands to complete much quicker.
 
 When installed, the fsmonitor extension will automatically launch a
 background watchman daemon for accessed Mercurial repositories. It
@@ -238,16 +252,17 @@ buglink = 'https://bugzilla.mozilla.org/
 cmdtable = {}
 command = cmdutil.command(cmdtable)
 
 wizardsteps = {
     'hgversion',
     'username',
     'diff',
     'color',
+    'pager',
     'historyediting',
     'fsmonitor',
     'blackbox',
     'wip',
     'security',
     'firefoxtree',
     'codereview',
     'pushtotry',
@@ -285,16 +300,19 @@ def configwizard(ui, repo, statedir=None
         _checkusername(ui, cw)
 
     if 'diff' in runsteps:
         _checkdiffsettings(ui, cw)
 
     if 'color' in runsteps:
         _promptnativeextension(ui, cw, 'color', 'Enable color output to your terminal')
 
+    if 'pager' in runsteps:
+        _checkpager(ui, cw)
+
     if 'historyediting' in runsteps:
         _checkhistoryediting(ui, cw)
 
     if 'fsmonitor' in runsteps:
         _checkfsmonitor(ui, cw, hgversion)
 
     if 'blackbox' in runsteps:
         _promptnativeextension(ui, cw, 'blackbox',
@@ -446,16 +464,59 @@ def _promptvctextension(ui, cw, ext, msg
         return
 
     if uipromptchoice(ui, '%s (Yn) $$ &Yes $$ &No' % msg):
         return
 
     _enableext(cw, ext, ext_path)
 
 
+def _checkpager(ui, cw):
+    haveext = ui.hasconfig('extensions', 'pager')
+    attends = {
+        'help',
+        'incoming',
+        'outgoing',
+        'status',
+    }
+
+    haveattends = all(ui.hasconfig('pager', 'attend-%s' % a) for a in attends)
+    haveconfig = ui.hasconfig('pager', 'pager')
+
+    if haveext and haveattends and haveconfig:
+        return
+
+    answer = uipromptchoice(ui, PAGER_INFO, default=0) + 1
+    if answer == 3:
+        return
+
+    cw.c.setdefault('extensions', {})
+    cw.c['extensions']['pager'] = ''
+
+    if answer == 2:
+        return
+
+    cw.c.setdefault('pager', {})
+
+    # Set the pager invocation to a more reasonable default than Mercurial's.
+    # Don't overwrite user-specified value.
+    #
+    # -F quit if one screen
+    # -R raw control chars
+    # -S chop long lines instead of wrap
+    # -Q quiet (no terminal bell)
+    # -X no termcap init/deinit (won't clear screen afterwards)
+    if not haveconfig:
+        cw.c['pager']['pager'] = 'LESS=FRSXQ less'
+
+    for a in sorted(attends):
+        if not ui.hasconfig('pager', 'attend-%s' % a):
+            cw.c['pager']['attend-%s' % a] = 'true'
+
+
 def _checkhistoryediting(ui, cw):
     if all(ui.hasconfig('extensions', e) for e in ('histedit', 'rebase')):
         return
 
     if ui.promptchoice('Enable history rewriting commands (Yn)? $$ &Yes $$ &No'):
         return
 
     if 'extensions' not in cw.c:
@@ -522,16 +583,21 @@ def _checkwip(ui, cw):
             '{label("log.tag", if(fxheads," {fxheads}"))} '
             '{label("log.bookmark", if(bookmarks," {bookmarks}"))}'
             '\\n'
             # first line of commit message
             '{label(ifcontains(rev, revset("."), "desc.here"),desc|firstline)}'
             "'"
         )
 
+    # Ensure pager is configured for wip alias if pager is configured.
+    if ui.hasconfig('extensions', 'pager') or 'pager' in cw.c.get('extensions', {}):
+        cw.c.setdefault('pager', {})
+        cw.c['pager']['attend-wip'] = 'true'
+
 
 def _checksecurity(ui, cw, hgversion):
     import ssl
 
     # Python + Mercurial didn't have terrific TLS handling until Python
     # 2.7.9 and Mercurial 3.4. For this reason, it was recommended to pin
     # certificates in Mercurial config files. In modern versions of
     # Mercurial, the system CA store is used and old, legacy TLS protocols
new file mode 100644
--- /dev/null
+++ b/hgext/configwizard/tests/test-pager.t
@@ -0,0 +1,204 @@
+  $ . $TESTDIR/hgext/configwizard/tests/helpers.sh
+
+Rejecting pager doesn't enable it
+
+  $ hg --config ui.interactive=true --config configwizard.steps=pager,configchange configwizard << EOF
+  > 
+  > 3
+  > EOF
+  This wizard will guide you through configuring Mercurial for an optimal
+  experience contributing to Mozilla projects.
+  
+  The wizard makes no changes without your permission.
+  
+  To begin, press the enter/return key.
+   <RETURN>
+  The "pager" extension transparently redirects command output to a pager
+  program (like "less") so command output can be more easily consumed
+  (e.g. output longer than the terminal can be scrolled).
+  
+  Please select one of the following for configuring pager:
+  
+    1. Enable pager and configure with recommended settings (preferred)
+    2. Enable pager with default configuration
+    3. Don't enable pager
+  
+  Which option would you like?  3
+
+Can enable without configuring
+
+  $ hg --config ui.interactive=true --config configwizard.steps=pager,configchange configwizard << EOF
+  > 
+  > 2
+  > y
+  > y
+  > EOF
+  This wizard will guide you through configuring Mercurial for an optimal
+  experience contributing to Mozilla projects.
+  
+  The wizard makes no changes without your permission.
+  
+  To begin, press the enter/return key.
+   <RETURN>
+  The "pager" extension transparently redirects command output to a pager
+  program (like "less") so command output can be more easily consumed
+  (e.g. output longer than the terminal can be scrolled).
+  
+  Please select one of the following for configuring pager:
+  
+    1. Enable pager and configure with recommended settings (preferred)
+    2. Enable pager with default configuration
+    3. Don't enable pager
+  
+  Which option would you like?  2
+  Your config file needs updating.
+  Would you like to see a diff of the changes first (Yn)?  y
+  --- hgrc.old
+  +++ hgrc.new
+  @@ -0,0 +1,2 @@
+  +[extensions]
+  +pager =
+  
+  Write changes to hgrc file (Yn)?  y
+
+Configuring sets pager invocation and default attends list
+
+  $ hg --config ui.interactive=true --config configwizard.steps=pager,configchange configwizard << EOF
+  > 
+  > 1
+  > y
+  > y
+  > EOF
+  This wizard will guide you through configuring Mercurial for an optimal
+  experience contributing to Mozilla projects.
+  
+  The wizard makes no changes without your permission.
+  
+  To begin, press the enter/return key.
+   <RETURN>
+  The "pager" extension transparently redirects command output to a pager
+  program (like "less") so command output can be more easily consumed
+  (e.g. output longer than the terminal can be scrolled).
+  
+  Please select one of the following for configuring pager:
+  
+    1. Enable pager and configure with recommended settings (preferred)
+    2. Enable pager with default configuration
+    3. Don't enable pager
+  
+  Which option would you like?  1
+  Your config file needs updating.
+  Would you like to see a diff of the changes first (Yn)?  y
+  --- hgrc.old
+  +++ hgrc.new
+  @@ -1,2 +1,8 @@
+   [extensions]
+   pager =
+  +[pager]
+  +pager = LESS=FRSXQ less
+  +attend-help = true
+  +attend-incoming = true
+  +attend-outgoing = true
+  +attend-status = true
+  
+  Write changes to hgrc file (Yn)?  y
+
+No-op if everything is configured
+
+  $ HGRCPATH=.hgrc hg --config extensions.configwizard=$TESTDIR/hgext/configwizard --config configwizard.steps=pager,configchange configwizard
+  This wizard will guide you through configuring Mercurial for an optimal
+  experience contributing to Mozilla projects.
+  
+  The wizard makes no changes without your permission.
+  
+  To begin, press the enter/return key.
+   <RETURN>
+
+less.less isn't changed if defined
+
+  $ rm .hgrc
+  $ hg --config ui.interactive=true --config configwizard.steps=pager,configchange --config pager.pager=less configwizard << EOF
+  > 
+  > 1
+  > y
+  > y
+  > EOF
+  This wizard will guide you through configuring Mercurial for an optimal
+  experience contributing to Mozilla projects.
+  
+  The wizard makes no changes without your permission.
+  
+  To begin, press the enter/return key.
+   <RETURN>
+  The "pager" extension transparently redirects command output to a pager
+  program (like "less") so command output can be more easily consumed
+  (e.g. output longer than the terminal can be scrolled).
+  
+  Please select one of the following for configuring pager:
+  
+    1. Enable pager and configure with recommended settings (preferred)
+    2. Enable pager with default configuration
+    3. Don't enable pager
+  
+  Which option would you like?  1
+  Your config file needs updating.
+  Would you like to see a diff of the changes first (Yn)?  y
+  --- hgrc.old
+  +++ hgrc.new
+  @@ -0,0 +1,7 @@
+  +[extensions]
+  +pager =
+  +[pager]
+  +attend-help = true
+  +attend-incoming = true
+  +attend-outgoing = true
+  +attend-status = true
+  
+  Write changes to hgrc file (Yn)?  y
+
+new attend default is added
+
+  $ cat > .hgrc << EOF
+  > [extensions]
+  > pager =
+  > [pager]
+  > attend-incoming = true
+  > attend-outgoing = true
+  > EOF
+
+  $ hg --config ui.interactive=true --config configwizard.steps=pager,configchange --config pager.pager=less configwizard << EOF
+  > 
+  > 1
+  > y
+  > y
+  > EOF
+  This wizard will guide you through configuring Mercurial for an optimal
+  experience contributing to Mozilla projects.
+  
+  The wizard makes no changes without your permission.
+  
+  To begin, press the enter/return key.
+   <RETURN>
+  The "pager" extension transparently redirects command output to a pager
+  program (like "less") so command output can be more easily consumed
+  (e.g. output longer than the terminal can be scrolled).
+  
+  Please select one of the following for configuring pager:
+  
+    1. Enable pager and configure with recommended settings (preferred)
+    2. Enable pager with default configuration
+    3. Don't enable pager
+  
+  Which option would you like?  1
+  Your config file needs updating.
+  Would you like to see a diff of the changes first (Yn)?  y
+  --- hgrc.old
+  +++ hgrc.new
+  @@ -3,3 +3,5 @@
+   [pager]
+   attend-incoming = true
+   attend-outgoing = true
+  +attend-help = true
+  +attend-status = true
+  
+  Write changes to hgrc file (Yn)?  y
--- a/hgext/configwizard/tests/test-wip.t
+++ b/hgext/configwizard/tests/test-wip.t
@@ -84,8 +84,71 @@ wip enabled when requested
 
   $ cat .hgrc
   [alias]
   wip = log --graph --rev=wip --template=wip
   [revsetalias]
   wip = (parents(not public()) or not public() or . or (head() and branch(default))) and (not obsolete() or unstable()^) and not closed()
   [templates]
   wip = '{label("log.branch", branches)} {label("changeset.{phase}", rev)}{label("changeset.{phase}", ":")}{label("changeset.{phase}", short(node))} {label("grep.user", author|user)}{label("log.tag", if(tags," {tags}"))}{label("log.tag", if(fxheads," {fxheads}"))} {label("log.bookmark", if(bookmarks," {bookmarks}"))}\n{label(ifcontains(rev, revset("."), "desc.here"),desc|firstline)}'
+
+wip alias has pager configuration when pager enabled
+
+  $ hg --config configwizard.steps=pager,wip,configchange configwizard
+  This wizard will guide you through configuring Mercurial for an optimal
+  experience contributing to Mozilla projects.
+  
+  The wizard makes no changes without your permission.
+  
+  To begin, press the enter/return key.
+   <RETURN>
+  The "pager" extension transparently redirects command output to a pager
+  program (like "less") so command output can be more easily consumed
+  (e.g. output longer than the terminal can be scrolled).
+  
+  Please select one of the following for configuring pager:
+  
+    1. Enable pager and configure with recommended settings (preferred)
+    2. Enable pager with default configuration
+    3. Don't enable pager
+  
+  Which option would you like?  1
+  It is common to want a quick view of changesets that are in progress.
+  
+  The ``hg wip`` command provides such a view.
+  
+  Example Usage:
+  
+    $ hg wip
+    o   4084:fcfa34d0387b dminor @
+    |  mozreview: use repository name when displaying treeherder results (bug 1230548) r=mcote
+    | @   4083:786baf6d476a gps
+    | |  mozreview: create child review requests from batch API
+    | o   4082:3f100fa4a94f gps
+    | |  mozreview: copy more read-only processing code; r?smacleod
+    | o   4081:939417680cbe gps
+    |/   mozreview: add web API to submit an entire series of commits (bug 1229468); r?smacleod
+  
+  (Not shown are the colors that help denote the state each changeset
+  is in.)
+  
+  (Relevant config options: alias.wip, revsetalias.wip, templates.wip)
+  
+  Would you like to install the `hg wip` alias (Yn)?  y
+  Your config file needs updating.
+  Would you like to see a diff of the changes first (Yn)?  y
+  --- hgrc.old
+  +++ hgrc.new
+  @@ -4,3 +4,12 @@
+   wip = (parents(not public()) or not public() or . or (head() and branch(default))) and (not obsolete() or unstable()^) and not closed()
+   [templates]
+   wip = '{label("log.branch", branches)} {label("changeset.{phase}", rev)}{label("changeset.{phase}", ":")}{label("changeset.{phase}", short(node))} {label("grep.user", author|user)}{label("log.tag", if(tags," {tags}"))}{label("log.tag", if(fxheads," {fxheads}"))} {label("log.bookmark", if(bookmarks," {bookmarks}"))}\n{label(ifcontains(rev, revset("."), "desc.here"),desc|firstline)}'
+  +[extensions]
+  +pager =
+  +[pager]
+  +pager = LESS=FRSXQ less
+  +attend-help = true
+  +attend-incoming = true
+  +attend-outgoing = true
+  +attend-status = true
+  +attend-wip = true
+  
+  Write changes to hgrc file (Yn)?  y