[PATCH 1 of 3] store: add a contains method to basicstore

S Muralidhar smuralid at yahoo.com
Fri Sep 14 02:01:23 CDT 2012


# HG changeset patch
# User smuralid
# Date 1347580834 25200
# Node ID 293063ca7f0332f26e5278b341628d83f2ef37f8
# Parent  fc1a5d0eb3bbb1116051b65dcd2873389f9d7ed4
store: add a contains method to basicstore

Adds a __contains__ method to basicstore that checks if a file/dir is present in the store

diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -286,6 +286,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, openertype):
         self.path = path + '/store'


More information about the Mercurial-devel mailing list