[Commented On] D11057: compat: enforce upper case drive letter in mercurial too

baymax (Baymax, Your Personal Patch-care Companion) phabricator at mercurial-scm.org
Sat Jul 10 03:45:10 UTC 2021


baymax added a comment.
baymax updated this revision to Diff 29111.


  ✅ refresh by Heptapod after a successful CI run (🐙 💚)

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D11057?vs=29071&id=29111

BRANCH
  default

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

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

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
@@ -9,6 +9,7 @@
 
 import locale
 import os
+import re
 import unicodedata
 
 from .pycompat import getattr
@@ -352,6 +353,8 @@
         environ[tolocal(k.encode('utf-8'))] = tolocal(v.encode('utf-8'))
 
 
+DRIVE_RE = re.compile(b'^[a-z]:')
+
 if pycompat.ispy3:
     # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which
     # returns bytes.
@@ -363,7 +366,18 @@
         # os.path.realpath(), which is used on ``repo.root``.  Since those
         # strings are compared in various places as simple strings, also call
         # realpath here.  See https://bugs.python.org/issue40368
-        getcwd = lambda: strtolocal(os.path.realpath(os.getcwd()))  # re-exports
+        #
+        # However this is not reliable, so lets explicitly make this drive
+        # letter upper case.
+
+        def getcwd():
+            cwd = os.getcwd()  # re-exports
+            cwd = os.path.realpath(cwd)
+            cwd = strtolocal(cwd)
+            if DRIVE_RE.match(cwd):
+                cwd = cwd[0:1].upper() + cwd[1:]
+            return cwd
+
     else:
         getcwd = os.getcwdb  # re-exports
 else:



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


More information about the Mercurial-patches mailing list