changeset 40083:4fd0fac48922

localrepo: allow narrowmatch() to accept matcher to intersect with It's pretty common that we need to intersect a matcher we already have (usually from the user) with the narrow matcher. Let's make repo.narrowmatch() take an optional matcher to intersect with. Differential Revision: https://phab.mercurial-scm.org/D4896
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 28 Sep 2018 12:29:21 -0700
parents a4d62ff9a86d
children 48a0ce67d67a
files mercurial/changegroup.py mercurial/commands.py mercurial/localrepo.py
diffstat 3 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/changegroup.py	Fri Oct 05 01:55:51 2018 +0300
+++ b/mercurial/changegroup.py	Fri Sep 28 12:29:21 2018 -0700
@@ -1271,8 +1271,7 @@
 
     # Requested files could include files not in the local store. So
     # filter those out.
-    filematcher = matchmod.intersectmatchers(repo.narrowmatch(),
-                                             filematcher)
+    filematcher = repo.narrowmatch(filematcher)
 
     fn = _packermap[version][0]
     return fn(repo, filematcher, bundlecaps, ellipses=ellipses,
--- a/mercurial/commands.py	Fri Oct 05 01:55:51 2018 +0300
+++ b/mercurial/commands.py	Fri Sep 28 12:29:21 2018 -0700
@@ -44,7 +44,6 @@
     help,
     hg,
     logcmdutil,
-    match as matchmod,
     merge as mergemod,
     narrowspec,
     obsolete,
@@ -1970,7 +1969,7 @@
 
     diffopts = patch.diffallopts(ui, opts)
     m = scmutil.match(ctx2, pats, opts)
-    m = matchmod.intersectmatchers(m, repo.narrowmatch())
+    m = repo.narrowmatch(m)
     ui.pager('diff')
     logcmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat,
                               listsubrepos=opts.get('subrepos'),
--- a/mercurial/localrepo.py	Fri Oct 05 01:55:51 2018 +0300
+++ b/mercurial/localrepo.py	Fri Sep 28 12:29:21 2018 -0700
@@ -1200,8 +1200,14 @@
         include, exclude = self.narrowpats
         return narrowspec.match(self.root, include=include, exclude=exclude)
 
-    # TODO(martinvonz): make this property-like instead?
-    def narrowmatch(self):
+    def narrowmatch(self, match=None):
+        """matcher corresponding the the repo's narrowspec
+
+        If `match` is given, then that will be intersected with the narrow
+        matcher.
+        """
+        if match:
+            return matchmod.intersectmatchers(match, self._narrowmatch)
         return self._narrowmatch
 
     def setnarrowpats(self, newincludes, newexcludes):