changeset 17744:09d5b2055295

store: add a contains method to basicstore Adds a __contains__ method to basicstore that checks if a file/dir is present in the store
author smuralid
date Thu, 13 Sep 2012 17:00:34 -0700
parents 6047947afb6b
children b9a56b816ff2
files mercurial/store.py
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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')