equal
deleted
inserted
replaced
7 |
7 |
8 from __future__ import absolute_import, print_function |
8 from __future__ import absolute_import, print_function |
9 |
9 |
10 import locale |
10 import locale |
11 import os |
11 import os |
|
12 import re |
12 import unicodedata |
13 import unicodedata |
13 |
14 |
14 from .pycompat import getattr |
15 from .pycompat import getattr |
15 from . import ( |
16 from . import ( |
16 error, |
17 error, |
350 |
351 |
351 for k, v in os.environ.items(): # re-exports |
352 for k, v in os.environ.items(): # re-exports |
352 environ[tolocal(k.encode('utf-8'))] = tolocal(v.encode('utf-8')) |
353 environ[tolocal(k.encode('utf-8'))] = tolocal(v.encode('utf-8')) |
353 |
354 |
354 |
355 |
|
356 DRIVE_RE = re.compile(b'^[a-z]:') |
|
357 |
355 if pycompat.ispy3: |
358 if pycompat.ispy3: |
356 # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which |
359 # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which |
357 # returns bytes. |
360 # returns bytes. |
358 if pycompat.iswindows: |
361 if pycompat.iswindows: |
359 # Python 3 on Windows issues a DeprecationWarning about using the bytes |
362 # Python 3 on Windows issues a DeprecationWarning about using the bytes |
361 # |
364 # |
362 # Additionally, py3.8+ uppercases the drive letter when calling |
365 # Additionally, py3.8+ uppercases the drive letter when calling |
363 # os.path.realpath(), which is used on ``repo.root``. Since those |
366 # os.path.realpath(), which is used on ``repo.root``. Since those |
364 # strings are compared in various places as simple strings, also call |
367 # strings are compared in various places as simple strings, also call |
365 # realpath here. See https://bugs.python.org/issue40368 |
368 # realpath here. See https://bugs.python.org/issue40368 |
366 getcwd = lambda: strtolocal(os.path.realpath(os.getcwd())) # re-exports |
369 # |
|
370 # However this is not reliable, so lets explicitly make this drive |
|
371 # letter upper case. |
|
372 # |
|
373 # note: we should consider dropping realpath here since it seems to |
|
374 # change the semantic of `getcwd`. |
|
375 |
|
376 def getcwd(): |
|
377 cwd = os.getcwd() # re-exports |
|
378 cwd = os.path.realpath(cwd) |
|
379 cwd = strtolocal(cwd) |
|
380 if DRIVE_RE.match(cwd): |
|
381 cwd = cwd[0:1].upper() + cwd[1:] |
|
382 return cwd |
|
383 |
367 else: |
384 else: |
368 getcwd = os.getcwdb # re-exports |
385 getcwd = os.getcwdb # re-exports |
369 else: |
386 else: |
370 getcwd = os.getcwd # re-exports |
387 getcwd = os.getcwd # re-exports |
371 |
388 |