mercurial/pathutil.py
branchstable
changeset 21568 8dd17b19e722
parent 20033 f962870712da
child 23139 e53f6b72a0e4
child 23598 c02a05cc6f5e
--- a/mercurial/pathutil.py	Thu May 08 19:03:00 2014 +0900
+++ b/mercurial/pathutil.py	Thu May 08 19:03:00 2014 +0900
@@ -142,3 +142,25 @@
             name = dirname
 
         raise util.Abort(_("%s not under root '%s'") % (myname, root))
+
+def normasprefix(path):
+    '''normalize the specified path as path prefix
+
+    Returned vaule can be used safely for "p.startswith(prefix)",
+    "p[len(prefix):]", and so on.
+
+    For efficiency, this expects "path" argument to be already
+    normalized by "os.path.normpath", "os.path.realpath", and so on.
+
+    See also issue3033 for detail about need of this function.
+
+    >>> normasprefix('/foo/bar').replace(os.sep, '/')
+    '/foo/bar/'
+    >>> normasprefix('/').replace(os.sep, '/')
+    '/'
+    '''
+    d, p = os.path.splitdrive(path)
+    if len(p) != len(os.sep):
+        return path + os.sep
+    else:
+        return path