mercurial/hg.py
changeset 786 902b12d55751
parent 785 46a8dd3145cc
child 788 64d2a558c943
child 793 445970ccf57a
child 813 80fd2958235a
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -16,8 +16,22 @@ demandload(globals(), "bisect select")
 class filelog(revlog):
     def __init__(self, opener, path):
         revlog.__init__(self, opener,
-                        os.path.join("data", path + ".i"),
-                        os.path.join("data", path + ".d"))
+                        os.path.join("data", self.encodedir(path + ".i")),
+                        os.path.join("data", self.encodedir(path + ".d")))
+
+    # This avoids a collision between a file named foo and a dir named
+    # foo.i or foo.d
+    def encodedir(self, path):
+        path.replace(".hg/", ".hg.hg/")
+        path.replace(".i/", ".i.hg/")
+        path.replace(".d/", ".i.hg/")
+        return path
+
+    def decodedir(self, path):
+        path.replace(".d.hg/", ".d/")
+        path.replace(".i.hg/", ".i/")
+        path.replace(".hg.hg/", ".hg/")
+        return path
 
     def read(self, node):
         t = self.revision(node)