Patchwork [2,of,9] fileset: rewrite andset() to not use mctx.narrow()

login
register
mail settings
Submitter Yuya Nishihara
Date July 10, 2018, 3:07 p.m.
Message ID <564f439a0b7b6360d0d2.1531235260@mimosa>
Download mbox | patch
Permalink /patch/32760/
State Accepted
Headers show

Comments

Yuya Nishihara - July 10, 2018, 3:07 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1528535509 -32400
#      Sat Jun 09 18:11:49 2018 +0900
# Node ID 564f439a0b7b6360d0d2858172940706f9f5aecc
# Parent  79b280fd446047cbc75834aafad75b4d2290aa9b
fileset: rewrite andset() to not use mctx.narrow()

New code is less efficient than the original, but it helps porting andset()
to matcher composition. This will be cleaned up later.

This effectively disables the fullmatchctx magic since mctx will never be
demoted to the matchctx. The fullmatchctx class will be removed later.

Patch

diff --git a/mercurial/fileset.py b/mercurial/fileset.py
--- a/mercurial/fileset.py
+++ b/mercurial/fileset.py
@@ -154,7 +154,9 @@  def kindpatset(mctx, x, y):
                                        _("pattern must be a string")))
 
 def andset(mctx, x, y):
-    return getset(mctx.narrow(getset(mctx, x)), y)
+    xl = set(getset(mctx, x))
+    yl = getset(mctx, y)
+    return [f for f in yl if f in xl]
 
 def orset(mctx, x, y):
     # needs optimizing
@@ -627,8 +629,7 @@  class matchctx(object):
             unknown = set()
         return (f for f in self.subset
                 if (f in self.ctx and f not in removed) or f in unknown)
-    def narrow(self, files):
-        return matchctx(self.ctx, self.filter(files), self._status, self._badfn)
+
     def switch(self, ctx, status=None):
         subset = self.filter(_buildsubset(ctx, status))
         return matchctx(ctx, subset, status, self._badfn)