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