Patchwork [2,of,3] manifestdict: add a new method to intersect with a set of files

login
register
mail settings
Submitter Siddharth Agarwal
Date July 13, 2014, 1:41 a.m.
Message ID <9b0e9a5840aadf91fca6.1405215661@dev1738.prn1.facebook.com>
Download mbox | patch
Permalink /patch/5155/
State Accepted
Commit 090dcaaf3fffa126b161c7525354efbf240043e7
Headers show

Comments

Siddharth Agarwal - July 13, 2014, 1:41 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1405213045 25200
#      Sat Jul 12 17:57:25 2014 -0700
# Node ID 9b0e9a5840aadf91fca63dd6d8cd8e45dd429a06
# Parent  6ba1d8cf21e5dfc86c05b9eb856d99831eeb720b
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.

Patch

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -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, "")