Show More
@@ -1,109 +1,109 b'' | |||||
1 | # narrowwirepeer.py - passes narrow spec with unbundle command |
|
1 | # narrowwirepeer.py - passes narrow spec with unbundle command | |
2 | # |
|
2 | # | |
3 | # Copyright 2017 Google, Inc. |
|
3 | # Copyright 2017 Google, Inc. | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
10 | from mercurial import ( |
|
10 | from mercurial import ( | |
11 | bundle2, |
|
11 | bundle2, | |
12 | error, |
|
12 | error, | |
13 | extensions, |
|
13 | extensions, | |
14 | hg, |
|
14 | hg, | |
15 | match as matchmod, |
|
15 | match as matchmod, | |
16 | narrowspec, |
|
16 | narrowspec, | |
17 | pycompat, |
|
17 | pycompat, | |
18 | wireprototypes, |
|
18 | wireprototypes, | |
19 | wireprotov1peer, |
|
19 | wireprotov1peer, | |
20 | wireprotov1server, |
|
20 | wireprotov1server, | |
21 | ) |
|
21 | ) | |
22 |
|
22 | |||
23 | def uisetup(): |
|
23 | def uisetup(): | |
24 | wireprotov1peer.wirepeer.narrow_widen = peernarrowwiden |
|
24 | wireprotov1peer.wirepeer.narrow_widen = peernarrowwiden | |
25 |
|
25 | |||
26 | def reposetup(repo): |
|
26 | def reposetup(repo): | |
27 | def wirereposetup(ui, peer): |
|
27 | def wirereposetup(ui, peer): | |
28 | def wrapped(orig, cmd, *args, **kwargs): |
|
28 | def wrapped(orig, cmd, *args, **kwargs): | |
29 | if cmd == 'unbundle': |
|
29 | if cmd == 'unbundle': | |
30 | # TODO: don't blindly add include/exclude wireproto |
|
30 | # TODO: don't blindly add include/exclude wireproto | |
31 | # arguments to unbundle. |
|
31 | # arguments to unbundle. | |
32 | include, exclude = repo.narrowpats |
|
32 | include, exclude = repo.narrowpats | |
33 | kwargs[r"includepats"] = ','.join(include) |
|
33 | kwargs[r"includepats"] = ','.join(include) | |
34 | kwargs[r"excludepats"] = ','.join(exclude) |
|
34 | kwargs[r"excludepats"] = ','.join(exclude) | |
35 | return orig(cmd, *args, **kwargs) |
|
35 | return orig(cmd, *args, **kwargs) | |
36 | extensions.wrapfunction(peer, '_calltwowaystream', wrapped) |
|
36 | extensions.wrapfunction(peer, '_calltwowaystream', wrapped) | |
37 | hg.wirepeersetupfuncs.append(wirereposetup) |
|
37 | hg.wirepeersetupfuncs.append(wirereposetup) | |
38 |
|
38 | |||
39 | @wireprotov1server.wireprotocommand('narrow_widen', 'oldincludes oldexcludes' |
|
39 | @wireprotov1server.wireprotocommand('narrow_widen', 'oldincludes oldexcludes' | |
40 | ' newincludes newexcludes' |
|
40 | ' newincludes newexcludes' | |
41 | ' commonheads cgversion' |
|
41 | ' commonheads cgversion' | |
42 | ' known ellipses', |
|
42 | ' known ellipses', | |
43 | permission='pull') |
|
43 | permission='pull') | |
44 | def narrow_widen(repo, proto, oldincludes, oldexcludes, newincludes, |
|
44 | def narrow_widen(repo, proto, oldincludes, oldexcludes, newincludes, | |
45 | newexcludes, commonheads, cgversion, known, ellipses): |
|
45 | newexcludes, commonheads, cgversion, known, ellipses): | |
46 | """wireprotocol command to send data when a narrow clone is widen. We will |
|
46 | """wireprotocol command to send data when a narrow clone is widen. We will | |
47 | be sending a changegroup here. |
|
47 | be sending a changegroup here. | |
48 |
|
48 | |||
49 | The current set of arguments which are required: |
|
49 | The current set of arguments which are required: | |
50 | oldincludes: the old includes of the narrow copy |
|
50 | oldincludes: the old includes of the narrow copy | |
51 | oldexcludes: the old excludes of the narrow copy |
|
51 | oldexcludes: the old excludes of the narrow copy | |
52 | newincludes: the new includes of the narrow copy |
|
52 | newincludes: the new includes of the narrow copy | |
53 | newexcludes: the new excludes of the narrow copy |
|
53 | newexcludes: the new excludes of the narrow copy | |
54 | commonheads: list of heads which are common between the server and client |
|
54 | commonheads: list of heads which are common between the server and client | |
55 | cgversion(maybe): the changegroup version to produce |
|
55 | cgversion(maybe): the changegroup version to produce | |
56 | known: list of nodes which are known on the client (used in ellipses cases) |
|
56 | known: list of nodes which are known on the client (used in ellipses cases) | |
57 | ellipses: whether to send ellipses data or not |
|
57 | ellipses: whether to send ellipses data or not | |
58 | """ |
|
58 | """ | |
59 |
|
59 | |||
60 | preferuncompressed = False |
|
60 | preferuncompressed = False | |
61 | try: |
|
61 | try: | |
62 | oldincludes = wireprototypes.decodelist(oldincludes) |
|
62 | oldincludes = wireprototypes.decodelist(oldincludes) | |
63 | newincludes = wireprototypes.decodelist(newincludes) |
|
63 | newincludes = wireprototypes.decodelist(newincludes) | |
64 | oldexcludes = wireprototypes.decodelist(oldexcludes) |
|
64 | oldexcludes = wireprototypes.decodelist(oldexcludes) | |
65 | newexcludes = wireprototypes.decodelist(newexcludes) |
|
65 | newexcludes = wireprototypes.decodelist(newexcludes) | |
66 | # validate the patterns |
|
66 | # validate the patterns | |
67 | narrowspec.validatepatterns(set(oldincludes)) |
|
67 | narrowspec.validatepatterns(set(oldincludes)) | |
68 | narrowspec.validatepatterns(set(newincludes)) |
|
68 | narrowspec.validatepatterns(set(newincludes)) | |
69 | narrowspec.validatepatterns(set(oldexcludes)) |
|
69 | narrowspec.validatepatterns(set(oldexcludes)) | |
70 | narrowspec.validatepatterns(set(newexcludes)) |
|
70 | narrowspec.validatepatterns(set(newexcludes)) | |
71 |
|
71 | |||
72 | common = wireprototypes.decodelist(commonheads) |
|
72 | common = wireprototypes.decodelist(commonheads) | |
73 | known = None |
|
73 | known = None | |
74 | if known: |
|
74 | if known: | |
75 | known = wireprototypes.decodelist(known) |
|
75 | known = wireprototypes.decodelist(known) | |
76 | if ellipses == '0': |
|
76 | if ellipses == '0': | |
77 | ellipses = False |
|
77 | ellipses = False | |
78 | else: |
|
78 | else: | |
79 | ellipses = bool(ellipses) |
|
79 | ellipses = bool(ellipses) | |
80 | cgversion = cgversion |
|
80 | cgversion = cgversion | |
81 | newmatch = narrowspec.match(repo.root, include=newincludes, |
|
81 | newmatch = narrowspec.match(repo.root, include=newincludes, | |
82 | exclude=newexcludes) |
|
82 | exclude=newexcludes) | |
83 | oldmatch = narrowspec.match(repo.root, include=oldincludes, |
|
83 | oldmatch = narrowspec.match(repo.root, include=oldincludes, | |
84 | exclude=oldexcludes) |
|
84 | exclude=oldexcludes) | |
85 | diffmatch = matchmod.differencematcher(newmatch, oldmatch) |
|
85 | diffmatch = matchmod.differencematcher(newmatch, oldmatch) | |
86 |
|
86 | |||
87 | bundler = bundle2.widen_bundle(repo, diffmatch, common, known, |
|
87 | bundler = bundle2.widen_bundle(repo, diffmatch, common, known, | |
88 | cgversion, ellipses) |
|
88 | cgversion, ellipses) | |
89 | except error.Abort as exc: |
|
89 | except error.Abort as exc: | |
90 | bundler = bundle2.bundle20(repo.ui) |
|
90 | bundler = bundle2.bundle20(repo.ui) | |
91 | manargs = [('message', pycompat.bytestr(exc))] |
|
91 | manargs = [('message', pycompat.bytestr(exc))] | |
92 | advargs = [] |
|
92 | advargs = [] | |
93 | if exc.hint is not None: |
|
93 | if exc.hint is not None: | |
94 | advargs.append(('hint', exc.hint)) |
|
94 | advargs.append(('hint', exc.hint)) | |
95 | bundler.addpart(bundle2.bundlepart('error:abort', manargs, advargs)) |
|
95 | bundler.addpart(bundle2.bundlepart('error:abort', manargs, advargs)) | |
96 | preferuncompressed = True |
|
96 | preferuncompressed = True | |
97 |
|
97 | |||
98 | chunks = bundler.getchunks() |
|
98 | chunks = bundler.getchunks() | |
99 | return wireprototypes.streamres(gen=chunks, |
|
99 | return wireprototypes.streamres(gen=chunks, | |
100 | prefer_uncompressed=preferuncompressed) |
|
100 | prefer_uncompressed=preferuncompressed) | |
101 |
|
101 | |||
102 | def peernarrowwiden(remote, **kwargs): |
|
102 | def peernarrowwiden(remote, **kwargs): | |
103 | for ch in ('oldincludes', 'newincludes', 'oldexcludes', 'newexcludes', |
|
103 | for ch in (r'oldincludes', r'newincludes', r'oldexcludes', r'newexcludes', | |
104 | 'commonheads', 'known'): |
|
104 | r'commonheads', r'known'): | |
105 | kwargs[ch] = wireprototypes.encodelist(kwargs[ch]) |
|
105 | kwargs[ch] = wireprototypes.encodelist(kwargs[ch]) | |
106 |
|
106 | |||
107 | kwargs['ellipses'] = '%i' % bool(kwargs['ellipses']) |
|
107 | kwargs[r'ellipses'] = '%i' % bool(kwargs[r'ellipses']) | |
108 | f = remote._callcompressable('narrow_widen', **kwargs) |
|
108 | f = remote._callcompressable('narrow_widen', **kwargs) | |
109 | return bundle2.getunbundler(remote.ui, f) |
|
109 | return bundle2.getunbundler(remote.ui, f) |
General Comments 0
You need to be logged in to leave comments.
Login now