[PATCH 2 of 3] store: Add a fncachestore.__contains__ method. Extend fncache.__contains_ to look for direcories

S Muralidhar smuralid at yahoo.com
Thu Sep 13 12:41:27 CDT 2012


# HG changeset patch
# User smuralid
# Date 1347510651 25200
# Node ID 53e10b4a0769c55d7f475a2669d8fa9294352aae
# Parent  d6d5af14c18dcc7f483d1fc069660255d16d034a
store: Add a fncachestore.__contains__ method. Extend fncache.__contains_ to look for direcories

diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -364,7 +364,15 @@
     def __contains__(self, fn):
         if self.entries is None:
             self._load()
-        return fn in self.entries
+        # Check for files (exact match)
+        if fn in self.entries:
+            return True
+        # Now check for directories (prefix match)
+        if fn.endswith('/'):
+            for e in self.entries:
+                if e.startswith(fn):
+                    return True
+        return False
 
     def __iter__(self):
         if self.entries is None:
@@ -426,6 +434,11 @@
     def write(self):
         self.fncache.write()
 
+    def __contains__(self, path):
+        '''Checks if this path exists in the store'''
+        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