diff --git a/hgext/pager.py b/hgext/pager.py --- a/hgext/pager.py +++ b/hgext/pager.py @@ -71,6 +71,7 @@ from mercurial import ( cmdutil, commands, dispatch, + encoding, extensions, util, ) @@ -123,7 +124,7 @@ def uisetup(ui): return def pagecmd(orig, ui, options, cmd, cmdfunc): - 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' diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py --- a/hgext/patchbomb.py +++ b/hgext/patchbomb.py @@ -75,6 +75,7 @@ from mercurial.i18n import _ from mercurial import ( cmdutil, commands, + encoding, error, hg, mail, @@ -693,8 +694,8 @@ def email(ui, repo, *revs, **opts): if opts.get('test'): ui.status(_('displaying '), subj, ' ...\n') ui.flush() - if 'PAGER' in os.environ and not ui.plain(): - fp = util.popen(os.environ['PAGER'], 'w') + if 'PAGER' in encoding.environ and not ui.plain(): + fp = util.popen(encoding.environ['PAGER'], 'w') else: fp = ui generator = emailmod.Generator.Generator(fp, mangle_from_=False) diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py --- a/mercurial/chgserver.py +++ b/mercurial/chgserver.py @@ -55,6 +55,7 @@ from .i18n import _ from . import ( cmdutil, commandserver, + encoding, error, extensions, osutil, @@ -102,7 +103,8 @@ def _confighash(ui): 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 @@ def _setuppagercmd(ui, options, cmd): 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 @@ def _newchgui(srcui, csystem): 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() @@ -512,8 +514,8 @@ class chgcmdserver(commandserver.server) 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, @@ -628,8 +630,8 @@ class chgunixservicehandler(object): 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 --git a/mercurial/sshserver.py b/mercurial/sshserver.py --- a/mercurial/sshserver.py +++ b/mercurial/sshserver.py @@ -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 @@ class sshserver(wireproto.abstractserver 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 --git a/mercurial/subrepo.py b/mercurial/subrepo.py --- a/mercurial/subrepo.py +++ b/mercurial/subrepo.py @@ -24,6 +24,7 @@ from .i18n import _ from . import ( cmdutil, config, + encoding, error, exchange, filemerge, @@ -1102,7 +1103,7 @@ class svnsubrepo(abstractsubrepo): 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 @@ class gitsubrepo(abstractsubrepo): """ 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 @@ class gitsubrepo(abstractsubrepo): 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 --git a/mercurial/worker.py b/mercurial/worker.py --- a/mercurial/worker.py +++ b/mercurial/worker.py @@ -14,6 +14,7 @@ import sys from .i18n import _ from . import ( + encoding, error, scmutil, util, @@ -32,7 +33,7 @@ def countcpus(): # windows try: - n = int(os.environ['NUMBER_OF_PROCESSORS']) + n = int(encoding.environ['NUMBER_OF_PROCESSORS']) if n > 0: return n except (KeyError, ValueError):