Mercurial > public > mercurial-scm > hg
comparison mercurial/encoding.py @ 46319:3dfebba99ef6
windows: wrap `os.getcwd()` in `os.path.realpath()` on py3
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.
.
Differential Revision: https://phab.mercurial-scm.org/D9806
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 09 Dec 2020 00:51:35 -0500 |
parents | 89a2afe31e82 |
children | d4ba4d51f85f |
comparison
equal
deleted
inserted
replaced
46318:e74274fc1b35 | 46319:3dfebba99ef6 |
---|---|
296 # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which | 296 # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which |
297 # returns bytes. | 297 # returns bytes. |
298 if pycompat.iswindows: | 298 if pycompat.iswindows: |
299 # Python 3 on Windows issues a DeprecationWarning about using the bytes | 299 # Python 3 on Windows issues a DeprecationWarning about using the bytes |
300 # API when os.getcwdb() is called. | 300 # API when os.getcwdb() is called. |
301 getcwd = lambda: strtolocal(os.getcwd()) # re-exports | 301 # |
302 # Additionally, py3.8+ uppercases the drive letter when calling | |
303 # os.path.realpath(), which is used on ``repo.root``. Since those | |
304 # strings are compared in various places as simple strings, also call | |
305 # realpath here. See https://bugs.python.org/issue40368 | |
306 getcwd = lambda: strtolocal(os.path.realpath(os.getcwd())) # re-exports | |
302 else: | 307 else: |
303 getcwd = os.getcwdb # re-exports | 308 getcwd = os.getcwdb # re-exports |
304 else: | 309 else: |
305 getcwd = os.getcwd # re-exports | 310 getcwd = os.getcwd # re-exports |
306 | 311 |