diff hgext/narrow/narrowchangegroup.py @ 38794:1d01cf0416a5

changegroup: move file matcher from narrow extension Sparse changegroup generation requires the use of a matcher to filter which files are relevant. This commit moves the file matcher from the narrow extension to core and updates the narrow extension to use it. I'm not sure why the narrow extension was storing the matcher as a callable that resolved to a matcher. So I changed it to be a simple matcher instance. In addition, code from narrow to intersect the matcher with the local narrow spec is now performed automatically when the changegroup packer is created. If a matcher is not passed into getbundler() an alwaysmatcher() is assumed. This ensures that a matcher is always defined for all operations. Differential Revision: https://phab.mercurial-scm.org/D4011
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 28 Jul 2018 11:40:31 -0700
parents e7aa113b14f7
children 5742d0428ed9
line wrap: on
line diff
--- a/hgext/narrow/narrowchangegroup.py	Thu Jul 26 17:11:03 2018 -0700
+++ b/hgext/narrow/narrowchangegroup.py	Sat Jul 28 11:40:31 2018 -0700
@@ -13,7 +13,6 @@
     error,
     extensions,
     manifest,
-    match as matchmod,
     mdiff,
     node,
     pycompat,
@@ -22,30 +21,19 @@
 )
 
 def setup():
-
-    def _cgmatcher(cgpacker):
-        localmatcher = cgpacker._repo.narrowmatch()
-        remotematcher = getattr(cgpacker, '_narrow_matcher', lambda: None)()
-        if remotematcher:
-            return matchmod.intersectmatchers(localmatcher, remotematcher)
-        else:
-            return localmatcher
-
     def prune(orig, self, revlog, missing, commonrevs):
         if isinstance(revlog, manifest.manifestrevlog):
-            matcher = _cgmatcher(self)
-            if (matcher and
-                not matcher.visitdir(revlog._dir[:-1] or '.')):
+            if not self._filematcher.visitdir(revlog._dir[:-1] or '.'):
                 return []
+
         return orig(self, revlog, missing, commonrevs)
 
     extensions.wrapfunction(changegroup.cg1packer, 'prune', prune)
 
     def generatefiles(orig, self, changedfiles, linknodes, commonrevs,
                       source):
-        matcher = _cgmatcher(self)
-        if matcher:
-            changedfiles = list(filter(matcher, changedfiles))
+        changedfiles = list(filter(self._filematcher, changedfiles))
+
         if getattr(self, 'is_shallow', False):
             # See comment in generate() for why this sadness is a thing.
             mfdicts = self._mfdicts