[PATCH STABLE] pager: set MORE=FRX on OS X and FreeBSD

Gregory Szorc gregory.szorc at gmail.com
Fri Apr 21 20:19:37 EDT 2017


On Fri, Apr 21, 2017 at 4:16 PM, Jun Wu <quark at fb.com> wrote:

> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1492816528 25200
> #      Fri Apr 21 16:15:28 2017 -0700
> # Node ID 166f5440301761a12a6441afda4aa9a87223ffdc
> # Parent  6e0368b6e0bb2aa5210daec091c0200583553a78
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r
> 166f54403017
> pager: set MORE=FRX on OS X and FreeBSD
>
> We use "more" as the fallback pager when no config is loaded (ex.
> HGRCPATH=/dev/null). Interestingly, "more" on Linux supports colors out of
> box. But on FreeBSD and OS X, "more" is backed by "less" and need the "R"
> flag to support colors. This patch sets MORE=FRX on FreeBSD and OS X.
>
> Note: we cannot set it on Linux because that leads to "unknown option
> -FRX".
>
> This solves an OS X pager and color issue reported at [1].
>
> [1]: https://www.mercurial-scm.org/pipermail/mercurial-devel/2017
> -April/097021.html


I think this patch is acceptable. However, at the point we're sniffing
platforms and assuming that `more` is `less`, wouldn't we be better off
switching the default pager to `less` on these platforms? After all,
`MORE=FRX more` will cause actual/not-less `more` to error with "unknown
option -FRX." So if we know we're using `less,` let's just use it and avoid
less's "more compatibility mode" altogether.

In terms of failure scenarios, I think "less not found" on the output from
an hg command is easier to comprehend than "more: unknown option -FRX"
(which includes several lines of help output from `more` BTW). On that
front, I think we need better messaging around failures to invoke the
pager. Right now:

  $ hg log --config pager.pager=foobar
  /bin/sh: 1: foobar: not found

  $ PAGER=foobar hg log
  /bin/sh: 1: foobar: not found

I really think hg needs to be explicit that the pager failed to invoke.


>
>
> diff --git a/mercurial/rcutil.py b/mercurial/rcutil.py
> --- a/mercurial/rcutil.py
> +++ b/mercurial/rcutil.py
> @@ -9,4 +9,5 @@ from __future__ import absolute_import
>
>  import os
> +import re
>
>  from . import (
> @@ -96,3 +97,11 @@ def defaultpagerenv():
>      intended to be set before starting a pager.
>      '''
> -    return {'LESS': 'FRX', 'LV': '-c'}
> +    pagerenv = {'LESS': 'FRX', 'LV': '-c'}
> +    if re.search('freebsd|darwin', pycompat.sysplatform):
> +        # On OS X and FreeBSD, "more" is "less" [1], and needs "R" to not
> lose
> +        # color. On Linux, "more" is a different binary [2] that supports
> +        # colors by default and will crash if it sees those unrecognised
> flags.
> +        # [1]: http://www.greenwoodsoftware.com/less/
> +        # [2]: https://www.kernel.org/pub/linux/utils/util-linux/
> +        pagerenv['MORE'] = 'FRX'
> +    return pagerenv
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20170421/c91276c0/attachment.html>


More information about the Mercurial-devel mailing list