[Updated] D10998: windows: replicate the normalizing behavior of os.environ

Alphare (Raphaël Gomès) phabricator at mercurial-scm.org
Thu Jul 8 20:20:10 UTC 2021


Closed by commit rHGaf633293a5bd: windows: replicate the normalizing behavior of os.environ (authored by Alphare).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D10998?vs=28999&id=29025

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D10998/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D10998

AFFECTED FILES
  mercurial/encoding.py

CHANGE DETAILS

diff --git a/mercurial/encoding.py b/mercurial/encoding.py
--- a/mercurial/encoding.py
+++ b/mercurial/encoding.py
@@ -338,10 +338,19 @@
 if not _nativeenviron:
     # now encoding and helper functions are available, recreate the environ
     # dict to be exported to other modules
-    environ = {
-        tolocal(k.encode('utf-8')): tolocal(v.encode('utf-8'))
-        for k, v in os.environ.items()  # re-exports
-    }
+    if pycompat.iswindows and pycompat.ispy3:
+
+        class WindowsEnviron(dict):
+            """`os.environ` normalizes environment variables to uppercase on windows"""
+
+            def get(self, key, default=None):
+                return super().get(upper(key), default)
+
+        environ = WindowsEnviron()
+
+    for k, v in os.environ.items():  # re-exports
+        environ[tolocal(k.encode('utf-8'))] = tolocal(v.encode('utf-8'))
+
 
 if pycompat.ispy3:
     # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which



To: Alphare, #hg-reviewers, marmoute
Cc: marmoute, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20210708/c8216dcf/attachment-0002.html>


More information about the Mercurial-patches mailing list