changeset 21879:090dcaaf3fff

manifestdict: add a new method to intersect with a set of files This is meant to be used when the set of files is known in advance, e.g. with a match object with no patterns.
author Siddharth Agarwal <sid0@fb.com>
date Sat, 12 Jul 2014 17:57:25 -0700
parents e2530d4a47c1
children e6754f5e4cf7
files mercurial/manifest.py
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/manifest.py	Sat Jul 12 18:31:18 2014 -0700
+++ b/mercurial/manifest.py	Sat Jul 12 17:57:25 2014 -0700
@@ -25,6 +25,18 @@
         self._flags[f] = flags
     def copy(self):
         return manifestdict(self, dict.copy(self._flags))
+    def intersectfiles(self, files):
+        '''make a new manifestdict with the intersection of self with files
+
+        The algorithm assumes that files is much smaller than self.'''
+        ret = manifestdict()
+        for fn in files:
+            if fn in self:
+                ret[fn] = self[fn]
+                flags = self._flags.get(fn, None)
+                if flags:
+                    ret._flags[fn] = flags
+        return ret
     def flagsdiff(self, d2):
         return dicthelpers.diff(self._flags, d2._flags, "")