##// END OF EJS Templates
narrow: don't compress the bundle2 when sending 'error:abort'...
Pulkit Goyal -
r40183:74558635 default
parent child Browse files
Show More
@@ -1,106 +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 preferuncompressed = False
60 61 try:
61 62 oldincludes = wireprototypes.decodelist(oldincludes)
62 63 newincludes = wireprototypes.decodelist(newincludes)
63 64 oldexcludes = wireprototypes.decodelist(oldexcludes)
64 65 newexcludes = wireprototypes.decodelist(newexcludes)
65 66 # validate the patterns
66 67 narrowspec.validatepatterns(set(oldincludes))
67 68 narrowspec.validatepatterns(set(newincludes))
68 69 narrowspec.validatepatterns(set(oldexcludes))
69 70 narrowspec.validatepatterns(set(newexcludes))
70 71
71 72 common = wireprototypes.decodelist(commonheads)
72 73 known = None
73 74 if known:
74 75 known = wireprototypes.decodelist(known)
75 76 if ellipses == '0':
76 77 ellipses = False
77 78 else:
78 79 ellipses = bool(ellipses)
79 80 cgversion = cgversion
80 81 newmatch = narrowspec.match(repo.root, include=newincludes,
81 82 exclude=newexcludes)
82 83 oldmatch = narrowspec.match(repo.root, include=oldincludes,
83 84 exclude=oldexcludes)
84 85 diffmatch = matchmod.differencematcher(newmatch, oldmatch)
85 86
86 87 bundler = bundle2.widen_bundle(repo, diffmatch, common, known,
87 88 cgversion, ellipses)
88 89 except error.Abort as exc:
89 90 bundler = bundle2.bundle20(repo.ui)
90 91 manargs = [('message', pycompat.bytestr(exc))]
91 92 advargs = []
92 93 if exc.hint is not None:
93 94 advargs.append(('hint', exc.hint))
94 95 bundler.addpart(bundle2.bundlepart('error:abort', manargs, advargs))
96 preferuncompressed = True
95 97
96 98 chunks = bundler.getchunks()
97 return wireprototypes.streamres(gen=chunks)
99 return wireprototypes.streamres(gen=chunks,
100 prefer_uncompressed=preferuncompressed)
98 101
99 102 def peernarrowwiden(remote, **kwargs):
100 103 for ch in ('oldincludes', 'newincludes', 'oldexcludes', 'newexcludes',
101 104 'commonheads', 'known'):
102 105 kwargs[ch] = wireprototypes.encodelist(kwargs[ch])
103 106
104 107 kwargs['ellipses'] = '%i' % bool(kwargs['ellipses'])
105 108 f = remote._callcompressable('narrow_widen', **kwargs)
106 109 return bundle2.getunbundler(remote.ui, f)
General Comments 0
You need to be logged in to leave comments. Login now