Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
38793:6c8e3c847977 | 38794:1d01cf0416a5 |
---|---|
11 from mercurial import ( | 11 from mercurial import ( |
12 changegroup, | 12 changegroup, |
13 error, | 13 error, |
14 extensions, | 14 extensions, |
15 manifest, | 15 manifest, |
16 match as matchmod, | |
17 mdiff, | 16 mdiff, |
18 node, | 17 node, |
19 pycompat, | 18 pycompat, |
20 revlog, | 19 revlog, |
21 util, | 20 util, |
22 ) | 21 ) |
23 | 22 |
24 def setup(): | 23 def setup(): |
25 | |
26 def _cgmatcher(cgpacker): | |
27 localmatcher = cgpacker._repo.narrowmatch() | |
28 remotematcher = getattr(cgpacker, '_narrow_matcher', lambda: None)() | |
29 if remotematcher: | |
30 return matchmod.intersectmatchers(localmatcher, remotematcher) | |
31 else: | |
32 return localmatcher | |
33 | |
34 def prune(orig, self, revlog, missing, commonrevs): | 24 def prune(orig, self, revlog, missing, commonrevs): |
35 if isinstance(revlog, manifest.manifestrevlog): | 25 if isinstance(revlog, manifest.manifestrevlog): |
36 matcher = _cgmatcher(self) | 26 if not self._filematcher.visitdir(revlog._dir[:-1] or '.'): |
37 if (matcher and | |
38 not matcher.visitdir(revlog._dir[:-1] or '.')): | |
39 return [] | 27 return [] |
28 | |
40 return orig(self, revlog, missing, commonrevs) | 29 return orig(self, revlog, missing, commonrevs) |
41 | 30 |
42 extensions.wrapfunction(changegroup.cg1packer, 'prune', prune) | 31 extensions.wrapfunction(changegroup.cg1packer, 'prune', prune) |
43 | 32 |
44 def generatefiles(orig, self, changedfiles, linknodes, commonrevs, | 33 def generatefiles(orig, self, changedfiles, linknodes, commonrevs, |
45 source): | 34 source): |
46 matcher = _cgmatcher(self) | 35 changedfiles = list(filter(self._filematcher, changedfiles)) |
47 if matcher: | 36 |
48 changedfiles = list(filter(matcher, changedfiles)) | |
49 if getattr(self, 'is_shallow', False): | 37 if getattr(self, 'is_shallow', False): |
50 # See comment in generate() for why this sadness is a thing. | 38 # See comment in generate() for why this sadness is a thing. |
51 mfdicts = self._mfdicts | 39 mfdicts = self._mfdicts |
52 del self._mfdicts | 40 del self._mfdicts |
53 # In a shallow clone, the linknodes callback needs to also include | 41 # In a shallow clone, the linknodes callback needs to also include |