Patchwork [7,of,7] fileset: narrow status computation by left-hand-side of 'and' node

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 5, 2018, 2:31 p.m.
Message ID <9694afb6b7a1f3822003.1533479487@mimosa>
Download mbox | patch
Permalink /patch/33279/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 5, 2018, 2:31 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1532256530 -32400
#      Sun Jul 22 19:48:50 2018 +0900
# Node ID 9694afb6b7a1f3822003f6a8055d6cfb8b7892f2
# Parent  e8bfa8f38e3bf8739f6e1bbe8fe742cf0e1fe7f5
fileset: narrow status computation by left-hand-side of 'and' node

Timing with warm disk cache:

  $ hg status --cwd mozilla-central 'set:path:build/ and unknown()' --time
  (orig) time: real 1.970 secs (user 1.560+0.000 sys 0.410+0.000)
  (new)  time: real 0.330 secs (user 0.310+0.000 sys 0.020+0.000)
via Mercurial-devel - Aug. 6, 2018, 6:53 a.m.
On Sun, Aug 5, 2018 at 7:31 AM Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1532256530 -32400
> #      Sun Jul 22 19:48:50 2018 +0900
> # Node ID 9694afb6b7a1f3822003f6a8055d6cfb8b7892f2
> # Parent  e8bfa8f38e3bf8739f6e1bbe8fe742cf0e1fe7f5
> fileset: narrow status computation by left-hand-side of 'and' node
>

Queued, thanks.

Patch

diff --git a/mercurial/fileset.py b/mercurial/fileset.py
--- a/mercurial/fileset.py
+++ b/mercurial/fileset.py
@@ -62,7 +62,7 @@  def patternsmatch(mctx, *xs):
 
 def andmatch(mctx, x, y):
     xm = getmatch(mctx, x)
-    ym = getmatch(mctx, y)
+    ym = getmatch(mctx.narrowed(xm), y)
     return matchmod.intersectmatchers(xm, ym)
 
 def ormatch(mctx, *xs):
@@ -75,7 +75,7 @@  def notmatch(mctx, x):
 
 def minusmatch(mctx, x, y):
     xm = getmatch(mctx, x)
-    ym = getmatch(mctx, y)
+    ym = getmatch(mctx.narrowed(xm), y)
     return matchmod.differencematcher(xm, ym)
 
 def listmatch(mctx, *xs):
@@ -460,19 +460,31 @@  class matchctx(object):
         self._basectx = basectx
         self.ctx = ctx
         self._badfn = badfn
+        self._match = None
         self._status = None
 
+    def narrowed(self, match):
+        """Create matchctx for a sub-tree narrowed by the given matcher"""
+        mctx = matchctx(self._basectx, self.ctx, self._badfn)
+        mctx._match = match
+        # leave wider status which we don't have to care
+        mctx._status = self._status
+        return mctx
+
     def switch(self, basectx, ctx):
-        return matchctx(basectx, ctx, self._badfn)
+        mctx = matchctx(basectx, ctx, self._badfn)
+        mctx._match = self._match
+        return mctx
 
     def withstatus(self, keys):
         """Create matchctx which has precomputed status specified by the keys"""
         mctx = matchctx(self._basectx, self.ctx, self._badfn)
+        mctx._match = self._match
         mctx._buildstatus(keys)
         return mctx
 
     def _buildstatus(self, keys):
-        self._status = self._basectx.status(self.ctx,
+        self._status = self._basectx.status(self.ctx, self._match,
                                             listignored='ignored' in keys,
                                             listclean=True,
                                             listunknown='unknown' in keys)