[PATCH STABLE] pager: set MORE=FRX on OS X and FreeBSD
Augie Fackler
raf at durin42.com
Fri Apr 21 21:02:31 EDT 2017
> On Apr 21, 2017, at 20:19, Gregory Szorc <gregory.szorc at gmail.com> wrote:
>
> On Fri, Apr 21, 2017 at 4:16 PM, Jun Wu <quark at fb.com <mailto:quark at fb.com>> wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com <mailto: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 <https://bitbucket.org/quark-zju/hg-draft>
> # hg pull https://bitbucket.org/quark-zju/hg-draft <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 <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?
The vision I had for this was that packages would specify a sane pager for their platform in /etc/mercurial/pager.rc or something. I'm opposed to this patch, because it's putting the OS-specific preferences in Mercurial instead of in the packaging where it belongs.
> 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/ <http://www.greenwoodsoftware.com/less/>
> + # [2]: https://www.kernel.org/pub/linux/utils/util-linux/ <https://www.kernel.org/pub/linux/utils/util-linux/>
> + pagerenv['MORE'] = 'FRX'
> + return pagerenv
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org <mailto:Mercurial-devel at mercurial-scm.org>
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel <https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel>
>
> _______________________________________________
> 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/5aacaeaf/attachment.html>
More information about the Mercurial-devel
mailing list