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

Matt Mackall mpm at selenic.com
Thu Sep 13 15:20:44 CDT 2012


On Thu, 2012-09-13 at 10:41 -0700, S Muralidhar wrote:
> # 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

This doesn't work on files at all, because they don't arrive with a
'.i'. Nor does it work on directories without slashes (which is a bad
API). Also, the argument name suggests it only works on files. I tested
it with something like this:

diff -r 17f1ef5cfaa5 mercurial/store.py
--- a/mercurial/store.py	Wed Sep 12 21:30:51 2012 -0700
+++ b/mercurial/store.py	Thu Sep 13 15:18:16 2012 -0500
@@ -361,17 +361,18 @@
             self._dirty = True
             self.entries.add(fn)
 
-    def __contains__(self, fn):
+    def __contains__(self, path):
         if self.entries is None:
             self._load()
         # Check for files (exact match)
-        if fn in self.entries:
+        if path + ".i" 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
+        if not path.endswith('/'):
+            path += '/'
+        for e in self.entries:
+            if e.startswith(path):
+                return True
         return False
 
     def __iter__(self):

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list