[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 16:35:08 CDT 2012
Thanks, Matt - let me go back and make sure that files are handled (and directories as you mention)
Thanks
Murali
________________________________
From: Matt Mackall <mpm at selenic.com>
To: S Muralidhar <smuralid at yahoo.com>
Cc: mercurial-devel at selenic.com
Sent: Thursday, September 13, 2012 1:20 PM
Subject: Re: [PATCH 2 of 3] store: Add a fncachestore.__contains__ method. Extend fncache.__contains_ to look for direcories
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20120913/4167f072/attachment.html>
More information about the Mercurial-devel
mailing list