Patchwork [2,of,9] py3: replace os.environ with encoding.environ (part 2 of 5)

login
register
mail settings
Submitter Pulkit Goyal
Date Dec. 20, 2016, 2:03 p.m.
Message ID <c1a8b0e2a088a8cd365f.1482242628@pulkit-goyal.Home>
Download mbox | patch
Permalink /patch/17974/
State Accepted
Headers show

Comments

Pulkit Goyal - Dec. 20, 2016, 2:03 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1482005799 -19800
#      Sun Dec 18 01:46:39 2016 +0530
# Node ID c1a8b0e2a088a8cd365f7aa6a3f5d609fc57a92f
# Parent  961ff24b8c2f9d71ff8f5d6539f760e78d88d07a
py3: replace os.environ with encoding.environ (part 2 of 5)
Pierre-Yves David - Dec. 21, 2016, 12:03 p.m.
On 12/20/2016 03:03 PM, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1482005799 -19800
> #      Sun Dec 18 01:46:39 2016 +0530
> # Node ID c1a8b0e2a088a8cd365f7aa6a3f5d609fc57a92f
> # Parent  961ff24b8c2f9d71ff8f5d6539f760e78d88d07a
> py3: replace os.environ with encoding.environ (part 2 of 5)
>
> diff -r 961ff24b8c2f -r c1a8b0e2a088 mercurial/chgserver.py
> --- a/mercurial/chgserver.py	Sun Dec 18 01:34:41 2016 +0530
> +++ b/mercurial/chgserver.py	Sun Dec 18 01:46:39 2016 +0530
> @@ -55,6 +55,7 @@
>  from . import (
>      cmdutil,
>      commandserver,
> +    encoding,
>      error,
>      extensions,
>      osutil,
> @@ -102,7 +103,8 @@
>      for section in _configsections:
>          sectionitems.append(ui.configitems(section))
>      sectionhash = _hashlist(sectionitems)
> -    envitems = [(k, v) for k, v in os.environ.iteritems() if _envre.match(k)]
> +    envitems = [(k, v) for k, v in encoding.environ.iteritems()\
> +                    if _envre.match(k)]

You do not need the \ here because you are an open '[' so python knows 
there is more coming. There was an handful of these, I fixed them inflight.

If there is not open '([{' to get that effect, we usually favor adding 
'(' around the expression than adding '\'.

(also we tend to rely on temporary variable when the line becomes too long).

>      envhash = _hashlist(sorted(envitems))
>      return sectionhash[:6] + envhash[:6]
>
> @@ -177,7 +179,7 @@
>      if not ui.formatted():
>          return
>
> -    p = ui.config("pager", "pager", os.environ.get("PAGER"))
> +    p = ui.config("pager", "pager", encoding.environ.get("PAGER"))
>      usepager = False
>      always = util.parsebool(options['pager'])
>      auto = options['pager'] == 'auto'
> @@ -237,7 +239,7 @@
>                  if val is True:
>                      return '1'
>                  return str(val)
> -            env = os.environ.copy()
> +            env = encoding.environ.copy()
>              if environ:
>                  env.update((k, py2shell(v)) for k, v in environ.iteritems())
>              env['HG'] = util.hgexecutable()
> @@ -515,8 +517,8 @@
>          except ValueError:
>              raise ValueError('unexpected value in setenv request')
>          _log('setenv: %r\n' % sorted(newenv.keys()))
> -        os.environ.clear()
> -        os.environ.update(newenv)
> +        encoding.environ.clear()
> +        encoding.environ.update(newenv)
>
>      capabilities = commandserver.server.capabilities.copy()
>      capabilities.update({'attachio': attachio,
> @@ -626,8 +628,8 @@
>  def chgunixservice(ui, repo, opts):
>      # CHGINTERNALMARK is temporarily set by chg client to detect if chg will
>      # start another chg. drop it to avoid possible side effects.
> -    if 'CHGINTERNALMARK' in os.environ:
> -        del os.environ['CHGINTERNALMARK']
> +    if 'CHGINTERNALMARK' in encoding.environ:
> +        del encoding.environ['CHGINTERNALMARK']
>
>      if repo:
>          # one chgserver can serve multiple repos. drop repo information
> diff -r 961ff24b8c2f -r c1a8b0e2a088 mercurial/sshserver.py
> --- a/mercurial/sshserver.py	Sun Dec 18 01:34:41 2016 +0530
> +++ b/mercurial/sshserver.py	Sun Dec 18 01:46:39 2016 +0530
> @@ -8,11 +8,11 @@
>
>  from __future__ import absolute_import
>
> -import os
>  import sys
>
>  from .i18n import _
>  from . import (
> +    encoding,
>      error,
>      hook,
>      util,
> @@ -131,5 +131,5 @@
>          return cmd != ''
>
>      def _client(self):
> -        client = os.environ.get('SSH_CLIENT', '').split(' ', 1)[0]
> +        client = encoding.environ.get('SSH_CLIENT', '').split(' ', 1)[0]
>          return 'remote:ssh:' + client
> diff -r 961ff24b8c2f -r c1a8b0e2a088 mercurial/subrepo.py
> --- a/mercurial/subrepo.py	Sun Dec 18 01:34:41 2016 +0530
> +++ b/mercurial/subrepo.py	Sun Dec 18 01:46:39 2016 +0530
> @@ -24,6 +24,7 @@
>  from . import (
>      cmdutil,
>      config,
> +    encoding,
>      error,
>      exchange,
>      filemerge,
> @@ -1102,7 +1103,7 @@
>              path = self.wvfs.reljoin(self._ctx.repo().origroot,
>                                       self._path, filename)
>              cmd.append(path)
> -        env = dict(os.environ)
> +        env = dict(encoding.environ)
>          # Avoid localized output, preserve current locale for everything else.
>          lc_all = env.get('LC_ALL')
>          if lc_all:
> @@ -1398,7 +1399,7 @@
>          """
>          self.ui.debug('%s: git %s\n' % (self._relpath, ' '.join(commands)))
>          if env is None:
> -            env = os.environ.copy()
> +            env = encoding.environ.copy()
>          # disable localization for Git output (issue5176)
>          env['LC_ALL'] = 'C'
>          # fix for Git CVE-2015-7545
> @@ -1633,7 +1634,7 @@
>          if self._gitmissing():
>              raise error.Abort(_("subrepo %s is missing") % self._relpath)
>          cmd = ['commit', '-a', '-m', text]
> -        env = os.environ.copy()
> +        env = encoding.environ.copy()
>          if user:
>              cmd += ['--author', user]
>          if date:
> diff -r 961ff24b8c2f -r c1a8b0e2a088 mercurial/worker.py
> --- a/mercurial/worker.py	Sun Dec 18 01:34:41 2016 +0530
> +++ b/mercurial/worker.py	Sun Dec 18 01:46:39 2016 +0530
> @@ -14,6 +14,7 @@
>
>  from .i18n import _
>  from . import (
> +    encoding,
>      error,
>      scmutil,
>      util,
> @@ -32,7 +33,7 @@
>
>      # windows
>      try:
> -        n = int(os.environ['NUMBER_OF_PROCESSORS'])
> +        n = int(encoding.environ['NUMBER_OF_PROCESSORS'])
>          if n > 0:
>              return n
>      except (KeyError, ValueError):
> diff -r 961ff24b8c2f -r c1a8b0e2a088 tests/test-check-config.t
> --- a/tests/test-check-config.t	Sun Dec 18 01:34:41 2016 +0530
> +++ b/tests/test-check-config.t	Sun Dec 18 01:46:39 2016 +0530
> @@ -7,3 +7,6 @@
>
>    $ hg files "set:(**.py or **.txt) - tests/**" | sed 's|\\|/|g' |
>    >   python contrib/check-config.py
> +      p = ui.config("pager", "pager", encoding.environ.get("PAGER"))
> +
> +  conflict on pager.pager: ('str', 'encoding.environ.get("PAGER"') != ('str', 'os.environ.get("PAGER"')
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
Pierre-Yves David - Dec. 21, 2016, 12:04 p.m.
On 12/21/2016 01:03 PM, Pierre-Yves David wrote:
>
>
> On 12/20/2016 03:03 PM, Pulkit Goyal wrote:
>> # HG changeset patch
>> # User Pulkit Goyal <7895pulkit@gmail.com>
>> # Date 1482005799 -19800
>> #      Sun Dec 18 01:46:39 2016 +0530
>> # Node ID c1a8b0e2a088a8cd365f7aa6a3f5d609fc57a92f
>> # Parent  961ff24b8c2f9d71ff8f5d6539f760e78d88d07a
>> py3: replace os.environ with encoding.environ (part 2 of 5)
>>
>> diff -r 961ff24b8c2f -r c1a8b0e2a088 mercurial/chgserver.py
>> --- a/mercurial/chgserver.py    Sun Dec 18 01:34:41 2016 +0530
>> +++ b/mercurial/chgserver.py    Sun Dec 18 01:46:39 2016 +0530
>> @@ -55,6 +55,7 @@
>>  from . import (
>>      cmdutil,
>>      commandserver,
>> +    encoding,
>>      error,
>>      extensions,
>>      osutil,
>> @@ -102,7 +103,8 @@
>>      for section in _configsections:
>>          sectionitems.append(ui.configitems(section))
>>      sectionhash = _hashlist(sectionitems)
>> -    envitems = [(k, v) for k, v in os.environ.iteritems() if
>> _envre.match(k)]
>> +    envitems = [(k, v) for k, v in encoding.environ.iteritems()\
>> +                    if _envre.match(k)]
>
> You do not need the \ here because you are an open '[' so python knows
> there is more coming. There was an handful of these, I fixed them inflight.
>
> If there is not open '([{' to get that effect, we usually favor adding
> '(' around the expression than adding '\'.
>
> (also we tend to rely on temporary variable when the line becomes too
> long).
>
>>      envhash = _hashlist(sorted(envitems))
>>      return sectionhash[:6] + envhash[:6]
>>
>> @@ -177,7 +179,7 @@
>>      if not ui.formatted():
>>          return
>>
>> -    p = ui.config("pager", "pager", os.environ.get("PAGER"))
>> +    p = ui.config("pager", "pager", encoding.environ.get("PAGER"))
>>      usepager = False
>>      always = util.parsebool(options['pager'])
>>      auto = options['pager'] == 'auto'
>> @@ -237,7 +239,7 @@
>>                  if val is True:
>>                      return '1'
>>                  return str(val)
>> -            env = os.environ.copy()
>> +            env = encoding.environ.copy()
>>              if environ:
>>                  env.update((k, py2shell(v)) for k, v in
>> environ.iteritems())
>>              env['HG'] = util.hgexecutable()
>> @@ -515,8 +517,8 @@
>>          except ValueError:
>>              raise ValueError('unexpected value in setenv request')
>>          _log('setenv: %r\n' % sorted(newenv.keys()))
>> -        os.environ.clear()
>> -        os.environ.update(newenv)
>> +        encoding.environ.clear()
>> +        encoding.environ.update(newenv)
>>
>>      capabilities = commandserver.server.capabilities.copy()
>>      capabilities.update({'attachio': attachio,
>> @@ -626,8 +628,8 @@
>>  def chgunixservice(ui, repo, opts):
>>      # CHGINTERNALMARK is temporarily set by chg client to detect if
>> chg will
>>      # start another chg. drop it to avoid possible side effects.
>> -    if 'CHGINTERNALMARK' in os.environ:
>> -        del os.environ['CHGINTERNALMARK']
>> +    if 'CHGINTERNALMARK' in encoding.environ:
>> +        del encoding.environ['CHGINTERNALMARK']
>>
>>      if repo:
>>          # one chgserver can serve multiple repos. drop repo information
>> diff -r 961ff24b8c2f -r c1a8b0e2a088 mercurial/sshserver.py
>> --- a/mercurial/sshserver.py    Sun Dec 18 01:34:41 2016 +0530
>> +++ b/mercurial/sshserver.py    Sun Dec 18 01:46:39 2016 +0530
>> @@ -8,11 +8,11 @@
>>
>>  from __future__ import absolute_import
>>
>> -import os
>>  import sys
>>
>>  from .i18n import _
>>  from . import (
>> +    encoding,
>>      error,
>>      hook,
>>      util,
>> @@ -131,5 +131,5 @@
>>          return cmd != ''
>>
>>      def _client(self):
>> -        client = os.environ.get('SSH_CLIENT', '').split(' ', 1)[0]
>> +        client = encoding.environ.get('SSH_CLIENT', '').split(' ', 1)[0]
>>          return 'remote:ssh:' + client
>> diff -r 961ff24b8c2f -r c1a8b0e2a088 mercurial/subrepo.py
>> --- a/mercurial/subrepo.py    Sun Dec 18 01:34:41 2016 +0530
>> +++ b/mercurial/subrepo.py    Sun Dec 18 01:46:39 2016 +0530
>> @@ -24,6 +24,7 @@
>>  from . import (
>>      cmdutil,
>>      config,
>> +    encoding,
>>      error,
>>      exchange,
>>      filemerge,
>> @@ -1102,7 +1103,7 @@
>>              path = self.wvfs.reljoin(self._ctx.repo().origroot,
>>                                       self._path, filename)
>>              cmd.append(path)
>> -        env = dict(os.environ)
>> +        env = dict(encoding.environ)
>>          # Avoid localized output, preserve current locale for
>> everything else.
>>          lc_all = env.get('LC_ALL')
>>          if lc_all:
>> @@ -1398,7 +1399,7 @@
>>          """
>>          self.ui.debug('%s: git %s\n' % (self._relpath, '
>> '.join(commands)))
>>          if env is None:
>> -            env = os.environ.copy()
>> +            env = encoding.environ.copy()
>>          # disable localization for Git output (issue5176)
>>          env['LC_ALL'] = 'C'
>>          # fix for Git CVE-2015-7545
>> @@ -1633,7 +1634,7 @@
>>          if self._gitmissing():
>>              raise error.Abort(_("subrepo %s is missing") %
>> self._relpath)
>>          cmd = ['commit', '-a', '-m', text]
>> -        env = os.environ.copy()
>> +        env = encoding.environ.copy()
>>          if user:
>>              cmd += ['--author', user]
>>          if date:
>> diff -r 961ff24b8c2f -r c1a8b0e2a088 mercurial/worker.py
>> --- a/mercurial/worker.py    Sun Dec 18 01:34:41 2016 +0530
>> +++ b/mercurial/worker.py    Sun Dec 18 01:46:39 2016 +0530
>> @@ -14,6 +14,7 @@
>>
>>  from .i18n import _
>>  from . import (
>> +    encoding,
>>      error,
>>      scmutil,
>>      util,
>> @@ -32,7 +33,7 @@
>>
>>      # windows
>>      try:
>> -        n = int(os.environ['NUMBER_OF_PROCESSORS'])
>> +        n = int(encoding.environ['NUMBER_OF_PROCESSORS'])
>>          if n > 0:
>>              return n
>>      except (KeyError, ValueError):
>> diff -r 961ff24b8c2f -r c1a8b0e2a088 tests/test-check-config.t
>> --- a/tests/test-check-config.t    Sun Dec 18 01:34:41 2016 +0530
>> +++ b/tests/test-check-config.t    Sun Dec 18 01:46:39 2016 +0530
>> @@ -7,3 +7,6 @@
>>
>>    $ hg files "set:(**.py or **.txt) - tests/**" | sed 's|\\|/|g' |
>>    >   python contrib/check-config.py
>> +      p = ui.config("pager", "pager", encoding.environ.get("PAGER"))
>> +
>> +  conflict on pager.pager: ('str', 'encoding.environ.get("PAGER"') !=
>> ('str', 'os.environ.get("PAGER"')

I've also gathered the other change touching that config in the same 
changeset to avoid this transient error. I'm not sure to understand your 
slicing algorithm here.

Cheers,
Pulkit Goyal - Dec. 21, 2016, 1:08 p.m.
>> You do not need the \ here because you are an open '[' so python knows
>> there is more coming. There was an handful of these, I fixed them
>> inflight.
>>
>> If there is not open '([{' to get that effect, we usually favor adding
>> '(' around the expression than adding '\'.
>>
>> (also we tend to rely on temporary variable when the line becomes too
>> long).

Okay will take care of it the next time.
>>
>>>      envhash = _hashlist(sorted(envitems))
>>>      return sectionhash[:6] + envhash[:6]
>>>
>>> @@ -177,7 +179,7 @@
>>>      if not ui.formatted():
>>>          return
>>>
>>> -    p = ui.config("pager", "pager", os.environ.get("PAGER"))
>>> +    p = ui.config("pager", "pager", encoding.environ.get("PAGER"))
>>>      usepager = False
>>>      always = util.parsebool(options['pager'])
>>>      auto = options['pager'] == 'auto'
>>> @@ -237,7 +239,7 @@
>>>                  if val is True:
>>>                      return '1'
>>>                  return str(val)
>>> -            env = os.environ.copy()
>>> +            env = encoding.environ.copy()
>>>              if environ:
>>>                  env.update((k, py2shell(v)) for k, v in
>>> environ.iteritems())
>>>              env['HG'] = util.hgexecutable()
>>> @@ -515,8 +517,8 @@
>>>          except ValueError:
>>>              raise ValueError('unexpected value in setenv request')
>>>          _log('setenv: %r\n' % sorted(newenv.keys()))
>>> -        os.environ.clear()
>>> -        os.environ.update(newenv)
>>> +        encoding.environ.clear()
>>> +        encoding.environ.update(newenv)
>>>
>>>      capabilities = commandserver.server.capabilities.copy()
>>>      capabilities.update({'attachio': attachio,
>>> @@ -626,8 +628,8 @@
>>>  def chgunixservice(ui, repo, opts):
>>>      # CHGINTERNALMARK is temporarily set by chg client to detect if
>>> chg will
>>>      # start another chg. drop it to avoid possible side effects.
>>> -    if 'CHGINTERNALMARK' in os.environ:
>>> -        del os.environ['CHGINTERNALMARK']
>>> +    if 'CHGINTERNALMARK' in encoding.environ:
>>> +        del encoding.environ['CHGINTERNALMARK']
>>>
>>>      if repo:
>>>          # one chgserver can serve multiple repos. drop repo information
>>> diff -r 961ff24b8c2f -r c1a8b0e2a088 mercurial/sshserver.py
>>> --- a/mercurial/sshserver.py    Sun Dec 18 01:34:41 2016 +0530
>>> +++ b/mercurial/sshserver.py    Sun Dec 18 01:46:39 2016 +0530
>>> @@ -8,11 +8,11 @@
>>>
>>>  from __future__ import absolute_import
>>>
>>> -import os
>>>  import sys
>>>
>>>  from .i18n import _
>>>  from . import (
>>> +    encoding,
>>>      error,
>>>      hook,
>>>      util,
>>> @@ -131,5 +131,5 @@
>>>          return cmd != ''
>>>
>>>      def _client(self):
>>> -        client = os.environ.get('SSH_CLIENT', '').split(' ', 1)[0]
>>> +        client = encoding.environ.get('SSH_CLIENT', '').split(' ', 1)[0]
>>>          return 'remote:ssh:' + client
>>> diff -r 961ff24b8c2f -r c1a8b0e2a088 mercurial/subrepo.py
>>> --- a/mercurial/subrepo.py    Sun Dec 18 01:34:41 2016 +0530
>>> +++ b/mercurial/subrepo.py    Sun Dec 18 01:46:39 2016 +0530
>>> @@ -24,6 +24,7 @@
>>>  from . import (
>>>      cmdutil,
>>>      config,
>>> +    encoding,
>>>      error,
>>>      exchange,
>>>      filemerge,
>>> @@ -1102,7 +1103,7 @@
>>>              path = self.wvfs.reljoin(self._ctx.repo().origroot,
>>>                                       self._path, filename)
>>>              cmd.append(path)
>>> -        env = dict(os.environ)
>>> +        env = dict(encoding.environ)
>>>          # Avoid localized output, preserve current locale for
>>> everything else.
>>>          lc_all = env.get('LC_ALL')
>>>          if lc_all:
>>> @@ -1398,7 +1399,7 @@
>>>          """
>>>          self.ui.debug('%s: git %s\n' % (self._relpath, '
>>> '.join(commands)))
>>>          if env is None:
>>> -            env = os.environ.copy()
>>> +            env = encoding.environ.copy()
>>>          # disable localization for Git output (issue5176)
>>>          env['LC_ALL'] = 'C'
>>>          # fix for Git CVE-2015-7545
>>> @@ -1633,7 +1634,7 @@
>>>          if self._gitmissing():
>>>              raise error.Abort(_("subrepo %s is missing") %
>>> self._relpath)
>>>          cmd = ['commit', '-a', '-m', text]
>>> -        env = os.environ.copy()
>>> +        env = encoding.environ.copy()
>>>          if user:
>>>              cmd += ['--author', user]
>>>          if date:
>>> diff -r 961ff24b8c2f -r c1a8b0e2a088 mercurial/worker.py
>>> --- a/mercurial/worker.py    Sun Dec 18 01:34:41 2016 +0530
>>> +++ b/mercurial/worker.py    Sun Dec 18 01:46:39 2016 +0530
>>> @@ -14,6 +14,7 @@
>>>
>>>  from .i18n import _
>>>  from . import (
>>> +    encoding,
>>>      error,
>>>      scmutil,
>>>      util,
>>> @@ -32,7 +33,7 @@
>>>
>>>      # windows
>>>      try:
>>> -        n = int(os.environ['NUMBER_OF_PROCESSORS'])
>>> +        n = int(encoding.environ['NUMBER_OF_PROCESSORS'])
>>>          if n > 0:
>>>              return n
>>>      except (KeyError, ValueError):
>>> diff -r 961ff24b8c2f -r c1a8b0e2a088 tests/test-check-config.t
>>> --- a/tests/test-check-config.t    Sun Dec 18 01:34:41 2016 +0530
>>> +++ b/tests/test-check-config.t    Sun Dec 18 01:46:39 2016 +0530
>>> @@ -7,3 +7,6 @@
>>>
>>>    $ hg files "set:(**.py or **.txt) - tests/**" | sed 's|\\|/|g' |
>>>    >   python contrib/check-config.py
>>> +      p = ui.config("pager", "pager", encoding.environ.get("PAGER"))
>>> +
>>> +  conflict on pager.pager: ('str', 'encoding.environ.get("PAGER"') !=
>>> ('str', 'os.environ.get("PAGER"')
>
>
> I've also gathered the other change touching that config in the same
> changeset to avoid this transient error. I'm not sure to understand your
> slicing algorithm here.
>

It was just pick first five from the grep result. I will take care of
this also the next time.
> Cheers,
>
> --
> Pierre-Yves David

Patch

diff -r 961ff24b8c2f -r c1a8b0e2a088 mercurial/chgserver.py
--- a/mercurial/chgserver.py	Sun Dec 18 01:34:41 2016 +0530
+++ b/mercurial/chgserver.py	Sun Dec 18 01:46:39 2016 +0530
@@ -55,6 +55,7 @@ 
 from . import (
     cmdutil,
     commandserver,
+    encoding,
     error,
     extensions,
     osutil,
@@ -102,7 +103,8 @@ 
     for section in _configsections:
         sectionitems.append(ui.configitems(section))
     sectionhash = _hashlist(sectionitems)
-    envitems = [(k, v) for k, v in os.environ.iteritems() if _envre.match(k)]
+    envitems = [(k, v) for k, v in encoding.environ.iteritems()\
+                    if _envre.match(k)]
     envhash = _hashlist(sorted(envitems))
     return sectionhash[:6] + envhash[:6]
 
@@ -177,7 +179,7 @@ 
     if not ui.formatted():
         return
 
-    p = ui.config("pager", "pager", os.environ.get("PAGER"))
+    p = ui.config("pager", "pager", encoding.environ.get("PAGER"))
     usepager = False
     always = util.parsebool(options['pager'])
     auto = options['pager'] == 'auto'
@@ -237,7 +239,7 @@ 
                 if val is True:
                     return '1'
                 return str(val)
-            env = os.environ.copy()
+            env = encoding.environ.copy()
             if environ:
                 env.update((k, py2shell(v)) for k, v in environ.iteritems())
             env['HG'] = util.hgexecutable()
@@ -515,8 +517,8 @@ 
         except ValueError:
             raise ValueError('unexpected value in setenv request')
         _log('setenv: %r\n' % sorted(newenv.keys()))
-        os.environ.clear()
-        os.environ.update(newenv)
+        encoding.environ.clear()
+        encoding.environ.update(newenv)
 
     capabilities = commandserver.server.capabilities.copy()
     capabilities.update({'attachio': attachio,
@@ -626,8 +628,8 @@ 
 def chgunixservice(ui, repo, opts):
     # CHGINTERNALMARK is temporarily set by chg client to detect if chg will
     # start another chg. drop it to avoid possible side effects.
-    if 'CHGINTERNALMARK' in os.environ:
-        del os.environ['CHGINTERNALMARK']
+    if 'CHGINTERNALMARK' in encoding.environ:
+        del encoding.environ['CHGINTERNALMARK']
 
     if repo:
         # one chgserver can serve multiple repos. drop repo information
diff -r 961ff24b8c2f -r c1a8b0e2a088 mercurial/sshserver.py
--- a/mercurial/sshserver.py	Sun Dec 18 01:34:41 2016 +0530
+++ b/mercurial/sshserver.py	Sun Dec 18 01:46:39 2016 +0530
@@ -8,11 +8,11 @@ 
 
 from __future__ import absolute_import
 
-import os
 import sys
 
 from .i18n import _
 from . import (
+    encoding,
     error,
     hook,
     util,
@@ -131,5 +131,5 @@ 
         return cmd != ''
 
     def _client(self):
-        client = os.environ.get('SSH_CLIENT', '').split(' ', 1)[0]
+        client = encoding.environ.get('SSH_CLIENT', '').split(' ', 1)[0]
         return 'remote:ssh:' + client
diff -r 961ff24b8c2f -r c1a8b0e2a088 mercurial/subrepo.py
--- a/mercurial/subrepo.py	Sun Dec 18 01:34:41 2016 +0530
+++ b/mercurial/subrepo.py	Sun Dec 18 01:46:39 2016 +0530
@@ -24,6 +24,7 @@ 
 from . import (
     cmdutil,
     config,
+    encoding,
     error,
     exchange,
     filemerge,
@@ -1102,7 +1103,7 @@ 
             path = self.wvfs.reljoin(self._ctx.repo().origroot,
                                      self._path, filename)
             cmd.append(path)
-        env = dict(os.environ)
+        env = dict(encoding.environ)
         # Avoid localized output, preserve current locale for everything else.
         lc_all = env.get('LC_ALL')
         if lc_all:
@@ -1398,7 +1399,7 @@ 
         """
         self.ui.debug('%s: git %s\n' % (self._relpath, ' '.join(commands)))
         if env is None:
-            env = os.environ.copy()
+            env = encoding.environ.copy()
         # disable localization for Git output (issue5176)
         env['LC_ALL'] = 'C'
         # fix for Git CVE-2015-7545
@@ -1633,7 +1634,7 @@ 
         if self._gitmissing():
             raise error.Abort(_("subrepo %s is missing") % self._relpath)
         cmd = ['commit', '-a', '-m', text]
-        env = os.environ.copy()
+        env = encoding.environ.copy()
         if user:
             cmd += ['--author', user]
         if date:
diff -r 961ff24b8c2f -r c1a8b0e2a088 mercurial/worker.py
--- a/mercurial/worker.py	Sun Dec 18 01:34:41 2016 +0530
+++ b/mercurial/worker.py	Sun Dec 18 01:46:39 2016 +0530
@@ -14,6 +14,7 @@ 
 
 from .i18n import _
 from . import (
+    encoding,
     error,
     scmutil,
     util,
@@ -32,7 +33,7 @@ 
 
     # windows
     try:
-        n = int(os.environ['NUMBER_OF_PROCESSORS'])
+        n = int(encoding.environ['NUMBER_OF_PROCESSORS'])
         if n > 0:
             return n
     except (KeyError, ValueError):
diff -r 961ff24b8c2f -r c1a8b0e2a088 tests/test-check-config.t
--- a/tests/test-check-config.t	Sun Dec 18 01:34:41 2016 +0530
+++ b/tests/test-check-config.t	Sun Dec 18 01:46:39 2016 +0530
@@ -7,3 +7,6 @@ 
 
   $ hg files "set:(**.py or **.txt) - tests/**" | sed 's|\\|/|g' |
   >   python contrib/check-config.py
+      p = ui.config("pager", "pager", encoding.environ.get("PAGER"))
+  
+  conflict on pager.pager: ('str', 'encoding.environ.get("PAGER"') != ('str', 'os.environ.get("PAGER"')