comparison hgext/narrow/narrowbundle2.py @ 38808:d99083996398

exchange: move simple narrow changegroup generation from extension The narrow extension completely replaced the function generating the changegroup part when a narrow changegroup was requested. Previous commits have taught the in-core changegroup code how to filter files based on a matcher. This commit teaches the in-core bundle2 part generation code to construct a matcher based on arguments. It will also emit a bundle2 part describing the narrow spec. I believe the changegroup part generation code in the narrow extension is now limited to ellipsis serving mode. i.e. core is now capable of narrow changegroup generation when ellipsis mode is disabled. Differential Revision: https://phab.mercurial-scm.org/D4014
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 28 Jul 2018 17:42:36 -0700
parents 98df52d5042c
children a232e6744ba3
comparison
equal deleted inserted replaced
38807:98df52d5042c 38808:d99083996398
85 85
86 # Serve a changegroup for a client with a narrow clone. 86 # Serve a changegroup for a client with a narrow clone.
87 def getbundlechangegrouppart_narrow(bundler, repo, source, 87 def getbundlechangegrouppart_narrow(bundler, repo, source,
88 bundlecaps=None, b2caps=None, heads=None, 88 bundlecaps=None, b2caps=None, heads=None,
89 common=None, **kwargs): 89 common=None, **kwargs):
90 assert repo.ui.configbool('experimental', 'narrowservebrokenellipses')
91
90 cgversions = b2caps.get('changegroup') 92 cgversions = b2caps.get('changegroup')
91 if cgversions: # 3.1 and 3.2 ship with an empty value 93 if cgversions: # 3.1 and 3.2 ship with an empty value
92 cgversions = [v for v in cgversions 94 cgversions = [v for v in cgversions
93 if v in changegroup.supportedoutgoingversions(repo)] 95 if v in changegroup.supportedoutgoingversions(repo)]
94 if not cgversions: 96 if not cgversions:
99 " can't negotiate support for ellipsis nodes")) 101 " can't negotiate support for ellipsis nodes"))
100 102
101 include = sorted(filter(bool, kwargs.get(r'includepats', []))) 103 include = sorted(filter(bool, kwargs.get(r'includepats', [])))
102 exclude = sorted(filter(bool, kwargs.get(r'excludepats', []))) 104 exclude = sorted(filter(bool, kwargs.get(r'excludepats', [])))
103 newmatch = narrowspec.match(repo.root, include=include, exclude=exclude) 105 newmatch = narrowspec.match(repo.root, include=include, exclude=exclude)
104 if not repo.ui.configbool("experimental", "narrowservebrokenellipses"):
105 outgoing = exchange._computeoutgoing(repo, heads, common)
106 if not outgoing.missing:
107 return
108
109 cg = changegroup.makestream(repo, outgoing, version, source,
110 filematcher=newmatch)
111 part = bundler.newpart('changegroup', data=cg)
112 part.addparam('version', version)
113 if 'treemanifest' in repo.requirements:
114 part.addparam('treemanifest', '1')
115
116 if include or exclude:
117 narrowspecpart = bundler.newpart(_SPECPART)
118 if include:
119 narrowspecpart.addparam(
120 _SPECPART_INCLUDE, '\n'.join(include), mandatory=True)
121 if exclude:
122 narrowspecpart.addparam(
123 _SPECPART_EXCLUDE, '\n'.join(exclude), mandatory=True)
124
125 return
126 106
127 depth = kwargs.get(r'depth', None) 107 depth = kwargs.get(r'depth', None)
128 if depth is not None: 108 if depth is not None:
129 depth = int(depth) 109 depth = int(depth)
130 if depth < 1: 110 if depth < 1:
309 def wrappedcgfn(*args, **kwargs): 289 def wrappedcgfn(*args, **kwargs):
310 repo = args[1] 290 repo = args[1]
311 if repo.ui.has_section(_NARROWACL_SECTION): 291 if repo.ui.has_section(_NARROWACL_SECTION):
312 kwargs = exchange.applynarrowacl(repo, kwargs) 292 kwargs = exchange.applynarrowacl(repo, kwargs)
313 293
314 if kwargs.get(r'narrow', False): 294 if (kwargs.get(r'narrow', False) and
295 repo.ui.configbool('experimental', 'narrowservebrokenellipses')):
315 getbundlechangegrouppart_narrow(*args, **kwargs) 296 getbundlechangegrouppart_narrow(*args, **kwargs)
316 else: 297 else:
317 origcgfn(*args, **kwargs) 298 origcgfn(*args, **kwargs)
318 exchange.getbundle2partsmapping['changegroup'] = wrappedcgfn 299 exchange.getbundle2partsmapping['changegroup'] = wrappedcgfn
319 300