py3: replace os.environ with encoding.environ (part 1 of 5)
authorPulkit Goyal <7895pulkit@gmail.com>
Sun, 18 Dec 2016 01:34:41 +0530
changeset 35266 ad15646dc61c54bd51c73283aeb119522f99171b
parent 35265 fd244e047ec0c62a20744772cac332694a432a9e
child 35267 a150173da1c12a290fa94dee0695e419040c22fe
push id424
push usergszorc@mozilla.com
push dateThu, 22 Dec 2016 17:34:22 +0000
py3: replace os.environ with encoding.environ (part 1 of 5) os.environ is a dictionary which has string elements on Python 3. We have encoding.environ which take care of all these things. This is the first patch of 5 patch series which tend to replace the occurences of os.environ with encoding.environ as using os.environ will result in unusual behaviour.
mercurial/bookmarks.py
mercurial/dirstate.py
mercurial/localrepo.py
mercurial/phases.py
mercurial/posix.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -3,17 +3,16 @@
 # Copyright 2008 David Soria Parra <dsp@php.net>
 #
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
 from __future__ import absolute_import
 
 import errno
-import os
 
 from .i18n import _
 from .node import (
     bin,
     hex,
 )
 from . import (
     encoding,
@@ -26,17 +25,17 @@ from . import (
 def _getbkfile(repo):
     """Hook so that extensions that mess with the store can hook bm storage.
 
     For core, this just handles wether we should see pending
     bookmarks or the committed ones. Other extensions (like share)
     may need to tweak this behavior further.
     """
     bkfile = None
-    if 'HG_PENDING' in os.environ:
+    if 'HG_PENDING' in encoding.environ:
         try:
             bkfile = repo.vfs('bookmarks.pending')
         except IOError as inst:
             if inst.errno != errno.ENOENT:
                 raise
     if bkfile is None:
         bkfile = repo.vfs('bookmarks')
     return bkfile
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -62,17 +62,17 @@ def nonnormalentries(dmap):
 def _trypending(root, vfs, filename):
     '''Open  file to be read according to HG_PENDING environment variable
 
     This opens '.pending' of specified 'filename' only when HG_PENDING
     is equal to 'root'.
 
     This returns '(fp, is_pending_opened)' tuple.
     '''
-    if root == os.environ.get('HG_PENDING'):
+    if root == encoding.environ.get('HG_PENDING'):
         try:
             return (vfs('%s.pending' % filename), True)
         except IOError as inst:
             if inst.errno != errno.ENOENT:
                 raise
     return (vfs(filename), False)
 
 class dirstate(object):
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -494,18 +494,18 @@ class localrepository(object):
             self.ui.warn(
                 _('obsolete feature not enabled but %i markers found!\n')
                 % len(list(store)))
         return store
 
     @storecache('00changelog.i')
     def changelog(self):
         c = changelog.changelog(self.svfs)
-        if 'HG_PENDING' in os.environ:
-            p = os.environ['HG_PENDING']
+        if 'HG_PENDING' in encoding.environ:
+            p = encoding.environ['HG_PENDING']
             if p.startswith(self.root):
                 c.readpending('00changelog.i.a')
         return c
 
     def _constructmanifest(self):
         # This is a temporary function while we migrate from manifest to
         # manifestlog. It allows bundlerepo and unionrepo to intercept the
         # manifest creation.
@@ -1294,17 +1294,17 @@ class localrepository(object):
             ce.refresh()
 
     def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc,
               inheritchecker=None, parentenvvar=None):
         parentlock = None
         # the contents of parentenvvar are used by the underlying lock to
         # determine whether it can be inherited
         if parentenvvar is not None:
-            parentlock = os.environ.get(parentenvvar)
+            parentlock = encoding.environ.get(parentenvvar)
         try:
             l = lockmod.lock(vfs, lockname, 0, releasefn=releasefn,
                              acquirefn=acquirefn, desc=desc,
                              inheritchecker=inheritchecker,
                              parentlock=parentlock)
         except error.LockHeld as inst:
             if not wait:
                 raise
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -98,27 +98,27 @@ Note: old client behave as a publishing 
 - other people see it as public
 - content is pushed as draft
 
 """
 
 from __future__ import absolute_import
 
 import errno
-import os
 
 from .i18n import _
 from .node import (
     bin,
     hex,
     nullid,
     nullrev,
     short,
 )
 from . import (
+    encoding,
     error,
 )
 
 allphases = public, draft, secret = range(3)
 trackedphases = allphases[1:]
 phasenames = ['public', 'draft', 'secret']
 
 def _readroots(repo, phasedefaults=None):
@@ -132,17 +132,17 @@ def _readroots(repo, phasedefaults=None)
     Return (roots, dirty) where dirty is true if roots differ from
     what is being stored.
     """
     repo = repo.unfiltered()
     dirty = False
     roots = [set() for i in allphases]
     try:
         f = None
-        if 'HG_PENDING' in os.environ:
+        if 'HG_PENDING' in encoding.environ:
             try:
                 f = repo.svfs('phaseroots.pending')
             except IOError as inst:
                 if inst.errno != errno.ENOENT:
                     raise
         if f is None:
             f = repo.svfs('phaseroots')
         try:
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -457,17 +457,17 @@ def findexe(command):
         return None
 
     if pycompat.ossep in command:
         return findexisting(command)
 
     if sys.platform == 'plan9':
         return findexisting(os.path.join('/bin', command))
 
-    for path in os.environ.get('PATH', '').split(pycompat.ospathsep):
+    for path in encoding.environ.get('PATH', '').split(pycompat.ospathsep):
         executable = findexisting(os.path.join(path, command))
         if executable is not None:
             return executable
     return None
 
 def setsignalhandler():
     pass