diff mercurial/manifest.py @ 23305:0cc283f44655

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()).
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 22 Oct 2014 21:38:30 -0700
parents ff93aa006e6a
children a4679a74df14
line wrap: on
line diff
--- a/mercurial/manifest.py	Wed Nov 12 22:20:36 2014 -0800
+++ b/mercurial/manifest.py	Wed Oct 22 21:38:30 2014 -0700
@@ -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