store: add a contains method to basicstore
authorsmuralid
Thu, 13 Sep 2012 17:00:34 -0700
changeset 17744 09d5b2055295
parent 17743 6047947afb6b
child 17745 b9a56b816ff2
store: add a contains method to basicstore Adds a __contains__ method to basicstore that checks if a file/dir is present in the store
mercurial/store.py
--- a/mercurial/store.py	Wed Oct 10 01:37:54 2012 +0200
+++ b/mercurial/store.py	Thu Sep 13 17:00:34 2012 -0700
@@ -341,6 +341,17 @@
     def write(self):
         pass
 
+    def __contains__(self, path):
+        '''Checks if the store contains path'''
+        path = "/".join(("data", path))
+        # file?
+        if os.path.exists(self.join(path + ".i")):
+            return True
+        # dir?
+        if not path.endswith("/"):
+            path = path + "/"
+        return os.path.exists(self.join(path))
+
 class encodedstore(basicstore):
     def __init__(self, path, vfstype):
         vfs = vfstype(path + '/store')