comparison mercurial/util.py @ 886:509de8ab6f31

Fix walk path handling on Windows
author Bryan O'Sullivan <bos@serpentine.com>
date Fri, 12 Aug 2005 15:06:52 -0800
parents 087771ebe2e6
children 882756761433 e7a943e8c52b
comparison
equal deleted inserted replaced
884:087771ebe2e6 886:509de8ab6f31
68 return head + res + tail 68 return head + res + tail
69 69
70 _globchars = {'[': 1, '{': 1, '*': 1, '?': 1} 70 _globchars = {'[': 1, '{': 1, '*': 1, '?': 1}
71 71
72 def pathto(n1, n2): 72 def pathto(n1, n2):
73 '''return the relative path from one place to another''' 73 '''return the relative path from one place to another.
74 if not n1: return n2 74 this returns a path in the form used by the local filesystem, not hg.'''
75 a, b = n1.split(os.sep), n2.split(os.sep) 75 if not n1: return localpath(n2)
76 a, b = n1.split('/'), n2.split('/')
76 a.reverse(), b.reverse() 77 a.reverse(), b.reverse()
77 while a and b and a[-1] == b[-1]: 78 while a and b and a[-1] == b[-1]:
78 a.pop(), b.pop() 79 a.pop(), b.pop()
79 b.reverse() 80 b.reverse()
80 return os.sep.join((['..'] * len(a)) + b) 81 return os.sep.join((['..'] * len(a)) + b)
84 name = myname 85 name = myname
85 if not name.startswith(os.sep): 86 if not name.startswith(os.sep):
86 name = os.path.join(repo.root, cwd, name) 87 name = os.path.join(repo.root, cwd, name)
87 name = os.path.normpath(name) 88 name = os.path.normpath(name)
88 if name.startswith(rootsep): 89 if name.startswith(rootsep):
89 return name[len(rootsep):] 90 return pconvert(name[len(rootsep):])
90 elif name == repo.root: 91 elif name == repo.root:
91 return '' 92 return ''
92 else: 93 else:
93 raise Abort('%s not under repository root' % myname) 94 raise Abort('%s not under repository root' % myname)
94 95
119 '''return the non-glob prefix of a path, e.g. foo/* -> foo''' 120 '''return the non-glob prefix of a path, e.g. foo/* -> foo'''
120 root = [] 121 root = []
121 for p in pat.split(os.sep): 122 for p in pat.split(os.sep):
122 if patkind(p)[0] == 'glob': break 123 if patkind(p)[0] == 'glob': break
123 root.append(p) 124 root.append(p)
124 return os.sep.join(root) 125 return '/'.join(root)
125 126
126 pats = [] 127 pats = []
127 files = [] 128 files = []
128 roots = [] 129 roots = []
129 for kind, name in map(patkind, names): 130 for kind, name in map(patkind, names):
202 pass 203 pass
203 204
204 def pconvert(path): 205 def pconvert(path):
205 return path.replace("\\", "/") 206 return path.replace("\\", "/")
206 207
208 def localpath(path):
209 return path.replace('/', '\\')
210
211 def normpath(path):
212 return pconvert(os.path.normpath(path))
213
207 makelock = _makelock_file 214 makelock = _makelock_file
208 readlock = _readlock_file 215 readlock = _readlock_file
209 216
210 def explain_exit(code): 217 def explain_exit(code):
211 return "exited with status %d" % code, code 218 return "exited with status %d" % code, code
230 os.chmod(f, s & 0666) 237 os.chmod(f, s & 0666)
231 238
232 def pconvert(path): 239 def pconvert(path):
233 return path 240 return path
234 241
242 def localpath(path):
243 return path
244
245 normpath = os.path.normpath
246
235 def makelock(info, pathname): 247 def makelock(info, pathname):
236 try: 248 try:
237 os.symlink(info, pathname) 249 os.symlink(info, pathname)
238 except OSError, why: 250 except OSError, why:
239 if why.errno == errno.EEXIST: 251 if why.errno == errno.EEXIST: