[PATCH 1 of 9 pager v2] pager: move pager-initiating code into core

Matt Harbison mharbison72 at gmail.com
Sat Feb 25 23:22:05 EST 2017


On Thu, 16 Feb 2017 11:59:10 -0500, Augie Fackler <raf at durin42.com> wrote:

> # HG changeset patch
> # User Augie Fackler <augie at google.com>
> # Date 1487198871 18000
> #      Wed Feb 15 17:47:51 2017 -0500
> # Node ID cd19a77477bcd18d1f7ab4fa73ee0dbf3c7a4e46
> # Parent  791b4e846a7b9a0783440b9504585438777fe2d2
> pager: move pager-initiating code into core
>
> No functionality change.
>
> A previous version of this API had a category argument on
> ui.pager(). As I migrated the commands in core, I couldn't come up
> with good enough consistency in any categorization scheme so I just
> scrapped the whole idea. It may be worth revisiting in the future.
>
> diff --git a/hgext/pager.py b/hgext/pager.py
> --- a/hgext/pager.py
> +++ b/hgext/pager.py
> +        # TODO: add a "system defaults" config section so this default
> +        # of more(1) can be easily replaced with a global
> +        # configuration file. For example, on OS X the sane default is
> +        # less(1), not more(1), and on debian it's
> +        # sensible-pager(1). We should probably also give the system
> +        # default editor command similar treatment.
> +        envpager = encoding.environ.get('PAGER', 'more')
> +        pagercmd = self.config('pager', 'pager', envpager)

Any thoughts on what this looks like?  It seems like it might be  
distantly(?) related to something I tried a couple years ago [1], and the  
discussions around it.

Does it seem reasonable to move the above to a method, similar to  
ui.editor()?  I'd like to detect MSYS and default to `less`.  IDK if we  
can pull that off with just a global config file.  (The only way I see to  
detect MSYS is to look for 'MSYSTEM' in env.)

In theory, the `less` command in GnuWin32 can be installed and made  
visible to cmd.exe too.  I wonder if (on some platforms anyway), there  
should be a list of default choices, and the first one found in $PATH  
used.  ui.editor() doesn't make sure the editor is valid, so I figured  
keeping that kind of check out of ui was purposeful.  A bad editor will  
produce an error that tries to indicate the problem (though I missed it  
the first time in the OS error output):

     $ HGEDITOR=xzy ../hg ci
     'xzy' is not recognized as an internal or external command,
     operable program or batch file.
     abort: edit failed: xzy exited with status 1

But not so much for the pager:

     hg>set PAGER=less
     hg>hg help filesets
     'less' is not recognized as an internal or external command,
     operable program or batch file.

I'm not sure if the right thing here is to error out, or to treat the  
pager as disabled.  Especially if it is on by default, with an env knob  
that isn't as obvious as the example above.  So it seems like we might  
need some sort of check, whether or not we try a list of defaults.


[1]  
https://www.mercurial-scm.org/pipermail/mercurial-devel/2015-March/067563.html


More information about the Mercurial-devel mailing list