##// END OF EJS Templates
changegroup: move file matcher from narrow extension...
Gregory Szorc -
r38830:1d01cf04 default
parent child Browse files
Show More
@@ -60,10 +60,8 b' def _packellipsischangegroup(repo, commo'
60 60 # set, we know we have an ellipsis node and we should defer
61 61 # sending that node's data. We override close() to detect
62 62 # pending ellipsis nodes and flush them.
63 packer = changegroup.getbundler(version, repo)
64 # Let the packer have access to the narrow matcher so it can
65 # omit filelogs and dirlogs as needed
66 packer._narrow_matcher = lambda : match
63 packer = changegroup.getbundler(version, repo,
64 filematcher=match)
67 65 # Give the packer the list of nodes which should not be
68 66 # ellipsis nodes. We store this rather than the set of nodes
69 67 # that should be an ellipsis because for very large histories
@@ -107,13 +105,9 b' def getbundlechangegrouppart_narrow(bund'
107 105 outgoing = exchange._computeoutgoing(repo, heads, common)
108 106 if not outgoing.missing:
109 107 return
110 def wrappedgetbundler(orig, *args, **kwargs):
111 bundler = orig(*args, **kwargs)
112 bundler._narrow_matcher = lambda : newmatch
113 return bundler
114 with extensions.wrappedfunction(changegroup, 'getbundler',
115 wrappedgetbundler):
116 cg = changegroup.makestream(repo, outgoing, version, source)
108
109 cg = changegroup.makestream(repo, outgoing, version, source,
110 filematcher=newmatch)
117 111 part = bundler.newpart('changegroup', data=cg)
118 112 part.addparam('version', version)
119 113 if 'treemanifest' in repo.requirements:
@@ -13,7 +13,6 b' from mercurial import ('
13 13 error,
14 14 extensions,
15 15 manifest,
16 match as matchmod,
17 16 mdiff,
18 17 node,
19 18 pycompat,
@@ -22,30 +21,19 b' from mercurial import ('
22 21 )
23 22
24 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 24 def prune(orig, self, revlog, missing, commonrevs):
35 25 if isinstance(revlog, manifest.manifestrevlog):
36 matcher = _cgmatcher(self)
37 if (matcher and
38 not matcher.visitdir(revlog._dir[:-1] or '.')):
26 if not self._filematcher.visitdir(revlog._dir[:-1] or '.'):
39 27 return []
28
40 29 return orig(self, revlog, missing, commonrevs)
41 30
42 31 extensions.wrapfunction(changegroup.cg1packer, 'prune', prune)
43 32
44 33 def generatefiles(orig, self, changedfiles, linknodes, commonrevs,
45 34 source):
46 matcher = _cgmatcher(self)
47 if matcher:
48 changedfiles = list(filter(matcher, changedfiles))
35 changedfiles = list(filter(self._filematcher, changedfiles))
36
49 37 if getattr(self, 'is_shallow', False):
50 38 # See comment in generate() for why this sadness is a thing.
51 39 mfdicts = self._mfdicts
@@ -21,6 +21,7 b' from .node import ('
21 21 from . import (
22 22 dagutil,
23 23 error,
24 match as matchmod,
24 25 mdiff,
25 26 phases,
26 27 pycompat,
@@ -496,14 +497,20 b' class headerlessfixup(object):'
496 497 class cg1packer(object):
497 498 deltaheader = _CHANGEGROUPV1_DELTA_HEADER
498 499 version = '01'
499 def __init__(self, repo, bundlecaps=None):
500 def __init__(self, repo, filematcher, bundlecaps=None):
500 501 """Given a source repo, construct a bundler.
501 502
503 filematcher is a matcher that matches on files to include in the
504 changegroup. Used to facilitate sparse changegroups.
505
502 506 bundlecaps is optional and can be used to specify the set of
503 507 capabilities which can be used to build the bundle. While bundlecaps is
504 508 unused in core Mercurial, extensions rely on this feature to communicate
505 509 capabilities to customize the changegroup packer.
506 510 """
511 assert filematcher
512 self._filematcher = filematcher
513
507 514 # Set of capabilities we can use to build the bundle.
508 515 if bundlecaps is None:
509 516 bundlecaps = set()
@@ -813,8 +820,10 b' class cg2packer(cg1packer):'
813 820 version = '02'
814 821 deltaheader = _CHANGEGROUPV2_DELTA_HEADER
815 822
816 def __init__(self, repo, bundlecaps=None):
817 super(cg2packer, self).__init__(repo, bundlecaps)
823 def __init__(self, repo, filematcher, bundlecaps=None):
824 super(cg2packer, self).__init__(repo, filematcher,
825 bundlecaps=bundlecaps)
826
818 827 if self._reorder is None:
819 828 # Since generaldelta is directly supported by cg2, reordering
820 829 # generally doesn't help, so we disable it by default (treating
@@ -927,9 +936,23 b' def safeversion(repo):'
927 936 assert versions
928 937 return min(versions)
929 938
930 def getbundler(version, repo, bundlecaps=None):
939 def getbundler(version, repo, bundlecaps=None, filematcher=None):
931 940 assert version in supportedoutgoingversions(repo)
932 return _packermap[version][0](repo, bundlecaps)
941
942 if filematcher is None:
943 filematcher = matchmod.alwaysmatcher(repo.root, '')
944
945 if version == '01' and not filematcher.always():
946 raise error.ProgrammingError('version 01 changegroups do not support '
947 'sparse file matchers')
948
949 # Requested files could include files not in the local store. So
950 # filter those out.
951 filematcher = matchmod.intersectmatchers(repo.narrowmatch(),
952 filematcher)
953
954 return _packermap[version][0](repo, filematcher=filematcher,
955 bundlecaps=bundlecaps)
933 956
934 957 def getunbundler(version, fh, alg, extras=None):
935 958 return _packermap[version][1](fh, alg, extras=extras)
@@ -950,8 +973,9 b' def makechangegroup(repo, outgoing, vers'
950 973 {'clcount': len(outgoing.missing) })
951 974
952 975 def makestream(repo, outgoing, version, source, fastpath=False,
953 bundlecaps=None):
954 bundler = getbundler(version, repo, bundlecaps=bundlecaps)
976 bundlecaps=None, filematcher=None):
977 bundler = getbundler(version, repo, bundlecaps=bundlecaps,
978 filematcher=filematcher)
955 979
956 980 repo = repo.unfiltered()
957 981 commonrevs = outgoing.common
General Comments 0
You need to be logged in to leave comments. Login now