##// END OF EJS Templates
narrow: the first version of narrow_widen wireprotocol command...
Pulkit Goyal -
r40106:8feae5b9 default
parent child Browse files
Show More
@@ -21,7 +21,6 b' from mercurial import ('
21 error,
21 error,
22 exchange,
22 exchange,
23 extensions,
23 extensions,
24 match as matchmod,
25 narrowspec,
24 narrowspec,
26 repair,
25 repair,
27 repository,
26 repository,
@@ -57,7 +56,7 b' def widen_bundle(repo, diffmatcher, comm'
57 repo is the localrepository instance
56 repo is the localrepository instance
58 diffmatcher is a differencemacther of '(newincludes, newexcludes) -
57 diffmatcher is a differencemacther of '(newincludes, newexcludes) -
59 (oldincludes, oldexcludes)'
58 (oldincludes, oldexcludes)'
60 common is set of common revs between server and client
59 common is set of common heads between server and client
61 known is a set of revs known on the client side (used in ellipses)
60 known is a set of revs known on the client side (used in ellipses)
62 cgversion is the changegroup version to send
61 cgversion is the changegroup version to send
63 ellipses is boolean value telling whether to send ellipses data or not
62 ellipses is boolean value telling whether to send ellipses data or not
@@ -84,41 +83,6 b' def widen_bundle(repo, diffmatcher, comm'
84
83
85 return None
84 return None
86
85
87 def getbundlechangegrouppart_widen(bundler, repo, source, bundlecaps=None,
88 b2caps=None, heads=None, common=None,
89 **kwargs):
90 """Handling changegroup changegroup generation on the server when user
91 is widening their narrowspec"""
92
93 cgversions = b2caps.get('changegroup')
94 if cgversions: # 3.1 and 3.2 ship with an empty value
95 cgversions = [v for v in cgversions
96 if v in changegroup.supportedoutgoingversions(repo)]
97 if not cgversions:
98 raise ValueError(_('no common changegroup version'))
99 version = max(cgversions)
100 else:
101 raise ValueError(_("server does not advertise changegroup version,"
102 " can't negotiate support for ellipsis nodes"))
103
104 include = sorted(filter(bool, kwargs.get(r'includepats', [])))
105 exclude = sorted(filter(bool, kwargs.get(r'excludepats', [])))
106 newmatch = narrowspec.match(repo.root, include=include, exclude=exclude)
107 oldinclude = sorted(filter(bool, kwargs.get(r'oldincludepats', [])))
108 oldexclude = sorted(filter(bool, kwargs.get(r'oldexcludepats', [])))
109 oldmatch = narrowspec.match(repo.root, include=oldinclude,
110 exclude=oldexclude)
111 diffmatch = matchmod.differencematcher(newmatch, oldmatch)
112 common = set(common or [nullid])
113
114 if (oldinclude != include or oldexclude != exclude):
115 cgdata = widen_bundle(repo, diffmatch, common, [], version, False)
116 if cgdata is not None:
117 part = bundler.newpart('changegroup', data=cgdata)
118 part.addparam('version', version)
119 if 'treemanifest' in repo.requirements:
120 part.addparam('treemanifest', '1')
121
122 # Serve a changegroup for a client with a narrow clone.
86 # Serve a changegroup for a client with a narrow clone.
123 def getbundlechangegrouppart_narrow(bundler, repo, source,
87 def getbundlechangegrouppart_narrow(bundler, repo, source,
124 bundlecaps=None, b2caps=None, heads=None,
88 bundlecaps=None, b2caps=None, heads=None,
@@ -326,7 +290,6 b' def setup():'
326 getbundleargs = wireprototypes.GETBUNDLE_ARGUMENTS
290 getbundleargs = wireprototypes.GETBUNDLE_ARGUMENTS
327
291
328 getbundleargs['narrow'] = 'boolean'
292 getbundleargs['narrow'] = 'boolean'
329 getbundleargs['widen'] = 'boolean'
330 getbundleargs['depth'] = 'plain'
293 getbundleargs['depth'] = 'plain'
331 getbundleargs['oldincludepats'] = 'csv'
294 getbundleargs['oldincludepats'] = 'csv'
332 getbundleargs['oldexcludepats'] = 'csv'
295 getbundleargs['oldexcludepats'] = 'csv'
@@ -344,8 +307,6 b' def setup():'
344 if (kwargs.get(r'narrow', False) and
307 if (kwargs.get(r'narrow', False) and
345 repo.ui.configbool('experimental', 'narrowservebrokenellipses')):
308 repo.ui.configbool('experimental', 'narrowservebrokenellipses')):
346 getbundlechangegrouppart_narrow(*args, **kwargs)
309 getbundlechangegrouppart_narrow(*args, **kwargs)
347 elif kwargs.get(r'widen', False) and kwargs.get(r'narrow', False):
348 getbundlechangegrouppart_widen(*args, **kwargs)
349 else:
310 else:
350 origcgfn(*args, **kwargs)
311 origcgfn(*args, **kwargs)
351 exchange.getbundle2partsmapping['changegroup'] = wrappedcgfn
312 exchange.getbundle2partsmapping['changegroup'] = wrappedcgfn
@@ -11,6 +11,7 b' import os'
11
11
12 from mercurial.i18n import _
12 from mercurial.i18n import _
13 from mercurial import (
13 from mercurial import (
14 bundle2,
14 cmdutil,
15 cmdutil,
15 commands,
16 commands,
16 discovery,
17 discovery,
@@ -265,7 +266,6 b' def _widen(ui, repo, remote, commoninc, '
265 # The old{in,ex}cludepats have already been set by orig()
266 # The old{in,ex}cludepats have already been set by orig()
266 kwargs['includepats'] = newincludes
267 kwargs['includepats'] = newincludes
267 kwargs['excludepats'] = newexcludes
268 kwargs['excludepats'] = newexcludes
268 kwargs['widen'] = True
269 wrappedextraprepare = extensions.wrappedfunction(exchange,
269 wrappedextraprepare = extensions.wrappedfunction(exchange,
270 '_pullbundle2extraprepare', pullbundle2extraprepare_widen)
270 '_pullbundle2extraprepare', pullbundle2extraprepare_widen)
271
271
@@ -290,9 +290,23 b' def _widen(ui, repo, remote, commoninc, '
290 with ds.parentchange():
290 with ds.parentchange():
291 ds.setparents(p1, p2)
291 ds.setparents(p1, p2)
292 else:
292 else:
293 with wrappedextraprepare,\
293 with remote.commandexecutor() as e:
294 bundle = e.callcommand('narrow_widen', {
295 'oldincludes': oldincludes,
296 'oldexcludes': oldexcludes,
297 'newincludes': newincludes,
298 'newexcludes': newexcludes,
299 'cgversion': '03',
300 'commonheads': common,
301 'known': [],
302 'ellipses': False,
303 }).result()
304
305 with repo.transaction('widening') as tr,\
294 repo.ui.configoverride(overrides, 'widen'):
306 repo.ui.configoverride(overrides, 'widen'):
295 exchange.pull(repo, remote, heads=common)
307 tgetter = lambda: tr
308 bundle2.processbundle(repo, bundle,
309 transactiongetter=tgetter)
296
310
297 repo.setnewnarrowpats()
311 repo.setnewnarrowpats()
298 actions = {k: [] for k in 'a am f g cd dc r dm dg m e k p pr'.split()}
312 actions = {k: [] for k in 'a am f g cd dc r dm dg m e k p pr'.split()}
@@ -8,14 +8,24 b''
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 from mercurial import (
10 from mercurial import (
11 bundle2,
12 error,
11 extensions,
13 extensions,
12 hg,
14 hg,
15 match as matchmod,
16 narrowspec,
17 pycompat,
13 wireprotoserver,
18 wireprotoserver,
19 wireprototypes,
20 wireprotov1peer,
14 wireprotov1server,
21 wireprotov1server,
15 )
22 )
16
23
24 from . import narrowbundle2
25
17 def uisetup():
26 def uisetup():
18 extensions.wrapfunction(wireprotov1server, '_capabilities', addnarrowcap)
27 extensions.wrapfunction(wireprotov1server, '_capabilities', addnarrowcap)
28 wireprotov1peer.wirepeer.narrow_widen = peernarrowwiden
19
29
20 def addnarrowcap(orig, repo, proto):
30 def addnarrowcap(orig, repo, proto):
21 """add the narrow capability to the server"""
31 """add the narrow capability to the server"""
@@ -37,3 +47,78 b' def reposetup(repo):'
37 return orig(cmd, *args, **kwargs)
47 return orig(cmd, *args, **kwargs)
38 extensions.wrapfunction(peer, '_calltwowaystream', wrapped)
48 extensions.wrapfunction(peer, '_calltwowaystream', wrapped)
39 hg.wirepeersetupfuncs.append(wirereposetup)
49 hg.wirepeersetupfuncs.append(wirereposetup)
50
51 @wireprotov1server.wireprotocommand('narrow_widen', 'oldincludes oldexcludes'
52 ' newincludes newexcludes'
53 ' commonheads cgversion'
54 ' known ellipses',
55 permission='pull')
56 def narrow_widen(repo, proto, oldincludes, oldexcludes, newincludes,
57 newexcludes, commonheads, cgversion, known, ellipses):
58 """wireprotocol command to send data when a narrow clone is widen. We will
59 be sending a changegroup here.
60
61 The current set of arguments which are required:
62 oldincludes: the old includes of the narrow copy
63 oldexcludes: the old excludes of the narrow copy
64 newincludes: the new includes of the narrow copy
65 newexcludes: the new excludes of the narrow copy
66 commonheads: list of heads which are common between the server and client
67 cgversion(maybe): the changegroup version to produce
68 known: list of nodes which are known on the client (used in ellipses cases)
69 ellipses: whether to send ellipses data or not
70 """
71
72 bundler = bundle2.bundle20(repo.ui)
73 try:
74 oldincludes = wireprototypes.decodelist(oldincludes)
75 newincludes = wireprototypes.decodelist(newincludes)
76 oldexcludes = wireprototypes.decodelist(oldexcludes)
77 newexcludes = wireprototypes.decodelist(newexcludes)
78 # validate the patterns
79 narrowspec.validatepatterns(set(oldincludes))
80 narrowspec.validatepatterns(set(newincludes))
81 narrowspec.validatepatterns(set(oldexcludes))
82 narrowspec.validatepatterns(set(newexcludes))
83
84 common = wireprototypes.decodelist(commonheads)
85 known = None
86 if known:
87 known = wireprototypes.decodelist(known)
88 if ellipses == '0':
89 ellipses = False
90 else:
91 ellipses = bool(ellipses)
92 cgversion = cgversion
93 newmatch = narrowspec.match(repo.root, include=newincludes,
94 exclude=newexcludes)
95 oldmatch = narrowspec.match(repo.root, include=oldincludes,
96 exclude=oldexcludes)
97 diffmatch = matchmod.differencematcher(newmatch, oldmatch)
98
99 # get changegroup data
100 cg = narrowbundle2.widen_bundle(repo, diffmatch, common, known,
101 cgversion, ellipses)
102 if cg is not None:
103 part = bundler.newpart('changegroup', data=cg)
104 part.addparam('version', cgversion)
105 if 'treemanifest' in repo.requirements:
106 part.addparam('treemanifest', '1')
107 except error.Abort as exc:
108 manargs = [('message', pycompat.bytestr(exc))]
109 advargs = []
110 if exc.hint is not None:
111 advargs.append(('hint', exc.hint))
112 bundler.addpart(bundle2.bundlepart('error:abort', manargs, advargs))
113
114 chunks = bundler.getchunks()
115 return wireprototypes.streamres(gen=chunks)
116
117 def peernarrowwiden(remote, **kwargs):
118 for ch in ('oldincludes', 'newincludes', 'oldexcludes', 'newexcludes',
119 'commonheads', 'known'):
120 kwargs[ch] = wireprototypes.encodelist(kwargs[ch])
121
122 kwargs['ellipses'] = '%i' % bool(kwargs['ellipses'])
123 f = remote._callcompressable('narrow_widen', **kwargs)
124 return bundle2.getunbundler(remote.ui, f)
@@ -104,8 +104,7 b' added upstream revisions.'
104 sending batch command
104 sending batch command
105 searching for changes
105 searching for changes
106 all local heads known remotely
106 all local heads known remotely
107 no changes found
107 sending narrow_widen command
108 sending getbundle command
109 bundle2-input-bundle: with-transaction
108 bundle2-input-bundle: with-transaction
110 bundle2-input-part: "changegroup" (params: * mandatory) supported (glob)
109 bundle2-input-part: "changegroup" (params: * mandatory) supported (glob)
111 adding changesets
110 adding changesets
@@ -115,12 +114,7 b' added upstream revisions.'
115 adding widest/f revisions (tree !)
114 adding widest/f revisions (tree !)
116 added 0 changesets with 1 changes to 1 files
115 added 0 changesets with 1 changes to 1 files
117 bundle2-input-part: total payload size * (glob)
116 bundle2-input-part: total payload size * (glob)
118 bundle2-input-part: "listkeys" (params: 1 mandatory) supported
117 bundle2-input-bundle: 0 parts total
119 bundle2-input-part: "phase-heads" supported
120 bundle2-input-part: total payload size 24
121 bundle2-input-bundle: 2 parts total
122 checking for updated bookmarks
123 3 local changesets published
124 widest/f: add from widened narrow clone -> g
118 widest/f: add from widened narrow clone -> g
125 getting widest/f
119 getting widest/f
126 $ hg tracked
120 $ hg tracked
@@ -143,6 +137,7 b' Pull down the newly added upstream revis'
143 adding file changes
137 adding file changes
144 added 5 changesets with 4 changes to 2 files
138 added 5 changesets with 4 changes to 2 files
145 new changesets *:* (glob)
139 new changesets *:* (glob)
140 3 local changesets published
146 (run 'hg update' to get a working copy)
141 (run 'hg update' to get a working copy)
147 $ hg update -r 'desc("add wider")'
142 $ hg update -r 'desc("add wider")'
148 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
143 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -179,12 +174,10 b' widen the narrow spec to include the wid'
179 $ hg tracked --addinclude wider
174 $ hg tracked --addinclude wider
180 comparing with ssh://user@dummy/master
175 comparing with ssh://user@dummy/master
181 searching for changes
176 searching for changes
182 no changes found
183 adding changesets
177 adding changesets
184 adding manifests
178 adding manifests
185 adding file changes
179 adding file changes
186 added 0 changesets with 1 changes to 1 files
180 added 0 changesets with 1 changes to 1 files
187 5 local changesets published
188 $ hg tracked
181 $ hg tracked
189 I path:inside
182 I path:inside
190 I path:wider
183 I path:wider
@@ -284,12 +277,10 b' make narrow clone with every third node.'
284 $ hg tracked --addinclude d1
277 $ hg tracked --addinclude d1
285 comparing with ssh://user@dummy/upstream
278 comparing with ssh://user@dummy/upstream
286 searching for changes
279 searching for changes
287 no changes found
288 adding changesets
280 adding changesets
289 adding manifests
281 adding manifests
290 adding file changes
282 adding file changes
291 added 0 changesets with 1 changes to 1 files
283 added 0 changesets with 1 changes to 1 files
292 11 local changesets published
293 $ hg tracked
284 $ hg tracked
294 I path:d0
285 I path:d0
295 I path:d1
286 I path:d1
@@ -376,12 +367,10 b' Widening that fails can be recovered fro'
376 $ hg --config hooks.pretxnchangegroup.bad=false tracked --addinclude d1
367 $ hg --config hooks.pretxnchangegroup.bad=false tracked --addinclude d1
377 comparing with ssh://user@dummy/upstream
368 comparing with ssh://user@dummy/upstream
378 searching for changes
369 searching for changes
379 no changes found
380 adding changesets
370 adding changesets
381 adding manifests
371 adding manifests
382 adding file changes
372 adding file changes
383 added 0 changesets with 1 changes to 1 files
373 added 0 changesets with 1 changes to 1 files
384 11 local changesets published
385 $ hg log -T "{if(ellipsis, '...')}{rev}: {desc}\n"
374 $ hg log -T "{if(ellipsis, '...')}{rev}: {desc}\n"
386 11: local
375 11: local
387 10: add d10/f
376 10: add d10/f
General Comments 0
You need to be logged in to leave comments. Login now