##// END OF EJS Templates
posix: fix split() for the case where the path is at the root of the filesystem...
Remy Blank -
r18288:0d5a22f7 default
parent child Browse files
Show More
@@ -21,14 +21,26 b' umask = os.umask(0)'
21 os.umask(umask)
21 os.umask(umask)
22
22
23 def split(p):
23 def split(p):
24 '''Same as os.path.split, but faster'''
24 '''Same as posixpath.split, but faster
25
26 >>> import posixpath
27 >>> for f in ['/absolute/path/to/file',
28 ... 'relative/path/to/file',
29 ... 'file_alone',
30 ... 'path/to/directory/',
31 ... '/multiple/path//separators',
32 ... '/file_at_root',
33 ... '///multiple_leading_separators_at_root',
34 ... '']:
35 ... assert split(f) == posixpath.split(f), f
36 '''
25 ht = p.rsplit('/', 1)
37 ht = p.rsplit('/', 1)
26 if len(ht) == 1:
38 if len(ht) == 1:
27 return '', p
39 return '', p
28 nh = ht[0].rstrip('/')
40 nh = ht[0].rstrip('/')
29 if nh:
41 if nh:
30 return nh, ht[1]
42 return nh, ht[1]
31 return ht
43 return ht[0] + '/', ht[1]
32
44
33 def openhardlinks():
45 def openhardlinks():
34 '''return true if it is safe to hold open file handles to hardlinks'''
46 '''return true if it is safe to hold open file handles to hardlinks'''
@@ -6,6 +6,8 b' import doctest'
6
6
7 import mercurial.util
7 import mercurial.util
8 doctest.testmod(mercurial.util)
8 doctest.testmod(mercurial.util)
9 # Only run doctests for the current platform
10 doctest.testmod(mercurial.util.platform)
9
11
10 import mercurial.changelog
12 import mercurial.changelog
11 doctest.testmod(mercurial.changelog)
13 doctest.testmod(mercurial.changelog)
General Comments 0
You need to be logged in to leave comments. Login now