[PATCH 2 of 2 V2] templater: add '{envvars}' to access environment variables

Matt Harbison mharbison72 at gmail.com
Wed Jan 18 21:39:47 EST 2017


On Wed, 18 Jan 2017 08:44:55 -0500, Yuya Nishihara <yuya at tcha.org> wrote:

> On Tue, 17 Jan 2017 23:50:47 -0500, Matt Harbison wrote:
>> # HG changeset patch
>> # User Matt Harbison <matt_harbison at yahoo.com>
>> # Date 1484712774 18000
>> #      Tue Jan 17 23:12:54 2017 -0500
>> # Node ID fce42f9dba7bab71463c0bcec44e6d87fdf275b2
>> # Parent  5a03e25ec0c0417e915b2014995bd83443ef97ec
>> templater: add '{envvars}' to access environment variables
>>
>> Since the option for ui.exportableenviron is experimental, so is this  
>> template
>> until the underlying API is sorted out.
>>
>> diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
>> --- a/mercurial/cmdutil.py
>> +++ b/mercurial/cmdutil.py
>> @@ -1448,7 +1448,8 @@
>>              'parent': '{rev}:{node|formatnode} ',
>>              'manifest': '{rev}:{node|formatnode}',
>>              'file_copy': '{name} ({source})',
>> -            'extra': '{key}={value|stringescape}'
>> +            'extra': '{key}={value|stringescape}',
>> +            'envvar': '{key}={value|stringescape}'
>
> Dropped '|stringescape' since {envvar} should be readable text in  
> general.

The only reason I thought it was necessary is because MSYS is apparently  
putting a couple '\n' in $PS1.

$ ../hg log -r . -T "{get(envvars, 'PS1')}" --config  
"experimental.exportableenviron=*"
\[\033]0;$MSYSTEM:\w\007
\033[32m\]\u@\h \[\033[33m\w\033[0m\]

vs

$ echo $PS1
\[\033]0;$MSYSTEM:\w\007 \033[32m\]\u@\h \[\033[33m\w\033[0m\] $

Maybe that's too much of a corner case to care.  Dropping the escaping  
also prevents the Windows paths from showing as 'C:\\Windows\\..', so  
maybe that's a good thing.


>> --- a/mercurial/templatekw.py
>> +++ b/mercurial/templatekw.py
>> @@ -303,6 +303,18 @@
>>      maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
>>      return '%s: +%s/-%s' % (len(stats), adds, removes)
>>
>> + at templatekeyword('envvars')
>> +def showenviron(repo, **args):
>
> s/showenviron/showenvvars/


More information about the Mercurial-devel mailing list