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 |