comparison mercurial/util.py @ 12077:ff6f5310ad92

util: add optional path auditor argument to canonpath The canonpath function will default to creating its own path auditor, but in some cases it will be useful to use a specialized auditor, e.g., one that wont abort if a path lies within a subrepository.
author Martin Geisler <mg@lazybytes.net>
date Sun, 29 Aug 2010 23:56:19 +0200
parents 49463314c24f
children e03ca36ba9f3
comparison
equal deleted inserted replaced
12076:49463314c24f 12077:ff6f5310ad92
290 a.pop() 290 a.pop()
291 b.pop() 291 b.pop()
292 b.reverse() 292 b.reverse()
293 return os.sep.join((['..'] * len(a)) + b) or '.' 293 return os.sep.join((['..'] * len(a)) + b) or '.'
294 294
295 def canonpath(root, cwd, myname): 295 def canonpath(root, cwd, myname, audit_path=None):
296 """return the canonical path of myname, given cwd and root""" 296 """return the canonical path of myname, given cwd and root"""
297 if endswithsep(root): 297 if endswithsep(root):
298 rootsep = root 298 rootsep = root
299 else: 299 else:
300 rootsep = root + os.sep 300 rootsep = root + os.sep
301 name = myname 301 name = myname
302 if not os.path.isabs(name): 302 if not os.path.isabs(name):
303 name = os.path.join(root, cwd, name) 303 name = os.path.join(root, cwd, name)
304 name = os.path.normpath(name) 304 name = os.path.normpath(name)
305 audit_path = path_auditor(root) 305 if audit_path is None:
306 audit_path = path_auditor(root)
306 if name != rootsep and name.startswith(rootsep): 307 if name != rootsep and name.startswith(rootsep):
307 name = name[len(rootsep):] 308 name = name[len(rootsep):]
308 audit_path(name) 309 audit_path(name)
309 return pconvert(name) 310 return pconvert(name)
310 elif name == root: 311 elif name == root: