diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
index e607099d8b938bef4fc2581385917a4cf80a803a_bWVyY3VyaWFsL3NjbXV0aWwucHk=..5d8ae9248a70f082b852535dbc62ac926eee1979_bWVyY3VyaWFsL3NjbXV0aWwucHk= 100644
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -803,9 +803,12 @@
 
     if relative:
         cwd = repo.getcwd()
-        pathto = repo.pathto
-        return lambda f: pathto(f, cwd)
-    elif repo.ui.configbool(b'ui', b'slash'):
+        if cwd != b'':
+            # this branch is correct when cwd == b'', ie cwd = repo root,
+            # but it's slower
+            pathto = repo.pathto
+            return lambda f: pathto(f, cwd)
+    if repo.ui.configbool(b'ui', b'slash'):
         return lambda f: f
     else:
         return util.localpath