Submitter | Martin von Zweigbergk |
---|---|
Date | Nov. 14, 2014, 5:53 a.m. |
Message ID | <36e990ef2fc4c96fac15.1415944431@martinvonz.mtv.corp.google.com> |
Download | mbox | patch |
Permalink | /patch/6730/ |
State | Accepted |
Headers | show |
Comments
Martin von Zweigbergk writes: > # HG changeset patch > # User Martin von Zweigbergk <martinvonz@google.com> > # Date 1414039110 25200 > # Wed Oct 22 21:38:30 2014 -0700 > # Node ID 36e990ef2fc4c96fac15052f0fbb05d1a96bd616 > # Parent 394c79df66c39923477528b2ea2092b6944b965b > manifest: add matches() method > > Move the code in context._manifestmatches() into a new > manifest.matches(). It's a natural place for the code to live and it > allows other callers to easily use it. It should also make it easier > to optimize the new method in alternative implementations of the > manifest (same reasoning as with manifest.diff()). That makes sense. +1
On 11/14/2014 05:53 AM, Martin von Zweigbergk wrote: > # HG changeset patch > # User Martin von Zweigbergk <martinvonz@google.com> > # Date 1414039110 25200 > # Wed Oct 22 21:38:30 2014 -0700 > # Node ID 36e990ef2fc4c96fac15052f0fbb05d1a96bd616 > # Parent 394c79df66c39923477528b2ea2092b6944b965b > manifest: add matches() method pushed to the clowncopter, thanks
Patch
diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -71,19 +71,7 @@ object oriented way for other contexts to customize the manifest generation. """ - if match.always(): - return self.manifest().copy() - - files = match.files() - if (match.matchfn == match.exact or - (not match.anypats() and util.all(fn in self for fn in files))): - return self.manifest().intersectfiles(files) - - mf = self.manifest().copy() - for fn in mf.keys(): - if not match(fn): - del mf[fn] - return mf + return self.manifest().matches(match) def _matchstatus(self, other, match): """return match.always if match is none diff --git a/mercurial/manifest.py b/mercurial/manifest.py --- a/mercurial/manifest.py +++ b/mercurial/manifest.py @@ -39,6 +39,22 @@ ret._flags[fn] = flags return ret + def matches(self, match): + '''generate a new manifest filtered by the match argument''' + if match.always(): + return self.copy() + + files = match.files() + if (match.matchfn == match.exact or + (not match.anypats() and util.all(fn in self for fn in files))): + return self.intersectfiles(files) + + mf = self.copy() + for fn in mf.keys(): + if not match(fn): + del mf[fn] + return mf + def diff(self, m2): '''Finds changes between the current manifest and m2. The result is returned as a dict with filename as key and values of the form