@@ -11,7 +11,6 @@ from __future__ import absolute_import
import errno
import hashlib
-import os
import shutil
from mercurial.i18n import _
@@ -460,11 +459,11 @@ def updatelfiles(ui, repo, filelist=None
wctx = repo[None]
for lfile in lfiles:
rellfile = lfile
- rellfileorig = os.path.relpath(
+ rellfileorig = util.relpath(
scmutil.origpath(ui, repo, wvfs.join(rellfile)),
start=repo.root)
relstandin = lfutil.standin(lfile)
- relstandinorig = os.path.relpath(
+ relstandinorig = util.relpath(
scmutil.origpath(ui, repo, wvfs.join(relstandin)),
start=repo.root)
if wvfs.exists(relstandin):
@@ -241,7 +241,7 @@ def share(ui, source, dest=None, update=
if relative:
try:
- sharedpath = os.path.relpath(sharedpath, destvfs.base)
+ sharedpath = util.relpath(sharedpath, destvfs.base)
requirements += 'relshared\n'
except IOError as e:
raise error.Abort(_('cannot calculate relative path'),
@@ -2227,7 +2227,7 @@ class localrepository(object):
fp.write(text)
finally:
fp.close()
- return self.pathto(fp.name[len(self.root) + 1:])
+ return self.pathto(util.relpath(fp.name, self.root))
# used to avoid circular references so destructors work
def aftertrans(files):
@@ -185,7 +185,7 @@ def canonpath(root, cwd, myname, auditor
if cwd != root:
canonpath(root, root, myname, auditor)
hint = (_("consider using '--cwd %s'")
- % os.path.relpath(root, cwd))
+ % util.relpath(root, cwd))
except error.Abort:
pass
@@ -679,3 +679,6 @@ def absjoin(absprefix, relpath):
the passed absolute path already contains a terminating directory
separator."""
return absprefix + relpath
+
+relpath = os.path.relpath
+
@@ -559,7 +559,7 @@ def origpath(ui, repo, filepath):
if origbackuppath is None:
return filepath + ".orig"
- filepathfromroot = os.path.relpath(filepath, start=repo.root)
+ filepathfromroot = util.relpath(filepath, start=repo.root)
fullorigpath = repo.wjoin(origbackuppath, filepathfromroot)
origbackupdir = repo.vfs.dirname(fullorigpath)
@@ -151,6 +151,7 @@ umask = platform.umask
unlink = platform.unlink
username = platform.username
absjoin = platform.absjoin
+relpath = platform.relpath
try:
recvfds = osutil.recvfds
@@ -270,6 +270,14 @@ def absjoin(absprefix, relpath):
else:
return converttontpath(absprefix + relpath)
+def relpath(path, start=os.path.curdir):
+ """Relpath which knows how to work with //?/ prefixes"""
+ if not hasntprefix(path) and os.path.isabs(path):
+ path = converttontpath(path)
+ if not hasntprefix(start) and os.path.isabs(start):
+ start = converttontpath(start)
+ return os.path.relpath(path, start)
+
# see posix.py for definitions
normcasespec = encoding.normcasespecs.upper
normcasefallback = encoding.upperfallback