On Wed, 12 Apr 2017 16:51:05 -0700, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <qu...@fb.com>
> # Date 1492039375 25200
> #      Wed Apr 12 16:22:55 2017 -0700
> # Node ID c8f21c8e1a9a8b5ca97bb87916ede5770d6f7021
> # Parent  1c398f7f4aa437a7c692025f0434c0564dbf72ff
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r 
> c8f21c8e1a9a
> pager: set some environment variables if they're not set
> 
> Git did this already [1] [2]. We want this behavior too [3].
> 
> This provides a better default user experience (like, supporting colors) if
> users have things like "PAGER=less" set, which is not uncommon.
> 
> [1]: 
> https://github.com/git/git/blob/6a5ff7acb5965718cc7016c0ab6c601454fd7cde/pager.c#L87
> [2]: 
> https://github.com/git/git/blob/6a5ff7acb5965718cc7016c0ab6c601454fd7cde/Makefile#L1545
> [3]: 
> https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-March/094780.html

> diff --git a/mercurial/help/pager.txt b/mercurial/help/pager.txt
> --- a/mercurial/help/pager.txt
> +++ b/mercurial/help/pager.txt
> @@ -34,2 +34,11 @@ To globally turn off all attempts to use
>  
>  which will prevent the pager from running.
> +
> +In order to provide a better default user experience, some environment
> +variables will be set if they are not set. For example, if LESS is not set, 
> it
> +will be set to FRX. To override the list of environment variables, set::
> +
> +  [pager]
> +  defaultenv = LESS=FRQXi, LESSKEY=~/.lesskey
> +
> +Commas are needed to separate multiple default environment variables.
> diff --git a/mercurial/ui.py b/mercurial/ui.py
> --- a/mercurial/ui.py
> +++ b/mercurial/ui.py
> @@ -855,4 +855,13 @@ class ui(object):
>              return
>  
> +        pagerenv = encoding.environ.copy()
> +        for entry in self.configlist('pager', 'defaultenv',
> +                                     ['LESS=FRX', 'LV=-c']):
> +            if '=' not in entry:
> +                raise error.Abort(_('invalid pager.defaultenv config: %s')
> +                                  % entry)
> +            name, value = entry.split('=', 1)
> +            pagerenv.setdefault(name, value)

Instead of introducing defaultenv config, how about always setting
"LESS=FRX LV=-c" unless they are in environ dict? Users can easily override
them by pager command:

  [pager]
  pager = LESS=whatever less

I feel writing environs in the configlist syntax isn't nice.

> @@ -913,5 +922,6 @@ class ui(object):
>                  command, shell=shell, bufsize=-1,
>                  close_fds=util.closefds, stdin=subprocess.PIPE,
> -                stdout=util.stdout, stderr=util.stderr)
> +                stdout=util.stdout, stderr=util.stderr,
> +                env=util.shellenviron(env))

Nit: util.shellenviron() only needs a partial environ dict to override.
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to