[PATCH 2 of 3] store: add a contains method to fncachestore

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


# HG changeset patch
# User smuralid
# Date 1347584263 25200
# Node ID 2597f6ccb7a0402a543425f7596a11af9079911c
# Parent  293063ca7f0332f26e5278b341628d83f2ef37f8
store: add a contains method to fncachestore

Adds a __contains__ method to fncachestore to check for file/dir existence (using fncache.__contains__).
Also extends fncache.__contains__ to check for directories (by prefix matching)

diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -368,10 +368,19 @@
             self._dirty = True
             self.entries.add(fn)
 
-    def __contains__(self, fn):
+    def __contains__(self, path):
         if self.entries is None:
             self._load()
-        return fn in self.entries
+        # Check for files (exact match)
+        if path + ".i" in self.entries:
+            return True
+        # Now check for directories (prefix match)
+        if not path.endswith('/'):
+            path += '/'
+        for e in self.entries:
+            if e.startswith(path):
+                return True
+        return False
 
     def __iter__(self):
         if self.entries is None:
@@ -433,6 +442,11 @@
     def write(self):
         self.fncache.write()
 
+    def __contains__(self, path):
+        '''Checks if the store contains path'''
+        path = "/".join(("data", path))
+        return path in self.fncache
+
 def store(requirements, path, openertype):
     if 'store' in requirements:
         if 'fncache' in requirements:


More information about the Mercurial-devel mailing list