mercurial/windows.py
changeset 47622 bb917eea1605
parent 47424 f77404040776
child 47789 064cd182555f
--- a/mercurial/windows.py	Sat Jul 10 13:10:18 2021 +0200
+++ b/mercurial/windows.py	Sat Jul 10 13:46:24 2021 +0200
@@ -333,6 +333,25 @@
     return encoding.upper(path)  # NTFS compares via upper()
 
 
+DRIVE_RE_B = re.compile(b'^[a-z]:')
+DRIVE_RE_S = re.compile('^[a-z]:')
+
+
+def abspath(path):
+    abs_path = os.path.abspath(path)  # re-exports
+    # Python on Windows is inconsistent regarding the capitalization of drive
+    # letter and this cause issue with various path comparison along the way.
+    # So we normalize the drive later to upper case here.
+    #
+    # See https://bugs.python.org/issue40368 for and example of this hell.
+    if isinstance(abs_path, bytes):
+        if DRIVE_RE_B.match(abs_path):
+            abs_path = abs_path[0:1].upper() + abs_path[1:]
+    elif DRIVE_RE_S.match(abs_path):
+        abs_path = abs_path[0:1].upper() + abs_path[1:]
+    return abs_path
+
+
 # see posix.py for definitions
 normcasespec = encoding.normcasespecs.upper
 normcasefallback = encoding.upperfallback