Add util.splitpath() and use it instead of using os.sep directly.
authorShun-ichi GOTO <shunichi.goto@gmail.com>
Wed, 09 Jan 2008 21:30:36 +0900
changeset 5844 07d8eb78dd68
parent 5843 83c354c4d529
child 5845 5924a11aa419
Add util.splitpath() and use it instead of using os.sep directly. This change is intended to allow hooking splitpath() by win32mbcs extension for MBCS support.
mercurial/util.py
--- a/mercurial/util.py	Wed Jan 09 21:30:35 2008 +0900
+++ b/mercurial/util.py	Wed Jan 09 21:30:36 2008 +0900
@@ -328,7 +328,7 @@
         if os.path.splitdrive(root)[0] != os.path.splitdrive(n1)[0]:
             return os.path.join(root, localpath(n2))
         n2 = '/'.join((pconvert(root), n2))
-    a, b = n1.split(os.sep), n2.split('/')
+    a, b = splitpath(n1), n2.split('/')
     a.reverse()
     b.reverse()
     while a and b and a[-1] == b[-1]:
@@ -692,7 +692,7 @@
         if path in self.audited:
             return
         normpath = os.path.normcase(path)
-        parts = normpath.split(os.sep)
+        parts = splitpath(normpath)
         if (os.path.splitdrive(path)[0] or parts[0] in ('.hg', '')
             or os.pardir in parts):
             raise Abort(_("path contains illegal component: %s") % path)
@@ -886,6 +886,14 @@
     '''Check path ends with os.sep or os.altsep.'''
     return path.endswith(os.sep) or os.altsep and path.endswith(os.altsep)
 
+def splitpath(path):
+    '''Split path by os.sep.
+    Note that this function does not use os.altsep because this is
+    an alternative of simple "xxx.split(os.sep)".
+    It is recommended to use os.path.normpath() before using this
+    function if need.'''
+    return path.split(os.sep)
+
 # Platform specific variants
 if os.name == 'nt':
     import msvcrt
@@ -983,7 +991,7 @@
         msvcrt.setmode(fd.fileno(), os.O_BINARY)
 
     def pconvert(path):
-        return path.replace("\\", "/")
+        return '/'.join(splitpath(path))
 
     def localpath(path):
         return path.replace('/', '\\')