comparison mercurial/scmutil.py @ 17007:21e18c608b68

scmutil: change canonpath to use util.samefile (issue2167) Fixes (on Windows in cmd.exe): $ hg -R v:\x\a status V:\x\a\bar abort: V:\x\a\bar not under root where v:\x\a is a valid repository with a checked-out file "bar" (Note the difference in casing: "v:\" versus "V:\")
author Adrian Buehlmann <adrian@cadifra.com>
date Thu, 14 Jun 2012 11:43:48 +0200
parents 8abee656e14c
children 419966126a05
comparison
equal deleted inserted replaced
17006:6fc7fd72ba3e 17007:21e18c608b68
322 elif name == root: 322 elif name == root:
323 return '' 323 return ''
324 else: 324 else:
325 # Determine whether `name' is in the hierarchy at or beneath `root', 325 # Determine whether `name' is in the hierarchy at or beneath `root',
326 # by iterating name=dirname(name) until that causes no change (can't 326 # by iterating name=dirname(name) until that causes no change (can't
327 # check name == '/', because that doesn't work on windows). For each 327 # check name == '/', because that doesn't work on windows). The list
328 # `name', compare dev/inode numbers. If they match, the list `rel' 328 # `rel' holds the reversed list of components making up the relative
329 # holds the reversed list of components making up the relative file 329 # file name we want.
330 # name we want.
331 root_st = os.stat(root)
332 rel = [] 330 rel = []
333 while True: 331 while True:
334 try: 332 try:
335 name_st = os.stat(name) 333 s = util.samefile(name, root)
336 except OSError: 334 except OSError:
337 name_st = None 335 s = False
338 if name_st and util.samestat(name_st, root_st): 336 if s:
339 if not rel: 337 if not rel:
340 # name was actually the same as root (maybe a symlink) 338 # name was actually the same as root (maybe a symlink)
341 return '' 339 return ''
342 rel.reverse() 340 rel.reverse()
343 name = os.path.join(*rel) 341 name = os.path.join(*rel)