Patchwork D9806: windows: wrap `os.getcwd()` in `os.path.realpath()` on py3

login
register
mail settings
Submitter phabricator
Date Jan. 17, 2021, 7:18 a.m.
Message ID <differential-rev-PHID-DREV-jaeltj6hu4hdhwmvcbtz-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48117/
State Superseded
Headers show

Comments

phabricator - Jan. 17, 2021, 7:18 a.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  I noticed various `test-check-*` failures that were printing absolute paths
  when repo relative paths were expected.  This was due to the drive letter in
  `repo.root` being uppercased as it is run through `os.path.realpath()`, and then
  the simple string comparison against the (lowercased) `_cwd` member of dirstate
  in `dirstate.getcwd()` causing an absolute path to be returned, instead of the
  expected `b''`.  That in turn causes `scmutil.getuipathfn()` to wrongly use
  `repo.pathto()` with an absolute cwd path.
  .

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/encoding.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/encoding.py b/mercurial/encoding.py
--- a/mercurial/encoding.py
+++ b/mercurial/encoding.py
@@ -298,7 +298,12 @@ 
     if pycompat.iswindows:
         # Python 3 on Windows issues a DeprecationWarning about using the bytes
         # API when os.getcwdb() is called.
-        getcwd = lambda: strtolocal(os.getcwd())  # re-exports
+        #
+        # Additionally, py3.8+ uppercases the drive letter when calling
+        # 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
     else:
         getcwd = os.getcwdb  # re-exports
 else: