Show More
@@ -1,3090 +1,3086 b'' | |||||
1 | # exchange.py - utility to exchange data between repos. |
|
1 | # exchange.py - utility to exchange data between repos. | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | |
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 | import collections |
|
10 | import collections | |
11 | import hashlib |
|
11 | import hashlib | |
12 |
|
12 | |||
13 | from .i18n import _ |
|
13 | from .i18n import _ | |
14 | from .node import ( |
|
14 | from .node import ( | |
15 | hex, |
|
15 | hex, | |
16 | nullid, |
|
16 | nullid, | |
17 | nullrev, |
|
17 | nullrev, | |
18 | ) |
|
18 | ) | |
19 | from .thirdparty import attr |
|
19 | from .thirdparty import attr | |
20 | from . import ( |
|
20 | from . import ( | |
21 | bookmarks as bookmod, |
|
21 | bookmarks as bookmod, | |
22 | bundle2, |
|
22 | bundle2, | |
23 | changegroup, |
|
23 | changegroup, | |
24 | discovery, |
|
24 | discovery, | |
25 | error, |
|
25 | error, | |
26 | exchangev2, |
|
26 | exchangev2, | |
27 | lock as lockmod, |
|
27 | lock as lockmod, | |
28 | logexchange, |
|
28 | logexchange, | |
29 | narrowspec, |
|
29 | narrowspec, | |
30 | obsolete, |
|
30 | obsolete, | |
|
31 | obsutil, | |||
31 | phases, |
|
32 | phases, | |
32 | pushkey, |
|
33 | pushkey, | |
33 | pycompat, |
|
34 | pycompat, | |
34 | scmutil, |
|
35 | scmutil, | |
35 | sslutil, |
|
36 | sslutil, | |
36 | streamclone, |
|
37 | streamclone, | |
37 | url as urlmod, |
|
38 | url as urlmod, | |
38 | util, |
|
39 | util, | |
39 | wireprototypes, |
|
40 | wireprototypes, | |
40 | ) |
|
41 | ) | |
41 | from .interfaces import repository |
|
42 | from .interfaces import repository | |
42 | from .utils import stringutil |
|
43 | from .utils import stringutil | |
43 |
|
44 | |||
44 | urlerr = util.urlerr |
|
45 | urlerr = util.urlerr | |
45 | urlreq = util.urlreq |
|
46 | urlreq = util.urlreq | |
46 |
|
47 | |||
47 | _NARROWACL_SECTION = b'narrowacl' |
|
48 | _NARROWACL_SECTION = b'narrowacl' | |
48 |
|
49 | |||
49 | # Maps bundle version human names to changegroup versions. |
|
50 | # Maps bundle version human names to changegroup versions. | |
50 | _bundlespeccgversions = { |
|
51 | _bundlespeccgversions = { | |
51 | b'v1': b'01', |
|
52 | b'v1': b'01', | |
52 | b'v2': b'02', |
|
53 | b'v2': b'02', | |
53 | b'packed1': b's1', |
|
54 | b'packed1': b's1', | |
54 | b'bundle2': b'02', # legacy |
|
55 | b'bundle2': b'02', # legacy | |
55 | } |
|
56 | } | |
56 |
|
57 | |||
57 | # Maps bundle version with content opts to choose which part to bundle |
|
58 | # Maps bundle version with content opts to choose which part to bundle | |
58 | _bundlespeccontentopts = { |
|
59 | _bundlespeccontentopts = { | |
59 | b'v1': { |
|
60 | b'v1': { | |
60 | b'changegroup': True, |
|
61 | b'changegroup': True, | |
61 | b'cg.version': b'01', |
|
62 | b'cg.version': b'01', | |
62 | b'obsolescence': False, |
|
63 | b'obsolescence': False, | |
63 | b'phases': False, |
|
64 | b'phases': False, | |
64 | b'tagsfnodescache': False, |
|
65 | b'tagsfnodescache': False, | |
65 | b'revbranchcache': False, |
|
66 | b'revbranchcache': False, | |
66 | }, |
|
67 | }, | |
67 | b'v2': { |
|
68 | b'v2': { | |
68 | b'changegroup': True, |
|
69 | b'changegroup': True, | |
69 | b'cg.version': b'02', |
|
70 | b'cg.version': b'02', | |
70 | b'obsolescence': False, |
|
71 | b'obsolescence': False, | |
71 | b'phases': False, |
|
72 | b'phases': False, | |
72 | b'tagsfnodescache': True, |
|
73 | b'tagsfnodescache': True, | |
73 | b'revbranchcache': True, |
|
74 | b'revbranchcache': True, | |
74 | }, |
|
75 | }, | |
75 | b'packed1': {b'cg.version': b's1'}, |
|
76 | b'packed1': {b'cg.version': b's1'}, | |
76 | } |
|
77 | } | |
77 | _bundlespeccontentopts[b'bundle2'] = _bundlespeccontentopts[b'v2'] |
|
78 | _bundlespeccontentopts[b'bundle2'] = _bundlespeccontentopts[b'v2'] | |
78 |
|
79 | |||
79 | _bundlespecvariants = { |
|
80 | _bundlespecvariants = { | |
80 | b"streamv2": { |
|
81 | b"streamv2": { | |
81 | b"changegroup": False, |
|
82 | b"changegroup": False, | |
82 | b"streamv2": True, |
|
83 | b"streamv2": True, | |
83 | b"tagsfnodescache": False, |
|
84 | b"tagsfnodescache": False, | |
84 | b"revbranchcache": False, |
|
85 | b"revbranchcache": False, | |
85 | } |
|
86 | } | |
86 | } |
|
87 | } | |
87 |
|
88 | |||
88 | # Compression engines allowed in version 1. THIS SHOULD NEVER CHANGE. |
|
89 | # Compression engines allowed in version 1. THIS SHOULD NEVER CHANGE. | |
89 | _bundlespecv1compengines = {b'gzip', b'bzip2', b'none'} |
|
90 | _bundlespecv1compengines = {b'gzip', b'bzip2', b'none'} | |
90 |
|
91 | |||
91 |
|
92 | |||
92 | @attr.s |
|
93 | @attr.s | |
93 | class bundlespec(object): |
|
94 | class bundlespec(object): | |
94 | compression = attr.ib() |
|
95 | compression = attr.ib() | |
95 | wirecompression = attr.ib() |
|
96 | wirecompression = attr.ib() | |
96 | version = attr.ib() |
|
97 | version = attr.ib() | |
97 | wireversion = attr.ib() |
|
98 | wireversion = attr.ib() | |
98 | params = attr.ib() |
|
99 | params = attr.ib() | |
99 | contentopts = attr.ib() |
|
100 | contentopts = attr.ib() | |
100 |
|
101 | |||
101 |
|
102 | |||
102 | def _sortedmarkers(markers): |
|
|||
103 | # last item of marker tuple ('parents') may be None or a tuple |
|
|||
104 | return sorted(markers, key=lambda m: m[:-1] + (m[-1] or (),)) |
|
|||
105 |
|
||||
106 |
|
||||
107 | def parsebundlespec(repo, spec, strict=True): |
|
103 | def parsebundlespec(repo, spec, strict=True): | |
108 | """Parse a bundle string specification into parts. |
|
104 | """Parse a bundle string specification into parts. | |
109 |
|
105 | |||
110 | Bundle specifications denote a well-defined bundle/exchange format. |
|
106 | Bundle specifications denote a well-defined bundle/exchange format. | |
111 | The content of a given specification should not change over time in |
|
107 | The content of a given specification should not change over time in | |
112 | order to ensure that bundles produced by a newer version of Mercurial are |
|
108 | order to ensure that bundles produced by a newer version of Mercurial are | |
113 | readable from an older version. |
|
109 | readable from an older version. | |
114 |
|
110 | |||
115 | The string currently has the form: |
|
111 | The string currently has the form: | |
116 |
|
112 | |||
117 | <compression>-<type>[;<parameter0>[;<parameter1>]] |
|
113 | <compression>-<type>[;<parameter0>[;<parameter1>]] | |
118 |
|
114 | |||
119 | Where <compression> is one of the supported compression formats |
|
115 | Where <compression> is one of the supported compression formats | |
120 | and <type> is (currently) a version string. A ";" can follow the type and |
|
116 | and <type> is (currently) a version string. A ";" can follow the type and | |
121 | all text afterwards is interpreted as URI encoded, ";" delimited key=value |
|
117 | all text afterwards is interpreted as URI encoded, ";" delimited key=value | |
122 | pairs. |
|
118 | pairs. | |
123 |
|
119 | |||
124 | If ``strict`` is True (the default) <compression> is required. Otherwise, |
|
120 | If ``strict`` is True (the default) <compression> is required. Otherwise, | |
125 | it is optional. |
|
121 | it is optional. | |
126 |
|
122 | |||
127 | Returns a bundlespec object of (compression, version, parameters). |
|
123 | Returns a bundlespec object of (compression, version, parameters). | |
128 | Compression will be ``None`` if not in strict mode and a compression isn't |
|
124 | Compression will be ``None`` if not in strict mode and a compression isn't | |
129 | defined. |
|
125 | defined. | |
130 |
|
126 | |||
131 | An ``InvalidBundleSpecification`` is raised when the specification is |
|
127 | An ``InvalidBundleSpecification`` is raised when the specification is | |
132 | not syntactically well formed. |
|
128 | not syntactically well formed. | |
133 |
|
129 | |||
134 | An ``UnsupportedBundleSpecification`` is raised when the compression or |
|
130 | An ``UnsupportedBundleSpecification`` is raised when the compression or | |
135 | bundle type/version is not recognized. |
|
131 | bundle type/version is not recognized. | |
136 |
|
132 | |||
137 | Note: this function will likely eventually return a more complex data |
|
133 | Note: this function will likely eventually return a more complex data | |
138 | structure, including bundle2 part information. |
|
134 | structure, including bundle2 part information. | |
139 | """ |
|
135 | """ | |
140 |
|
136 | |||
141 | def parseparams(s): |
|
137 | def parseparams(s): | |
142 | if b';' not in s: |
|
138 | if b';' not in s: | |
143 | return s, {} |
|
139 | return s, {} | |
144 |
|
140 | |||
145 | params = {} |
|
141 | params = {} | |
146 | version, paramstr = s.split(b';', 1) |
|
142 | version, paramstr = s.split(b';', 1) | |
147 |
|
143 | |||
148 | for p in paramstr.split(b';'): |
|
144 | for p in paramstr.split(b';'): | |
149 | if b'=' not in p: |
|
145 | if b'=' not in p: | |
150 | raise error.InvalidBundleSpecification( |
|
146 | raise error.InvalidBundleSpecification( | |
151 | _( |
|
147 | _( | |
152 | b'invalid bundle specification: ' |
|
148 | b'invalid bundle specification: ' | |
153 | b'missing "=" in parameter: %s' |
|
149 | b'missing "=" in parameter: %s' | |
154 | ) |
|
150 | ) | |
155 | % p |
|
151 | % p | |
156 | ) |
|
152 | ) | |
157 |
|
153 | |||
158 | key, value = p.split(b'=', 1) |
|
154 | key, value = p.split(b'=', 1) | |
159 | key = urlreq.unquote(key) |
|
155 | key = urlreq.unquote(key) | |
160 | value = urlreq.unquote(value) |
|
156 | value = urlreq.unquote(value) | |
161 | params[key] = value |
|
157 | params[key] = value | |
162 |
|
158 | |||
163 | return version, params |
|
159 | return version, params | |
164 |
|
160 | |||
165 | if strict and b'-' not in spec: |
|
161 | if strict and b'-' not in spec: | |
166 | raise error.InvalidBundleSpecification( |
|
162 | raise error.InvalidBundleSpecification( | |
167 | _( |
|
163 | _( | |
168 | b'invalid bundle specification; ' |
|
164 | b'invalid bundle specification; ' | |
169 | b'must be prefixed with compression: %s' |
|
165 | b'must be prefixed with compression: %s' | |
170 | ) |
|
166 | ) | |
171 | % spec |
|
167 | % spec | |
172 | ) |
|
168 | ) | |
173 |
|
169 | |||
174 | if b'-' in spec: |
|
170 | if b'-' in spec: | |
175 | compression, version = spec.split(b'-', 1) |
|
171 | compression, version = spec.split(b'-', 1) | |
176 |
|
172 | |||
177 | if compression not in util.compengines.supportedbundlenames: |
|
173 | if compression not in util.compengines.supportedbundlenames: | |
178 | raise error.UnsupportedBundleSpecification( |
|
174 | raise error.UnsupportedBundleSpecification( | |
179 | _(b'%s compression is not supported') % compression |
|
175 | _(b'%s compression is not supported') % compression | |
180 | ) |
|
176 | ) | |
181 |
|
177 | |||
182 | version, params = parseparams(version) |
|
178 | version, params = parseparams(version) | |
183 |
|
179 | |||
184 | if version not in _bundlespeccgversions: |
|
180 | if version not in _bundlespeccgversions: | |
185 | raise error.UnsupportedBundleSpecification( |
|
181 | raise error.UnsupportedBundleSpecification( | |
186 | _(b'%s is not a recognized bundle version') % version |
|
182 | _(b'%s is not a recognized bundle version') % version | |
187 | ) |
|
183 | ) | |
188 | else: |
|
184 | else: | |
189 | # Value could be just the compression or just the version, in which |
|
185 | # Value could be just the compression or just the version, in which | |
190 | # case some defaults are assumed (but only when not in strict mode). |
|
186 | # case some defaults are assumed (but only when not in strict mode). | |
191 | assert not strict |
|
187 | assert not strict | |
192 |
|
188 | |||
193 | spec, params = parseparams(spec) |
|
189 | spec, params = parseparams(spec) | |
194 |
|
190 | |||
195 | if spec in util.compengines.supportedbundlenames: |
|
191 | if spec in util.compengines.supportedbundlenames: | |
196 | compression = spec |
|
192 | compression = spec | |
197 | version = b'v1' |
|
193 | version = b'v1' | |
198 | # Generaldelta repos require v2. |
|
194 | # Generaldelta repos require v2. | |
199 | if b'generaldelta' in repo.requirements: |
|
195 | if b'generaldelta' in repo.requirements: | |
200 | version = b'v2' |
|
196 | version = b'v2' | |
201 | # Modern compression engines require v2. |
|
197 | # Modern compression engines require v2. | |
202 | if compression not in _bundlespecv1compengines: |
|
198 | if compression not in _bundlespecv1compengines: | |
203 | version = b'v2' |
|
199 | version = b'v2' | |
204 | elif spec in _bundlespeccgversions: |
|
200 | elif spec in _bundlespeccgversions: | |
205 | if spec == b'packed1': |
|
201 | if spec == b'packed1': | |
206 | compression = b'none' |
|
202 | compression = b'none' | |
207 | else: |
|
203 | else: | |
208 | compression = b'bzip2' |
|
204 | compression = b'bzip2' | |
209 | version = spec |
|
205 | version = spec | |
210 | else: |
|
206 | else: | |
211 | raise error.UnsupportedBundleSpecification( |
|
207 | raise error.UnsupportedBundleSpecification( | |
212 | _(b'%s is not a recognized bundle specification') % spec |
|
208 | _(b'%s is not a recognized bundle specification') % spec | |
213 | ) |
|
209 | ) | |
214 |
|
210 | |||
215 | # Bundle version 1 only supports a known set of compression engines. |
|
211 | # Bundle version 1 only supports a known set of compression engines. | |
216 | if version == b'v1' and compression not in _bundlespecv1compengines: |
|
212 | if version == b'v1' and compression not in _bundlespecv1compengines: | |
217 | raise error.UnsupportedBundleSpecification( |
|
213 | raise error.UnsupportedBundleSpecification( | |
218 | _(b'compression engine %s is not supported on v1 bundles') |
|
214 | _(b'compression engine %s is not supported on v1 bundles') | |
219 | % compression |
|
215 | % compression | |
220 | ) |
|
216 | ) | |
221 |
|
217 | |||
222 | # The specification for packed1 can optionally declare the data formats |
|
218 | # The specification for packed1 can optionally declare the data formats | |
223 | # required to apply it. If we see this metadata, compare against what the |
|
219 | # required to apply it. If we see this metadata, compare against what the | |
224 | # repo supports and error if the bundle isn't compatible. |
|
220 | # repo supports and error if the bundle isn't compatible. | |
225 | if version == b'packed1' and b'requirements' in params: |
|
221 | if version == b'packed1' and b'requirements' in params: | |
226 | requirements = set(params[b'requirements'].split(b',')) |
|
222 | requirements = set(params[b'requirements'].split(b',')) | |
227 | missingreqs = requirements - repo.supportedformats |
|
223 | missingreqs = requirements - repo.supportedformats | |
228 | if missingreqs: |
|
224 | if missingreqs: | |
229 | raise error.UnsupportedBundleSpecification( |
|
225 | raise error.UnsupportedBundleSpecification( | |
230 | _(b'missing support for repository features: %s') |
|
226 | _(b'missing support for repository features: %s') | |
231 | % b', '.join(sorted(missingreqs)) |
|
227 | % b', '.join(sorted(missingreqs)) | |
232 | ) |
|
228 | ) | |
233 |
|
229 | |||
234 | # Compute contentopts based on the version |
|
230 | # Compute contentopts based on the version | |
235 | contentopts = _bundlespeccontentopts.get(version, {}).copy() |
|
231 | contentopts = _bundlespeccontentopts.get(version, {}).copy() | |
236 |
|
232 | |||
237 | # Process the variants |
|
233 | # Process the variants | |
238 | if b"stream" in params and params[b"stream"] == b"v2": |
|
234 | if b"stream" in params and params[b"stream"] == b"v2": | |
239 | variant = _bundlespecvariants[b"streamv2"] |
|
235 | variant = _bundlespecvariants[b"streamv2"] | |
240 | contentopts.update(variant) |
|
236 | contentopts.update(variant) | |
241 |
|
237 | |||
242 | engine = util.compengines.forbundlename(compression) |
|
238 | engine = util.compengines.forbundlename(compression) | |
243 | compression, wirecompression = engine.bundletype() |
|
239 | compression, wirecompression = engine.bundletype() | |
244 | wireversion = _bundlespeccgversions[version] |
|
240 | wireversion = _bundlespeccgversions[version] | |
245 |
|
241 | |||
246 | return bundlespec( |
|
242 | return bundlespec( | |
247 | compression, wirecompression, version, wireversion, params, contentopts |
|
243 | compression, wirecompression, version, wireversion, params, contentopts | |
248 | ) |
|
244 | ) | |
249 |
|
245 | |||
250 |
|
246 | |||
251 | def readbundle(ui, fh, fname, vfs=None): |
|
247 | def readbundle(ui, fh, fname, vfs=None): | |
252 | header = changegroup.readexactly(fh, 4) |
|
248 | header = changegroup.readexactly(fh, 4) | |
253 |
|
249 | |||
254 | alg = None |
|
250 | alg = None | |
255 | if not fname: |
|
251 | if not fname: | |
256 | fname = b"stream" |
|
252 | fname = b"stream" | |
257 | if not header.startswith(b'HG') and header.startswith(b'\0'): |
|
253 | if not header.startswith(b'HG') and header.startswith(b'\0'): | |
258 | fh = changegroup.headerlessfixup(fh, header) |
|
254 | fh = changegroup.headerlessfixup(fh, header) | |
259 | header = b"HG10" |
|
255 | header = b"HG10" | |
260 | alg = b'UN' |
|
256 | alg = b'UN' | |
261 | elif vfs: |
|
257 | elif vfs: | |
262 | fname = vfs.join(fname) |
|
258 | fname = vfs.join(fname) | |
263 |
|
259 | |||
264 | magic, version = header[0:2], header[2:4] |
|
260 | magic, version = header[0:2], header[2:4] | |
265 |
|
261 | |||
266 | if magic != b'HG': |
|
262 | if magic != b'HG': | |
267 | raise error.Abort(_(b'%s: not a Mercurial bundle') % fname) |
|
263 | raise error.Abort(_(b'%s: not a Mercurial bundle') % fname) | |
268 | if version == b'10': |
|
264 | if version == b'10': | |
269 | if alg is None: |
|
265 | if alg is None: | |
270 | alg = changegroup.readexactly(fh, 2) |
|
266 | alg = changegroup.readexactly(fh, 2) | |
271 | return changegroup.cg1unpacker(fh, alg) |
|
267 | return changegroup.cg1unpacker(fh, alg) | |
272 | elif version.startswith(b'2'): |
|
268 | elif version.startswith(b'2'): | |
273 | return bundle2.getunbundler(ui, fh, magicstring=magic + version) |
|
269 | return bundle2.getunbundler(ui, fh, magicstring=magic + version) | |
274 | elif version == b'S1': |
|
270 | elif version == b'S1': | |
275 | return streamclone.streamcloneapplier(fh) |
|
271 | return streamclone.streamcloneapplier(fh) | |
276 | else: |
|
272 | else: | |
277 | raise error.Abort( |
|
273 | raise error.Abort( | |
278 | _(b'%s: unknown bundle version %s') % (fname, version) |
|
274 | _(b'%s: unknown bundle version %s') % (fname, version) | |
279 | ) |
|
275 | ) | |
280 |
|
276 | |||
281 |
|
277 | |||
282 | def getbundlespec(ui, fh): |
|
278 | def getbundlespec(ui, fh): | |
283 | """Infer the bundlespec from a bundle file handle. |
|
279 | """Infer the bundlespec from a bundle file handle. | |
284 |
|
280 | |||
285 | The input file handle is seeked and the original seek position is not |
|
281 | The input file handle is seeked and the original seek position is not | |
286 | restored. |
|
282 | restored. | |
287 | """ |
|
283 | """ | |
288 |
|
284 | |||
289 | def speccompression(alg): |
|
285 | def speccompression(alg): | |
290 | try: |
|
286 | try: | |
291 | return util.compengines.forbundletype(alg).bundletype()[0] |
|
287 | return util.compengines.forbundletype(alg).bundletype()[0] | |
292 | except KeyError: |
|
288 | except KeyError: | |
293 | return None |
|
289 | return None | |
294 |
|
290 | |||
295 | b = readbundle(ui, fh, None) |
|
291 | b = readbundle(ui, fh, None) | |
296 | if isinstance(b, changegroup.cg1unpacker): |
|
292 | if isinstance(b, changegroup.cg1unpacker): | |
297 | alg = b._type |
|
293 | alg = b._type | |
298 | if alg == b'_truncatedBZ': |
|
294 | if alg == b'_truncatedBZ': | |
299 | alg = b'BZ' |
|
295 | alg = b'BZ' | |
300 | comp = speccompression(alg) |
|
296 | comp = speccompression(alg) | |
301 | if not comp: |
|
297 | if not comp: | |
302 | raise error.Abort(_(b'unknown compression algorithm: %s') % alg) |
|
298 | raise error.Abort(_(b'unknown compression algorithm: %s') % alg) | |
303 | return b'%s-v1' % comp |
|
299 | return b'%s-v1' % comp | |
304 | elif isinstance(b, bundle2.unbundle20): |
|
300 | elif isinstance(b, bundle2.unbundle20): | |
305 | if b'Compression' in b.params: |
|
301 | if b'Compression' in b.params: | |
306 | comp = speccompression(b.params[b'Compression']) |
|
302 | comp = speccompression(b.params[b'Compression']) | |
307 | if not comp: |
|
303 | if not comp: | |
308 | raise error.Abort( |
|
304 | raise error.Abort( | |
309 | _(b'unknown compression algorithm: %s') % comp |
|
305 | _(b'unknown compression algorithm: %s') % comp | |
310 | ) |
|
306 | ) | |
311 | else: |
|
307 | else: | |
312 | comp = b'none' |
|
308 | comp = b'none' | |
313 |
|
309 | |||
314 | version = None |
|
310 | version = None | |
315 | for part in b.iterparts(): |
|
311 | for part in b.iterparts(): | |
316 | if part.type == b'changegroup': |
|
312 | if part.type == b'changegroup': | |
317 | version = part.params[b'version'] |
|
313 | version = part.params[b'version'] | |
318 | if version in (b'01', b'02'): |
|
314 | if version in (b'01', b'02'): | |
319 | version = b'v2' |
|
315 | version = b'v2' | |
320 | else: |
|
316 | else: | |
321 | raise error.Abort( |
|
317 | raise error.Abort( | |
322 | _( |
|
318 | _( | |
323 | b'changegroup version %s does not have ' |
|
319 | b'changegroup version %s does not have ' | |
324 | b'a known bundlespec' |
|
320 | b'a known bundlespec' | |
325 | ) |
|
321 | ) | |
326 | % version, |
|
322 | % version, | |
327 | hint=_(b'try upgrading your Mercurial client'), |
|
323 | hint=_(b'try upgrading your Mercurial client'), | |
328 | ) |
|
324 | ) | |
329 | elif part.type == b'stream2' and version is None: |
|
325 | elif part.type == b'stream2' and version is None: | |
330 | # A stream2 part requires to be part of a v2 bundle |
|
326 | # A stream2 part requires to be part of a v2 bundle | |
331 | requirements = urlreq.unquote(part.params[b'requirements']) |
|
327 | requirements = urlreq.unquote(part.params[b'requirements']) | |
332 | splitted = requirements.split() |
|
328 | splitted = requirements.split() | |
333 | params = bundle2._formatrequirementsparams(splitted) |
|
329 | params = bundle2._formatrequirementsparams(splitted) | |
334 | return b'none-v2;stream=v2;%s' % params |
|
330 | return b'none-v2;stream=v2;%s' % params | |
335 |
|
331 | |||
336 | if not version: |
|
332 | if not version: | |
337 | raise error.Abort( |
|
333 | raise error.Abort( | |
338 | _(b'could not identify changegroup version in bundle') |
|
334 | _(b'could not identify changegroup version in bundle') | |
339 | ) |
|
335 | ) | |
340 |
|
336 | |||
341 | return b'%s-%s' % (comp, version) |
|
337 | return b'%s-%s' % (comp, version) | |
342 | elif isinstance(b, streamclone.streamcloneapplier): |
|
338 | elif isinstance(b, streamclone.streamcloneapplier): | |
343 | requirements = streamclone.readbundle1header(fh)[2] |
|
339 | requirements = streamclone.readbundle1header(fh)[2] | |
344 | formatted = bundle2._formatrequirementsparams(requirements) |
|
340 | formatted = bundle2._formatrequirementsparams(requirements) | |
345 | return b'none-packed1;%s' % formatted |
|
341 | return b'none-packed1;%s' % formatted | |
346 | else: |
|
342 | else: | |
347 | raise error.Abort(_(b'unknown bundle type: %s') % b) |
|
343 | raise error.Abort(_(b'unknown bundle type: %s') % b) | |
348 |
|
344 | |||
349 |
|
345 | |||
350 | def _computeoutgoing(repo, heads, common): |
|
346 | def _computeoutgoing(repo, heads, common): | |
351 | """Computes which revs are outgoing given a set of common |
|
347 | """Computes which revs are outgoing given a set of common | |
352 | and a set of heads. |
|
348 | and a set of heads. | |
353 |
|
349 | |||
354 | This is a separate function so extensions can have access to |
|
350 | This is a separate function so extensions can have access to | |
355 | the logic. |
|
351 | the logic. | |
356 |
|
352 | |||
357 | Returns a discovery.outgoing object. |
|
353 | Returns a discovery.outgoing object. | |
358 | """ |
|
354 | """ | |
359 | cl = repo.changelog |
|
355 | cl = repo.changelog | |
360 | if common: |
|
356 | if common: | |
361 | hasnode = cl.hasnode |
|
357 | hasnode = cl.hasnode | |
362 | common = [n for n in common if hasnode(n)] |
|
358 | common = [n for n in common if hasnode(n)] | |
363 | else: |
|
359 | else: | |
364 | common = [nullid] |
|
360 | common = [nullid] | |
365 | if not heads: |
|
361 | if not heads: | |
366 | heads = cl.heads() |
|
362 | heads = cl.heads() | |
367 | return discovery.outgoing(repo, common, heads) |
|
363 | return discovery.outgoing(repo, common, heads) | |
368 |
|
364 | |||
369 |
|
365 | |||
370 | def _checkpublish(pushop): |
|
366 | def _checkpublish(pushop): | |
371 | repo = pushop.repo |
|
367 | repo = pushop.repo | |
372 | ui = repo.ui |
|
368 | ui = repo.ui | |
373 | behavior = ui.config(b'experimental', b'auto-publish') |
|
369 | behavior = ui.config(b'experimental', b'auto-publish') | |
374 | if pushop.publish or behavior not in (b'warn', b'confirm', b'abort'): |
|
370 | if pushop.publish or behavior not in (b'warn', b'confirm', b'abort'): | |
375 | return |
|
371 | return | |
376 | remotephases = listkeys(pushop.remote, b'phases') |
|
372 | remotephases = listkeys(pushop.remote, b'phases') | |
377 | if not remotephases.get(b'publishing', False): |
|
373 | if not remotephases.get(b'publishing', False): | |
378 | return |
|
374 | return | |
379 |
|
375 | |||
380 | if pushop.revs is None: |
|
376 | if pushop.revs is None: | |
381 | published = repo.filtered(b'served').revs(b'not public()') |
|
377 | published = repo.filtered(b'served').revs(b'not public()') | |
382 | else: |
|
378 | else: | |
383 | published = repo.revs(b'::%ln - public()', pushop.revs) |
|
379 | published = repo.revs(b'::%ln - public()', pushop.revs) | |
384 | if published: |
|
380 | if published: | |
385 | if behavior == b'warn': |
|
381 | if behavior == b'warn': | |
386 | ui.warn( |
|
382 | ui.warn( | |
387 | _(b'%i changesets about to be published\n') % len(published) |
|
383 | _(b'%i changesets about to be published\n') % len(published) | |
388 | ) |
|
384 | ) | |
389 | elif behavior == b'confirm': |
|
385 | elif behavior == b'confirm': | |
390 | if ui.promptchoice( |
|
386 | if ui.promptchoice( | |
391 | _(b'push and publish %i changesets (yn)?$$ &Yes $$ &No') |
|
387 | _(b'push and publish %i changesets (yn)?$$ &Yes $$ &No') | |
392 | % len(published) |
|
388 | % len(published) | |
393 | ): |
|
389 | ): | |
394 | raise error.Abort(_(b'user quit')) |
|
390 | raise error.Abort(_(b'user quit')) | |
395 | elif behavior == b'abort': |
|
391 | elif behavior == b'abort': | |
396 | msg = _(b'push would publish %i changesets') % len(published) |
|
392 | msg = _(b'push would publish %i changesets') % len(published) | |
397 | hint = _( |
|
393 | hint = _( | |
398 | b"use --publish or adjust 'experimental.auto-publish'" |
|
394 | b"use --publish or adjust 'experimental.auto-publish'" | |
399 | b" config" |
|
395 | b" config" | |
400 | ) |
|
396 | ) | |
401 | raise error.Abort(msg, hint=hint) |
|
397 | raise error.Abort(msg, hint=hint) | |
402 |
|
398 | |||
403 |
|
399 | |||
404 | def _forcebundle1(op): |
|
400 | def _forcebundle1(op): | |
405 | """return true if a pull/push must use bundle1 |
|
401 | """return true if a pull/push must use bundle1 | |
406 |
|
402 | |||
407 | This function is used to allow testing of the older bundle version""" |
|
403 | This function is used to allow testing of the older bundle version""" | |
408 | ui = op.repo.ui |
|
404 | ui = op.repo.ui | |
409 | # The goal is this config is to allow developer to choose the bundle |
|
405 | # The goal is this config is to allow developer to choose the bundle | |
410 | # version used during exchanged. This is especially handy during test. |
|
406 | # version used during exchanged. This is especially handy during test. | |
411 | # Value is a list of bundle version to be picked from, highest version |
|
407 | # Value is a list of bundle version to be picked from, highest version | |
412 | # should be used. |
|
408 | # should be used. | |
413 | # |
|
409 | # | |
414 | # developer config: devel.legacy.exchange |
|
410 | # developer config: devel.legacy.exchange | |
415 | exchange = ui.configlist(b'devel', b'legacy.exchange') |
|
411 | exchange = ui.configlist(b'devel', b'legacy.exchange') | |
416 | forcebundle1 = b'bundle2' not in exchange and b'bundle1' in exchange |
|
412 | forcebundle1 = b'bundle2' not in exchange and b'bundle1' in exchange | |
417 | return forcebundle1 or not op.remote.capable(b'bundle2') |
|
413 | return forcebundle1 or not op.remote.capable(b'bundle2') | |
418 |
|
414 | |||
419 |
|
415 | |||
420 | class pushoperation(object): |
|
416 | class pushoperation(object): | |
421 | """A object that represent a single push operation |
|
417 | """A object that represent a single push operation | |
422 |
|
418 | |||
423 | Its purpose is to carry push related state and very common operations. |
|
419 | Its purpose is to carry push related state and very common operations. | |
424 |
|
420 | |||
425 | A new pushoperation should be created at the beginning of each push and |
|
421 | A new pushoperation should be created at the beginning of each push and | |
426 | discarded afterward. |
|
422 | discarded afterward. | |
427 | """ |
|
423 | """ | |
428 |
|
424 | |||
429 | def __init__( |
|
425 | def __init__( | |
430 | self, |
|
426 | self, | |
431 | repo, |
|
427 | repo, | |
432 | remote, |
|
428 | remote, | |
433 | force=False, |
|
429 | force=False, | |
434 | revs=None, |
|
430 | revs=None, | |
435 | newbranch=False, |
|
431 | newbranch=False, | |
436 | bookmarks=(), |
|
432 | bookmarks=(), | |
437 | publish=False, |
|
433 | publish=False, | |
438 | pushvars=None, |
|
434 | pushvars=None, | |
439 | ): |
|
435 | ): | |
440 | # repo we push from |
|
436 | # repo we push from | |
441 | self.repo = repo |
|
437 | self.repo = repo | |
442 | self.ui = repo.ui |
|
438 | self.ui = repo.ui | |
443 | # repo we push to |
|
439 | # repo we push to | |
444 | self.remote = remote |
|
440 | self.remote = remote | |
445 | # force option provided |
|
441 | # force option provided | |
446 | self.force = force |
|
442 | self.force = force | |
447 | # revs to be pushed (None is "all") |
|
443 | # revs to be pushed (None is "all") | |
448 | self.revs = revs |
|
444 | self.revs = revs | |
449 | # bookmark explicitly pushed |
|
445 | # bookmark explicitly pushed | |
450 | self.bookmarks = bookmarks |
|
446 | self.bookmarks = bookmarks | |
451 | # allow push of new branch |
|
447 | # allow push of new branch | |
452 | self.newbranch = newbranch |
|
448 | self.newbranch = newbranch | |
453 | # step already performed |
|
449 | # step already performed | |
454 | # (used to check what steps have been already performed through bundle2) |
|
450 | # (used to check what steps have been already performed through bundle2) | |
455 | self.stepsdone = set() |
|
451 | self.stepsdone = set() | |
456 | # Integer version of the changegroup push result |
|
452 | # Integer version of the changegroup push result | |
457 | # - None means nothing to push |
|
453 | # - None means nothing to push | |
458 | # - 0 means HTTP error |
|
454 | # - 0 means HTTP error | |
459 | # - 1 means we pushed and remote head count is unchanged *or* |
|
455 | # - 1 means we pushed and remote head count is unchanged *or* | |
460 | # we have outgoing changesets but refused to push |
|
456 | # we have outgoing changesets but refused to push | |
461 | # - other values as described by addchangegroup() |
|
457 | # - other values as described by addchangegroup() | |
462 | self.cgresult = None |
|
458 | self.cgresult = None | |
463 | # Boolean value for the bookmark push |
|
459 | # Boolean value for the bookmark push | |
464 | self.bkresult = None |
|
460 | self.bkresult = None | |
465 | # discover.outgoing object (contains common and outgoing data) |
|
461 | # discover.outgoing object (contains common and outgoing data) | |
466 | self.outgoing = None |
|
462 | self.outgoing = None | |
467 | # all remote topological heads before the push |
|
463 | # all remote topological heads before the push | |
468 | self.remoteheads = None |
|
464 | self.remoteheads = None | |
469 | # Details of the remote branch pre and post push |
|
465 | # Details of the remote branch pre and post push | |
470 | # |
|
466 | # | |
471 | # mapping: {'branch': ([remoteheads], |
|
467 | # mapping: {'branch': ([remoteheads], | |
472 | # [newheads], |
|
468 | # [newheads], | |
473 | # [unsyncedheads], |
|
469 | # [unsyncedheads], | |
474 | # [discardedheads])} |
|
470 | # [discardedheads])} | |
475 | # - branch: the branch name |
|
471 | # - branch: the branch name | |
476 | # - remoteheads: the list of remote heads known locally |
|
472 | # - remoteheads: the list of remote heads known locally | |
477 | # None if the branch is new |
|
473 | # None if the branch is new | |
478 | # - newheads: the new remote heads (known locally) with outgoing pushed |
|
474 | # - newheads: the new remote heads (known locally) with outgoing pushed | |
479 | # - unsyncedheads: the list of remote heads unknown locally. |
|
475 | # - unsyncedheads: the list of remote heads unknown locally. | |
480 | # - discardedheads: the list of remote heads made obsolete by the push |
|
476 | # - discardedheads: the list of remote heads made obsolete by the push | |
481 | self.pushbranchmap = None |
|
477 | self.pushbranchmap = None | |
482 | # testable as a boolean indicating if any nodes are missing locally. |
|
478 | # testable as a boolean indicating if any nodes are missing locally. | |
483 | self.incoming = None |
|
479 | self.incoming = None | |
484 | # summary of the remote phase situation |
|
480 | # summary of the remote phase situation | |
485 | self.remotephases = None |
|
481 | self.remotephases = None | |
486 | # phases changes that must be pushed along side the changesets |
|
482 | # phases changes that must be pushed along side the changesets | |
487 | self.outdatedphases = None |
|
483 | self.outdatedphases = None | |
488 | # phases changes that must be pushed if changeset push fails |
|
484 | # phases changes that must be pushed if changeset push fails | |
489 | self.fallbackoutdatedphases = None |
|
485 | self.fallbackoutdatedphases = None | |
490 | # outgoing obsmarkers |
|
486 | # outgoing obsmarkers | |
491 | self.outobsmarkers = set() |
|
487 | self.outobsmarkers = set() | |
492 | # outgoing bookmarks, list of (bm, oldnode | '', newnode | '') |
|
488 | # outgoing bookmarks, list of (bm, oldnode | '', newnode | '') | |
493 | self.outbookmarks = [] |
|
489 | self.outbookmarks = [] | |
494 | # transaction manager |
|
490 | # transaction manager | |
495 | self.trmanager = None |
|
491 | self.trmanager = None | |
496 | # map { pushkey partid -> callback handling failure} |
|
492 | # map { pushkey partid -> callback handling failure} | |
497 | # used to handle exception from mandatory pushkey part failure |
|
493 | # used to handle exception from mandatory pushkey part failure | |
498 | self.pkfailcb = {} |
|
494 | self.pkfailcb = {} | |
499 | # an iterable of pushvars or None |
|
495 | # an iterable of pushvars or None | |
500 | self.pushvars = pushvars |
|
496 | self.pushvars = pushvars | |
501 | # publish pushed changesets |
|
497 | # publish pushed changesets | |
502 | self.publish = publish |
|
498 | self.publish = publish | |
503 |
|
499 | |||
504 | @util.propertycache |
|
500 | @util.propertycache | |
505 | def futureheads(self): |
|
501 | def futureheads(self): | |
506 | """future remote heads if the changeset push succeeds""" |
|
502 | """future remote heads if the changeset push succeeds""" | |
507 | return self.outgoing.missingheads |
|
503 | return self.outgoing.missingheads | |
508 |
|
504 | |||
509 | @util.propertycache |
|
505 | @util.propertycache | |
510 | def fallbackheads(self): |
|
506 | def fallbackheads(self): | |
511 | """future remote heads if the changeset push fails""" |
|
507 | """future remote heads if the changeset push fails""" | |
512 | if self.revs is None: |
|
508 | if self.revs is None: | |
513 | # not target to push, all common are relevant |
|
509 | # not target to push, all common are relevant | |
514 | return self.outgoing.commonheads |
|
510 | return self.outgoing.commonheads | |
515 | unfi = self.repo.unfiltered() |
|
511 | unfi = self.repo.unfiltered() | |
516 | # I want cheads = heads(::missingheads and ::commonheads) |
|
512 | # I want cheads = heads(::missingheads and ::commonheads) | |
517 | # (missingheads is revs with secret changeset filtered out) |
|
513 | # (missingheads is revs with secret changeset filtered out) | |
518 | # |
|
514 | # | |
519 | # This can be expressed as: |
|
515 | # This can be expressed as: | |
520 | # cheads = ( (missingheads and ::commonheads) |
|
516 | # cheads = ( (missingheads and ::commonheads) | |
521 | # + (commonheads and ::missingheads))" |
|
517 | # + (commonheads and ::missingheads))" | |
522 | # ) |
|
518 | # ) | |
523 | # |
|
519 | # | |
524 | # while trying to push we already computed the following: |
|
520 | # while trying to push we already computed the following: | |
525 | # common = (::commonheads) |
|
521 | # common = (::commonheads) | |
526 | # missing = ((commonheads::missingheads) - commonheads) |
|
522 | # missing = ((commonheads::missingheads) - commonheads) | |
527 | # |
|
523 | # | |
528 | # We can pick: |
|
524 | # We can pick: | |
529 | # * missingheads part of common (::commonheads) |
|
525 | # * missingheads part of common (::commonheads) | |
530 | common = self.outgoing.common |
|
526 | common = self.outgoing.common | |
531 | nm = self.repo.changelog.nodemap |
|
527 | nm = self.repo.changelog.nodemap | |
532 | cheads = [node for node in self.revs if nm[node] in common] |
|
528 | cheads = [node for node in self.revs if nm[node] in common] | |
533 | # and |
|
529 | # and | |
534 | # * commonheads parents on missing |
|
530 | # * commonheads parents on missing | |
535 | revset = unfi.set( |
|
531 | revset = unfi.set( | |
536 | b'%ln and parents(roots(%ln))', |
|
532 | b'%ln and parents(roots(%ln))', | |
537 | self.outgoing.commonheads, |
|
533 | self.outgoing.commonheads, | |
538 | self.outgoing.missing, |
|
534 | self.outgoing.missing, | |
539 | ) |
|
535 | ) | |
540 | cheads.extend(c.node() for c in revset) |
|
536 | cheads.extend(c.node() for c in revset) | |
541 | return cheads |
|
537 | return cheads | |
542 |
|
538 | |||
543 | @property |
|
539 | @property | |
544 | def commonheads(self): |
|
540 | def commonheads(self): | |
545 | """set of all common heads after changeset bundle push""" |
|
541 | """set of all common heads after changeset bundle push""" | |
546 | if self.cgresult: |
|
542 | if self.cgresult: | |
547 | return self.futureheads |
|
543 | return self.futureheads | |
548 | else: |
|
544 | else: | |
549 | return self.fallbackheads |
|
545 | return self.fallbackheads | |
550 |
|
546 | |||
551 |
|
547 | |||
552 | # mapping of message used when pushing bookmark |
|
548 | # mapping of message used when pushing bookmark | |
553 | bookmsgmap = { |
|
549 | bookmsgmap = { | |
554 | b'update': ( |
|
550 | b'update': ( | |
555 | _(b"updating bookmark %s\n"), |
|
551 | _(b"updating bookmark %s\n"), | |
556 | _(b'updating bookmark %s failed!\n'), |
|
552 | _(b'updating bookmark %s failed!\n'), | |
557 | ), |
|
553 | ), | |
558 | b'export': ( |
|
554 | b'export': ( | |
559 | _(b"exporting bookmark %s\n"), |
|
555 | _(b"exporting bookmark %s\n"), | |
560 | _(b'exporting bookmark %s failed!\n'), |
|
556 | _(b'exporting bookmark %s failed!\n'), | |
561 | ), |
|
557 | ), | |
562 | b'delete': ( |
|
558 | b'delete': ( | |
563 | _(b"deleting remote bookmark %s\n"), |
|
559 | _(b"deleting remote bookmark %s\n"), | |
564 | _(b'deleting remote bookmark %s failed!\n'), |
|
560 | _(b'deleting remote bookmark %s failed!\n'), | |
565 | ), |
|
561 | ), | |
566 | } |
|
562 | } | |
567 |
|
563 | |||
568 |
|
564 | |||
569 | def push( |
|
565 | def push( | |
570 | repo, |
|
566 | repo, | |
571 | remote, |
|
567 | remote, | |
572 | force=False, |
|
568 | force=False, | |
573 | revs=None, |
|
569 | revs=None, | |
574 | newbranch=False, |
|
570 | newbranch=False, | |
575 | bookmarks=(), |
|
571 | bookmarks=(), | |
576 | publish=False, |
|
572 | publish=False, | |
577 | opargs=None, |
|
573 | opargs=None, | |
578 | ): |
|
574 | ): | |
579 | '''Push outgoing changesets (limited by revs) from a local |
|
575 | '''Push outgoing changesets (limited by revs) from a local | |
580 | repository to remote. Return an integer: |
|
576 | repository to remote. Return an integer: | |
581 | - None means nothing to push |
|
577 | - None means nothing to push | |
582 | - 0 means HTTP error |
|
578 | - 0 means HTTP error | |
583 | - 1 means we pushed and remote head count is unchanged *or* |
|
579 | - 1 means we pushed and remote head count is unchanged *or* | |
584 | we have outgoing changesets but refused to push |
|
580 | we have outgoing changesets but refused to push | |
585 | - other values as described by addchangegroup() |
|
581 | - other values as described by addchangegroup() | |
586 | ''' |
|
582 | ''' | |
587 | if opargs is None: |
|
583 | if opargs is None: | |
588 | opargs = {} |
|
584 | opargs = {} | |
589 | pushop = pushoperation( |
|
585 | pushop = pushoperation( | |
590 | repo, |
|
586 | repo, | |
591 | remote, |
|
587 | remote, | |
592 | force, |
|
588 | force, | |
593 | revs, |
|
589 | revs, | |
594 | newbranch, |
|
590 | newbranch, | |
595 | bookmarks, |
|
591 | bookmarks, | |
596 | publish, |
|
592 | publish, | |
597 | **pycompat.strkwargs(opargs) |
|
593 | **pycompat.strkwargs(opargs) | |
598 | ) |
|
594 | ) | |
599 | if pushop.remote.local(): |
|
595 | if pushop.remote.local(): | |
600 | missing = ( |
|
596 | missing = ( | |
601 | set(pushop.repo.requirements) - pushop.remote.local().supported |
|
597 | set(pushop.repo.requirements) - pushop.remote.local().supported | |
602 | ) |
|
598 | ) | |
603 | if missing: |
|
599 | if missing: | |
604 | msg = _( |
|
600 | msg = _( | |
605 | b"required features are not" |
|
601 | b"required features are not" | |
606 | b" supported in the destination:" |
|
602 | b" supported in the destination:" | |
607 | b" %s" |
|
603 | b" %s" | |
608 | ) % (b', '.join(sorted(missing))) |
|
604 | ) % (b', '.join(sorted(missing))) | |
609 | raise error.Abort(msg) |
|
605 | raise error.Abort(msg) | |
610 |
|
606 | |||
611 | if not pushop.remote.canpush(): |
|
607 | if not pushop.remote.canpush(): | |
612 | raise error.Abort(_(b"destination does not support push")) |
|
608 | raise error.Abort(_(b"destination does not support push")) | |
613 |
|
609 | |||
614 | if not pushop.remote.capable(b'unbundle'): |
|
610 | if not pushop.remote.capable(b'unbundle'): | |
615 | raise error.Abort( |
|
611 | raise error.Abort( | |
616 | _( |
|
612 | _( | |
617 | b'cannot push: destination does not support the ' |
|
613 | b'cannot push: destination does not support the ' | |
618 | b'unbundle wire protocol command' |
|
614 | b'unbundle wire protocol command' | |
619 | ) |
|
615 | ) | |
620 | ) |
|
616 | ) | |
621 |
|
617 | |||
622 | # get lock as we might write phase data |
|
618 | # get lock as we might write phase data | |
623 | wlock = lock = None |
|
619 | wlock = lock = None | |
624 | try: |
|
620 | try: | |
625 | # bundle2 push may receive a reply bundle touching bookmarks |
|
621 | # bundle2 push may receive a reply bundle touching bookmarks | |
626 | # requiring the wlock. Take it now to ensure proper ordering. |
|
622 | # requiring the wlock. Take it now to ensure proper ordering. | |
627 | maypushback = pushop.ui.configbool(b'experimental', b'bundle2.pushback') |
|
623 | maypushback = pushop.ui.configbool(b'experimental', b'bundle2.pushback') | |
628 | if ( |
|
624 | if ( | |
629 | (not _forcebundle1(pushop)) |
|
625 | (not _forcebundle1(pushop)) | |
630 | and maypushback |
|
626 | and maypushback | |
631 | and not bookmod.bookmarksinstore(repo) |
|
627 | and not bookmod.bookmarksinstore(repo) | |
632 | ): |
|
628 | ): | |
633 | wlock = pushop.repo.wlock() |
|
629 | wlock = pushop.repo.wlock() | |
634 | lock = pushop.repo.lock() |
|
630 | lock = pushop.repo.lock() | |
635 | pushop.trmanager = transactionmanager( |
|
631 | pushop.trmanager = transactionmanager( | |
636 | pushop.repo, b'push-response', pushop.remote.url() |
|
632 | pushop.repo, b'push-response', pushop.remote.url() | |
637 | ) |
|
633 | ) | |
638 | except error.LockUnavailable as err: |
|
634 | except error.LockUnavailable as err: | |
639 | # source repo cannot be locked. |
|
635 | # source repo cannot be locked. | |
640 | # We do not abort the push, but just disable the local phase |
|
636 | # We do not abort the push, but just disable the local phase | |
641 | # synchronisation. |
|
637 | # synchronisation. | |
642 | msg = b'cannot lock source repository: %s\n' % stringutil.forcebytestr( |
|
638 | msg = b'cannot lock source repository: %s\n' % stringutil.forcebytestr( | |
643 | err |
|
639 | err | |
644 | ) |
|
640 | ) | |
645 | pushop.ui.debug(msg) |
|
641 | pushop.ui.debug(msg) | |
646 |
|
642 | |||
647 | with wlock or util.nullcontextmanager(): |
|
643 | with wlock or util.nullcontextmanager(): | |
648 | with lock or util.nullcontextmanager(): |
|
644 | with lock or util.nullcontextmanager(): | |
649 | with pushop.trmanager or util.nullcontextmanager(): |
|
645 | with pushop.trmanager or util.nullcontextmanager(): | |
650 | pushop.repo.checkpush(pushop) |
|
646 | pushop.repo.checkpush(pushop) | |
651 | _checkpublish(pushop) |
|
647 | _checkpublish(pushop) | |
652 | _pushdiscovery(pushop) |
|
648 | _pushdiscovery(pushop) | |
653 | if not _forcebundle1(pushop): |
|
649 | if not _forcebundle1(pushop): | |
654 | _pushbundle2(pushop) |
|
650 | _pushbundle2(pushop) | |
655 | _pushchangeset(pushop) |
|
651 | _pushchangeset(pushop) | |
656 | _pushsyncphase(pushop) |
|
652 | _pushsyncphase(pushop) | |
657 | _pushobsolete(pushop) |
|
653 | _pushobsolete(pushop) | |
658 | _pushbookmark(pushop) |
|
654 | _pushbookmark(pushop) | |
659 |
|
655 | |||
660 | if repo.ui.configbool(b'experimental', b'remotenames'): |
|
656 | if repo.ui.configbool(b'experimental', b'remotenames'): | |
661 | logexchange.pullremotenames(repo, remote) |
|
657 | logexchange.pullremotenames(repo, remote) | |
662 |
|
658 | |||
663 | return pushop |
|
659 | return pushop | |
664 |
|
660 | |||
665 |
|
661 | |||
666 | # list of steps to perform discovery before push |
|
662 | # list of steps to perform discovery before push | |
667 | pushdiscoveryorder = [] |
|
663 | pushdiscoveryorder = [] | |
668 |
|
664 | |||
669 | # Mapping between step name and function |
|
665 | # Mapping between step name and function | |
670 | # |
|
666 | # | |
671 | # This exists to help extensions wrap steps if necessary |
|
667 | # This exists to help extensions wrap steps if necessary | |
672 | pushdiscoverymapping = {} |
|
668 | pushdiscoverymapping = {} | |
673 |
|
669 | |||
674 |
|
670 | |||
675 | def pushdiscovery(stepname): |
|
671 | def pushdiscovery(stepname): | |
676 | """decorator for function performing discovery before push |
|
672 | """decorator for function performing discovery before push | |
677 |
|
673 | |||
678 | The function is added to the step -> function mapping and appended to the |
|
674 | The function is added to the step -> function mapping and appended to the | |
679 | list of steps. Beware that decorated function will be added in order (this |
|
675 | list of steps. Beware that decorated function will be added in order (this | |
680 | may matter). |
|
676 | may matter). | |
681 |
|
677 | |||
682 | You can only use this decorator for a new step, if you want to wrap a step |
|
678 | You can only use this decorator for a new step, if you want to wrap a step | |
683 | from an extension, change the pushdiscovery dictionary directly.""" |
|
679 | from an extension, change the pushdiscovery dictionary directly.""" | |
684 |
|
680 | |||
685 | def dec(func): |
|
681 | def dec(func): | |
686 | assert stepname not in pushdiscoverymapping |
|
682 | assert stepname not in pushdiscoverymapping | |
687 | pushdiscoverymapping[stepname] = func |
|
683 | pushdiscoverymapping[stepname] = func | |
688 | pushdiscoveryorder.append(stepname) |
|
684 | pushdiscoveryorder.append(stepname) | |
689 | return func |
|
685 | return func | |
690 |
|
686 | |||
691 | return dec |
|
687 | return dec | |
692 |
|
688 | |||
693 |
|
689 | |||
694 | def _pushdiscovery(pushop): |
|
690 | def _pushdiscovery(pushop): | |
695 | """Run all discovery steps""" |
|
691 | """Run all discovery steps""" | |
696 | for stepname in pushdiscoveryorder: |
|
692 | for stepname in pushdiscoveryorder: | |
697 | step = pushdiscoverymapping[stepname] |
|
693 | step = pushdiscoverymapping[stepname] | |
698 | step(pushop) |
|
694 | step(pushop) | |
699 |
|
695 | |||
700 |
|
696 | |||
701 | @pushdiscovery(b'changeset') |
|
697 | @pushdiscovery(b'changeset') | |
702 | def _pushdiscoverychangeset(pushop): |
|
698 | def _pushdiscoverychangeset(pushop): | |
703 | """discover the changeset that need to be pushed""" |
|
699 | """discover the changeset that need to be pushed""" | |
704 | fci = discovery.findcommonincoming |
|
700 | fci = discovery.findcommonincoming | |
705 | if pushop.revs: |
|
701 | if pushop.revs: | |
706 | commoninc = fci( |
|
702 | commoninc = fci( | |
707 | pushop.repo, |
|
703 | pushop.repo, | |
708 | pushop.remote, |
|
704 | pushop.remote, | |
709 | force=pushop.force, |
|
705 | force=pushop.force, | |
710 | ancestorsof=pushop.revs, |
|
706 | ancestorsof=pushop.revs, | |
711 | ) |
|
707 | ) | |
712 | else: |
|
708 | else: | |
713 | commoninc = fci(pushop.repo, pushop.remote, force=pushop.force) |
|
709 | commoninc = fci(pushop.repo, pushop.remote, force=pushop.force) | |
714 | common, inc, remoteheads = commoninc |
|
710 | common, inc, remoteheads = commoninc | |
715 | fco = discovery.findcommonoutgoing |
|
711 | fco = discovery.findcommonoutgoing | |
716 | outgoing = fco( |
|
712 | outgoing = fco( | |
717 | pushop.repo, |
|
713 | pushop.repo, | |
718 | pushop.remote, |
|
714 | pushop.remote, | |
719 | onlyheads=pushop.revs, |
|
715 | onlyheads=pushop.revs, | |
720 | commoninc=commoninc, |
|
716 | commoninc=commoninc, | |
721 | force=pushop.force, |
|
717 | force=pushop.force, | |
722 | ) |
|
718 | ) | |
723 | pushop.outgoing = outgoing |
|
719 | pushop.outgoing = outgoing | |
724 | pushop.remoteheads = remoteheads |
|
720 | pushop.remoteheads = remoteheads | |
725 | pushop.incoming = inc |
|
721 | pushop.incoming = inc | |
726 |
|
722 | |||
727 |
|
723 | |||
728 | @pushdiscovery(b'phase') |
|
724 | @pushdiscovery(b'phase') | |
729 | def _pushdiscoveryphase(pushop): |
|
725 | def _pushdiscoveryphase(pushop): | |
730 | """discover the phase that needs to be pushed |
|
726 | """discover the phase that needs to be pushed | |
731 |
|
727 | |||
732 | (computed for both success and failure case for changesets push)""" |
|
728 | (computed for both success and failure case for changesets push)""" | |
733 | outgoing = pushop.outgoing |
|
729 | outgoing = pushop.outgoing | |
734 | unfi = pushop.repo.unfiltered() |
|
730 | unfi = pushop.repo.unfiltered() | |
735 | remotephases = listkeys(pushop.remote, b'phases') |
|
731 | remotephases = listkeys(pushop.remote, b'phases') | |
736 |
|
732 | |||
737 | if ( |
|
733 | if ( | |
738 | pushop.ui.configbool(b'ui', b'_usedassubrepo') |
|
734 | pushop.ui.configbool(b'ui', b'_usedassubrepo') | |
739 | and remotephases # server supports phases |
|
735 | and remotephases # server supports phases | |
740 | and not pushop.outgoing.missing # no changesets to be pushed |
|
736 | and not pushop.outgoing.missing # no changesets to be pushed | |
741 | and remotephases.get(b'publishing', False) |
|
737 | and remotephases.get(b'publishing', False) | |
742 | ): |
|
738 | ): | |
743 | # When: |
|
739 | # When: | |
744 | # - this is a subrepo push |
|
740 | # - this is a subrepo push | |
745 | # - and remote support phase |
|
741 | # - and remote support phase | |
746 | # - and no changeset are to be pushed |
|
742 | # - and no changeset are to be pushed | |
747 | # - and remote is publishing |
|
743 | # - and remote is publishing | |
748 | # We may be in issue 3781 case! |
|
744 | # We may be in issue 3781 case! | |
749 | # We drop the possible phase synchronisation done by |
|
745 | # We drop the possible phase synchronisation done by | |
750 | # courtesy to publish changesets possibly locally draft |
|
746 | # courtesy to publish changesets possibly locally draft | |
751 | # on the remote. |
|
747 | # on the remote. | |
752 | pushop.outdatedphases = [] |
|
748 | pushop.outdatedphases = [] | |
753 | pushop.fallbackoutdatedphases = [] |
|
749 | pushop.fallbackoutdatedphases = [] | |
754 | return |
|
750 | return | |
755 |
|
751 | |||
756 | pushop.remotephases = phases.remotephasessummary( |
|
752 | pushop.remotephases = phases.remotephasessummary( | |
757 | pushop.repo, pushop.fallbackheads, remotephases |
|
753 | pushop.repo, pushop.fallbackheads, remotephases | |
758 | ) |
|
754 | ) | |
759 | droots = pushop.remotephases.draftroots |
|
755 | droots = pushop.remotephases.draftroots | |
760 |
|
756 | |||
761 | extracond = b'' |
|
757 | extracond = b'' | |
762 | if not pushop.remotephases.publishing: |
|
758 | if not pushop.remotephases.publishing: | |
763 | extracond = b' and public()' |
|
759 | extracond = b' and public()' | |
764 | revset = b'heads((%%ln::%%ln) %s)' % extracond |
|
760 | revset = b'heads((%%ln::%%ln) %s)' % extracond | |
765 | # Get the list of all revs draft on remote by public here. |
|
761 | # Get the list of all revs draft on remote by public here. | |
766 | # XXX Beware that revset break if droots is not strictly |
|
762 | # XXX Beware that revset break if droots is not strictly | |
767 | # XXX root we may want to ensure it is but it is costly |
|
763 | # XXX root we may want to ensure it is but it is costly | |
768 | fallback = list(unfi.set(revset, droots, pushop.fallbackheads)) |
|
764 | fallback = list(unfi.set(revset, droots, pushop.fallbackheads)) | |
769 | if not pushop.remotephases.publishing and pushop.publish: |
|
765 | if not pushop.remotephases.publishing and pushop.publish: | |
770 | future = list( |
|
766 | future = list( | |
771 | unfi.set( |
|
767 | unfi.set( | |
772 | b'%ln and (not public() or %ln::)', pushop.futureheads, droots |
|
768 | b'%ln and (not public() or %ln::)', pushop.futureheads, droots | |
773 | ) |
|
769 | ) | |
774 | ) |
|
770 | ) | |
775 | elif not outgoing.missing: |
|
771 | elif not outgoing.missing: | |
776 | future = fallback |
|
772 | future = fallback | |
777 | else: |
|
773 | else: | |
778 | # adds changeset we are going to push as draft |
|
774 | # adds changeset we are going to push as draft | |
779 | # |
|
775 | # | |
780 | # should not be necessary for publishing server, but because of an |
|
776 | # should not be necessary for publishing server, but because of an | |
781 | # issue fixed in xxxxx we have to do it anyway. |
|
777 | # issue fixed in xxxxx we have to do it anyway. | |
782 | fdroots = list( |
|
778 | fdroots = list( | |
783 | unfi.set(b'roots(%ln + %ln::)', outgoing.missing, droots) |
|
779 | unfi.set(b'roots(%ln + %ln::)', outgoing.missing, droots) | |
784 | ) |
|
780 | ) | |
785 | fdroots = [f.node() for f in fdroots] |
|
781 | fdroots = [f.node() for f in fdroots] | |
786 | future = list(unfi.set(revset, fdroots, pushop.futureheads)) |
|
782 | future = list(unfi.set(revset, fdroots, pushop.futureheads)) | |
787 | pushop.outdatedphases = future |
|
783 | pushop.outdatedphases = future | |
788 | pushop.fallbackoutdatedphases = fallback |
|
784 | pushop.fallbackoutdatedphases = fallback | |
789 |
|
785 | |||
790 |
|
786 | |||
791 | @pushdiscovery(b'obsmarker') |
|
787 | @pushdiscovery(b'obsmarker') | |
792 | def _pushdiscoveryobsmarkers(pushop): |
|
788 | def _pushdiscoveryobsmarkers(pushop): | |
793 | if not obsolete.isenabled(pushop.repo, obsolete.exchangeopt): |
|
789 | if not obsolete.isenabled(pushop.repo, obsolete.exchangeopt): | |
794 | return |
|
790 | return | |
795 |
|
791 | |||
796 | if not pushop.repo.obsstore: |
|
792 | if not pushop.repo.obsstore: | |
797 | return |
|
793 | return | |
798 |
|
794 | |||
799 | if b'obsolete' not in listkeys(pushop.remote, b'namespaces'): |
|
795 | if b'obsolete' not in listkeys(pushop.remote, b'namespaces'): | |
800 | return |
|
796 | return | |
801 |
|
797 | |||
802 | repo = pushop.repo |
|
798 | repo = pushop.repo | |
803 | # very naive computation, that can be quite expensive on big repo. |
|
799 | # very naive computation, that can be quite expensive on big repo. | |
804 | # However: evolution is currently slow on them anyway. |
|
800 | # However: evolution is currently slow on them anyway. | |
805 | nodes = (c.node() for c in repo.set(b'::%ln', pushop.futureheads)) |
|
801 | nodes = (c.node() for c in repo.set(b'::%ln', pushop.futureheads)) | |
806 | pushop.outobsmarkers = pushop.repo.obsstore.relevantmarkers(nodes) |
|
802 | pushop.outobsmarkers = pushop.repo.obsstore.relevantmarkers(nodes) | |
807 |
|
803 | |||
808 |
|
804 | |||
809 | @pushdiscovery(b'bookmarks') |
|
805 | @pushdiscovery(b'bookmarks') | |
810 | def _pushdiscoverybookmarks(pushop): |
|
806 | def _pushdiscoverybookmarks(pushop): | |
811 | ui = pushop.ui |
|
807 | ui = pushop.ui | |
812 | repo = pushop.repo.unfiltered() |
|
808 | repo = pushop.repo.unfiltered() | |
813 | remote = pushop.remote |
|
809 | remote = pushop.remote | |
814 | ui.debug(b"checking for updated bookmarks\n") |
|
810 | ui.debug(b"checking for updated bookmarks\n") | |
815 | ancestors = () |
|
811 | ancestors = () | |
816 | if pushop.revs: |
|
812 | if pushop.revs: | |
817 | revnums = pycompat.maplist(repo.changelog.rev, pushop.revs) |
|
813 | revnums = pycompat.maplist(repo.changelog.rev, pushop.revs) | |
818 | ancestors = repo.changelog.ancestors(revnums, inclusive=True) |
|
814 | ancestors = repo.changelog.ancestors(revnums, inclusive=True) | |
819 |
|
815 | |||
820 | remotebookmark = bookmod.unhexlifybookmarks(listkeys(remote, b'bookmarks')) |
|
816 | remotebookmark = bookmod.unhexlifybookmarks(listkeys(remote, b'bookmarks')) | |
821 |
|
817 | |||
822 | explicit = { |
|
818 | explicit = { | |
823 | repo._bookmarks.expandname(bookmark) for bookmark in pushop.bookmarks |
|
819 | repo._bookmarks.expandname(bookmark) for bookmark in pushop.bookmarks | |
824 | } |
|
820 | } | |
825 |
|
821 | |||
826 | comp = bookmod.comparebookmarks(repo, repo._bookmarks, remotebookmark) |
|
822 | comp = bookmod.comparebookmarks(repo, repo._bookmarks, remotebookmark) | |
827 | return _processcompared(pushop, ancestors, explicit, remotebookmark, comp) |
|
823 | return _processcompared(pushop, ancestors, explicit, remotebookmark, comp) | |
828 |
|
824 | |||
829 |
|
825 | |||
830 | def _processcompared(pushop, pushed, explicit, remotebms, comp): |
|
826 | def _processcompared(pushop, pushed, explicit, remotebms, comp): | |
831 | """take decision on bookmarks to push to the remote repo |
|
827 | """take decision on bookmarks to push to the remote repo | |
832 |
|
828 | |||
833 | Exists to help extensions alter this behavior. |
|
829 | Exists to help extensions alter this behavior. | |
834 | """ |
|
830 | """ | |
835 | addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = comp |
|
831 | addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = comp | |
836 |
|
832 | |||
837 | repo = pushop.repo |
|
833 | repo = pushop.repo | |
838 |
|
834 | |||
839 | for b, scid, dcid in advsrc: |
|
835 | for b, scid, dcid in advsrc: | |
840 | if b in explicit: |
|
836 | if b in explicit: | |
841 | explicit.remove(b) |
|
837 | explicit.remove(b) | |
842 | if not pushed or repo[scid].rev() in pushed: |
|
838 | if not pushed or repo[scid].rev() in pushed: | |
843 | pushop.outbookmarks.append((b, dcid, scid)) |
|
839 | pushop.outbookmarks.append((b, dcid, scid)) | |
844 | # search added bookmark |
|
840 | # search added bookmark | |
845 | for b, scid, dcid in addsrc: |
|
841 | for b, scid, dcid in addsrc: | |
846 | if b in explicit: |
|
842 | if b in explicit: | |
847 | explicit.remove(b) |
|
843 | explicit.remove(b) | |
848 | pushop.outbookmarks.append((b, b'', scid)) |
|
844 | pushop.outbookmarks.append((b, b'', scid)) | |
849 | # search for overwritten bookmark |
|
845 | # search for overwritten bookmark | |
850 | for b, scid, dcid in list(advdst) + list(diverge) + list(differ): |
|
846 | for b, scid, dcid in list(advdst) + list(diverge) + list(differ): | |
851 | if b in explicit: |
|
847 | if b in explicit: | |
852 | explicit.remove(b) |
|
848 | explicit.remove(b) | |
853 | pushop.outbookmarks.append((b, dcid, scid)) |
|
849 | pushop.outbookmarks.append((b, dcid, scid)) | |
854 | # search for bookmark to delete |
|
850 | # search for bookmark to delete | |
855 | for b, scid, dcid in adddst: |
|
851 | for b, scid, dcid in adddst: | |
856 | if b in explicit: |
|
852 | if b in explicit: | |
857 | explicit.remove(b) |
|
853 | explicit.remove(b) | |
858 | # treat as "deleted locally" |
|
854 | # treat as "deleted locally" | |
859 | pushop.outbookmarks.append((b, dcid, b'')) |
|
855 | pushop.outbookmarks.append((b, dcid, b'')) | |
860 | # identical bookmarks shouldn't get reported |
|
856 | # identical bookmarks shouldn't get reported | |
861 | for b, scid, dcid in same: |
|
857 | for b, scid, dcid in same: | |
862 | if b in explicit: |
|
858 | if b in explicit: | |
863 | explicit.remove(b) |
|
859 | explicit.remove(b) | |
864 |
|
860 | |||
865 | if explicit: |
|
861 | if explicit: | |
866 | explicit = sorted(explicit) |
|
862 | explicit = sorted(explicit) | |
867 | # we should probably list all of them |
|
863 | # we should probably list all of them | |
868 | pushop.ui.warn( |
|
864 | pushop.ui.warn( | |
869 | _( |
|
865 | _( | |
870 | b'bookmark %s does not exist on the local ' |
|
866 | b'bookmark %s does not exist on the local ' | |
871 | b'or remote repository!\n' |
|
867 | b'or remote repository!\n' | |
872 | ) |
|
868 | ) | |
873 | % explicit[0] |
|
869 | % explicit[0] | |
874 | ) |
|
870 | ) | |
875 | pushop.bkresult = 2 |
|
871 | pushop.bkresult = 2 | |
876 |
|
872 | |||
877 | pushop.outbookmarks.sort() |
|
873 | pushop.outbookmarks.sort() | |
878 |
|
874 | |||
879 |
|
875 | |||
880 | def _pushcheckoutgoing(pushop): |
|
876 | def _pushcheckoutgoing(pushop): | |
881 | outgoing = pushop.outgoing |
|
877 | outgoing = pushop.outgoing | |
882 | unfi = pushop.repo.unfiltered() |
|
878 | unfi = pushop.repo.unfiltered() | |
883 | if not outgoing.missing: |
|
879 | if not outgoing.missing: | |
884 | # nothing to push |
|
880 | # nothing to push | |
885 | scmutil.nochangesfound(unfi.ui, unfi, outgoing.excluded) |
|
881 | scmutil.nochangesfound(unfi.ui, unfi, outgoing.excluded) | |
886 | return False |
|
882 | return False | |
887 | # something to push |
|
883 | # something to push | |
888 | if not pushop.force: |
|
884 | if not pushop.force: | |
889 | # if repo.obsstore == False --> no obsolete |
|
885 | # if repo.obsstore == False --> no obsolete | |
890 | # then, save the iteration |
|
886 | # then, save the iteration | |
891 | if unfi.obsstore: |
|
887 | if unfi.obsstore: | |
892 | # this message are here for 80 char limit reason |
|
888 | # this message are here for 80 char limit reason | |
893 | mso = _(b"push includes obsolete changeset: %s!") |
|
889 | mso = _(b"push includes obsolete changeset: %s!") | |
894 | mspd = _(b"push includes phase-divergent changeset: %s!") |
|
890 | mspd = _(b"push includes phase-divergent changeset: %s!") | |
895 | mscd = _(b"push includes content-divergent changeset: %s!") |
|
891 | mscd = _(b"push includes content-divergent changeset: %s!") | |
896 | mst = { |
|
892 | mst = { | |
897 | b"orphan": _(b"push includes orphan changeset: %s!"), |
|
893 | b"orphan": _(b"push includes orphan changeset: %s!"), | |
898 | b"phase-divergent": mspd, |
|
894 | b"phase-divergent": mspd, | |
899 | b"content-divergent": mscd, |
|
895 | b"content-divergent": mscd, | |
900 | } |
|
896 | } | |
901 | # If we are to push if there is at least one |
|
897 | # If we are to push if there is at least one | |
902 | # obsolete or unstable changeset in missing, at |
|
898 | # obsolete or unstable changeset in missing, at | |
903 | # least one of the missinghead will be obsolete or |
|
899 | # least one of the missinghead will be obsolete or | |
904 | # unstable. So checking heads only is ok |
|
900 | # unstable. So checking heads only is ok | |
905 | for node in outgoing.missingheads: |
|
901 | for node in outgoing.missingheads: | |
906 | ctx = unfi[node] |
|
902 | ctx = unfi[node] | |
907 | if ctx.obsolete(): |
|
903 | if ctx.obsolete(): | |
908 | raise error.Abort(mso % ctx) |
|
904 | raise error.Abort(mso % ctx) | |
909 | elif ctx.isunstable(): |
|
905 | elif ctx.isunstable(): | |
910 | # TODO print more than one instability in the abort |
|
906 | # TODO print more than one instability in the abort | |
911 | # message |
|
907 | # message | |
912 | raise error.Abort(mst[ctx.instabilities()[0]] % ctx) |
|
908 | raise error.Abort(mst[ctx.instabilities()[0]] % ctx) | |
913 |
|
909 | |||
914 | discovery.checkheads(pushop) |
|
910 | discovery.checkheads(pushop) | |
915 | return True |
|
911 | return True | |
916 |
|
912 | |||
917 |
|
913 | |||
918 | # List of names of steps to perform for an outgoing bundle2, order matters. |
|
914 | # List of names of steps to perform for an outgoing bundle2, order matters. | |
919 | b2partsgenorder = [] |
|
915 | b2partsgenorder = [] | |
920 |
|
916 | |||
921 | # Mapping between step name and function |
|
917 | # Mapping between step name and function | |
922 | # |
|
918 | # | |
923 | # This exists to help extensions wrap steps if necessary |
|
919 | # This exists to help extensions wrap steps if necessary | |
924 | b2partsgenmapping = {} |
|
920 | b2partsgenmapping = {} | |
925 |
|
921 | |||
926 |
|
922 | |||
927 | def b2partsgenerator(stepname, idx=None): |
|
923 | def b2partsgenerator(stepname, idx=None): | |
928 | """decorator for function generating bundle2 part |
|
924 | """decorator for function generating bundle2 part | |
929 |
|
925 | |||
930 | The function is added to the step -> function mapping and appended to the |
|
926 | The function is added to the step -> function mapping and appended to the | |
931 | list of steps. Beware that decorated functions will be added in order |
|
927 | list of steps. Beware that decorated functions will be added in order | |
932 | (this may matter). |
|
928 | (this may matter). | |
933 |
|
929 | |||
934 | You can only use this decorator for new steps, if you want to wrap a step |
|
930 | You can only use this decorator for new steps, if you want to wrap a step | |
935 | from an extension, attack the b2partsgenmapping dictionary directly.""" |
|
931 | from an extension, attack the b2partsgenmapping dictionary directly.""" | |
936 |
|
932 | |||
937 | def dec(func): |
|
933 | def dec(func): | |
938 | assert stepname not in b2partsgenmapping |
|
934 | assert stepname not in b2partsgenmapping | |
939 | b2partsgenmapping[stepname] = func |
|
935 | b2partsgenmapping[stepname] = func | |
940 | if idx is None: |
|
936 | if idx is None: | |
941 | b2partsgenorder.append(stepname) |
|
937 | b2partsgenorder.append(stepname) | |
942 | else: |
|
938 | else: | |
943 | b2partsgenorder.insert(idx, stepname) |
|
939 | b2partsgenorder.insert(idx, stepname) | |
944 | return func |
|
940 | return func | |
945 |
|
941 | |||
946 | return dec |
|
942 | return dec | |
947 |
|
943 | |||
948 |
|
944 | |||
949 | def _pushb2ctxcheckheads(pushop, bundler): |
|
945 | def _pushb2ctxcheckheads(pushop, bundler): | |
950 | """Generate race condition checking parts |
|
946 | """Generate race condition checking parts | |
951 |
|
947 | |||
952 | Exists as an independent function to aid extensions |
|
948 | Exists as an independent function to aid extensions | |
953 | """ |
|
949 | """ | |
954 | # * 'force' do not check for push race, |
|
950 | # * 'force' do not check for push race, | |
955 | # * if we don't push anything, there are nothing to check. |
|
951 | # * if we don't push anything, there are nothing to check. | |
956 | if not pushop.force and pushop.outgoing.missingheads: |
|
952 | if not pushop.force and pushop.outgoing.missingheads: | |
957 | allowunrelated = b'related' in bundler.capabilities.get( |
|
953 | allowunrelated = b'related' in bundler.capabilities.get( | |
958 | b'checkheads', () |
|
954 | b'checkheads', () | |
959 | ) |
|
955 | ) | |
960 | emptyremote = pushop.pushbranchmap is None |
|
956 | emptyremote = pushop.pushbranchmap is None | |
961 | if not allowunrelated or emptyremote: |
|
957 | if not allowunrelated or emptyremote: | |
962 | bundler.newpart(b'check:heads', data=iter(pushop.remoteheads)) |
|
958 | bundler.newpart(b'check:heads', data=iter(pushop.remoteheads)) | |
963 | else: |
|
959 | else: | |
964 | affected = set() |
|
960 | affected = set() | |
965 | for branch, heads in pycompat.iteritems(pushop.pushbranchmap): |
|
961 | for branch, heads in pycompat.iteritems(pushop.pushbranchmap): | |
966 | remoteheads, newheads, unsyncedheads, discardedheads = heads |
|
962 | remoteheads, newheads, unsyncedheads, discardedheads = heads | |
967 | if remoteheads is not None: |
|
963 | if remoteheads is not None: | |
968 | remote = set(remoteheads) |
|
964 | remote = set(remoteheads) | |
969 | affected |= set(discardedheads) & remote |
|
965 | affected |= set(discardedheads) & remote | |
970 | affected |= remote - set(newheads) |
|
966 | affected |= remote - set(newheads) | |
971 | if affected: |
|
967 | if affected: | |
972 | data = iter(sorted(affected)) |
|
968 | data = iter(sorted(affected)) | |
973 | bundler.newpart(b'check:updated-heads', data=data) |
|
969 | bundler.newpart(b'check:updated-heads', data=data) | |
974 |
|
970 | |||
975 |
|
971 | |||
976 | def _pushing(pushop): |
|
972 | def _pushing(pushop): | |
977 | """return True if we are pushing anything""" |
|
973 | """return True if we are pushing anything""" | |
978 | return bool( |
|
974 | return bool( | |
979 | pushop.outgoing.missing |
|
975 | pushop.outgoing.missing | |
980 | or pushop.outdatedphases |
|
976 | or pushop.outdatedphases | |
981 | or pushop.outobsmarkers |
|
977 | or pushop.outobsmarkers | |
982 | or pushop.outbookmarks |
|
978 | or pushop.outbookmarks | |
983 | ) |
|
979 | ) | |
984 |
|
980 | |||
985 |
|
981 | |||
986 | @b2partsgenerator(b'check-bookmarks') |
|
982 | @b2partsgenerator(b'check-bookmarks') | |
987 | def _pushb2checkbookmarks(pushop, bundler): |
|
983 | def _pushb2checkbookmarks(pushop, bundler): | |
988 | """insert bookmark move checking""" |
|
984 | """insert bookmark move checking""" | |
989 | if not _pushing(pushop) or pushop.force: |
|
985 | if not _pushing(pushop) or pushop.force: | |
990 | return |
|
986 | return | |
991 | b2caps = bundle2.bundle2caps(pushop.remote) |
|
987 | b2caps = bundle2.bundle2caps(pushop.remote) | |
992 | hasbookmarkcheck = b'bookmarks' in b2caps |
|
988 | hasbookmarkcheck = b'bookmarks' in b2caps | |
993 | if not (pushop.outbookmarks and hasbookmarkcheck): |
|
989 | if not (pushop.outbookmarks and hasbookmarkcheck): | |
994 | return |
|
990 | return | |
995 | data = [] |
|
991 | data = [] | |
996 | for book, old, new in pushop.outbookmarks: |
|
992 | for book, old, new in pushop.outbookmarks: | |
997 | data.append((book, old)) |
|
993 | data.append((book, old)) | |
998 | checkdata = bookmod.binaryencode(data) |
|
994 | checkdata = bookmod.binaryencode(data) | |
999 | bundler.newpart(b'check:bookmarks', data=checkdata) |
|
995 | bundler.newpart(b'check:bookmarks', data=checkdata) | |
1000 |
|
996 | |||
1001 |
|
997 | |||
1002 | @b2partsgenerator(b'check-phases') |
|
998 | @b2partsgenerator(b'check-phases') | |
1003 | def _pushb2checkphases(pushop, bundler): |
|
999 | def _pushb2checkphases(pushop, bundler): | |
1004 | """insert phase move checking""" |
|
1000 | """insert phase move checking""" | |
1005 | if not _pushing(pushop) or pushop.force: |
|
1001 | if not _pushing(pushop) or pushop.force: | |
1006 | return |
|
1002 | return | |
1007 | b2caps = bundle2.bundle2caps(pushop.remote) |
|
1003 | b2caps = bundle2.bundle2caps(pushop.remote) | |
1008 | hasphaseheads = b'heads' in b2caps.get(b'phases', ()) |
|
1004 | hasphaseheads = b'heads' in b2caps.get(b'phases', ()) | |
1009 | if pushop.remotephases is not None and hasphaseheads: |
|
1005 | if pushop.remotephases is not None and hasphaseheads: | |
1010 | # check that the remote phase has not changed |
|
1006 | # check that the remote phase has not changed | |
1011 | checks = [[] for p in phases.allphases] |
|
1007 | checks = [[] for p in phases.allphases] | |
1012 | checks[phases.public].extend(pushop.remotephases.publicheads) |
|
1008 | checks[phases.public].extend(pushop.remotephases.publicheads) | |
1013 | checks[phases.draft].extend(pushop.remotephases.draftroots) |
|
1009 | checks[phases.draft].extend(pushop.remotephases.draftroots) | |
1014 | if any(checks): |
|
1010 | if any(checks): | |
1015 | for nodes in checks: |
|
1011 | for nodes in checks: | |
1016 | nodes.sort() |
|
1012 | nodes.sort() | |
1017 | checkdata = phases.binaryencode(checks) |
|
1013 | checkdata = phases.binaryencode(checks) | |
1018 | bundler.newpart(b'check:phases', data=checkdata) |
|
1014 | bundler.newpart(b'check:phases', data=checkdata) | |
1019 |
|
1015 | |||
1020 |
|
1016 | |||
1021 | @b2partsgenerator(b'changeset') |
|
1017 | @b2partsgenerator(b'changeset') | |
1022 | def _pushb2ctx(pushop, bundler): |
|
1018 | def _pushb2ctx(pushop, bundler): | |
1023 | """handle changegroup push through bundle2 |
|
1019 | """handle changegroup push through bundle2 | |
1024 |
|
1020 | |||
1025 | addchangegroup result is stored in the ``pushop.cgresult`` attribute. |
|
1021 | addchangegroup result is stored in the ``pushop.cgresult`` attribute. | |
1026 | """ |
|
1022 | """ | |
1027 | if b'changesets' in pushop.stepsdone: |
|
1023 | if b'changesets' in pushop.stepsdone: | |
1028 | return |
|
1024 | return | |
1029 | pushop.stepsdone.add(b'changesets') |
|
1025 | pushop.stepsdone.add(b'changesets') | |
1030 | # Send known heads to the server for race detection. |
|
1026 | # Send known heads to the server for race detection. | |
1031 | if not _pushcheckoutgoing(pushop): |
|
1027 | if not _pushcheckoutgoing(pushop): | |
1032 | return |
|
1028 | return | |
1033 | pushop.repo.prepushoutgoinghooks(pushop) |
|
1029 | pushop.repo.prepushoutgoinghooks(pushop) | |
1034 |
|
1030 | |||
1035 | _pushb2ctxcheckheads(pushop, bundler) |
|
1031 | _pushb2ctxcheckheads(pushop, bundler) | |
1036 |
|
1032 | |||
1037 | b2caps = bundle2.bundle2caps(pushop.remote) |
|
1033 | b2caps = bundle2.bundle2caps(pushop.remote) | |
1038 | version = b'01' |
|
1034 | version = b'01' | |
1039 | cgversions = b2caps.get(b'changegroup') |
|
1035 | cgversions = b2caps.get(b'changegroup') | |
1040 | if cgversions: # 3.1 and 3.2 ship with an empty value |
|
1036 | if cgversions: # 3.1 and 3.2 ship with an empty value | |
1041 | cgversions = [ |
|
1037 | cgversions = [ | |
1042 | v |
|
1038 | v | |
1043 | for v in cgversions |
|
1039 | for v in cgversions | |
1044 | if v in changegroup.supportedoutgoingversions(pushop.repo) |
|
1040 | if v in changegroup.supportedoutgoingversions(pushop.repo) | |
1045 | ] |
|
1041 | ] | |
1046 | if not cgversions: |
|
1042 | if not cgversions: | |
1047 | raise error.Abort(_(b'no common changegroup version')) |
|
1043 | raise error.Abort(_(b'no common changegroup version')) | |
1048 | version = max(cgversions) |
|
1044 | version = max(cgversions) | |
1049 | cgstream = changegroup.makestream( |
|
1045 | cgstream = changegroup.makestream( | |
1050 | pushop.repo, pushop.outgoing, version, b'push' |
|
1046 | pushop.repo, pushop.outgoing, version, b'push' | |
1051 | ) |
|
1047 | ) | |
1052 | cgpart = bundler.newpart(b'changegroup', data=cgstream) |
|
1048 | cgpart = bundler.newpart(b'changegroup', data=cgstream) | |
1053 | if cgversions: |
|
1049 | if cgversions: | |
1054 | cgpart.addparam(b'version', version) |
|
1050 | cgpart.addparam(b'version', version) | |
1055 | if b'treemanifest' in pushop.repo.requirements: |
|
1051 | if b'treemanifest' in pushop.repo.requirements: | |
1056 | cgpart.addparam(b'treemanifest', b'1') |
|
1052 | cgpart.addparam(b'treemanifest', b'1') | |
1057 | if b'exp-sidedata-flag' in pushop.repo.requirements: |
|
1053 | if b'exp-sidedata-flag' in pushop.repo.requirements: | |
1058 | cgpart.addparam(b'exp-sidedata', b'1') |
|
1054 | cgpart.addparam(b'exp-sidedata', b'1') | |
1059 |
|
1055 | |||
1060 | def handlereply(op): |
|
1056 | def handlereply(op): | |
1061 | """extract addchangegroup returns from server reply""" |
|
1057 | """extract addchangegroup returns from server reply""" | |
1062 | cgreplies = op.records.getreplies(cgpart.id) |
|
1058 | cgreplies = op.records.getreplies(cgpart.id) | |
1063 | assert len(cgreplies[b'changegroup']) == 1 |
|
1059 | assert len(cgreplies[b'changegroup']) == 1 | |
1064 | pushop.cgresult = cgreplies[b'changegroup'][0][b'return'] |
|
1060 | pushop.cgresult = cgreplies[b'changegroup'][0][b'return'] | |
1065 |
|
1061 | |||
1066 | return handlereply |
|
1062 | return handlereply | |
1067 |
|
1063 | |||
1068 |
|
1064 | |||
1069 | @b2partsgenerator(b'phase') |
|
1065 | @b2partsgenerator(b'phase') | |
1070 | def _pushb2phases(pushop, bundler): |
|
1066 | def _pushb2phases(pushop, bundler): | |
1071 | """handle phase push through bundle2""" |
|
1067 | """handle phase push through bundle2""" | |
1072 | if b'phases' in pushop.stepsdone: |
|
1068 | if b'phases' in pushop.stepsdone: | |
1073 | return |
|
1069 | return | |
1074 | b2caps = bundle2.bundle2caps(pushop.remote) |
|
1070 | b2caps = bundle2.bundle2caps(pushop.remote) | |
1075 | ui = pushop.repo.ui |
|
1071 | ui = pushop.repo.ui | |
1076 |
|
1072 | |||
1077 | legacyphase = b'phases' in ui.configlist(b'devel', b'legacy.exchange') |
|
1073 | legacyphase = b'phases' in ui.configlist(b'devel', b'legacy.exchange') | |
1078 | haspushkey = b'pushkey' in b2caps |
|
1074 | haspushkey = b'pushkey' in b2caps | |
1079 | hasphaseheads = b'heads' in b2caps.get(b'phases', ()) |
|
1075 | hasphaseheads = b'heads' in b2caps.get(b'phases', ()) | |
1080 |
|
1076 | |||
1081 | if hasphaseheads and not legacyphase: |
|
1077 | if hasphaseheads and not legacyphase: | |
1082 | return _pushb2phaseheads(pushop, bundler) |
|
1078 | return _pushb2phaseheads(pushop, bundler) | |
1083 | elif haspushkey: |
|
1079 | elif haspushkey: | |
1084 | return _pushb2phasespushkey(pushop, bundler) |
|
1080 | return _pushb2phasespushkey(pushop, bundler) | |
1085 |
|
1081 | |||
1086 |
|
1082 | |||
1087 | def _pushb2phaseheads(pushop, bundler): |
|
1083 | def _pushb2phaseheads(pushop, bundler): | |
1088 | """push phase information through a bundle2 - binary part""" |
|
1084 | """push phase information through a bundle2 - binary part""" | |
1089 | pushop.stepsdone.add(b'phases') |
|
1085 | pushop.stepsdone.add(b'phases') | |
1090 | if pushop.outdatedphases: |
|
1086 | if pushop.outdatedphases: | |
1091 | updates = [[] for p in phases.allphases] |
|
1087 | updates = [[] for p in phases.allphases] | |
1092 | updates[0].extend(h.node() for h in pushop.outdatedphases) |
|
1088 | updates[0].extend(h.node() for h in pushop.outdatedphases) | |
1093 | phasedata = phases.binaryencode(updates) |
|
1089 | phasedata = phases.binaryencode(updates) | |
1094 | bundler.newpart(b'phase-heads', data=phasedata) |
|
1090 | bundler.newpart(b'phase-heads', data=phasedata) | |
1095 |
|
1091 | |||
1096 |
|
1092 | |||
1097 | def _pushb2phasespushkey(pushop, bundler): |
|
1093 | def _pushb2phasespushkey(pushop, bundler): | |
1098 | """push phase information through a bundle2 - pushkey part""" |
|
1094 | """push phase information through a bundle2 - pushkey part""" | |
1099 | pushop.stepsdone.add(b'phases') |
|
1095 | pushop.stepsdone.add(b'phases') | |
1100 | part2node = [] |
|
1096 | part2node = [] | |
1101 |
|
1097 | |||
1102 | def handlefailure(pushop, exc): |
|
1098 | def handlefailure(pushop, exc): | |
1103 | targetid = int(exc.partid) |
|
1099 | targetid = int(exc.partid) | |
1104 | for partid, node in part2node: |
|
1100 | for partid, node in part2node: | |
1105 | if partid == targetid: |
|
1101 | if partid == targetid: | |
1106 | raise error.Abort(_(b'updating %s to public failed') % node) |
|
1102 | raise error.Abort(_(b'updating %s to public failed') % node) | |
1107 |
|
1103 | |||
1108 | enc = pushkey.encode |
|
1104 | enc = pushkey.encode | |
1109 | for newremotehead in pushop.outdatedphases: |
|
1105 | for newremotehead in pushop.outdatedphases: | |
1110 | part = bundler.newpart(b'pushkey') |
|
1106 | part = bundler.newpart(b'pushkey') | |
1111 | part.addparam(b'namespace', enc(b'phases')) |
|
1107 | part.addparam(b'namespace', enc(b'phases')) | |
1112 | part.addparam(b'key', enc(newremotehead.hex())) |
|
1108 | part.addparam(b'key', enc(newremotehead.hex())) | |
1113 | part.addparam(b'old', enc(b'%d' % phases.draft)) |
|
1109 | part.addparam(b'old', enc(b'%d' % phases.draft)) | |
1114 | part.addparam(b'new', enc(b'%d' % phases.public)) |
|
1110 | part.addparam(b'new', enc(b'%d' % phases.public)) | |
1115 | part2node.append((part.id, newremotehead)) |
|
1111 | part2node.append((part.id, newremotehead)) | |
1116 | pushop.pkfailcb[part.id] = handlefailure |
|
1112 | pushop.pkfailcb[part.id] = handlefailure | |
1117 |
|
1113 | |||
1118 | def handlereply(op): |
|
1114 | def handlereply(op): | |
1119 | for partid, node in part2node: |
|
1115 | for partid, node in part2node: | |
1120 | partrep = op.records.getreplies(partid) |
|
1116 | partrep = op.records.getreplies(partid) | |
1121 | results = partrep[b'pushkey'] |
|
1117 | results = partrep[b'pushkey'] | |
1122 | assert len(results) <= 1 |
|
1118 | assert len(results) <= 1 | |
1123 | msg = None |
|
1119 | msg = None | |
1124 | if not results: |
|
1120 | if not results: | |
1125 | msg = _(b'server ignored update of %s to public!\n') % node |
|
1121 | msg = _(b'server ignored update of %s to public!\n') % node | |
1126 | elif not int(results[0][b'return']): |
|
1122 | elif not int(results[0][b'return']): | |
1127 | msg = _(b'updating %s to public failed!\n') % node |
|
1123 | msg = _(b'updating %s to public failed!\n') % node | |
1128 | if msg is not None: |
|
1124 | if msg is not None: | |
1129 | pushop.ui.warn(msg) |
|
1125 | pushop.ui.warn(msg) | |
1130 |
|
1126 | |||
1131 | return handlereply |
|
1127 | return handlereply | |
1132 |
|
1128 | |||
1133 |
|
1129 | |||
1134 | @b2partsgenerator(b'obsmarkers') |
|
1130 | @b2partsgenerator(b'obsmarkers') | |
1135 | def _pushb2obsmarkers(pushop, bundler): |
|
1131 | def _pushb2obsmarkers(pushop, bundler): | |
1136 | if b'obsmarkers' in pushop.stepsdone: |
|
1132 | if b'obsmarkers' in pushop.stepsdone: | |
1137 | return |
|
1133 | return | |
1138 | remoteversions = bundle2.obsmarkersversion(bundler.capabilities) |
|
1134 | remoteversions = bundle2.obsmarkersversion(bundler.capabilities) | |
1139 | if obsolete.commonversion(remoteversions) is None: |
|
1135 | if obsolete.commonversion(remoteversions) is None: | |
1140 | return |
|
1136 | return | |
1141 | pushop.stepsdone.add(b'obsmarkers') |
|
1137 | pushop.stepsdone.add(b'obsmarkers') | |
1142 | if pushop.outobsmarkers: |
|
1138 | if pushop.outobsmarkers: | |
1143 |
markers = |
|
1139 | markers = obsutil.sortedmarkers(pushop.outobsmarkers) | |
1144 | bundle2.buildobsmarkerspart(bundler, markers) |
|
1140 | bundle2.buildobsmarkerspart(bundler, markers) | |
1145 |
|
1141 | |||
1146 |
|
1142 | |||
1147 | @b2partsgenerator(b'bookmarks') |
|
1143 | @b2partsgenerator(b'bookmarks') | |
1148 | def _pushb2bookmarks(pushop, bundler): |
|
1144 | def _pushb2bookmarks(pushop, bundler): | |
1149 | """handle bookmark push through bundle2""" |
|
1145 | """handle bookmark push through bundle2""" | |
1150 | if b'bookmarks' in pushop.stepsdone: |
|
1146 | if b'bookmarks' in pushop.stepsdone: | |
1151 | return |
|
1147 | return | |
1152 | b2caps = bundle2.bundle2caps(pushop.remote) |
|
1148 | b2caps = bundle2.bundle2caps(pushop.remote) | |
1153 |
|
1149 | |||
1154 | legacy = pushop.repo.ui.configlist(b'devel', b'legacy.exchange') |
|
1150 | legacy = pushop.repo.ui.configlist(b'devel', b'legacy.exchange') | |
1155 | legacybooks = b'bookmarks' in legacy |
|
1151 | legacybooks = b'bookmarks' in legacy | |
1156 |
|
1152 | |||
1157 | if not legacybooks and b'bookmarks' in b2caps: |
|
1153 | if not legacybooks and b'bookmarks' in b2caps: | |
1158 | return _pushb2bookmarkspart(pushop, bundler) |
|
1154 | return _pushb2bookmarkspart(pushop, bundler) | |
1159 | elif b'pushkey' in b2caps: |
|
1155 | elif b'pushkey' in b2caps: | |
1160 | return _pushb2bookmarkspushkey(pushop, bundler) |
|
1156 | return _pushb2bookmarkspushkey(pushop, bundler) | |
1161 |
|
1157 | |||
1162 |
|
1158 | |||
1163 | def _bmaction(old, new): |
|
1159 | def _bmaction(old, new): | |
1164 | """small utility for bookmark pushing""" |
|
1160 | """small utility for bookmark pushing""" | |
1165 | if not old: |
|
1161 | if not old: | |
1166 | return b'export' |
|
1162 | return b'export' | |
1167 | elif not new: |
|
1163 | elif not new: | |
1168 | return b'delete' |
|
1164 | return b'delete' | |
1169 | return b'update' |
|
1165 | return b'update' | |
1170 |
|
1166 | |||
1171 |
|
1167 | |||
1172 | def _abortonsecretctx(pushop, node, b): |
|
1168 | def _abortonsecretctx(pushop, node, b): | |
1173 | """abort if a given bookmark points to a secret changeset""" |
|
1169 | """abort if a given bookmark points to a secret changeset""" | |
1174 | if node and pushop.repo[node].phase() == phases.secret: |
|
1170 | if node and pushop.repo[node].phase() == phases.secret: | |
1175 | raise error.Abort( |
|
1171 | raise error.Abort( | |
1176 | _(b'cannot push bookmark %s as it points to a secret changeset') % b |
|
1172 | _(b'cannot push bookmark %s as it points to a secret changeset') % b | |
1177 | ) |
|
1173 | ) | |
1178 |
|
1174 | |||
1179 |
|
1175 | |||
1180 | def _pushb2bookmarkspart(pushop, bundler): |
|
1176 | def _pushb2bookmarkspart(pushop, bundler): | |
1181 | pushop.stepsdone.add(b'bookmarks') |
|
1177 | pushop.stepsdone.add(b'bookmarks') | |
1182 | if not pushop.outbookmarks: |
|
1178 | if not pushop.outbookmarks: | |
1183 | return |
|
1179 | return | |
1184 |
|
1180 | |||
1185 | allactions = [] |
|
1181 | allactions = [] | |
1186 | data = [] |
|
1182 | data = [] | |
1187 | for book, old, new in pushop.outbookmarks: |
|
1183 | for book, old, new in pushop.outbookmarks: | |
1188 | _abortonsecretctx(pushop, new, book) |
|
1184 | _abortonsecretctx(pushop, new, book) | |
1189 | data.append((book, new)) |
|
1185 | data.append((book, new)) | |
1190 | allactions.append((book, _bmaction(old, new))) |
|
1186 | allactions.append((book, _bmaction(old, new))) | |
1191 | checkdata = bookmod.binaryencode(data) |
|
1187 | checkdata = bookmod.binaryencode(data) | |
1192 | bundler.newpart(b'bookmarks', data=checkdata) |
|
1188 | bundler.newpart(b'bookmarks', data=checkdata) | |
1193 |
|
1189 | |||
1194 | def handlereply(op): |
|
1190 | def handlereply(op): | |
1195 | ui = pushop.ui |
|
1191 | ui = pushop.ui | |
1196 | # if success |
|
1192 | # if success | |
1197 | for book, action in allactions: |
|
1193 | for book, action in allactions: | |
1198 | ui.status(bookmsgmap[action][0] % book) |
|
1194 | ui.status(bookmsgmap[action][0] % book) | |
1199 |
|
1195 | |||
1200 | return handlereply |
|
1196 | return handlereply | |
1201 |
|
1197 | |||
1202 |
|
1198 | |||
1203 | def _pushb2bookmarkspushkey(pushop, bundler): |
|
1199 | def _pushb2bookmarkspushkey(pushop, bundler): | |
1204 | pushop.stepsdone.add(b'bookmarks') |
|
1200 | pushop.stepsdone.add(b'bookmarks') | |
1205 | part2book = [] |
|
1201 | part2book = [] | |
1206 | enc = pushkey.encode |
|
1202 | enc = pushkey.encode | |
1207 |
|
1203 | |||
1208 | def handlefailure(pushop, exc): |
|
1204 | def handlefailure(pushop, exc): | |
1209 | targetid = int(exc.partid) |
|
1205 | targetid = int(exc.partid) | |
1210 | for partid, book, action in part2book: |
|
1206 | for partid, book, action in part2book: | |
1211 | if partid == targetid: |
|
1207 | if partid == targetid: | |
1212 | raise error.Abort(bookmsgmap[action][1].rstrip() % book) |
|
1208 | raise error.Abort(bookmsgmap[action][1].rstrip() % book) | |
1213 | # we should not be called for part we did not generated |
|
1209 | # we should not be called for part we did not generated | |
1214 | assert False |
|
1210 | assert False | |
1215 |
|
1211 | |||
1216 | for book, old, new in pushop.outbookmarks: |
|
1212 | for book, old, new in pushop.outbookmarks: | |
1217 | _abortonsecretctx(pushop, new, book) |
|
1213 | _abortonsecretctx(pushop, new, book) | |
1218 | part = bundler.newpart(b'pushkey') |
|
1214 | part = bundler.newpart(b'pushkey') | |
1219 | part.addparam(b'namespace', enc(b'bookmarks')) |
|
1215 | part.addparam(b'namespace', enc(b'bookmarks')) | |
1220 | part.addparam(b'key', enc(book)) |
|
1216 | part.addparam(b'key', enc(book)) | |
1221 | part.addparam(b'old', enc(hex(old))) |
|
1217 | part.addparam(b'old', enc(hex(old))) | |
1222 | part.addparam(b'new', enc(hex(new))) |
|
1218 | part.addparam(b'new', enc(hex(new))) | |
1223 | action = b'update' |
|
1219 | action = b'update' | |
1224 | if not old: |
|
1220 | if not old: | |
1225 | action = b'export' |
|
1221 | action = b'export' | |
1226 | elif not new: |
|
1222 | elif not new: | |
1227 | action = b'delete' |
|
1223 | action = b'delete' | |
1228 | part2book.append((part.id, book, action)) |
|
1224 | part2book.append((part.id, book, action)) | |
1229 | pushop.pkfailcb[part.id] = handlefailure |
|
1225 | pushop.pkfailcb[part.id] = handlefailure | |
1230 |
|
1226 | |||
1231 | def handlereply(op): |
|
1227 | def handlereply(op): | |
1232 | ui = pushop.ui |
|
1228 | ui = pushop.ui | |
1233 | for partid, book, action in part2book: |
|
1229 | for partid, book, action in part2book: | |
1234 | partrep = op.records.getreplies(partid) |
|
1230 | partrep = op.records.getreplies(partid) | |
1235 | results = partrep[b'pushkey'] |
|
1231 | results = partrep[b'pushkey'] | |
1236 | assert len(results) <= 1 |
|
1232 | assert len(results) <= 1 | |
1237 | if not results: |
|
1233 | if not results: | |
1238 | pushop.ui.warn(_(b'server ignored bookmark %s update\n') % book) |
|
1234 | pushop.ui.warn(_(b'server ignored bookmark %s update\n') % book) | |
1239 | else: |
|
1235 | else: | |
1240 | ret = int(results[0][b'return']) |
|
1236 | ret = int(results[0][b'return']) | |
1241 | if ret: |
|
1237 | if ret: | |
1242 | ui.status(bookmsgmap[action][0] % book) |
|
1238 | ui.status(bookmsgmap[action][0] % book) | |
1243 | else: |
|
1239 | else: | |
1244 | ui.warn(bookmsgmap[action][1] % book) |
|
1240 | ui.warn(bookmsgmap[action][1] % book) | |
1245 | if pushop.bkresult is not None: |
|
1241 | if pushop.bkresult is not None: | |
1246 | pushop.bkresult = 1 |
|
1242 | pushop.bkresult = 1 | |
1247 |
|
1243 | |||
1248 | return handlereply |
|
1244 | return handlereply | |
1249 |
|
1245 | |||
1250 |
|
1246 | |||
1251 | @b2partsgenerator(b'pushvars', idx=0) |
|
1247 | @b2partsgenerator(b'pushvars', idx=0) | |
1252 | def _getbundlesendvars(pushop, bundler): |
|
1248 | def _getbundlesendvars(pushop, bundler): | |
1253 | '''send shellvars via bundle2''' |
|
1249 | '''send shellvars via bundle2''' | |
1254 | pushvars = pushop.pushvars |
|
1250 | pushvars = pushop.pushvars | |
1255 | if pushvars: |
|
1251 | if pushvars: | |
1256 | shellvars = {} |
|
1252 | shellvars = {} | |
1257 | for raw in pushvars: |
|
1253 | for raw in pushvars: | |
1258 | if b'=' not in raw: |
|
1254 | if b'=' not in raw: | |
1259 | msg = ( |
|
1255 | msg = ( | |
1260 | b"unable to parse variable '%s', should follow " |
|
1256 | b"unable to parse variable '%s', should follow " | |
1261 | b"'KEY=VALUE' or 'KEY=' format" |
|
1257 | b"'KEY=VALUE' or 'KEY=' format" | |
1262 | ) |
|
1258 | ) | |
1263 | raise error.Abort(msg % raw) |
|
1259 | raise error.Abort(msg % raw) | |
1264 | k, v = raw.split(b'=', 1) |
|
1260 | k, v = raw.split(b'=', 1) | |
1265 | shellvars[k] = v |
|
1261 | shellvars[k] = v | |
1266 |
|
1262 | |||
1267 | part = bundler.newpart(b'pushvars') |
|
1263 | part = bundler.newpart(b'pushvars') | |
1268 |
|
1264 | |||
1269 | for key, value in pycompat.iteritems(shellvars): |
|
1265 | for key, value in pycompat.iteritems(shellvars): | |
1270 | part.addparam(key, value, mandatory=False) |
|
1266 | part.addparam(key, value, mandatory=False) | |
1271 |
|
1267 | |||
1272 |
|
1268 | |||
1273 | def _pushbundle2(pushop): |
|
1269 | def _pushbundle2(pushop): | |
1274 | """push data to the remote using bundle2 |
|
1270 | """push data to the remote using bundle2 | |
1275 |
|
1271 | |||
1276 | The only currently supported type of data is changegroup but this will |
|
1272 | The only currently supported type of data is changegroup but this will | |
1277 | evolve in the future.""" |
|
1273 | evolve in the future.""" | |
1278 | bundler = bundle2.bundle20(pushop.ui, bundle2.bundle2caps(pushop.remote)) |
|
1274 | bundler = bundle2.bundle20(pushop.ui, bundle2.bundle2caps(pushop.remote)) | |
1279 | pushback = pushop.trmanager and pushop.ui.configbool( |
|
1275 | pushback = pushop.trmanager and pushop.ui.configbool( | |
1280 | b'experimental', b'bundle2.pushback' |
|
1276 | b'experimental', b'bundle2.pushback' | |
1281 | ) |
|
1277 | ) | |
1282 |
|
1278 | |||
1283 | # create reply capability |
|
1279 | # create reply capability | |
1284 | capsblob = bundle2.encodecaps( |
|
1280 | capsblob = bundle2.encodecaps( | |
1285 | bundle2.getrepocaps(pushop.repo, allowpushback=pushback, role=b'client') |
|
1281 | bundle2.getrepocaps(pushop.repo, allowpushback=pushback, role=b'client') | |
1286 | ) |
|
1282 | ) | |
1287 | bundler.newpart(b'replycaps', data=capsblob) |
|
1283 | bundler.newpart(b'replycaps', data=capsblob) | |
1288 | replyhandlers = [] |
|
1284 | replyhandlers = [] | |
1289 | for partgenname in b2partsgenorder: |
|
1285 | for partgenname in b2partsgenorder: | |
1290 | partgen = b2partsgenmapping[partgenname] |
|
1286 | partgen = b2partsgenmapping[partgenname] | |
1291 | ret = partgen(pushop, bundler) |
|
1287 | ret = partgen(pushop, bundler) | |
1292 | if callable(ret): |
|
1288 | if callable(ret): | |
1293 | replyhandlers.append(ret) |
|
1289 | replyhandlers.append(ret) | |
1294 | # do not push if nothing to push |
|
1290 | # do not push if nothing to push | |
1295 | if bundler.nbparts <= 1: |
|
1291 | if bundler.nbparts <= 1: | |
1296 | return |
|
1292 | return | |
1297 | stream = util.chunkbuffer(bundler.getchunks()) |
|
1293 | stream = util.chunkbuffer(bundler.getchunks()) | |
1298 | try: |
|
1294 | try: | |
1299 | try: |
|
1295 | try: | |
1300 | with pushop.remote.commandexecutor() as e: |
|
1296 | with pushop.remote.commandexecutor() as e: | |
1301 | reply = e.callcommand( |
|
1297 | reply = e.callcommand( | |
1302 | b'unbundle', |
|
1298 | b'unbundle', | |
1303 | { |
|
1299 | { | |
1304 | b'bundle': stream, |
|
1300 | b'bundle': stream, | |
1305 | b'heads': [b'force'], |
|
1301 | b'heads': [b'force'], | |
1306 | b'url': pushop.remote.url(), |
|
1302 | b'url': pushop.remote.url(), | |
1307 | }, |
|
1303 | }, | |
1308 | ).result() |
|
1304 | ).result() | |
1309 | except error.BundleValueError as exc: |
|
1305 | except error.BundleValueError as exc: | |
1310 | raise error.Abort(_(b'missing support for %s') % exc) |
|
1306 | raise error.Abort(_(b'missing support for %s') % exc) | |
1311 | try: |
|
1307 | try: | |
1312 | trgetter = None |
|
1308 | trgetter = None | |
1313 | if pushback: |
|
1309 | if pushback: | |
1314 | trgetter = pushop.trmanager.transaction |
|
1310 | trgetter = pushop.trmanager.transaction | |
1315 | op = bundle2.processbundle(pushop.repo, reply, trgetter) |
|
1311 | op = bundle2.processbundle(pushop.repo, reply, trgetter) | |
1316 | except error.BundleValueError as exc: |
|
1312 | except error.BundleValueError as exc: | |
1317 | raise error.Abort(_(b'missing support for %s') % exc) |
|
1313 | raise error.Abort(_(b'missing support for %s') % exc) | |
1318 | except bundle2.AbortFromPart as exc: |
|
1314 | except bundle2.AbortFromPart as exc: | |
1319 | pushop.ui.status(_(b'remote: %s\n') % exc) |
|
1315 | pushop.ui.status(_(b'remote: %s\n') % exc) | |
1320 | if exc.hint is not None: |
|
1316 | if exc.hint is not None: | |
1321 | pushop.ui.status(_(b'remote: %s\n') % (b'(%s)' % exc.hint)) |
|
1317 | pushop.ui.status(_(b'remote: %s\n') % (b'(%s)' % exc.hint)) | |
1322 | raise error.Abort(_(b'push failed on remote')) |
|
1318 | raise error.Abort(_(b'push failed on remote')) | |
1323 | except error.PushkeyFailed as exc: |
|
1319 | except error.PushkeyFailed as exc: | |
1324 | partid = int(exc.partid) |
|
1320 | partid = int(exc.partid) | |
1325 | if partid not in pushop.pkfailcb: |
|
1321 | if partid not in pushop.pkfailcb: | |
1326 | raise |
|
1322 | raise | |
1327 | pushop.pkfailcb[partid](pushop, exc) |
|
1323 | pushop.pkfailcb[partid](pushop, exc) | |
1328 | for rephand in replyhandlers: |
|
1324 | for rephand in replyhandlers: | |
1329 | rephand(op) |
|
1325 | rephand(op) | |
1330 |
|
1326 | |||
1331 |
|
1327 | |||
1332 | def _pushchangeset(pushop): |
|
1328 | def _pushchangeset(pushop): | |
1333 | """Make the actual push of changeset bundle to remote repo""" |
|
1329 | """Make the actual push of changeset bundle to remote repo""" | |
1334 | if b'changesets' in pushop.stepsdone: |
|
1330 | if b'changesets' in pushop.stepsdone: | |
1335 | return |
|
1331 | return | |
1336 | pushop.stepsdone.add(b'changesets') |
|
1332 | pushop.stepsdone.add(b'changesets') | |
1337 | if not _pushcheckoutgoing(pushop): |
|
1333 | if not _pushcheckoutgoing(pushop): | |
1338 | return |
|
1334 | return | |
1339 |
|
1335 | |||
1340 | # Should have verified this in push(). |
|
1336 | # Should have verified this in push(). | |
1341 | assert pushop.remote.capable(b'unbundle') |
|
1337 | assert pushop.remote.capable(b'unbundle') | |
1342 |
|
1338 | |||
1343 | pushop.repo.prepushoutgoinghooks(pushop) |
|
1339 | pushop.repo.prepushoutgoinghooks(pushop) | |
1344 | outgoing = pushop.outgoing |
|
1340 | outgoing = pushop.outgoing | |
1345 | # TODO: get bundlecaps from remote |
|
1341 | # TODO: get bundlecaps from remote | |
1346 | bundlecaps = None |
|
1342 | bundlecaps = None | |
1347 | # create a changegroup from local |
|
1343 | # create a changegroup from local | |
1348 | if pushop.revs is None and not ( |
|
1344 | if pushop.revs is None and not ( | |
1349 | outgoing.excluded or pushop.repo.changelog.filteredrevs |
|
1345 | outgoing.excluded or pushop.repo.changelog.filteredrevs | |
1350 | ): |
|
1346 | ): | |
1351 | # push everything, |
|
1347 | # push everything, | |
1352 | # use the fast path, no race possible on push |
|
1348 | # use the fast path, no race possible on push | |
1353 | cg = changegroup.makechangegroup( |
|
1349 | cg = changegroup.makechangegroup( | |
1354 | pushop.repo, |
|
1350 | pushop.repo, | |
1355 | outgoing, |
|
1351 | outgoing, | |
1356 | b'01', |
|
1352 | b'01', | |
1357 | b'push', |
|
1353 | b'push', | |
1358 | fastpath=True, |
|
1354 | fastpath=True, | |
1359 | bundlecaps=bundlecaps, |
|
1355 | bundlecaps=bundlecaps, | |
1360 | ) |
|
1356 | ) | |
1361 | else: |
|
1357 | else: | |
1362 | cg = changegroup.makechangegroup( |
|
1358 | cg = changegroup.makechangegroup( | |
1363 | pushop.repo, outgoing, b'01', b'push', bundlecaps=bundlecaps |
|
1359 | pushop.repo, outgoing, b'01', b'push', bundlecaps=bundlecaps | |
1364 | ) |
|
1360 | ) | |
1365 |
|
1361 | |||
1366 | # apply changegroup to remote |
|
1362 | # apply changegroup to remote | |
1367 | # local repo finds heads on server, finds out what |
|
1363 | # local repo finds heads on server, finds out what | |
1368 | # revs it must push. once revs transferred, if server |
|
1364 | # revs it must push. once revs transferred, if server | |
1369 | # finds it has different heads (someone else won |
|
1365 | # finds it has different heads (someone else won | |
1370 | # commit/push race), server aborts. |
|
1366 | # commit/push race), server aborts. | |
1371 | if pushop.force: |
|
1367 | if pushop.force: | |
1372 | remoteheads = [b'force'] |
|
1368 | remoteheads = [b'force'] | |
1373 | else: |
|
1369 | else: | |
1374 | remoteheads = pushop.remoteheads |
|
1370 | remoteheads = pushop.remoteheads | |
1375 | # ssh: return remote's addchangegroup() |
|
1371 | # ssh: return remote's addchangegroup() | |
1376 | # http: return remote's addchangegroup() or 0 for error |
|
1372 | # http: return remote's addchangegroup() or 0 for error | |
1377 | pushop.cgresult = pushop.remote.unbundle(cg, remoteheads, pushop.repo.url()) |
|
1373 | pushop.cgresult = pushop.remote.unbundle(cg, remoteheads, pushop.repo.url()) | |
1378 |
|
1374 | |||
1379 |
|
1375 | |||
1380 | def _pushsyncphase(pushop): |
|
1376 | def _pushsyncphase(pushop): | |
1381 | """synchronise phase information locally and remotely""" |
|
1377 | """synchronise phase information locally and remotely""" | |
1382 | cheads = pushop.commonheads |
|
1378 | cheads = pushop.commonheads | |
1383 | # even when we don't push, exchanging phase data is useful |
|
1379 | # even when we don't push, exchanging phase data is useful | |
1384 | remotephases = listkeys(pushop.remote, b'phases') |
|
1380 | remotephases = listkeys(pushop.remote, b'phases') | |
1385 | if ( |
|
1381 | if ( | |
1386 | pushop.ui.configbool(b'ui', b'_usedassubrepo') |
|
1382 | pushop.ui.configbool(b'ui', b'_usedassubrepo') | |
1387 | and remotephases # server supports phases |
|
1383 | and remotephases # server supports phases | |
1388 | and pushop.cgresult is None # nothing was pushed |
|
1384 | and pushop.cgresult is None # nothing was pushed | |
1389 | and remotephases.get(b'publishing', False) |
|
1385 | and remotephases.get(b'publishing', False) | |
1390 | ): |
|
1386 | ): | |
1391 | # When: |
|
1387 | # When: | |
1392 | # - this is a subrepo push |
|
1388 | # - this is a subrepo push | |
1393 | # - and remote support phase |
|
1389 | # - and remote support phase | |
1394 | # - and no changeset was pushed |
|
1390 | # - and no changeset was pushed | |
1395 | # - and remote is publishing |
|
1391 | # - and remote is publishing | |
1396 | # We may be in issue 3871 case! |
|
1392 | # We may be in issue 3871 case! | |
1397 | # We drop the possible phase synchronisation done by |
|
1393 | # We drop the possible phase synchronisation done by | |
1398 | # courtesy to publish changesets possibly locally draft |
|
1394 | # courtesy to publish changesets possibly locally draft | |
1399 | # on the remote. |
|
1395 | # on the remote. | |
1400 | remotephases = {b'publishing': b'True'} |
|
1396 | remotephases = {b'publishing': b'True'} | |
1401 | if not remotephases: # old server or public only reply from non-publishing |
|
1397 | if not remotephases: # old server or public only reply from non-publishing | |
1402 | _localphasemove(pushop, cheads) |
|
1398 | _localphasemove(pushop, cheads) | |
1403 | # don't push any phase data as there is nothing to push |
|
1399 | # don't push any phase data as there is nothing to push | |
1404 | else: |
|
1400 | else: | |
1405 | ana = phases.analyzeremotephases(pushop.repo, cheads, remotephases) |
|
1401 | ana = phases.analyzeremotephases(pushop.repo, cheads, remotephases) | |
1406 | pheads, droots = ana |
|
1402 | pheads, droots = ana | |
1407 | ### Apply remote phase on local |
|
1403 | ### Apply remote phase on local | |
1408 | if remotephases.get(b'publishing', False): |
|
1404 | if remotephases.get(b'publishing', False): | |
1409 | _localphasemove(pushop, cheads) |
|
1405 | _localphasemove(pushop, cheads) | |
1410 | else: # publish = False |
|
1406 | else: # publish = False | |
1411 | _localphasemove(pushop, pheads) |
|
1407 | _localphasemove(pushop, pheads) | |
1412 | _localphasemove(pushop, cheads, phases.draft) |
|
1408 | _localphasemove(pushop, cheads, phases.draft) | |
1413 | ### Apply local phase on remote |
|
1409 | ### Apply local phase on remote | |
1414 |
|
1410 | |||
1415 | if pushop.cgresult: |
|
1411 | if pushop.cgresult: | |
1416 | if b'phases' in pushop.stepsdone: |
|
1412 | if b'phases' in pushop.stepsdone: | |
1417 | # phases already pushed though bundle2 |
|
1413 | # phases already pushed though bundle2 | |
1418 | return |
|
1414 | return | |
1419 | outdated = pushop.outdatedphases |
|
1415 | outdated = pushop.outdatedphases | |
1420 | else: |
|
1416 | else: | |
1421 | outdated = pushop.fallbackoutdatedphases |
|
1417 | outdated = pushop.fallbackoutdatedphases | |
1422 |
|
1418 | |||
1423 | pushop.stepsdone.add(b'phases') |
|
1419 | pushop.stepsdone.add(b'phases') | |
1424 |
|
1420 | |||
1425 | # filter heads already turned public by the push |
|
1421 | # filter heads already turned public by the push | |
1426 | outdated = [c for c in outdated if c.node() not in pheads] |
|
1422 | outdated = [c for c in outdated if c.node() not in pheads] | |
1427 | # fallback to independent pushkey command |
|
1423 | # fallback to independent pushkey command | |
1428 | for newremotehead in outdated: |
|
1424 | for newremotehead in outdated: | |
1429 | with pushop.remote.commandexecutor() as e: |
|
1425 | with pushop.remote.commandexecutor() as e: | |
1430 | r = e.callcommand( |
|
1426 | r = e.callcommand( | |
1431 | b'pushkey', |
|
1427 | b'pushkey', | |
1432 | { |
|
1428 | { | |
1433 | b'namespace': b'phases', |
|
1429 | b'namespace': b'phases', | |
1434 | b'key': newremotehead.hex(), |
|
1430 | b'key': newremotehead.hex(), | |
1435 | b'old': b'%d' % phases.draft, |
|
1431 | b'old': b'%d' % phases.draft, | |
1436 | b'new': b'%d' % phases.public, |
|
1432 | b'new': b'%d' % phases.public, | |
1437 | }, |
|
1433 | }, | |
1438 | ).result() |
|
1434 | ).result() | |
1439 |
|
1435 | |||
1440 | if not r: |
|
1436 | if not r: | |
1441 | pushop.ui.warn( |
|
1437 | pushop.ui.warn( | |
1442 | _(b'updating %s to public failed!\n') % newremotehead |
|
1438 | _(b'updating %s to public failed!\n') % newremotehead | |
1443 | ) |
|
1439 | ) | |
1444 |
|
1440 | |||
1445 |
|
1441 | |||
1446 | def _localphasemove(pushop, nodes, phase=phases.public): |
|
1442 | def _localphasemove(pushop, nodes, phase=phases.public): | |
1447 | """move <nodes> to <phase> in the local source repo""" |
|
1443 | """move <nodes> to <phase> in the local source repo""" | |
1448 | if pushop.trmanager: |
|
1444 | if pushop.trmanager: | |
1449 | phases.advanceboundary( |
|
1445 | phases.advanceboundary( | |
1450 | pushop.repo, pushop.trmanager.transaction(), phase, nodes |
|
1446 | pushop.repo, pushop.trmanager.transaction(), phase, nodes | |
1451 | ) |
|
1447 | ) | |
1452 | else: |
|
1448 | else: | |
1453 | # repo is not locked, do not change any phases! |
|
1449 | # repo is not locked, do not change any phases! | |
1454 | # Informs the user that phases should have been moved when |
|
1450 | # Informs the user that phases should have been moved when | |
1455 | # applicable. |
|
1451 | # applicable. | |
1456 | actualmoves = [n for n in nodes if phase < pushop.repo[n].phase()] |
|
1452 | actualmoves = [n for n in nodes if phase < pushop.repo[n].phase()] | |
1457 | phasestr = phases.phasenames[phase] |
|
1453 | phasestr = phases.phasenames[phase] | |
1458 | if actualmoves: |
|
1454 | if actualmoves: | |
1459 | pushop.ui.status( |
|
1455 | pushop.ui.status( | |
1460 | _( |
|
1456 | _( | |
1461 | b'cannot lock source repo, skipping ' |
|
1457 | b'cannot lock source repo, skipping ' | |
1462 | b'local %s phase update\n' |
|
1458 | b'local %s phase update\n' | |
1463 | ) |
|
1459 | ) | |
1464 | % phasestr |
|
1460 | % phasestr | |
1465 | ) |
|
1461 | ) | |
1466 |
|
1462 | |||
1467 |
|
1463 | |||
1468 | def _pushobsolete(pushop): |
|
1464 | def _pushobsolete(pushop): | |
1469 | """utility function to push obsolete markers to a remote""" |
|
1465 | """utility function to push obsolete markers to a remote""" | |
1470 | if b'obsmarkers' in pushop.stepsdone: |
|
1466 | if b'obsmarkers' in pushop.stepsdone: | |
1471 | return |
|
1467 | return | |
1472 | repo = pushop.repo |
|
1468 | repo = pushop.repo | |
1473 | remote = pushop.remote |
|
1469 | remote = pushop.remote | |
1474 | pushop.stepsdone.add(b'obsmarkers') |
|
1470 | pushop.stepsdone.add(b'obsmarkers') | |
1475 | if pushop.outobsmarkers: |
|
1471 | if pushop.outobsmarkers: | |
1476 | pushop.ui.debug(b'try to push obsolete markers to remote\n') |
|
1472 | pushop.ui.debug(b'try to push obsolete markers to remote\n') | |
1477 | rslts = [] |
|
1473 | rslts = [] | |
1478 |
markers = |
|
1474 | markers = obsutil.sortedmarkers(pushop.outobsmarkers) | |
1479 | remotedata = obsolete._pushkeyescape(markers) |
|
1475 | remotedata = obsolete._pushkeyescape(markers) | |
1480 | for key in sorted(remotedata, reverse=True): |
|
1476 | for key in sorted(remotedata, reverse=True): | |
1481 | # reverse sort to ensure we end with dump0 |
|
1477 | # reverse sort to ensure we end with dump0 | |
1482 | data = remotedata[key] |
|
1478 | data = remotedata[key] | |
1483 | rslts.append(remote.pushkey(b'obsolete', key, b'', data)) |
|
1479 | rslts.append(remote.pushkey(b'obsolete', key, b'', data)) | |
1484 | if [r for r in rslts if not r]: |
|
1480 | if [r for r in rslts if not r]: | |
1485 | msg = _(b'failed to push some obsolete markers!\n') |
|
1481 | msg = _(b'failed to push some obsolete markers!\n') | |
1486 | repo.ui.warn(msg) |
|
1482 | repo.ui.warn(msg) | |
1487 |
|
1483 | |||
1488 |
|
1484 | |||
1489 | def _pushbookmark(pushop): |
|
1485 | def _pushbookmark(pushop): | |
1490 | """Update bookmark position on remote""" |
|
1486 | """Update bookmark position on remote""" | |
1491 | if pushop.cgresult == 0 or b'bookmarks' in pushop.stepsdone: |
|
1487 | if pushop.cgresult == 0 or b'bookmarks' in pushop.stepsdone: | |
1492 | return |
|
1488 | return | |
1493 | pushop.stepsdone.add(b'bookmarks') |
|
1489 | pushop.stepsdone.add(b'bookmarks') | |
1494 | ui = pushop.ui |
|
1490 | ui = pushop.ui | |
1495 | remote = pushop.remote |
|
1491 | remote = pushop.remote | |
1496 |
|
1492 | |||
1497 | for b, old, new in pushop.outbookmarks: |
|
1493 | for b, old, new in pushop.outbookmarks: | |
1498 | action = b'update' |
|
1494 | action = b'update' | |
1499 | if not old: |
|
1495 | if not old: | |
1500 | action = b'export' |
|
1496 | action = b'export' | |
1501 | elif not new: |
|
1497 | elif not new: | |
1502 | action = b'delete' |
|
1498 | action = b'delete' | |
1503 |
|
1499 | |||
1504 | with remote.commandexecutor() as e: |
|
1500 | with remote.commandexecutor() as e: | |
1505 | r = e.callcommand( |
|
1501 | r = e.callcommand( | |
1506 | b'pushkey', |
|
1502 | b'pushkey', | |
1507 | { |
|
1503 | { | |
1508 | b'namespace': b'bookmarks', |
|
1504 | b'namespace': b'bookmarks', | |
1509 | b'key': b, |
|
1505 | b'key': b, | |
1510 | b'old': hex(old), |
|
1506 | b'old': hex(old), | |
1511 | b'new': hex(new), |
|
1507 | b'new': hex(new), | |
1512 | }, |
|
1508 | }, | |
1513 | ).result() |
|
1509 | ).result() | |
1514 |
|
1510 | |||
1515 | if r: |
|
1511 | if r: | |
1516 | ui.status(bookmsgmap[action][0] % b) |
|
1512 | ui.status(bookmsgmap[action][0] % b) | |
1517 | else: |
|
1513 | else: | |
1518 | ui.warn(bookmsgmap[action][1] % b) |
|
1514 | ui.warn(bookmsgmap[action][1] % b) | |
1519 | # discovery can have set the value form invalid entry |
|
1515 | # discovery can have set the value form invalid entry | |
1520 | if pushop.bkresult is not None: |
|
1516 | if pushop.bkresult is not None: | |
1521 | pushop.bkresult = 1 |
|
1517 | pushop.bkresult = 1 | |
1522 |
|
1518 | |||
1523 |
|
1519 | |||
1524 | class pulloperation(object): |
|
1520 | class pulloperation(object): | |
1525 | """A object that represent a single pull operation |
|
1521 | """A object that represent a single pull operation | |
1526 |
|
1522 | |||
1527 | It purpose is to carry pull related state and very common operation. |
|
1523 | It purpose is to carry pull related state and very common operation. | |
1528 |
|
1524 | |||
1529 | A new should be created at the beginning of each pull and discarded |
|
1525 | A new should be created at the beginning of each pull and discarded | |
1530 | afterward. |
|
1526 | afterward. | |
1531 | """ |
|
1527 | """ | |
1532 |
|
1528 | |||
1533 | def __init__( |
|
1529 | def __init__( | |
1534 | self, |
|
1530 | self, | |
1535 | repo, |
|
1531 | repo, | |
1536 | remote, |
|
1532 | remote, | |
1537 | heads=None, |
|
1533 | heads=None, | |
1538 | force=False, |
|
1534 | force=False, | |
1539 | bookmarks=(), |
|
1535 | bookmarks=(), | |
1540 | remotebookmarks=None, |
|
1536 | remotebookmarks=None, | |
1541 | streamclonerequested=None, |
|
1537 | streamclonerequested=None, | |
1542 | includepats=None, |
|
1538 | includepats=None, | |
1543 | excludepats=None, |
|
1539 | excludepats=None, | |
1544 | depth=None, |
|
1540 | depth=None, | |
1545 | ): |
|
1541 | ): | |
1546 | # repo we pull into |
|
1542 | # repo we pull into | |
1547 | self.repo = repo |
|
1543 | self.repo = repo | |
1548 | # repo we pull from |
|
1544 | # repo we pull from | |
1549 | self.remote = remote |
|
1545 | self.remote = remote | |
1550 | # revision we try to pull (None is "all") |
|
1546 | # revision we try to pull (None is "all") | |
1551 | self.heads = heads |
|
1547 | self.heads = heads | |
1552 | # bookmark pulled explicitly |
|
1548 | # bookmark pulled explicitly | |
1553 | self.explicitbookmarks = [ |
|
1549 | self.explicitbookmarks = [ | |
1554 | repo._bookmarks.expandname(bookmark) for bookmark in bookmarks |
|
1550 | repo._bookmarks.expandname(bookmark) for bookmark in bookmarks | |
1555 | ] |
|
1551 | ] | |
1556 | # do we force pull? |
|
1552 | # do we force pull? | |
1557 | self.force = force |
|
1553 | self.force = force | |
1558 | # whether a streaming clone was requested |
|
1554 | # whether a streaming clone was requested | |
1559 | self.streamclonerequested = streamclonerequested |
|
1555 | self.streamclonerequested = streamclonerequested | |
1560 | # transaction manager |
|
1556 | # transaction manager | |
1561 | self.trmanager = None |
|
1557 | self.trmanager = None | |
1562 | # set of common changeset between local and remote before pull |
|
1558 | # set of common changeset between local and remote before pull | |
1563 | self.common = None |
|
1559 | self.common = None | |
1564 | # set of pulled head |
|
1560 | # set of pulled head | |
1565 | self.rheads = None |
|
1561 | self.rheads = None | |
1566 | # list of missing changeset to fetch remotely |
|
1562 | # list of missing changeset to fetch remotely | |
1567 | self.fetch = None |
|
1563 | self.fetch = None | |
1568 | # remote bookmarks data |
|
1564 | # remote bookmarks data | |
1569 | self.remotebookmarks = remotebookmarks |
|
1565 | self.remotebookmarks = remotebookmarks | |
1570 | # result of changegroup pulling (used as return code by pull) |
|
1566 | # result of changegroup pulling (used as return code by pull) | |
1571 | self.cgresult = None |
|
1567 | self.cgresult = None | |
1572 | # list of step already done |
|
1568 | # list of step already done | |
1573 | self.stepsdone = set() |
|
1569 | self.stepsdone = set() | |
1574 | # Whether we attempted a clone from pre-generated bundles. |
|
1570 | # Whether we attempted a clone from pre-generated bundles. | |
1575 | self.clonebundleattempted = False |
|
1571 | self.clonebundleattempted = False | |
1576 | # Set of file patterns to include. |
|
1572 | # Set of file patterns to include. | |
1577 | self.includepats = includepats |
|
1573 | self.includepats = includepats | |
1578 | # Set of file patterns to exclude. |
|
1574 | # Set of file patterns to exclude. | |
1579 | self.excludepats = excludepats |
|
1575 | self.excludepats = excludepats | |
1580 | # Number of ancestor changesets to pull from each pulled head. |
|
1576 | # Number of ancestor changesets to pull from each pulled head. | |
1581 | self.depth = depth |
|
1577 | self.depth = depth | |
1582 |
|
1578 | |||
1583 | @util.propertycache |
|
1579 | @util.propertycache | |
1584 | def pulledsubset(self): |
|
1580 | def pulledsubset(self): | |
1585 | """heads of the set of changeset target by the pull""" |
|
1581 | """heads of the set of changeset target by the pull""" | |
1586 | # compute target subset |
|
1582 | # compute target subset | |
1587 | if self.heads is None: |
|
1583 | if self.heads is None: | |
1588 | # We pulled every thing possible |
|
1584 | # We pulled every thing possible | |
1589 | # sync on everything common |
|
1585 | # sync on everything common | |
1590 | c = set(self.common) |
|
1586 | c = set(self.common) | |
1591 | ret = list(self.common) |
|
1587 | ret = list(self.common) | |
1592 | for n in self.rheads: |
|
1588 | for n in self.rheads: | |
1593 | if n not in c: |
|
1589 | if n not in c: | |
1594 | ret.append(n) |
|
1590 | ret.append(n) | |
1595 | return ret |
|
1591 | return ret | |
1596 | else: |
|
1592 | else: | |
1597 | # We pulled a specific subset |
|
1593 | # We pulled a specific subset | |
1598 | # sync on this subset |
|
1594 | # sync on this subset | |
1599 | return self.heads |
|
1595 | return self.heads | |
1600 |
|
1596 | |||
1601 | @util.propertycache |
|
1597 | @util.propertycache | |
1602 | def canusebundle2(self): |
|
1598 | def canusebundle2(self): | |
1603 | return not _forcebundle1(self) |
|
1599 | return not _forcebundle1(self) | |
1604 |
|
1600 | |||
1605 | @util.propertycache |
|
1601 | @util.propertycache | |
1606 | def remotebundle2caps(self): |
|
1602 | def remotebundle2caps(self): | |
1607 | return bundle2.bundle2caps(self.remote) |
|
1603 | return bundle2.bundle2caps(self.remote) | |
1608 |
|
1604 | |||
1609 | def gettransaction(self): |
|
1605 | def gettransaction(self): | |
1610 | # deprecated; talk to trmanager directly |
|
1606 | # deprecated; talk to trmanager directly | |
1611 | return self.trmanager.transaction() |
|
1607 | return self.trmanager.transaction() | |
1612 |
|
1608 | |||
1613 |
|
1609 | |||
1614 | class transactionmanager(util.transactional): |
|
1610 | class transactionmanager(util.transactional): | |
1615 | """An object to manage the life cycle of a transaction |
|
1611 | """An object to manage the life cycle of a transaction | |
1616 |
|
1612 | |||
1617 | It creates the transaction on demand and calls the appropriate hooks when |
|
1613 | It creates the transaction on demand and calls the appropriate hooks when | |
1618 | closing the transaction.""" |
|
1614 | closing the transaction.""" | |
1619 |
|
1615 | |||
1620 | def __init__(self, repo, source, url): |
|
1616 | def __init__(self, repo, source, url): | |
1621 | self.repo = repo |
|
1617 | self.repo = repo | |
1622 | self.source = source |
|
1618 | self.source = source | |
1623 | self.url = url |
|
1619 | self.url = url | |
1624 | self._tr = None |
|
1620 | self._tr = None | |
1625 |
|
1621 | |||
1626 | def transaction(self): |
|
1622 | def transaction(self): | |
1627 | """Return an open transaction object, constructing if necessary""" |
|
1623 | """Return an open transaction object, constructing if necessary""" | |
1628 | if not self._tr: |
|
1624 | if not self._tr: | |
1629 | trname = b'%s\n%s' % (self.source, util.hidepassword(self.url)) |
|
1625 | trname = b'%s\n%s' % (self.source, util.hidepassword(self.url)) | |
1630 | self._tr = self.repo.transaction(trname) |
|
1626 | self._tr = self.repo.transaction(trname) | |
1631 | self._tr.hookargs[b'source'] = self.source |
|
1627 | self._tr.hookargs[b'source'] = self.source | |
1632 | self._tr.hookargs[b'url'] = self.url |
|
1628 | self._tr.hookargs[b'url'] = self.url | |
1633 | return self._tr |
|
1629 | return self._tr | |
1634 |
|
1630 | |||
1635 | def close(self): |
|
1631 | def close(self): | |
1636 | """close transaction if created""" |
|
1632 | """close transaction if created""" | |
1637 | if self._tr is not None: |
|
1633 | if self._tr is not None: | |
1638 | self._tr.close() |
|
1634 | self._tr.close() | |
1639 |
|
1635 | |||
1640 | def release(self): |
|
1636 | def release(self): | |
1641 | """release transaction if created""" |
|
1637 | """release transaction if created""" | |
1642 | if self._tr is not None: |
|
1638 | if self._tr is not None: | |
1643 | self._tr.release() |
|
1639 | self._tr.release() | |
1644 |
|
1640 | |||
1645 |
|
1641 | |||
1646 | def listkeys(remote, namespace): |
|
1642 | def listkeys(remote, namespace): | |
1647 | with remote.commandexecutor() as e: |
|
1643 | with remote.commandexecutor() as e: | |
1648 | return e.callcommand(b'listkeys', {b'namespace': namespace}).result() |
|
1644 | return e.callcommand(b'listkeys', {b'namespace': namespace}).result() | |
1649 |
|
1645 | |||
1650 |
|
1646 | |||
1651 | def _fullpullbundle2(repo, pullop): |
|
1647 | def _fullpullbundle2(repo, pullop): | |
1652 | # The server may send a partial reply, i.e. when inlining |
|
1648 | # The server may send a partial reply, i.e. when inlining | |
1653 | # pre-computed bundles. In that case, update the common |
|
1649 | # pre-computed bundles. In that case, update the common | |
1654 | # set based on the results and pull another bundle. |
|
1650 | # set based on the results and pull another bundle. | |
1655 | # |
|
1651 | # | |
1656 | # There are two indicators that the process is finished: |
|
1652 | # There are two indicators that the process is finished: | |
1657 | # - no changeset has been added, or |
|
1653 | # - no changeset has been added, or | |
1658 | # - all remote heads are known locally. |
|
1654 | # - all remote heads are known locally. | |
1659 | # The head check must use the unfiltered view as obsoletion |
|
1655 | # The head check must use the unfiltered view as obsoletion | |
1660 | # markers can hide heads. |
|
1656 | # markers can hide heads. | |
1661 | unfi = repo.unfiltered() |
|
1657 | unfi = repo.unfiltered() | |
1662 | unficl = unfi.changelog |
|
1658 | unficl = unfi.changelog | |
1663 |
|
1659 | |||
1664 | def headsofdiff(h1, h2): |
|
1660 | def headsofdiff(h1, h2): | |
1665 | """Returns heads(h1 % h2)""" |
|
1661 | """Returns heads(h1 % h2)""" | |
1666 | res = unfi.set(b'heads(%ln %% %ln)', h1, h2) |
|
1662 | res = unfi.set(b'heads(%ln %% %ln)', h1, h2) | |
1667 | return set(ctx.node() for ctx in res) |
|
1663 | return set(ctx.node() for ctx in res) | |
1668 |
|
1664 | |||
1669 | def headsofunion(h1, h2): |
|
1665 | def headsofunion(h1, h2): | |
1670 | """Returns heads((h1 + h2) - null)""" |
|
1666 | """Returns heads((h1 + h2) - null)""" | |
1671 | res = unfi.set(b'heads((%ln + %ln - null))', h1, h2) |
|
1667 | res = unfi.set(b'heads((%ln + %ln - null))', h1, h2) | |
1672 | return set(ctx.node() for ctx in res) |
|
1668 | return set(ctx.node() for ctx in res) | |
1673 |
|
1669 | |||
1674 | while True: |
|
1670 | while True: | |
1675 | old_heads = unficl.heads() |
|
1671 | old_heads = unficl.heads() | |
1676 | clstart = len(unficl) |
|
1672 | clstart = len(unficl) | |
1677 | _pullbundle2(pullop) |
|
1673 | _pullbundle2(pullop) | |
1678 | if repository.NARROW_REQUIREMENT in repo.requirements: |
|
1674 | if repository.NARROW_REQUIREMENT in repo.requirements: | |
1679 | # XXX narrow clones filter the heads on the server side during |
|
1675 | # XXX narrow clones filter the heads on the server side during | |
1680 | # XXX getbundle and result in partial replies as well. |
|
1676 | # XXX getbundle and result in partial replies as well. | |
1681 | # XXX Disable pull bundles in this case as band aid to avoid |
|
1677 | # XXX Disable pull bundles in this case as band aid to avoid | |
1682 | # XXX extra round trips. |
|
1678 | # XXX extra round trips. | |
1683 | break |
|
1679 | break | |
1684 | if clstart == len(unficl): |
|
1680 | if clstart == len(unficl): | |
1685 | break |
|
1681 | break | |
1686 | if all(unficl.hasnode(n) for n in pullop.rheads): |
|
1682 | if all(unficl.hasnode(n) for n in pullop.rheads): | |
1687 | break |
|
1683 | break | |
1688 | new_heads = headsofdiff(unficl.heads(), old_heads) |
|
1684 | new_heads = headsofdiff(unficl.heads(), old_heads) | |
1689 | pullop.common = headsofunion(new_heads, pullop.common) |
|
1685 | pullop.common = headsofunion(new_heads, pullop.common) | |
1690 | pullop.rheads = set(pullop.rheads) - pullop.common |
|
1686 | pullop.rheads = set(pullop.rheads) - pullop.common | |
1691 |
|
1687 | |||
1692 |
|
1688 | |||
1693 | def pull( |
|
1689 | def pull( | |
1694 | repo, |
|
1690 | repo, | |
1695 | remote, |
|
1691 | remote, | |
1696 | heads=None, |
|
1692 | heads=None, | |
1697 | force=False, |
|
1693 | force=False, | |
1698 | bookmarks=(), |
|
1694 | bookmarks=(), | |
1699 | opargs=None, |
|
1695 | opargs=None, | |
1700 | streamclonerequested=None, |
|
1696 | streamclonerequested=None, | |
1701 | includepats=None, |
|
1697 | includepats=None, | |
1702 | excludepats=None, |
|
1698 | excludepats=None, | |
1703 | depth=None, |
|
1699 | depth=None, | |
1704 | ): |
|
1700 | ): | |
1705 | """Fetch repository data from a remote. |
|
1701 | """Fetch repository data from a remote. | |
1706 |
|
1702 | |||
1707 | This is the main function used to retrieve data from a remote repository. |
|
1703 | This is the main function used to retrieve data from a remote repository. | |
1708 |
|
1704 | |||
1709 | ``repo`` is the local repository to clone into. |
|
1705 | ``repo`` is the local repository to clone into. | |
1710 | ``remote`` is a peer instance. |
|
1706 | ``remote`` is a peer instance. | |
1711 | ``heads`` is an iterable of revisions we want to pull. ``None`` (the |
|
1707 | ``heads`` is an iterable of revisions we want to pull. ``None`` (the | |
1712 | default) means to pull everything from the remote. |
|
1708 | default) means to pull everything from the remote. | |
1713 | ``bookmarks`` is an iterable of bookmarks requesting to be pulled. By |
|
1709 | ``bookmarks`` is an iterable of bookmarks requesting to be pulled. By | |
1714 | default, all remote bookmarks are pulled. |
|
1710 | default, all remote bookmarks are pulled. | |
1715 | ``opargs`` are additional keyword arguments to pass to ``pulloperation`` |
|
1711 | ``opargs`` are additional keyword arguments to pass to ``pulloperation`` | |
1716 | initialization. |
|
1712 | initialization. | |
1717 | ``streamclonerequested`` is a boolean indicating whether a "streaming |
|
1713 | ``streamclonerequested`` is a boolean indicating whether a "streaming | |
1718 | clone" is requested. A "streaming clone" is essentially a raw file copy |
|
1714 | clone" is requested. A "streaming clone" is essentially a raw file copy | |
1719 | of revlogs from the server. This only works when the local repository is |
|
1715 | of revlogs from the server. This only works when the local repository is | |
1720 | empty. The default value of ``None`` means to respect the server |
|
1716 | empty. The default value of ``None`` means to respect the server | |
1721 | configuration for preferring stream clones. |
|
1717 | configuration for preferring stream clones. | |
1722 | ``includepats`` and ``excludepats`` define explicit file patterns to |
|
1718 | ``includepats`` and ``excludepats`` define explicit file patterns to | |
1723 | include and exclude in storage, respectively. If not defined, narrow |
|
1719 | include and exclude in storage, respectively. If not defined, narrow | |
1724 | patterns from the repo instance are used, if available. |
|
1720 | patterns from the repo instance are used, if available. | |
1725 | ``depth`` is an integer indicating the DAG depth of history we're |
|
1721 | ``depth`` is an integer indicating the DAG depth of history we're | |
1726 | interested in. If defined, for each revision specified in ``heads``, we |
|
1722 | interested in. If defined, for each revision specified in ``heads``, we | |
1727 | will fetch up to this many of its ancestors and data associated with them. |
|
1723 | will fetch up to this many of its ancestors and data associated with them. | |
1728 |
|
1724 | |||
1729 | Returns the ``pulloperation`` created for this pull. |
|
1725 | Returns the ``pulloperation`` created for this pull. | |
1730 | """ |
|
1726 | """ | |
1731 | if opargs is None: |
|
1727 | if opargs is None: | |
1732 | opargs = {} |
|
1728 | opargs = {} | |
1733 |
|
1729 | |||
1734 | # We allow the narrow patterns to be passed in explicitly to provide more |
|
1730 | # We allow the narrow patterns to be passed in explicitly to provide more | |
1735 | # flexibility for API consumers. |
|
1731 | # flexibility for API consumers. | |
1736 | if includepats or excludepats: |
|
1732 | if includepats or excludepats: | |
1737 | includepats = includepats or set() |
|
1733 | includepats = includepats or set() | |
1738 | excludepats = excludepats or set() |
|
1734 | excludepats = excludepats or set() | |
1739 | else: |
|
1735 | else: | |
1740 | includepats, excludepats = repo.narrowpats |
|
1736 | includepats, excludepats = repo.narrowpats | |
1741 |
|
1737 | |||
1742 | narrowspec.validatepatterns(includepats) |
|
1738 | narrowspec.validatepatterns(includepats) | |
1743 | narrowspec.validatepatterns(excludepats) |
|
1739 | narrowspec.validatepatterns(excludepats) | |
1744 |
|
1740 | |||
1745 | pullop = pulloperation( |
|
1741 | pullop = pulloperation( | |
1746 | repo, |
|
1742 | repo, | |
1747 | remote, |
|
1743 | remote, | |
1748 | heads, |
|
1744 | heads, | |
1749 | force, |
|
1745 | force, | |
1750 | bookmarks=bookmarks, |
|
1746 | bookmarks=bookmarks, | |
1751 | streamclonerequested=streamclonerequested, |
|
1747 | streamclonerequested=streamclonerequested, | |
1752 | includepats=includepats, |
|
1748 | includepats=includepats, | |
1753 | excludepats=excludepats, |
|
1749 | excludepats=excludepats, | |
1754 | depth=depth, |
|
1750 | depth=depth, | |
1755 | **pycompat.strkwargs(opargs) |
|
1751 | **pycompat.strkwargs(opargs) | |
1756 | ) |
|
1752 | ) | |
1757 |
|
1753 | |||
1758 | peerlocal = pullop.remote.local() |
|
1754 | peerlocal = pullop.remote.local() | |
1759 | if peerlocal: |
|
1755 | if peerlocal: | |
1760 | missing = set(peerlocal.requirements) - pullop.repo.supported |
|
1756 | missing = set(peerlocal.requirements) - pullop.repo.supported | |
1761 | if missing: |
|
1757 | if missing: | |
1762 | msg = _( |
|
1758 | msg = _( | |
1763 | b"required features are not" |
|
1759 | b"required features are not" | |
1764 | b" supported in the destination:" |
|
1760 | b" supported in the destination:" | |
1765 | b" %s" |
|
1761 | b" %s" | |
1766 | ) % (b', '.join(sorted(missing))) |
|
1762 | ) % (b', '.join(sorted(missing))) | |
1767 | raise error.Abort(msg) |
|
1763 | raise error.Abort(msg) | |
1768 |
|
1764 | |||
1769 | pullop.trmanager = transactionmanager(repo, b'pull', remote.url()) |
|
1765 | pullop.trmanager = transactionmanager(repo, b'pull', remote.url()) | |
1770 | wlock = util.nullcontextmanager() |
|
1766 | wlock = util.nullcontextmanager() | |
1771 | if not bookmod.bookmarksinstore(repo): |
|
1767 | if not bookmod.bookmarksinstore(repo): | |
1772 | wlock = repo.wlock() |
|
1768 | wlock = repo.wlock() | |
1773 | with wlock, repo.lock(), pullop.trmanager: |
|
1769 | with wlock, repo.lock(), pullop.trmanager: | |
1774 | # Use the modern wire protocol, if available. |
|
1770 | # Use the modern wire protocol, if available. | |
1775 | if remote.capable(b'command-changesetdata'): |
|
1771 | if remote.capable(b'command-changesetdata'): | |
1776 | exchangev2.pull(pullop) |
|
1772 | exchangev2.pull(pullop) | |
1777 | else: |
|
1773 | else: | |
1778 | # This should ideally be in _pullbundle2(). However, it needs to run |
|
1774 | # This should ideally be in _pullbundle2(). However, it needs to run | |
1779 | # before discovery to avoid extra work. |
|
1775 | # before discovery to avoid extra work. | |
1780 | _maybeapplyclonebundle(pullop) |
|
1776 | _maybeapplyclonebundle(pullop) | |
1781 | streamclone.maybeperformlegacystreamclone(pullop) |
|
1777 | streamclone.maybeperformlegacystreamclone(pullop) | |
1782 | _pulldiscovery(pullop) |
|
1778 | _pulldiscovery(pullop) | |
1783 | if pullop.canusebundle2: |
|
1779 | if pullop.canusebundle2: | |
1784 | _fullpullbundle2(repo, pullop) |
|
1780 | _fullpullbundle2(repo, pullop) | |
1785 | _pullchangeset(pullop) |
|
1781 | _pullchangeset(pullop) | |
1786 | _pullphase(pullop) |
|
1782 | _pullphase(pullop) | |
1787 | _pullbookmarks(pullop) |
|
1783 | _pullbookmarks(pullop) | |
1788 | _pullobsolete(pullop) |
|
1784 | _pullobsolete(pullop) | |
1789 |
|
1785 | |||
1790 | # storing remotenames |
|
1786 | # storing remotenames | |
1791 | if repo.ui.configbool(b'experimental', b'remotenames'): |
|
1787 | if repo.ui.configbool(b'experimental', b'remotenames'): | |
1792 | logexchange.pullremotenames(repo, remote) |
|
1788 | logexchange.pullremotenames(repo, remote) | |
1793 |
|
1789 | |||
1794 | return pullop |
|
1790 | return pullop | |
1795 |
|
1791 | |||
1796 |
|
1792 | |||
1797 | # list of steps to perform discovery before pull |
|
1793 | # list of steps to perform discovery before pull | |
1798 | pulldiscoveryorder = [] |
|
1794 | pulldiscoveryorder = [] | |
1799 |
|
1795 | |||
1800 | # Mapping between step name and function |
|
1796 | # Mapping between step name and function | |
1801 | # |
|
1797 | # | |
1802 | # This exists to help extensions wrap steps if necessary |
|
1798 | # This exists to help extensions wrap steps if necessary | |
1803 | pulldiscoverymapping = {} |
|
1799 | pulldiscoverymapping = {} | |
1804 |
|
1800 | |||
1805 |
|
1801 | |||
1806 | def pulldiscovery(stepname): |
|
1802 | def pulldiscovery(stepname): | |
1807 | """decorator for function performing discovery before pull |
|
1803 | """decorator for function performing discovery before pull | |
1808 |
|
1804 | |||
1809 | The function is added to the step -> function mapping and appended to the |
|
1805 | The function is added to the step -> function mapping and appended to the | |
1810 | list of steps. Beware that decorated function will be added in order (this |
|
1806 | list of steps. Beware that decorated function will be added in order (this | |
1811 | may matter). |
|
1807 | may matter). | |
1812 |
|
1808 | |||
1813 | You can only use this decorator for a new step, if you want to wrap a step |
|
1809 | You can only use this decorator for a new step, if you want to wrap a step | |
1814 | from an extension, change the pulldiscovery dictionary directly.""" |
|
1810 | from an extension, change the pulldiscovery dictionary directly.""" | |
1815 |
|
1811 | |||
1816 | def dec(func): |
|
1812 | def dec(func): | |
1817 | assert stepname not in pulldiscoverymapping |
|
1813 | assert stepname not in pulldiscoverymapping | |
1818 | pulldiscoverymapping[stepname] = func |
|
1814 | pulldiscoverymapping[stepname] = func | |
1819 | pulldiscoveryorder.append(stepname) |
|
1815 | pulldiscoveryorder.append(stepname) | |
1820 | return func |
|
1816 | return func | |
1821 |
|
1817 | |||
1822 | return dec |
|
1818 | return dec | |
1823 |
|
1819 | |||
1824 |
|
1820 | |||
1825 | def _pulldiscovery(pullop): |
|
1821 | def _pulldiscovery(pullop): | |
1826 | """Run all discovery steps""" |
|
1822 | """Run all discovery steps""" | |
1827 | for stepname in pulldiscoveryorder: |
|
1823 | for stepname in pulldiscoveryorder: | |
1828 | step = pulldiscoverymapping[stepname] |
|
1824 | step = pulldiscoverymapping[stepname] | |
1829 | step(pullop) |
|
1825 | step(pullop) | |
1830 |
|
1826 | |||
1831 |
|
1827 | |||
1832 | @pulldiscovery(b'b1:bookmarks') |
|
1828 | @pulldiscovery(b'b1:bookmarks') | |
1833 | def _pullbookmarkbundle1(pullop): |
|
1829 | def _pullbookmarkbundle1(pullop): | |
1834 | """fetch bookmark data in bundle1 case |
|
1830 | """fetch bookmark data in bundle1 case | |
1835 |
|
1831 | |||
1836 | If not using bundle2, we have to fetch bookmarks before changeset |
|
1832 | If not using bundle2, we have to fetch bookmarks before changeset | |
1837 | discovery to reduce the chance and impact of race conditions.""" |
|
1833 | discovery to reduce the chance and impact of race conditions.""" | |
1838 | if pullop.remotebookmarks is not None: |
|
1834 | if pullop.remotebookmarks is not None: | |
1839 | return |
|
1835 | return | |
1840 | if pullop.canusebundle2 and b'listkeys' in pullop.remotebundle2caps: |
|
1836 | if pullop.canusebundle2 and b'listkeys' in pullop.remotebundle2caps: | |
1841 | # all known bundle2 servers now support listkeys, but lets be nice with |
|
1837 | # all known bundle2 servers now support listkeys, but lets be nice with | |
1842 | # new implementation. |
|
1838 | # new implementation. | |
1843 | return |
|
1839 | return | |
1844 | books = listkeys(pullop.remote, b'bookmarks') |
|
1840 | books = listkeys(pullop.remote, b'bookmarks') | |
1845 | pullop.remotebookmarks = bookmod.unhexlifybookmarks(books) |
|
1841 | pullop.remotebookmarks = bookmod.unhexlifybookmarks(books) | |
1846 |
|
1842 | |||
1847 |
|
1843 | |||
1848 | @pulldiscovery(b'changegroup') |
|
1844 | @pulldiscovery(b'changegroup') | |
1849 | def _pulldiscoverychangegroup(pullop): |
|
1845 | def _pulldiscoverychangegroup(pullop): | |
1850 | """discovery phase for the pull |
|
1846 | """discovery phase for the pull | |
1851 |
|
1847 | |||
1852 | Current handle changeset discovery only, will change handle all discovery |
|
1848 | Current handle changeset discovery only, will change handle all discovery | |
1853 | at some point.""" |
|
1849 | at some point.""" | |
1854 | tmp = discovery.findcommonincoming( |
|
1850 | tmp = discovery.findcommonincoming( | |
1855 | pullop.repo, pullop.remote, heads=pullop.heads, force=pullop.force |
|
1851 | pullop.repo, pullop.remote, heads=pullop.heads, force=pullop.force | |
1856 | ) |
|
1852 | ) | |
1857 | common, fetch, rheads = tmp |
|
1853 | common, fetch, rheads = tmp | |
1858 | nm = pullop.repo.unfiltered().changelog.nodemap |
|
1854 | nm = pullop.repo.unfiltered().changelog.nodemap | |
1859 | if fetch and rheads: |
|
1855 | if fetch and rheads: | |
1860 | # If a remote heads is filtered locally, put in back in common. |
|
1856 | # If a remote heads is filtered locally, put in back in common. | |
1861 | # |
|
1857 | # | |
1862 | # This is a hackish solution to catch most of "common but locally |
|
1858 | # This is a hackish solution to catch most of "common but locally | |
1863 | # hidden situation". We do not performs discovery on unfiltered |
|
1859 | # hidden situation". We do not performs discovery on unfiltered | |
1864 | # repository because it end up doing a pathological amount of round |
|
1860 | # repository because it end up doing a pathological amount of round | |
1865 | # trip for w huge amount of changeset we do not care about. |
|
1861 | # trip for w huge amount of changeset we do not care about. | |
1866 | # |
|
1862 | # | |
1867 | # If a set of such "common but filtered" changeset exist on the server |
|
1863 | # If a set of such "common but filtered" changeset exist on the server | |
1868 | # but are not including a remote heads, we'll not be able to detect it, |
|
1864 | # but are not including a remote heads, we'll not be able to detect it, | |
1869 | scommon = set(common) |
|
1865 | scommon = set(common) | |
1870 | for n in rheads: |
|
1866 | for n in rheads: | |
1871 | if n in nm: |
|
1867 | if n in nm: | |
1872 | if n not in scommon: |
|
1868 | if n not in scommon: | |
1873 | common.append(n) |
|
1869 | common.append(n) | |
1874 | if set(rheads).issubset(set(common)): |
|
1870 | if set(rheads).issubset(set(common)): | |
1875 | fetch = [] |
|
1871 | fetch = [] | |
1876 | pullop.common = common |
|
1872 | pullop.common = common | |
1877 | pullop.fetch = fetch |
|
1873 | pullop.fetch = fetch | |
1878 | pullop.rheads = rheads |
|
1874 | pullop.rheads = rheads | |
1879 |
|
1875 | |||
1880 |
|
1876 | |||
1881 | def _pullbundle2(pullop): |
|
1877 | def _pullbundle2(pullop): | |
1882 | """pull data using bundle2 |
|
1878 | """pull data using bundle2 | |
1883 |
|
1879 | |||
1884 | For now, the only supported data are changegroup.""" |
|
1880 | For now, the only supported data are changegroup.""" | |
1885 | kwargs = {b'bundlecaps': caps20to10(pullop.repo, role=b'client')} |
|
1881 | kwargs = {b'bundlecaps': caps20to10(pullop.repo, role=b'client')} | |
1886 |
|
1882 | |||
1887 | # make ui easier to access |
|
1883 | # make ui easier to access | |
1888 | ui = pullop.repo.ui |
|
1884 | ui = pullop.repo.ui | |
1889 |
|
1885 | |||
1890 | # At the moment we don't do stream clones over bundle2. If that is |
|
1886 | # At the moment we don't do stream clones over bundle2. If that is | |
1891 | # implemented then here's where the check for that will go. |
|
1887 | # implemented then here's where the check for that will go. | |
1892 | streaming = streamclone.canperformstreamclone(pullop, bundle2=True)[0] |
|
1888 | streaming = streamclone.canperformstreamclone(pullop, bundle2=True)[0] | |
1893 |
|
1889 | |||
1894 | # declare pull perimeters |
|
1890 | # declare pull perimeters | |
1895 | kwargs[b'common'] = pullop.common |
|
1891 | kwargs[b'common'] = pullop.common | |
1896 | kwargs[b'heads'] = pullop.heads or pullop.rheads |
|
1892 | kwargs[b'heads'] = pullop.heads or pullop.rheads | |
1897 |
|
1893 | |||
1898 | # check server supports narrow and then adding includepats and excludepats |
|
1894 | # check server supports narrow and then adding includepats and excludepats | |
1899 | servernarrow = pullop.remote.capable(wireprototypes.NARROWCAP) |
|
1895 | servernarrow = pullop.remote.capable(wireprototypes.NARROWCAP) | |
1900 | if servernarrow and pullop.includepats: |
|
1896 | if servernarrow and pullop.includepats: | |
1901 | kwargs[b'includepats'] = pullop.includepats |
|
1897 | kwargs[b'includepats'] = pullop.includepats | |
1902 | if servernarrow and pullop.excludepats: |
|
1898 | if servernarrow and pullop.excludepats: | |
1903 | kwargs[b'excludepats'] = pullop.excludepats |
|
1899 | kwargs[b'excludepats'] = pullop.excludepats | |
1904 |
|
1900 | |||
1905 | if streaming: |
|
1901 | if streaming: | |
1906 | kwargs[b'cg'] = False |
|
1902 | kwargs[b'cg'] = False | |
1907 | kwargs[b'stream'] = True |
|
1903 | kwargs[b'stream'] = True | |
1908 | pullop.stepsdone.add(b'changegroup') |
|
1904 | pullop.stepsdone.add(b'changegroup') | |
1909 | pullop.stepsdone.add(b'phases') |
|
1905 | pullop.stepsdone.add(b'phases') | |
1910 |
|
1906 | |||
1911 | else: |
|
1907 | else: | |
1912 | # pulling changegroup |
|
1908 | # pulling changegroup | |
1913 | pullop.stepsdone.add(b'changegroup') |
|
1909 | pullop.stepsdone.add(b'changegroup') | |
1914 |
|
1910 | |||
1915 | kwargs[b'cg'] = pullop.fetch |
|
1911 | kwargs[b'cg'] = pullop.fetch | |
1916 |
|
1912 | |||
1917 | legacyphase = b'phases' in ui.configlist(b'devel', b'legacy.exchange') |
|
1913 | legacyphase = b'phases' in ui.configlist(b'devel', b'legacy.exchange') | |
1918 | hasbinaryphase = b'heads' in pullop.remotebundle2caps.get(b'phases', ()) |
|
1914 | hasbinaryphase = b'heads' in pullop.remotebundle2caps.get(b'phases', ()) | |
1919 | if not legacyphase and hasbinaryphase: |
|
1915 | if not legacyphase and hasbinaryphase: | |
1920 | kwargs[b'phases'] = True |
|
1916 | kwargs[b'phases'] = True | |
1921 | pullop.stepsdone.add(b'phases') |
|
1917 | pullop.stepsdone.add(b'phases') | |
1922 |
|
1918 | |||
1923 | if b'listkeys' in pullop.remotebundle2caps: |
|
1919 | if b'listkeys' in pullop.remotebundle2caps: | |
1924 | if b'phases' not in pullop.stepsdone: |
|
1920 | if b'phases' not in pullop.stepsdone: | |
1925 | kwargs[b'listkeys'] = [b'phases'] |
|
1921 | kwargs[b'listkeys'] = [b'phases'] | |
1926 |
|
1922 | |||
1927 | bookmarksrequested = False |
|
1923 | bookmarksrequested = False | |
1928 | legacybookmark = b'bookmarks' in ui.configlist(b'devel', b'legacy.exchange') |
|
1924 | legacybookmark = b'bookmarks' in ui.configlist(b'devel', b'legacy.exchange') | |
1929 | hasbinarybook = b'bookmarks' in pullop.remotebundle2caps |
|
1925 | hasbinarybook = b'bookmarks' in pullop.remotebundle2caps | |
1930 |
|
1926 | |||
1931 | if pullop.remotebookmarks is not None: |
|
1927 | if pullop.remotebookmarks is not None: | |
1932 | pullop.stepsdone.add(b'request-bookmarks') |
|
1928 | pullop.stepsdone.add(b'request-bookmarks') | |
1933 |
|
1929 | |||
1934 | if ( |
|
1930 | if ( | |
1935 | b'request-bookmarks' not in pullop.stepsdone |
|
1931 | b'request-bookmarks' not in pullop.stepsdone | |
1936 | and pullop.remotebookmarks is None |
|
1932 | and pullop.remotebookmarks is None | |
1937 | and not legacybookmark |
|
1933 | and not legacybookmark | |
1938 | and hasbinarybook |
|
1934 | and hasbinarybook | |
1939 | ): |
|
1935 | ): | |
1940 | kwargs[b'bookmarks'] = True |
|
1936 | kwargs[b'bookmarks'] = True | |
1941 | bookmarksrequested = True |
|
1937 | bookmarksrequested = True | |
1942 |
|
1938 | |||
1943 | if b'listkeys' in pullop.remotebundle2caps: |
|
1939 | if b'listkeys' in pullop.remotebundle2caps: | |
1944 | if b'request-bookmarks' not in pullop.stepsdone: |
|
1940 | if b'request-bookmarks' not in pullop.stepsdone: | |
1945 | # make sure to always includes bookmark data when migrating |
|
1941 | # make sure to always includes bookmark data when migrating | |
1946 | # `hg incoming --bundle` to using this function. |
|
1942 | # `hg incoming --bundle` to using this function. | |
1947 | pullop.stepsdone.add(b'request-bookmarks') |
|
1943 | pullop.stepsdone.add(b'request-bookmarks') | |
1948 | kwargs.setdefault(b'listkeys', []).append(b'bookmarks') |
|
1944 | kwargs.setdefault(b'listkeys', []).append(b'bookmarks') | |
1949 |
|
1945 | |||
1950 | # If this is a full pull / clone and the server supports the clone bundles |
|
1946 | # If this is a full pull / clone and the server supports the clone bundles | |
1951 | # feature, tell the server whether we attempted a clone bundle. The |
|
1947 | # feature, tell the server whether we attempted a clone bundle. The | |
1952 | # presence of this flag indicates the client supports clone bundles. This |
|
1948 | # presence of this flag indicates the client supports clone bundles. This | |
1953 | # will enable the server to treat clients that support clone bundles |
|
1949 | # will enable the server to treat clients that support clone bundles | |
1954 | # differently from those that don't. |
|
1950 | # differently from those that don't. | |
1955 | if ( |
|
1951 | if ( | |
1956 | pullop.remote.capable(b'clonebundles') |
|
1952 | pullop.remote.capable(b'clonebundles') | |
1957 | and pullop.heads is None |
|
1953 | and pullop.heads is None | |
1958 | and list(pullop.common) == [nullid] |
|
1954 | and list(pullop.common) == [nullid] | |
1959 | ): |
|
1955 | ): | |
1960 | kwargs[b'cbattempted'] = pullop.clonebundleattempted |
|
1956 | kwargs[b'cbattempted'] = pullop.clonebundleattempted | |
1961 |
|
1957 | |||
1962 | if streaming: |
|
1958 | if streaming: | |
1963 | pullop.repo.ui.status(_(b'streaming all changes\n')) |
|
1959 | pullop.repo.ui.status(_(b'streaming all changes\n')) | |
1964 | elif not pullop.fetch: |
|
1960 | elif not pullop.fetch: | |
1965 | pullop.repo.ui.status(_(b"no changes found\n")) |
|
1961 | pullop.repo.ui.status(_(b"no changes found\n")) | |
1966 | pullop.cgresult = 0 |
|
1962 | pullop.cgresult = 0 | |
1967 | else: |
|
1963 | else: | |
1968 | if pullop.heads is None and list(pullop.common) == [nullid]: |
|
1964 | if pullop.heads is None and list(pullop.common) == [nullid]: | |
1969 | pullop.repo.ui.status(_(b"requesting all changes\n")) |
|
1965 | pullop.repo.ui.status(_(b"requesting all changes\n")) | |
1970 | if obsolete.isenabled(pullop.repo, obsolete.exchangeopt): |
|
1966 | if obsolete.isenabled(pullop.repo, obsolete.exchangeopt): | |
1971 | remoteversions = bundle2.obsmarkersversion(pullop.remotebundle2caps) |
|
1967 | remoteversions = bundle2.obsmarkersversion(pullop.remotebundle2caps) | |
1972 | if obsolete.commonversion(remoteversions) is not None: |
|
1968 | if obsolete.commonversion(remoteversions) is not None: | |
1973 | kwargs[b'obsmarkers'] = True |
|
1969 | kwargs[b'obsmarkers'] = True | |
1974 | pullop.stepsdone.add(b'obsmarkers') |
|
1970 | pullop.stepsdone.add(b'obsmarkers') | |
1975 | _pullbundle2extraprepare(pullop, kwargs) |
|
1971 | _pullbundle2extraprepare(pullop, kwargs) | |
1976 |
|
1972 | |||
1977 | with pullop.remote.commandexecutor() as e: |
|
1973 | with pullop.remote.commandexecutor() as e: | |
1978 | args = dict(kwargs) |
|
1974 | args = dict(kwargs) | |
1979 | args[b'source'] = b'pull' |
|
1975 | args[b'source'] = b'pull' | |
1980 | bundle = e.callcommand(b'getbundle', args).result() |
|
1976 | bundle = e.callcommand(b'getbundle', args).result() | |
1981 |
|
1977 | |||
1982 | try: |
|
1978 | try: | |
1983 | op = bundle2.bundleoperation( |
|
1979 | op = bundle2.bundleoperation( | |
1984 | pullop.repo, pullop.gettransaction, source=b'pull' |
|
1980 | pullop.repo, pullop.gettransaction, source=b'pull' | |
1985 | ) |
|
1981 | ) | |
1986 | op.modes[b'bookmarks'] = b'records' |
|
1982 | op.modes[b'bookmarks'] = b'records' | |
1987 | bundle2.processbundle(pullop.repo, bundle, op=op) |
|
1983 | bundle2.processbundle(pullop.repo, bundle, op=op) | |
1988 | except bundle2.AbortFromPart as exc: |
|
1984 | except bundle2.AbortFromPart as exc: | |
1989 | pullop.repo.ui.status(_(b'remote: abort: %s\n') % exc) |
|
1985 | pullop.repo.ui.status(_(b'remote: abort: %s\n') % exc) | |
1990 | raise error.Abort(_(b'pull failed on remote'), hint=exc.hint) |
|
1986 | raise error.Abort(_(b'pull failed on remote'), hint=exc.hint) | |
1991 | except error.BundleValueError as exc: |
|
1987 | except error.BundleValueError as exc: | |
1992 | raise error.Abort(_(b'missing support for %s') % exc) |
|
1988 | raise error.Abort(_(b'missing support for %s') % exc) | |
1993 |
|
1989 | |||
1994 | if pullop.fetch: |
|
1990 | if pullop.fetch: | |
1995 | pullop.cgresult = bundle2.combinechangegroupresults(op) |
|
1991 | pullop.cgresult = bundle2.combinechangegroupresults(op) | |
1996 |
|
1992 | |||
1997 | # processing phases change |
|
1993 | # processing phases change | |
1998 | for namespace, value in op.records[b'listkeys']: |
|
1994 | for namespace, value in op.records[b'listkeys']: | |
1999 | if namespace == b'phases': |
|
1995 | if namespace == b'phases': | |
2000 | _pullapplyphases(pullop, value) |
|
1996 | _pullapplyphases(pullop, value) | |
2001 |
|
1997 | |||
2002 | # processing bookmark update |
|
1998 | # processing bookmark update | |
2003 | if bookmarksrequested: |
|
1999 | if bookmarksrequested: | |
2004 | books = {} |
|
2000 | books = {} | |
2005 | for record in op.records[b'bookmarks']: |
|
2001 | for record in op.records[b'bookmarks']: | |
2006 | books[record[b'bookmark']] = record[b"node"] |
|
2002 | books[record[b'bookmark']] = record[b"node"] | |
2007 | pullop.remotebookmarks = books |
|
2003 | pullop.remotebookmarks = books | |
2008 | else: |
|
2004 | else: | |
2009 | for namespace, value in op.records[b'listkeys']: |
|
2005 | for namespace, value in op.records[b'listkeys']: | |
2010 | if namespace == b'bookmarks': |
|
2006 | if namespace == b'bookmarks': | |
2011 | pullop.remotebookmarks = bookmod.unhexlifybookmarks(value) |
|
2007 | pullop.remotebookmarks = bookmod.unhexlifybookmarks(value) | |
2012 |
|
2008 | |||
2013 | # bookmark data were either already there or pulled in the bundle |
|
2009 | # bookmark data were either already there or pulled in the bundle | |
2014 | if pullop.remotebookmarks is not None: |
|
2010 | if pullop.remotebookmarks is not None: | |
2015 | _pullbookmarks(pullop) |
|
2011 | _pullbookmarks(pullop) | |
2016 |
|
2012 | |||
2017 |
|
2013 | |||
2018 | def _pullbundle2extraprepare(pullop, kwargs): |
|
2014 | def _pullbundle2extraprepare(pullop, kwargs): | |
2019 | """hook function so that extensions can extend the getbundle call""" |
|
2015 | """hook function so that extensions can extend the getbundle call""" | |
2020 |
|
2016 | |||
2021 |
|
2017 | |||
2022 | def _pullchangeset(pullop): |
|
2018 | def _pullchangeset(pullop): | |
2023 | """pull changeset from unbundle into the local repo""" |
|
2019 | """pull changeset from unbundle into the local repo""" | |
2024 | # We delay the open of the transaction as late as possible so we |
|
2020 | # We delay the open of the transaction as late as possible so we | |
2025 | # don't open transaction for nothing or you break future useful |
|
2021 | # don't open transaction for nothing or you break future useful | |
2026 | # rollback call |
|
2022 | # rollback call | |
2027 | if b'changegroup' in pullop.stepsdone: |
|
2023 | if b'changegroup' in pullop.stepsdone: | |
2028 | return |
|
2024 | return | |
2029 | pullop.stepsdone.add(b'changegroup') |
|
2025 | pullop.stepsdone.add(b'changegroup') | |
2030 | if not pullop.fetch: |
|
2026 | if not pullop.fetch: | |
2031 | pullop.repo.ui.status(_(b"no changes found\n")) |
|
2027 | pullop.repo.ui.status(_(b"no changes found\n")) | |
2032 | pullop.cgresult = 0 |
|
2028 | pullop.cgresult = 0 | |
2033 | return |
|
2029 | return | |
2034 | tr = pullop.gettransaction() |
|
2030 | tr = pullop.gettransaction() | |
2035 | if pullop.heads is None and list(pullop.common) == [nullid]: |
|
2031 | if pullop.heads is None and list(pullop.common) == [nullid]: | |
2036 | pullop.repo.ui.status(_(b"requesting all changes\n")) |
|
2032 | pullop.repo.ui.status(_(b"requesting all changes\n")) | |
2037 | elif pullop.heads is None and pullop.remote.capable(b'changegroupsubset'): |
|
2033 | elif pullop.heads is None and pullop.remote.capable(b'changegroupsubset'): | |
2038 | # issue1320, avoid a race if remote changed after discovery |
|
2034 | # issue1320, avoid a race if remote changed after discovery | |
2039 | pullop.heads = pullop.rheads |
|
2035 | pullop.heads = pullop.rheads | |
2040 |
|
2036 | |||
2041 | if pullop.remote.capable(b'getbundle'): |
|
2037 | if pullop.remote.capable(b'getbundle'): | |
2042 | # TODO: get bundlecaps from remote |
|
2038 | # TODO: get bundlecaps from remote | |
2043 | cg = pullop.remote.getbundle( |
|
2039 | cg = pullop.remote.getbundle( | |
2044 | b'pull', common=pullop.common, heads=pullop.heads or pullop.rheads |
|
2040 | b'pull', common=pullop.common, heads=pullop.heads or pullop.rheads | |
2045 | ) |
|
2041 | ) | |
2046 | elif pullop.heads is None: |
|
2042 | elif pullop.heads is None: | |
2047 | with pullop.remote.commandexecutor() as e: |
|
2043 | with pullop.remote.commandexecutor() as e: | |
2048 | cg = e.callcommand( |
|
2044 | cg = e.callcommand( | |
2049 | b'changegroup', {b'nodes': pullop.fetch, b'source': b'pull',} |
|
2045 | b'changegroup', {b'nodes': pullop.fetch, b'source': b'pull',} | |
2050 | ).result() |
|
2046 | ).result() | |
2051 |
|
2047 | |||
2052 | elif not pullop.remote.capable(b'changegroupsubset'): |
|
2048 | elif not pullop.remote.capable(b'changegroupsubset'): | |
2053 | raise error.Abort( |
|
2049 | raise error.Abort( | |
2054 | _( |
|
2050 | _( | |
2055 | b"partial pull cannot be done because " |
|
2051 | b"partial pull cannot be done because " | |
2056 | b"other repository doesn't support " |
|
2052 | b"other repository doesn't support " | |
2057 | b"changegroupsubset." |
|
2053 | b"changegroupsubset." | |
2058 | ) |
|
2054 | ) | |
2059 | ) |
|
2055 | ) | |
2060 | else: |
|
2056 | else: | |
2061 | with pullop.remote.commandexecutor() as e: |
|
2057 | with pullop.remote.commandexecutor() as e: | |
2062 | cg = e.callcommand( |
|
2058 | cg = e.callcommand( | |
2063 | b'changegroupsubset', |
|
2059 | b'changegroupsubset', | |
2064 | { |
|
2060 | { | |
2065 | b'bases': pullop.fetch, |
|
2061 | b'bases': pullop.fetch, | |
2066 | b'heads': pullop.heads, |
|
2062 | b'heads': pullop.heads, | |
2067 | b'source': b'pull', |
|
2063 | b'source': b'pull', | |
2068 | }, |
|
2064 | }, | |
2069 | ).result() |
|
2065 | ).result() | |
2070 |
|
2066 | |||
2071 | bundleop = bundle2.applybundle( |
|
2067 | bundleop = bundle2.applybundle( | |
2072 | pullop.repo, cg, tr, b'pull', pullop.remote.url() |
|
2068 | pullop.repo, cg, tr, b'pull', pullop.remote.url() | |
2073 | ) |
|
2069 | ) | |
2074 | pullop.cgresult = bundle2.combinechangegroupresults(bundleop) |
|
2070 | pullop.cgresult = bundle2.combinechangegroupresults(bundleop) | |
2075 |
|
2071 | |||
2076 |
|
2072 | |||
2077 | def _pullphase(pullop): |
|
2073 | def _pullphase(pullop): | |
2078 | # Get remote phases data from remote |
|
2074 | # Get remote phases data from remote | |
2079 | if b'phases' in pullop.stepsdone: |
|
2075 | if b'phases' in pullop.stepsdone: | |
2080 | return |
|
2076 | return | |
2081 | remotephases = listkeys(pullop.remote, b'phases') |
|
2077 | remotephases = listkeys(pullop.remote, b'phases') | |
2082 | _pullapplyphases(pullop, remotephases) |
|
2078 | _pullapplyphases(pullop, remotephases) | |
2083 |
|
2079 | |||
2084 |
|
2080 | |||
2085 | def _pullapplyphases(pullop, remotephases): |
|
2081 | def _pullapplyphases(pullop, remotephases): | |
2086 | """apply phase movement from observed remote state""" |
|
2082 | """apply phase movement from observed remote state""" | |
2087 | if b'phases' in pullop.stepsdone: |
|
2083 | if b'phases' in pullop.stepsdone: | |
2088 | return |
|
2084 | return | |
2089 | pullop.stepsdone.add(b'phases') |
|
2085 | pullop.stepsdone.add(b'phases') | |
2090 | publishing = bool(remotephases.get(b'publishing', False)) |
|
2086 | publishing = bool(remotephases.get(b'publishing', False)) | |
2091 | if remotephases and not publishing: |
|
2087 | if remotephases and not publishing: | |
2092 | # remote is new and non-publishing |
|
2088 | # remote is new and non-publishing | |
2093 | pheads, _dr = phases.analyzeremotephases( |
|
2089 | pheads, _dr = phases.analyzeremotephases( | |
2094 | pullop.repo, pullop.pulledsubset, remotephases |
|
2090 | pullop.repo, pullop.pulledsubset, remotephases | |
2095 | ) |
|
2091 | ) | |
2096 | dheads = pullop.pulledsubset |
|
2092 | dheads = pullop.pulledsubset | |
2097 | else: |
|
2093 | else: | |
2098 | # Remote is old or publishing all common changesets |
|
2094 | # Remote is old or publishing all common changesets | |
2099 | # should be seen as public |
|
2095 | # should be seen as public | |
2100 | pheads = pullop.pulledsubset |
|
2096 | pheads = pullop.pulledsubset | |
2101 | dheads = [] |
|
2097 | dheads = [] | |
2102 | unfi = pullop.repo.unfiltered() |
|
2098 | unfi = pullop.repo.unfiltered() | |
2103 | phase = unfi._phasecache.phase |
|
2099 | phase = unfi._phasecache.phase | |
2104 | rev = unfi.changelog.nodemap.get |
|
2100 | rev = unfi.changelog.nodemap.get | |
2105 | public = phases.public |
|
2101 | public = phases.public | |
2106 | draft = phases.draft |
|
2102 | draft = phases.draft | |
2107 |
|
2103 | |||
2108 | # exclude changesets already public locally and update the others |
|
2104 | # exclude changesets already public locally and update the others | |
2109 | pheads = [pn for pn in pheads if phase(unfi, rev(pn)) > public] |
|
2105 | pheads = [pn for pn in pheads if phase(unfi, rev(pn)) > public] | |
2110 | if pheads: |
|
2106 | if pheads: | |
2111 | tr = pullop.gettransaction() |
|
2107 | tr = pullop.gettransaction() | |
2112 | phases.advanceboundary(pullop.repo, tr, public, pheads) |
|
2108 | phases.advanceboundary(pullop.repo, tr, public, pheads) | |
2113 |
|
2109 | |||
2114 | # exclude changesets already draft locally and update the others |
|
2110 | # exclude changesets already draft locally and update the others | |
2115 | dheads = [pn for pn in dheads if phase(unfi, rev(pn)) > draft] |
|
2111 | dheads = [pn for pn in dheads if phase(unfi, rev(pn)) > draft] | |
2116 | if dheads: |
|
2112 | if dheads: | |
2117 | tr = pullop.gettransaction() |
|
2113 | tr = pullop.gettransaction() | |
2118 | phases.advanceboundary(pullop.repo, tr, draft, dheads) |
|
2114 | phases.advanceboundary(pullop.repo, tr, draft, dheads) | |
2119 |
|
2115 | |||
2120 |
|
2116 | |||
2121 | def _pullbookmarks(pullop): |
|
2117 | def _pullbookmarks(pullop): | |
2122 | """process the remote bookmark information to update the local one""" |
|
2118 | """process the remote bookmark information to update the local one""" | |
2123 | if b'bookmarks' in pullop.stepsdone: |
|
2119 | if b'bookmarks' in pullop.stepsdone: | |
2124 | return |
|
2120 | return | |
2125 | pullop.stepsdone.add(b'bookmarks') |
|
2121 | pullop.stepsdone.add(b'bookmarks') | |
2126 | repo = pullop.repo |
|
2122 | repo = pullop.repo | |
2127 | remotebookmarks = pullop.remotebookmarks |
|
2123 | remotebookmarks = pullop.remotebookmarks | |
2128 | bookmod.updatefromremote( |
|
2124 | bookmod.updatefromremote( | |
2129 | repo.ui, |
|
2125 | repo.ui, | |
2130 | repo, |
|
2126 | repo, | |
2131 | remotebookmarks, |
|
2127 | remotebookmarks, | |
2132 | pullop.remote.url(), |
|
2128 | pullop.remote.url(), | |
2133 | pullop.gettransaction, |
|
2129 | pullop.gettransaction, | |
2134 | explicit=pullop.explicitbookmarks, |
|
2130 | explicit=pullop.explicitbookmarks, | |
2135 | ) |
|
2131 | ) | |
2136 |
|
2132 | |||
2137 |
|
2133 | |||
2138 | def _pullobsolete(pullop): |
|
2134 | def _pullobsolete(pullop): | |
2139 | """utility function to pull obsolete markers from a remote |
|
2135 | """utility function to pull obsolete markers from a remote | |
2140 |
|
2136 | |||
2141 | The `gettransaction` is function that return the pull transaction, creating |
|
2137 | The `gettransaction` is function that return the pull transaction, creating | |
2142 | one if necessary. We return the transaction to inform the calling code that |
|
2138 | one if necessary. We return the transaction to inform the calling code that | |
2143 | a new transaction have been created (when applicable). |
|
2139 | a new transaction have been created (when applicable). | |
2144 |
|
2140 | |||
2145 | Exists mostly to allow overriding for experimentation purpose""" |
|
2141 | Exists mostly to allow overriding for experimentation purpose""" | |
2146 | if b'obsmarkers' in pullop.stepsdone: |
|
2142 | if b'obsmarkers' in pullop.stepsdone: | |
2147 | return |
|
2143 | return | |
2148 | pullop.stepsdone.add(b'obsmarkers') |
|
2144 | pullop.stepsdone.add(b'obsmarkers') | |
2149 | tr = None |
|
2145 | tr = None | |
2150 | if obsolete.isenabled(pullop.repo, obsolete.exchangeopt): |
|
2146 | if obsolete.isenabled(pullop.repo, obsolete.exchangeopt): | |
2151 | pullop.repo.ui.debug(b'fetching remote obsolete markers\n') |
|
2147 | pullop.repo.ui.debug(b'fetching remote obsolete markers\n') | |
2152 | remoteobs = listkeys(pullop.remote, b'obsolete') |
|
2148 | remoteobs = listkeys(pullop.remote, b'obsolete') | |
2153 | if b'dump0' in remoteobs: |
|
2149 | if b'dump0' in remoteobs: | |
2154 | tr = pullop.gettransaction() |
|
2150 | tr = pullop.gettransaction() | |
2155 | markers = [] |
|
2151 | markers = [] | |
2156 | for key in sorted(remoteobs, reverse=True): |
|
2152 | for key in sorted(remoteobs, reverse=True): | |
2157 | if key.startswith(b'dump'): |
|
2153 | if key.startswith(b'dump'): | |
2158 | data = util.b85decode(remoteobs[key]) |
|
2154 | data = util.b85decode(remoteobs[key]) | |
2159 | version, newmarks = obsolete._readmarkers(data) |
|
2155 | version, newmarks = obsolete._readmarkers(data) | |
2160 | markers += newmarks |
|
2156 | markers += newmarks | |
2161 | if markers: |
|
2157 | if markers: | |
2162 | pullop.repo.obsstore.add(tr, markers) |
|
2158 | pullop.repo.obsstore.add(tr, markers) | |
2163 | pullop.repo.invalidatevolatilesets() |
|
2159 | pullop.repo.invalidatevolatilesets() | |
2164 | return tr |
|
2160 | return tr | |
2165 |
|
2161 | |||
2166 |
|
2162 | |||
2167 | def applynarrowacl(repo, kwargs): |
|
2163 | def applynarrowacl(repo, kwargs): | |
2168 | """Apply narrow fetch access control. |
|
2164 | """Apply narrow fetch access control. | |
2169 |
|
2165 | |||
2170 | This massages the named arguments for getbundle wire protocol commands |
|
2166 | This massages the named arguments for getbundle wire protocol commands | |
2171 | so requested data is filtered through access control rules. |
|
2167 | so requested data is filtered through access control rules. | |
2172 | """ |
|
2168 | """ | |
2173 | ui = repo.ui |
|
2169 | ui = repo.ui | |
2174 | # TODO this assumes existence of HTTP and is a layering violation. |
|
2170 | # TODO this assumes existence of HTTP and is a layering violation. | |
2175 | username = ui.shortuser(ui.environ.get(b'REMOTE_USER') or ui.username()) |
|
2171 | username = ui.shortuser(ui.environ.get(b'REMOTE_USER') or ui.username()) | |
2176 | user_includes = ui.configlist( |
|
2172 | user_includes = ui.configlist( | |
2177 | _NARROWACL_SECTION, |
|
2173 | _NARROWACL_SECTION, | |
2178 | username + b'.includes', |
|
2174 | username + b'.includes', | |
2179 | ui.configlist(_NARROWACL_SECTION, b'default.includes'), |
|
2175 | ui.configlist(_NARROWACL_SECTION, b'default.includes'), | |
2180 | ) |
|
2176 | ) | |
2181 | user_excludes = ui.configlist( |
|
2177 | user_excludes = ui.configlist( | |
2182 | _NARROWACL_SECTION, |
|
2178 | _NARROWACL_SECTION, | |
2183 | username + b'.excludes', |
|
2179 | username + b'.excludes', | |
2184 | ui.configlist(_NARROWACL_SECTION, b'default.excludes'), |
|
2180 | ui.configlist(_NARROWACL_SECTION, b'default.excludes'), | |
2185 | ) |
|
2181 | ) | |
2186 | if not user_includes: |
|
2182 | if not user_includes: | |
2187 | raise error.Abort( |
|
2183 | raise error.Abort( | |
2188 | _(b"{} configuration for user {} is empty").format( |
|
2184 | _(b"{} configuration for user {} is empty").format( | |
2189 | _NARROWACL_SECTION, username |
|
2185 | _NARROWACL_SECTION, username | |
2190 | ) |
|
2186 | ) | |
2191 | ) |
|
2187 | ) | |
2192 |
|
2188 | |||
2193 | user_includes = [ |
|
2189 | user_includes = [ | |
2194 | b'path:.' if p == b'*' else b'path:' + p for p in user_includes |
|
2190 | b'path:.' if p == b'*' else b'path:' + p for p in user_includes | |
2195 | ] |
|
2191 | ] | |
2196 | user_excludes = [ |
|
2192 | user_excludes = [ | |
2197 | b'path:.' if p == b'*' else b'path:' + p for p in user_excludes |
|
2193 | b'path:.' if p == b'*' else b'path:' + p for p in user_excludes | |
2198 | ] |
|
2194 | ] | |
2199 |
|
2195 | |||
2200 | req_includes = set(kwargs.get(r'includepats', [])) |
|
2196 | req_includes = set(kwargs.get(r'includepats', [])) | |
2201 | req_excludes = set(kwargs.get(r'excludepats', [])) |
|
2197 | req_excludes = set(kwargs.get(r'excludepats', [])) | |
2202 |
|
2198 | |||
2203 | req_includes, req_excludes, invalid_includes = narrowspec.restrictpatterns( |
|
2199 | req_includes, req_excludes, invalid_includes = narrowspec.restrictpatterns( | |
2204 | req_includes, req_excludes, user_includes, user_excludes |
|
2200 | req_includes, req_excludes, user_includes, user_excludes | |
2205 | ) |
|
2201 | ) | |
2206 |
|
2202 | |||
2207 | if invalid_includes: |
|
2203 | if invalid_includes: | |
2208 | raise error.Abort( |
|
2204 | raise error.Abort( | |
2209 | _(b"The following includes are not accessible for {}: {}").format( |
|
2205 | _(b"The following includes are not accessible for {}: {}").format( | |
2210 | username, invalid_includes |
|
2206 | username, invalid_includes | |
2211 | ) |
|
2207 | ) | |
2212 | ) |
|
2208 | ) | |
2213 |
|
2209 | |||
2214 | new_args = {} |
|
2210 | new_args = {} | |
2215 | new_args.update(kwargs) |
|
2211 | new_args.update(kwargs) | |
2216 | new_args[r'narrow'] = True |
|
2212 | new_args[r'narrow'] = True | |
2217 | new_args[r'narrow_acl'] = True |
|
2213 | new_args[r'narrow_acl'] = True | |
2218 | new_args[r'includepats'] = req_includes |
|
2214 | new_args[r'includepats'] = req_includes | |
2219 | if req_excludes: |
|
2215 | if req_excludes: | |
2220 | new_args[r'excludepats'] = req_excludes |
|
2216 | new_args[r'excludepats'] = req_excludes | |
2221 |
|
2217 | |||
2222 | return new_args |
|
2218 | return new_args | |
2223 |
|
2219 | |||
2224 |
|
2220 | |||
2225 | def _computeellipsis(repo, common, heads, known, match, depth=None): |
|
2221 | def _computeellipsis(repo, common, heads, known, match, depth=None): | |
2226 | """Compute the shape of a narrowed DAG. |
|
2222 | """Compute the shape of a narrowed DAG. | |
2227 |
|
2223 | |||
2228 | Args: |
|
2224 | Args: | |
2229 | repo: The repository we're transferring. |
|
2225 | repo: The repository we're transferring. | |
2230 | common: The roots of the DAG range we're transferring. |
|
2226 | common: The roots of the DAG range we're transferring. | |
2231 | May be just [nullid], which means all ancestors of heads. |
|
2227 | May be just [nullid], which means all ancestors of heads. | |
2232 | heads: The heads of the DAG range we're transferring. |
|
2228 | heads: The heads of the DAG range we're transferring. | |
2233 | match: The narrowmatcher that allows us to identify relevant changes. |
|
2229 | match: The narrowmatcher that allows us to identify relevant changes. | |
2234 | depth: If not None, only consider nodes to be full nodes if they are at |
|
2230 | depth: If not None, only consider nodes to be full nodes if they are at | |
2235 | most depth changesets away from one of heads. |
|
2231 | most depth changesets away from one of heads. | |
2236 |
|
2232 | |||
2237 | Returns: |
|
2233 | Returns: | |
2238 | A tuple of (visitnodes, relevant_nodes, ellipsisroots) where: |
|
2234 | A tuple of (visitnodes, relevant_nodes, ellipsisroots) where: | |
2239 |
|
2235 | |||
2240 | visitnodes: The list of nodes (either full or ellipsis) which |
|
2236 | visitnodes: The list of nodes (either full or ellipsis) which | |
2241 | need to be sent to the client. |
|
2237 | need to be sent to the client. | |
2242 | relevant_nodes: The set of changelog nodes which change a file inside |
|
2238 | relevant_nodes: The set of changelog nodes which change a file inside | |
2243 | the narrowspec. The client needs these as non-ellipsis nodes. |
|
2239 | the narrowspec. The client needs these as non-ellipsis nodes. | |
2244 | ellipsisroots: A dict of {rev: parents} that is used in |
|
2240 | ellipsisroots: A dict of {rev: parents} that is used in | |
2245 | narrowchangegroup to produce ellipsis nodes with the |
|
2241 | narrowchangegroup to produce ellipsis nodes with the | |
2246 | correct parents. |
|
2242 | correct parents. | |
2247 | """ |
|
2243 | """ | |
2248 | cl = repo.changelog |
|
2244 | cl = repo.changelog | |
2249 | mfl = repo.manifestlog |
|
2245 | mfl = repo.manifestlog | |
2250 |
|
2246 | |||
2251 | clrev = cl.rev |
|
2247 | clrev = cl.rev | |
2252 |
|
2248 | |||
2253 | commonrevs = {clrev(n) for n in common} | {nullrev} |
|
2249 | commonrevs = {clrev(n) for n in common} | {nullrev} | |
2254 | headsrevs = {clrev(n) for n in heads} |
|
2250 | headsrevs = {clrev(n) for n in heads} | |
2255 |
|
2251 | |||
2256 | if depth: |
|
2252 | if depth: | |
2257 | revdepth = {h: 0 for h in headsrevs} |
|
2253 | revdepth = {h: 0 for h in headsrevs} | |
2258 |
|
2254 | |||
2259 | ellipsisheads = collections.defaultdict(set) |
|
2255 | ellipsisheads = collections.defaultdict(set) | |
2260 | ellipsisroots = collections.defaultdict(set) |
|
2256 | ellipsisroots = collections.defaultdict(set) | |
2261 |
|
2257 | |||
2262 | def addroot(head, curchange): |
|
2258 | def addroot(head, curchange): | |
2263 | """Add a root to an ellipsis head, splitting heads with 3 roots.""" |
|
2259 | """Add a root to an ellipsis head, splitting heads with 3 roots.""" | |
2264 | ellipsisroots[head].add(curchange) |
|
2260 | ellipsisroots[head].add(curchange) | |
2265 | # Recursively split ellipsis heads with 3 roots by finding the |
|
2261 | # Recursively split ellipsis heads with 3 roots by finding the | |
2266 | # roots' youngest common descendant which is an elided merge commit. |
|
2262 | # roots' youngest common descendant which is an elided merge commit. | |
2267 | # That descendant takes 2 of the 3 roots as its own, and becomes a |
|
2263 | # That descendant takes 2 of the 3 roots as its own, and becomes a | |
2268 | # root of the head. |
|
2264 | # root of the head. | |
2269 | while len(ellipsisroots[head]) > 2: |
|
2265 | while len(ellipsisroots[head]) > 2: | |
2270 | child, roots = splithead(head) |
|
2266 | child, roots = splithead(head) | |
2271 | splitroots(head, child, roots) |
|
2267 | splitroots(head, child, roots) | |
2272 | head = child # Recurse in case we just added a 3rd root |
|
2268 | head = child # Recurse in case we just added a 3rd root | |
2273 |
|
2269 | |||
2274 | def splitroots(head, child, roots): |
|
2270 | def splitroots(head, child, roots): | |
2275 | ellipsisroots[head].difference_update(roots) |
|
2271 | ellipsisroots[head].difference_update(roots) | |
2276 | ellipsisroots[head].add(child) |
|
2272 | ellipsisroots[head].add(child) | |
2277 | ellipsisroots[child].update(roots) |
|
2273 | ellipsisroots[child].update(roots) | |
2278 | ellipsisroots[child].discard(child) |
|
2274 | ellipsisroots[child].discard(child) | |
2279 |
|
2275 | |||
2280 | def splithead(head): |
|
2276 | def splithead(head): | |
2281 | r1, r2, r3 = sorted(ellipsisroots[head]) |
|
2277 | r1, r2, r3 = sorted(ellipsisroots[head]) | |
2282 | for nr1, nr2 in ((r2, r3), (r1, r3), (r1, r2)): |
|
2278 | for nr1, nr2 in ((r2, r3), (r1, r3), (r1, r2)): | |
2283 | mid = repo.revs( |
|
2279 | mid = repo.revs( | |
2284 | b'sort(merge() & %d::%d & %d::%d, -rev)', nr1, head, nr2, head |
|
2280 | b'sort(merge() & %d::%d & %d::%d, -rev)', nr1, head, nr2, head | |
2285 | ) |
|
2281 | ) | |
2286 | for j in mid: |
|
2282 | for j in mid: | |
2287 | if j == nr2: |
|
2283 | if j == nr2: | |
2288 | return nr2, (nr1, nr2) |
|
2284 | return nr2, (nr1, nr2) | |
2289 | if j not in ellipsisroots or len(ellipsisroots[j]) < 2: |
|
2285 | if j not in ellipsisroots or len(ellipsisroots[j]) < 2: | |
2290 | return j, (nr1, nr2) |
|
2286 | return j, (nr1, nr2) | |
2291 | raise error.Abort( |
|
2287 | raise error.Abort( | |
2292 | _( |
|
2288 | _( | |
2293 | b'Failed to split up ellipsis node! head: %d, ' |
|
2289 | b'Failed to split up ellipsis node! head: %d, ' | |
2294 | b'roots: %d %d %d' |
|
2290 | b'roots: %d %d %d' | |
2295 | ) |
|
2291 | ) | |
2296 | % (head, r1, r2, r3) |
|
2292 | % (head, r1, r2, r3) | |
2297 | ) |
|
2293 | ) | |
2298 |
|
2294 | |||
2299 | missing = list(cl.findmissingrevs(common=commonrevs, heads=headsrevs)) |
|
2295 | missing = list(cl.findmissingrevs(common=commonrevs, heads=headsrevs)) | |
2300 | visit = reversed(missing) |
|
2296 | visit = reversed(missing) | |
2301 | relevant_nodes = set() |
|
2297 | relevant_nodes = set() | |
2302 | visitnodes = [cl.node(m) for m in missing] |
|
2298 | visitnodes = [cl.node(m) for m in missing] | |
2303 | required = set(headsrevs) | known |
|
2299 | required = set(headsrevs) | known | |
2304 | for rev in visit: |
|
2300 | for rev in visit: | |
2305 | clrev = cl.changelogrevision(rev) |
|
2301 | clrev = cl.changelogrevision(rev) | |
2306 | ps = [prev for prev in cl.parentrevs(rev) if prev != nullrev] |
|
2302 | ps = [prev for prev in cl.parentrevs(rev) if prev != nullrev] | |
2307 | if depth is not None: |
|
2303 | if depth is not None: | |
2308 | curdepth = revdepth[rev] |
|
2304 | curdepth = revdepth[rev] | |
2309 | for p in ps: |
|
2305 | for p in ps: | |
2310 | revdepth[p] = min(curdepth + 1, revdepth.get(p, depth + 1)) |
|
2306 | revdepth[p] = min(curdepth + 1, revdepth.get(p, depth + 1)) | |
2311 | needed = False |
|
2307 | needed = False | |
2312 | shallow_enough = depth is None or revdepth[rev] <= depth |
|
2308 | shallow_enough = depth is None or revdepth[rev] <= depth | |
2313 | if shallow_enough: |
|
2309 | if shallow_enough: | |
2314 | curmf = mfl[clrev.manifest].read() |
|
2310 | curmf = mfl[clrev.manifest].read() | |
2315 | if ps: |
|
2311 | if ps: | |
2316 | # We choose to not trust the changed files list in |
|
2312 | # We choose to not trust the changed files list in | |
2317 | # changesets because it's not always correct. TODO: could |
|
2313 | # changesets because it's not always correct. TODO: could | |
2318 | # we trust it for the non-merge case? |
|
2314 | # we trust it for the non-merge case? | |
2319 | p1mf = mfl[cl.changelogrevision(ps[0]).manifest].read() |
|
2315 | p1mf = mfl[cl.changelogrevision(ps[0]).manifest].read() | |
2320 | needed = bool(curmf.diff(p1mf, match)) |
|
2316 | needed = bool(curmf.diff(p1mf, match)) | |
2321 | if not needed and len(ps) > 1: |
|
2317 | if not needed and len(ps) > 1: | |
2322 | # For merge changes, the list of changed files is not |
|
2318 | # For merge changes, the list of changed files is not | |
2323 | # helpful, since we need to emit the merge if a file |
|
2319 | # helpful, since we need to emit the merge if a file | |
2324 | # in the narrow spec has changed on either side of the |
|
2320 | # in the narrow spec has changed on either side of the | |
2325 | # merge. As a result, we do a manifest diff to check. |
|
2321 | # merge. As a result, we do a manifest diff to check. | |
2326 | p2mf = mfl[cl.changelogrevision(ps[1]).manifest].read() |
|
2322 | p2mf = mfl[cl.changelogrevision(ps[1]).manifest].read() | |
2327 | needed = bool(curmf.diff(p2mf, match)) |
|
2323 | needed = bool(curmf.diff(p2mf, match)) | |
2328 | else: |
|
2324 | else: | |
2329 | # For a root node, we need to include the node if any |
|
2325 | # For a root node, we need to include the node if any | |
2330 | # files in the node match the narrowspec. |
|
2326 | # files in the node match the narrowspec. | |
2331 | needed = any(curmf.walk(match)) |
|
2327 | needed = any(curmf.walk(match)) | |
2332 |
|
2328 | |||
2333 | if needed: |
|
2329 | if needed: | |
2334 | for head in ellipsisheads[rev]: |
|
2330 | for head in ellipsisheads[rev]: | |
2335 | addroot(head, rev) |
|
2331 | addroot(head, rev) | |
2336 | for p in ps: |
|
2332 | for p in ps: | |
2337 | required.add(p) |
|
2333 | required.add(p) | |
2338 | relevant_nodes.add(cl.node(rev)) |
|
2334 | relevant_nodes.add(cl.node(rev)) | |
2339 | else: |
|
2335 | else: | |
2340 | if not ps: |
|
2336 | if not ps: | |
2341 | ps = [nullrev] |
|
2337 | ps = [nullrev] | |
2342 | if rev in required: |
|
2338 | if rev in required: | |
2343 | for head in ellipsisheads[rev]: |
|
2339 | for head in ellipsisheads[rev]: | |
2344 | addroot(head, rev) |
|
2340 | addroot(head, rev) | |
2345 | for p in ps: |
|
2341 | for p in ps: | |
2346 | ellipsisheads[p].add(rev) |
|
2342 | ellipsisheads[p].add(rev) | |
2347 | else: |
|
2343 | else: | |
2348 | for p in ps: |
|
2344 | for p in ps: | |
2349 | ellipsisheads[p] |= ellipsisheads[rev] |
|
2345 | ellipsisheads[p] |= ellipsisheads[rev] | |
2350 |
|
2346 | |||
2351 | # add common changesets as roots of their reachable ellipsis heads |
|
2347 | # add common changesets as roots of their reachable ellipsis heads | |
2352 | for c in commonrevs: |
|
2348 | for c in commonrevs: | |
2353 | for head in ellipsisheads[c]: |
|
2349 | for head in ellipsisheads[c]: | |
2354 | addroot(head, c) |
|
2350 | addroot(head, c) | |
2355 | return visitnodes, relevant_nodes, ellipsisroots |
|
2351 | return visitnodes, relevant_nodes, ellipsisroots | |
2356 |
|
2352 | |||
2357 |
|
2353 | |||
2358 | def caps20to10(repo, role): |
|
2354 | def caps20to10(repo, role): | |
2359 | """return a set with appropriate options to use bundle20 during getbundle""" |
|
2355 | """return a set with appropriate options to use bundle20 during getbundle""" | |
2360 | caps = {b'HG20'} |
|
2356 | caps = {b'HG20'} | |
2361 | capsblob = bundle2.encodecaps(bundle2.getrepocaps(repo, role=role)) |
|
2357 | capsblob = bundle2.encodecaps(bundle2.getrepocaps(repo, role=role)) | |
2362 | caps.add(b'bundle2=' + urlreq.quote(capsblob)) |
|
2358 | caps.add(b'bundle2=' + urlreq.quote(capsblob)) | |
2363 | return caps |
|
2359 | return caps | |
2364 |
|
2360 | |||
2365 |
|
2361 | |||
2366 | # List of names of steps to perform for a bundle2 for getbundle, order matters. |
|
2362 | # List of names of steps to perform for a bundle2 for getbundle, order matters. | |
2367 | getbundle2partsorder = [] |
|
2363 | getbundle2partsorder = [] | |
2368 |
|
2364 | |||
2369 | # Mapping between step name and function |
|
2365 | # Mapping between step name and function | |
2370 | # |
|
2366 | # | |
2371 | # This exists to help extensions wrap steps if necessary |
|
2367 | # This exists to help extensions wrap steps if necessary | |
2372 | getbundle2partsmapping = {} |
|
2368 | getbundle2partsmapping = {} | |
2373 |
|
2369 | |||
2374 |
|
2370 | |||
2375 | def getbundle2partsgenerator(stepname, idx=None): |
|
2371 | def getbundle2partsgenerator(stepname, idx=None): | |
2376 | """decorator for function generating bundle2 part for getbundle |
|
2372 | """decorator for function generating bundle2 part for getbundle | |
2377 |
|
2373 | |||
2378 | The function is added to the step -> function mapping and appended to the |
|
2374 | The function is added to the step -> function mapping and appended to the | |
2379 | list of steps. Beware that decorated functions will be added in order |
|
2375 | list of steps. Beware that decorated functions will be added in order | |
2380 | (this may matter). |
|
2376 | (this may matter). | |
2381 |
|
2377 | |||
2382 | You can only use this decorator for new steps, if you want to wrap a step |
|
2378 | You can only use this decorator for new steps, if you want to wrap a step | |
2383 | from an extension, attack the getbundle2partsmapping dictionary directly.""" |
|
2379 | from an extension, attack the getbundle2partsmapping dictionary directly.""" | |
2384 |
|
2380 | |||
2385 | def dec(func): |
|
2381 | def dec(func): | |
2386 | assert stepname not in getbundle2partsmapping |
|
2382 | assert stepname not in getbundle2partsmapping | |
2387 | getbundle2partsmapping[stepname] = func |
|
2383 | getbundle2partsmapping[stepname] = func | |
2388 | if idx is None: |
|
2384 | if idx is None: | |
2389 | getbundle2partsorder.append(stepname) |
|
2385 | getbundle2partsorder.append(stepname) | |
2390 | else: |
|
2386 | else: | |
2391 | getbundle2partsorder.insert(idx, stepname) |
|
2387 | getbundle2partsorder.insert(idx, stepname) | |
2392 | return func |
|
2388 | return func | |
2393 |
|
2389 | |||
2394 | return dec |
|
2390 | return dec | |
2395 |
|
2391 | |||
2396 |
|
2392 | |||
2397 | def bundle2requested(bundlecaps): |
|
2393 | def bundle2requested(bundlecaps): | |
2398 | if bundlecaps is not None: |
|
2394 | if bundlecaps is not None: | |
2399 | return any(cap.startswith(b'HG2') for cap in bundlecaps) |
|
2395 | return any(cap.startswith(b'HG2') for cap in bundlecaps) | |
2400 | return False |
|
2396 | return False | |
2401 |
|
2397 | |||
2402 |
|
2398 | |||
2403 | def getbundlechunks( |
|
2399 | def getbundlechunks( | |
2404 | repo, source, heads=None, common=None, bundlecaps=None, **kwargs |
|
2400 | repo, source, heads=None, common=None, bundlecaps=None, **kwargs | |
2405 | ): |
|
2401 | ): | |
2406 | """Return chunks constituting a bundle's raw data. |
|
2402 | """Return chunks constituting a bundle's raw data. | |
2407 |
|
2403 | |||
2408 | Could be a bundle HG10 or a bundle HG20 depending on bundlecaps |
|
2404 | Could be a bundle HG10 or a bundle HG20 depending on bundlecaps | |
2409 | passed. |
|
2405 | passed. | |
2410 |
|
2406 | |||
2411 | Returns a 2-tuple of a dict with metadata about the generated bundle |
|
2407 | Returns a 2-tuple of a dict with metadata about the generated bundle | |
2412 | and an iterator over raw chunks (of varying sizes). |
|
2408 | and an iterator over raw chunks (of varying sizes). | |
2413 | """ |
|
2409 | """ | |
2414 | kwargs = pycompat.byteskwargs(kwargs) |
|
2410 | kwargs = pycompat.byteskwargs(kwargs) | |
2415 | info = {} |
|
2411 | info = {} | |
2416 | usebundle2 = bundle2requested(bundlecaps) |
|
2412 | usebundle2 = bundle2requested(bundlecaps) | |
2417 | # bundle10 case |
|
2413 | # bundle10 case | |
2418 | if not usebundle2: |
|
2414 | if not usebundle2: | |
2419 | if bundlecaps and not kwargs.get(b'cg', True): |
|
2415 | if bundlecaps and not kwargs.get(b'cg', True): | |
2420 | raise ValueError( |
|
2416 | raise ValueError( | |
2421 | _(b'request for bundle10 must include changegroup') |
|
2417 | _(b'request for bundle10 must include changegroup') | |
2422 | ) |
|
2418 | ) | |
2423 |
|
2419 | |||
2424 | if kwargs: |
|
2420 | if kwargs: | |
2425 | raise ValueError( |
|
2421 | raise ValueError( | |
2426 | _(b'unsupported getbundle arguments: %s') |
|
2422 | _(b'unsupported getbundle arguments: %s') | |
2427 | % b', '.join(sorted(kwargs.keys())) |
|
2423 | % b', '.join(sorted(kwargs.keys())) | |
2428 | ) |
|
2424 | ) | |
2429 | outgoing = _computeoutgoing(repo, heads, common) |
|
2425 | outgoing = _computeoutgoing(repo, heads, common) | |
2430 | info[b'bundleversion'] = 1 |
|
2426 | info[b'bundleversion'] = 1 | |
2431 | return ( |
|
2427 | return ( | |
2432 | info, |
|
2428 | info, | |
2433 | changegroup.makestream( |
|
2429 | changegroup.makestream( | |
2434 | repo, outgoing, b'01', source, bundlecaps=bundlecaps |
|
2430 | repo, outgoing, b'01', source, bundlecaps=bundlecaps | |
2435 | ), |
|
2431 | ), | |
2436 | ) |
|
2432 | ) | |
2437 |
|
2433 | |||
2438 | # bundle20 case |
|
2434 | # bundle20 case | |
2439 | info[b'bundleversion'] = 2 |
|
2435 | info[b'bundleversion'] = 2 | |
2440 | b2caps = {} |
|
2436 | b2caps = {} | |
2441 | for bcaps in bundlecaps: |
|
2437 | for bcaps in bundlecaps: | |
2442 | if bcaps.startswith(b'bundle2='): |
|
2438 | if bcaps.startswith(b'bundle2='): | |
2443 | blob = urlreq.unquote(bcaps[len(b'bundle2=') :]) |
|
2439 | blob = urlreq.unquote(bcaps[len(b'bundle2=') :]) | |
2444 | b2caps.update(bundle2.decodecaps(blob)) |
|
2440 | b2caps.update(bundle2.decodecaps(blob)) | |
2445 | bundler = bundle2.bundle20(repo.ui, b2caps) |
|
2441 | bundler = bundle2.bundle20(repo.ui, b2caps) | |
2446 |
|
2442 | |||
2447 | kwargs[b'heads'] = heads |
|
2443 | kwargs[b'heads'] = heads | |
2448 | kwargs[b'common'] = common |
|
2444 | kwargs[b'common'] = common | |
2449 |
|
2445 | |||
2450 | for name in getbundle2partsorder: |
|
2446 | for name in getbundle2partsorder: | |
2451 | func = getbundle2partsmapping[name] |
|
2447 | func = getbundle2partsmapping[name] | |
2452 | func( |
|
2448 | func( | |
2453 | bundler, |
|
2449 | bundler, | |
2454 | repo, |
|
2450 | repo, | |
2455 | source, |
|
2451 | source, | |
2456 | bundlecaps=bundlecaps, |
|
2452 | bundlecaps=bundlecaps, | |
2457 | b2caps=b2caps, |
|
2453 | b2caps=b2caps, | |
2458 | **pycompat.strkwargs(kwargs) |
|
2454 | **pycompat.strkwargs(kwargs) | |
2459 | ) |
|
2455 | ) | |
2460 |
|
2456 | |||
2461 | info[b'prefercompressed'] = bundler.prefercompressed |
|
2457 | info[b'prefercompressed'] = bundler.prefercompressed | |
2462 |
|
2458 | |||
2463 | return info, bundler.getchunks() |
|
2459 | return info, bundler.getchunks() | |
2464 |
|
2460 | |||
2465 |
|
2461 | |||
2466 | @getbundle2partsgenerator(b'stream2') |
|
2462 | @getbundle2partsgenerator(b'stream2') | |
2467 | def _getbundlestream2(bundler, repo, *args, **kwargs): |
|
2463 | def _getbundlestream2(bundler, repo, *args, **kwargs): | |
2468 | return bundle2.addpartbundlestream2(bundler, repo, **kwargs) |
|
2464 | return bundle2.addpartbundlestream2(bundler, repo, **kwargs) | |
2469 |
|
2465 | |||
2470 |
|
2466 | |||
2471 | @getbundle2partsgenerator(b'changegroup') |
|
2467 | @getbundle2partsgenerator(b'changegroup') | |
2472 | def _getbundlechangegrouppart( |
|
2468 | def _getbundlechangegrouppart( | |
2473 | bundler, |
|
2469 | bundler, | |
2474 | repo, |
|
2470 | repo, | |
2475 | source, |
|
2471 | source, | |
2476 | bundlecaps=None, |
|
2472 | bundlecaps=None, | |
2477 | b2caps=None, |
|
2473 | b2caps=None, | |
2478 | heads=None, |
|
2474 | heads=None, | |
2479 | common=None, |
|
2475 | common=None, | |
2480 | **kwargs |
|
2476 | **kwargs | |
2481 | ): |
|
2477 | ): | |
2482 | """add a changegroup part to the requested bundle""" |
|
2478 | """add a changegroup part to the requested bundle""" | |
2483 | if not kwargs.get(r'cg', True): |
|
2479 | if not kwargs.get(r'cg', True): | |
2484 | return |
|
2480 | return | |
2485 |
|
2481 | |||
2486 | version = b'01' |
|
2482 | version = b'01' | |
2487 | cgversions = b2caps.get(b'changegroup') |
|
2483 | cgversions = b2caps.get(b'changegroup') | |
2488 | if cgversions: # 3.1 and 3.2 ship with an empty value |
|
2484 | if cgversions: # 3.1 and 3.2 ship with an empty value | |
2489 | cgversions = [ |
|
2485 | cgversions = [ | |
2490 | v |
|
2486 | v | |
2491 | for v in cgversions |
|
2487 | for v in cgversions | |
2492 | if v in changegroup.supportedoutgoingversions(repo) |
|
2488 | if v in changegroup.supportedoutgoingversions(repo) | |
2493 | ] |
|
2489 | ] | |
2494 | if not cgversions: |
|
2490 | if not cgversions: | |
2495 | raise error.Abort(_(b'no common changegroup version')) |
|
2491 | raise error.Abort(_(b'no common changegroup version')) | |
2496 | version = max(cgversions) |
|
2492 | version = max(cgversions) | |
2497 |
|
2493 | |||
2498 | outgoing = _computeoutgoing(repo, heads, common) |
|
2494 | outgoing = _computeoutgoing(repo, heads, common) | |
2499 | if not outgoing.missing: |
|
2495 | if not outgoing.missing: | |
2500 | return |
|
2496 | return | |
2501 |
|
2497 | |||
2502 | if kwargs.get(r'narrow', False): |
|
2498 | if kwargs.get(r'narrow', False): | |
2503 | include = sorted(filter(bool, kwargs.get(r'includepats', []))) |
|
2499 | include = sorted(filter(bool, kwargs.get(r'includepats', []))) | |
2504 | exclude = sorted(filter(bool, kwargs.get(r'excludepats', []))) |
|
2500 | exclude = sorted(filter(bool, kwargs.get(r'excludepats', []))) | |
2505 | matcher = narrowspec.match(repo.root, include=include, exclude=exclude) |
|
2501 | matcher = narrowspec.match(repo.root, include=include, exclude=exclude) | |
2506 | else: |
|
2502 | else: | |
2507 | matcher = None |
|
2503 | matcher = None | |
2508 |
|
2504 | |||
2509 | cgstream = changegroup.makestream( |
|
2505 | cgstream = changegroup.makestream( | |
2510 | repo, outgoing, version, source, bundlecaps=bundlecaps, matcher=matcher |
|
2506 | repo, outgoing, version, source, bundlecaps=bundlecaps, matcher=matcher | |
2511 | ) |
|
2507 | ) | |
2512 |
|
2508 | |||
2513 | part = bundler.newpart(b'changegroup', data=cgstream) |
|
2509 | part = bundler.newpart(b'changegroup', data=cgstream) | |
2514 | if cgversions: |
|
2510 | if cgversions: | |
2515 | part.addparam(b'version', version) |
|
2511 | part.addparam(b'version', version) | |
2516 |
|
2512 | |||
2517 | part.addparam(b'nbchanges', b'%d' % len(outgoing.missing), mandatory=False) |
|
2513 | part.addparam(b'nbchanges', b'%d' % len(outgoing.missing), mandatory=False) | |
2518 |
|
2514 | |||
2519 | if b'treemanifest' in repo.requirements: |
|
2515 | if b'treemanifest' in repo.requirements: | |
2520 | part.addparam(b'treemanifest', b'1') |
|
2516 | part.addparam(b'treemanifest', b'1') | |
2521 |
|
2517 | |||
2522 | if b'exp-sidedata-flag' in repo.requirements: |
|
2518 | if b'exp-sidedata-flag' in repo.requirements: | |
2523 | part.addparam(b'exp-sidedata', b'1') |
|
2519 | part.addparam(b'exp-sidedata', b'1') | |
2524 |
|
2520 | |||
2525 | if ( |
|
2521 | if ( | |
2526 | kwargs.get(r'narrow', False) |
|
2522 | kwargs.get(r'narrow', False) | |
2527 | and kwargs.get(r'narrow_acl', False) |
|
2523 | and kwargs.get(r'narrow_acl', False) | |
2528 | and (include or exclude) |
|
2524 | and (include or exclude) | |
2529 | ): |
|
2525 | ): | |
2530 | # this is mandatory because otherwise ACL clients won't work |
|
2526 | # this is mandatory because otherwise ACL clients won't work | |
2531 | narrowspecpart = bundler.newpart(b'Narrow:responsespec') |
|
2527 | narrowspecpart = bundler.newpart(b'Narrow:responsespec') | |
2532 | narrowspecpart.data = b'%s\0%s' % ( |
|
2528 | narrowspecpart.data = b'%s\0%s' % ( | |
2533 | b'\n'.join(include), |
|
2529 | b'\n'.join(include), | |
2534 | b'\n'.join(exclude), |
|
2530 | b'\n'.join(exclude), | |
2535 | ) |
|
2531 | ) | |
2536 |
|
2532 | |||
2537 |
|
2533 | |||
2538 | @getbundle2partsgenerator(b'bookmarks') |
|
2534 | @getbundle2partsgenerator(b'bookmarks') | |
2539 | def _getbundlebookmarkpart( |
|
2535 | def _getbundlebookmarkpart( | |
2540 | bundler, repo, source, bundlecaps=None, b2caps=None, **kwargs |
|
2536 | bundler, repo, source, bundlecaps=None, b2caps=None, **kwargs | |
2541 | ): |
|
2537 | ): | |
2542 | """add a bookmark part to the requested bundle""" |
|
2538 | """add a bookmark part to the requested bundle""" | |
2543 | if not kwargs.get(r'bookmarks', False): |
|
2539 | if not kwargs.get(r'bookmarks', False): | |
2544 | return |
|
2540 | return | |
2545 | if b'bookmarks' not in b2caps: |
|
2541 | if b'bookmarks' not in b2caps: | |
2546 | raise error.Abort(_(b'no common bookmarks exchange method')) |
|
2542 | raise error.Abort(_(b'no common bookmarks exchange method')) | |
2547 | books = bookmod.listbinbookmarks(repo) |
|
2543 | books = bookmod.listbinbookmarks(repo) | |
2548 | data = bookmod.binaryencode(books) |
|
2544 | data = bookmod.binaryencode(books) | |
2549 | if data: |
|
2545 | if data: | |
2550 | bundler.newpart(b'bookmarks', data=data) |
|
2546 | bundler.newpart(b'bookmarks', data=data) | |
2551 |
|
2547 | |||
2552 |
|
2548 | |||
2553 | @getbundle2partsgenerator(b'listkeys') |
|
2549 | @getbundle2partsgenerator(b'listkeys') | |
2554 | def _getbundlelistkeysparts( |
|
2550 | def _getbundlelistkeysparts( | |
2555 | bundler, repo, source, bundlecaps=None, b2caps=None, **kwargs |
|
2551 | bundler, repo, source, bundlecaps=None, b2caps=None, **kwargs | |
2556 | ): |
|
2552 | ): | |
2557 | """add parts containing listkeys namespaces to the requested bundle""" |
|
2553 | """add parts containing listkeys namespaces to the requested bundle""" | |
2558 | listkeys = kwargs.get(r'listkeys', ()) |
|
2554 | listkeys = kwargs.get(r'listkeys', ()) | |
2559 | for namespace in listkeys: |
|
2555 | for namespace in listkeys: | |
2560 | part = bundler.newpart(b'listkeys') |
|
2556 | part = bundler.newpart(b'listkeys') | |
2561 | part.addparam(b'namespace', namespace) |
|
2557 | part.addparam(b'namespace', namespace) | |
2562 | keys = repo.listkeys(namespace).items() |
|
2558 | keys = repo.listkeys(namespace).items() | |
2563 | part.data = pushkey.encodekeys(keys) |
|
2559 | part.data = pushkey.encodekeys(keys) | |
2564 |
|
2560 | |||
2565 |
|
2561 | |||
2566 | @getbundle2partsgenerator(b'obsmarkers') |
|
2562 | @getbundle2partsgenerator(b'obsmarkers') | |
2567 | def _getbundleobsmarkerpart( |
|
2563 | def _getbundleobsmarkerpart( | |
2568 | bundler, repo, source, bundlecaps=None, b2caps=None, heads=None, **kwargs |
|
2564 | bundler, repo, source, bundlecaps=None, b2caps=None, heads=None, **kwargs | |
2569 | ): |
|
2565 | ): | |
2570 | """add an obsolescence markers part to the requested bundle""" |
|
2566 | """add an obsolescence markers part to the requested bundle""" | |
2571 | if kwargs.get(r'obsmarkers', False): |
|
2567 | if kwargs.get(r'obsmarkers', False): | |
2572 | if heads is None: |
|
2568 | if heads is None: | |
2573 | heads = repo.heads() |
|
2569 | heads = repo.heads() | |
2574 | subset = [c.node() for c in repo.set(b'::%ln', heads)] |
|
2570 | subset = [c.node() for c in repo.set(b'::%ln', heads)] | |
2575 | markers = repo.obsstore.relevantmarkers(subset) |
|
2571 | markers = repo.obsstore.relevantmarkers(subset) | |
2576 |
markers = |
|
2572 | markers = obsutil.sortedmarkers(markers) | |
2577 | bundle2.buildobsmarkerspart(bundler, markers) |
|
2573 | bundle2.buildobsmarkerspart(bundler, markers) | |
2578 |
|
2574 | |||
2579 |
|
2575 | |||
2580 | @getbundle2partsgenerator(b'phases') |
|
2576 | @getbundle2partsgenerator(b'phases') | |
2581 | def _getbundlephasespart( |
|
2577 | def _getbundlephasespart( | |
2582 | bundler, repo, source, bundlecaps=None, b2caps=None, heads=None, **kwargs |
|
2578 | bundler, repo, source, bundlecaps=None, b2caps=None, heads=None, **kwargs | |
2583 | ): |
|
2579 | ): | |
2584 | """add phase heads part to the requested bundle""" |
|
2580 | """add phase heads part to the requested bundle""" | |
2585 | if kwargs.get(r'phases', False): |
|
2581 | if kwargs.get(r'phases', False): | |
2586 | if not b'heads' in b2caps.get(b'phases'): |
|
2582 | if not b'heads' in b2caps.get(b'phases'): | |
2587 | raise error.Abort(_(b'no common phases exchange method')) |
|
2583 | raise error.Abort(_(b'no common phases exchange method')) | |
2588 | if heads is None: |
|
2584 | if heads is None: | |
2589 | heads = repo.heads() |
|
2585 | heads = repo.heads() | |
2590 |
|
2586 | |||
2591 | headsbyphase = collections.defaultdict(set) |
|
2587 | headsbyphase = collections.defaultdict(set) | |
2592 | if repo.publishing(): |
|
2588 | if repo.publishing(): | |
2593 | headsbyphase[phases.public] = heads |
|
2589 | headsbyphase[phases.public] = heads | |
2594 | else: |
|
2590 | else: | |
2595 | # find the appropriate heads to move |
|
2591 | # find the appropriate heads to move | |
2596 |
|
2592 | |||
2597 | phase = repo._phasecache.phase |
|
2593 | phase = repo._phasecache.phase | |
2598 | node = repo.changelog.node |
|
2594 | node = repo.changelog.node | |
2599 | rev = repo.changelog.rev |
|
2595 | rev = repo.changelog.rev | |
2600 | for h in heads: |
|
2596 | for h in heads: | |
2601 | headsbyphase[phase(repo, rev(h))].add(h) |
|
2597 | headsbyphase[phase(repo, rev(h))].add(h) | |
2602 | seenphases = list(headsbyphase.keys()) |
|
2598 | seenphases = list(headsbyphase.keys()) | |
2603 |
|
2599 | |||
2604 | # We do not handle anything but public and draft phase for now) |
|
2600 | # We do not handle anything but public and draft phase for now) | |
2605 | if seenphases: |
|
2601 | if seenphases: | |
2606 | assert max(seenphases) <= phases.draft |
|
2602 | assert max(seenphases) <= phases.draft | |
2607 |
|
2603 | |||
2608 | # if client is pulling non-public changesets, we need to find |
|
2604 | # if client is pulling non-public changesets, we need to find | |
2609 | # intermediate public heads. |
|
2605 | # intermediate public heads. | |
2610 | draftheads = headsbyphase.get(phases.draft, set()) |
|
2606 | draftheads = headsbyphase.get(phases.draft, set()) | |
2611 | if draftheads: |
|
2607 | if draftheads: | |
2612 | publicheads = headsbyphase.get(phases.public, set()) |
|
2608 | publicheads = headsbyphase.get(phases.public, set()) | |
2613 |
|
2609 | |||
2614 | revset = b'heads(only(%ln, %ln) and public())' |
|
2610 | revset = b'heads(only(%ln, %ln) and public())' | |
2615 | extraheads = repo.revs(revset, draftheads, publicheads) |
|
2611 | extraheads = repo.revs(revset, draftheads, publicheads) | |
2616 | for r in extraheads: |
|
2612 | for r in extraheads: | |
2617 | headsbyphase[phases.public].add(node(r)) |
|
2613 | headsbyphase[phases.public].add(node(r)) | |
2618 |
|
2614 | |||
2619 | # transform data in a format used by the encoding function |
|
2615 | # transform data in a format used by the encoding function | |
2620 | phasemapping = [] |
|
2616 | phasemapping = [] | |
2621 | for phase in phases.allphases: |
|
2617 | for phase in phases.allphases: | |
2622 | phasemapping.append(sorted(headsbyphase[phase])) |
|
2618 | phasemapping.append(sorted(headsbyphase[phase])) | |
2623 |
|
2619 | |||
2624 | # generate the actual part |
|
2620 | # generate the actual part | |
2625 | phasedata = phases.binaryencode(phasemapping) |
|
2621 | phasedata = phases.binaryencode(phasemapping) | |
2626 | bundler.newpart(b'phase-heads', data=phasedata) |
|
2622 | bundler.newpart(b'phase-heads', data=phasedata) | |
2627 |
|
2623 | |||
2628 |
|
2624 | |||
2629 | @getbundle2partsgenerator(b'hgtagsfnodes') |
|
2625 | @getbundle2partsgenerator(b'hgtagsfnodes') | |
2630 | def _getbundletagsfnodes( |
|
2626 | def _getbundletagsfnodes( | |
2631 | bundler, |
|
2627 | bundler, | |
2632 | repo, |
|
2628 | repo, | |
2633 | source, |
|
2629 | source, | |
2634 | bundlecaps=None, |
|
2630 | bundlecaps=None, | |
2635 | b2caps=None, |
|
2631 | b2caps=None, | |
2636 | heads=None, |
|
2632 | heads=None, | |
2637 | common=None, |
|
2633 | common=None, | |
2638 | **kwargs |
|
2634 | **kwargs | |
2639 | ): |
|
2635 | ): | |
2640 | """Transfer the .hgtags filenodes mapping. |
|
2636 | """Transfer the .hgtags filenodes mapping. | |
2641 |
|
2637 | |||
2642 | Only values for heads in this bundle will be transferred. |
|
2638 | Only values for heads in this bundle will be transferred. | |
2643 |
|
2639 | |||
2644 | The part data consists of pairs of 20 byte changeset node and .hgtags |
|
2640 | The part data consists of pairs of 20 byte changeset node and .hgtags | |
2645 | filenodes raw values. |
|
2641 | filenodes raw values. | |
2646 | """ |
|
2642 | """ | |
2647 | # Don't send unless: |
|
2643 | # Don't send unless: | |
2648 | # - changeset are being exchanged, |
|
2644 | # - changeset are being exchanged, | |
2649 | # - the client supports it. |
|
2645 | # - the client supports it. | |
2650 | if not (kwargs.get(r'cg', True) and b'hgtagsfnodes' in b2caps): |
|
2646 | if not (kwargs.get(r'cg', True) and b'hgtagsfnodes' in b2caps): | |
2651 | return |
|
2647 | return | |
2652 |
|
2648 | |||
2653 | outgoing = _computeoutgoing(repo, heads, common) |
|
2649 | outgoing = _computeoutgoing(repo, heads, common) | |
2654 | bundle2.addparttagsfnodescache(repo, bundler, outgoing) |
|
2650 | bundle2.addparttagsfnodescache(repo, bundler, outgoing) | |
2655 |
|
2651 | |||
2656 |
|
2652 | |||
2657 | @getbundle2partsgenerator(b'cache:rev-branch-cache') |
|
2653 | @getbundle2partsgenerator(b'cache:rev-branch-cache') | |
2658 | def _getbundlerevbranchcache( |
|
2654 | def _getbundlerevbranchcache( | |
2659 | bundler, |
|
2655 | bundler, | |
2660 | repo, |
|
2656 | repo, | |
2661 | source, |
|
2657 | source, | |
2662 | bundlecaps=None, |
|
2658 | bundlecaps=None, | |
2663 | b2caps=None, |
|
2659 | b2caps=None, | |
2664 | heads=None, |
|
2660 | heads=None, | |
2665 | common=None, |
|
2661 | common=None, | |
2666 | **kwargs |
|
2662 | **kwargs | |
2667 | ): |
|
2663 | ): | |
2668 | """Transfer the rev-branch-cache mapping |
|
2664 | """Transfer the rev-branch-cache mapping | |
2669 |
|
2665 | |||
2670 | The payload is a series of data related to each branch |
|
2666 | The payload is a series of data related to each branch | |
2671 |
|
2667 | |||
2672 | 1) branch name length |
|
2668 | 1) branch name length | |
2673 | 2) number of open heads |
|
2669 | 2) number of open heads | |
2674 | 3) number of closed heads |
|
2670 | 3) number of closed heads | |
2675 | 4) open heads nodes |
|
2671 | 4) open heads nodes | |
2676 | 5) closed heads nodes |
|
2672 | 5) closed heads nodes | |
2677 | """ |
|
2673 | """ | |
2678 | # Don't send unless: |
|
2674 | # Don't send unless: | |
2679 | # - changeset are being exchanged, |
|
2675 | # - changeset are being exchanged, | |
2680 | # - the client supports it. |
|
2676 | # - the client supports it. | |
2681 | # - narrow bundle isn't in play (not currently compatible). |
|
2677 | # - narrow bundle isn't in play (not currently compatible). | |
2682 | if ( |
|
2678 | if ( | |
2683 | not kwargs.get(r'cg', True) |
|
2679 | not kwargs.get(r'cg', True) | |
2684 | or b'rev-branch-cache' not in b2caps |
|
2680 | or b'rev-branch-cache' not in b2caps | |
2685 | or kwargs.get(r'narrow', False) |
|
2681 | or kwargs.get(r'narrow', False) | |
2686 | or repo.ui.has_section(_NARROWACL_SECTION) |
|
2682 | or repo.ui.has_section(_NARROWACL_SECTION) | |
2687 | ): |
|
2683 | ): | |
2688 | return |
|
2684 | return | |
2689 |
|
2685 | |||
2690 | outgoing = _computeoutgoing(repo, heads, common) |
|
2686 | outgoing = _computeoutgoing(repo, heads, common) | |
2691 | bundle2.addpartrevbranchcache(repo, bundler, outgoing) |
|
2687 | bundle2.addpartrevbranchcache(repo, bundler, outgoing) | |
2692 |
|
2688 | |||
2693 |
|
2689 | |||
2694 | def check_heads(repo, their_heads, context): |
|
2690 | def check_heads(repo, their_heads, context): | |
2695 | """check if the heads of a repo have been modified |
|
2691 | """check if the heads of a repo have been modified | |
2696 |
|
2692 | |||
2697 | Used by peer for unbundling. |
|
2693 | Used by peer for unbundling. | |
2698 | """ |
|
2694 | """ | |
2699 | heads = repo.heads() |
|
2695 | heads = repo.heads() | |
2700 | heads_hash = hashlib.sha1(b''.join(sorted(heads))).digest() |
|
2696 | heads_hash = hashlib.sha1(b''.join(sorted(heads))).digest() | |
2701 | if not ( |
|
2697 | if not ( | |
2702 | their_heads == [b'force'] |
|
2698 | their_heads == [b'force'] | |
2703 | or their_heads == heads |
|
2699 | or their_heads == heads | |
2704 | or their_heads == [b'hashed', heads_hash] |
|
2700 | or their_heads == [b'hashed', heads_hash] | |
2705 | ): |
|
2701 | ): | |
2706 | # someone else committed/pushed/unbundled while we |
|
2702 | # someone else committed/pushed/unbundled while we | |
2707 | # were transferring data |
|
2703 | # were transferring data | |
2708 | raise error.PushRaced( |
|
2704 | raise error.PushRaced( | |
2709 | b'repository changed while %s - please try again' % context |
|
2705 | b'repository changed while %s - please try again' % context | |
2710 | ) |
|
2706 | ) | |
2711 |
|
2707 | |||
2712 |
|
2708 | |||
2713 | def unbundle(repo, cg, heads, source, url): |
|
2709 | def unbundle(repo, cg, heads, source, url): | |
2714 | """Apply a bundle to a repo. |
|
2710 | """Apply a bundle to a repo. | |
2715 |
|
2711 | |||
2716 | this function makes sure the repo is locked during the application and have |
|
2712 | this function makes sure the repo is locked during the application and have | |
2717 | mechanism to check that no push race occurred between the creation of the |
|
2713 | mechanism to check that no push race occurred between the creation of the | |
2718 | bundle and its application. |
|
2714 | bundle and its application. | |
2719 |
|
2715 | |||
2720 | If the push was raced as PushRaced exception is raised.""" |
|
2716 | If the push was raced as PushRaced exception is raised.""" | |
2721 | r = 0 |
|
2717 | r = 0 | |
2722 | # need a transaction when processing a bundle2 stream |
|
2718 | # need a transaction when processing a bundle2 stream | |
2723 | # [wlock, lock, tr] - needs to be an array so nested functions can modify it |
|
2719 | # [wlock, lock, tr] - needs to be an array so nested functions can modify it | |
2724 | lockandtr = [None, None, None] |
|
2720 | lockandtr = [None, None, None] | |
2725 | recordout = None |
|
2721 | recordout = None | |
2726 | # quick fix for output mismatch with bundle2 in 3.4 |
|
2722 | # quick fix for output mismatch with bundle2 in 3.4 | |
2727 | captureoutput = repo.ui.configbool( |
|
2723 | captureoutput = repo.ui.configbool( | |
2728 | b'experimental', b'bundle2-output-capture' |
|
2724 | b'experimental', b'bundle2-output-capture' | |
2729 | ) |
|
2725 | ) | |
2730 | if url.startswith(b'remote:http:') or url.startswith(b'remote:https:'): |
|
2726 | if url.startswith(b'remote:http:') or url.startswith(b'remote:https:'): | |
2731 | captureoutput = True |
|
2727 | captureoutput = True | |
2732 | try: |
|
2728 | try: | |
2733 | # note: outside bundle1, 'heads' is expected to be empty and this |
|
2729 | # note: outside bundle1, 'heads' is expected to be empty and this | |
2734 | # 'check_heads' call wil be a no-op |
|
2730 | # 'check_heads' call wil be a no-op | |
2735 | check_heads(repo, heads, b'uploading changes') |
|
2731 | check_heads(repo, heads, b'uploading changes') | |
2736 | # push can proceed |
|
2732 | # push can proceed | |
2737 | if not isinstance(cg, bundle2.unbundle20): |
|
2733 | if not isinstance(cg, bundle2.unbundle20): | |
2738 | # legacy case: bundle1 (changegroup 01) |
|
2734 | # legacy case: bundle1 (changegroup 01) | |
2739 | txnname = b"\n".join([source, util.hidepassword(url)]) |
|
2735 | txnname = b"\n".join([source, util.hidepassword(url)]) | |
2740 | with repo.lock(), repo.transaction(txnname) as tr: |
|
2736 | with repo.lock(), repo.transaction(txnname) as tr: | |
2741 | op = bundle2.applybundle(repo, cg, tr, source, url) |
|
2737 | op = bundle2.applybundle(repo, cg, tr, source, url) | |
2742 | r = bundle2.combinechangegroupresults(op) |
|
2738 | r = bundle2.combinechangegroupresults(op) | |
2743 | else: |
|
2739 | else: | |
2744 | r = None |
|
2740 | r = None | |
2745 | try: |
|
2741 | try: | |
2746 |
|
2742 | |||
2747 | def gettransaction(): |
|
2743 | def gettransaction(): | |
2748 | if not lockandtr[2]: |
|
2744 | if not lockandtr[2]: | |
2749 | if not bookmod.bookmarksinstore(repo): |
|
2745 | if not bookmod.bookmarksinstore(repo): | |
2750 | lockandtr[0] = repo.wlock() |
|
2746 | lockandtr[0] = repo.wlock() | |
2751 | lockandtr[1] = repo.lock() |
|
2747 | lockandtr[1] = repo.lock() | |
2752 | lockandtr[2] = repo.transaction(source) |
|
2748 | lockandtr[2] = repo.transaction(source) | |
2753 | lockandtr[2].hookargs[b'source'] = source |
|
2749 | lockandtr[2].hookargs[b'source'] = source | |
2754 | lockandtr[2].hookargs[b'url'] = url |
|
2750 | lockandtr[2].hookargs[b'url'] = url | |
2755 | lockandtr[2].hookargs[b'bundle2'] = b'1' |
|
2751 | lockandtr[2].hookargs[b'bundle2'] = b'1' | |
2756 | return lockandtr[2] |
|
2752 | return lockandtr[2] | |
2757 |
|
2753 | |||
2758 | # Do greedy locking by default until we're satisfied with lazy |
|
2754 | # Do greedy locking by default until we're satisfied with lazy | |
2759 | # locking. |
|
2755 | # locking. | |
2760 | if not repo.ui.configbool( |
|
2756 | if not repo.ui.configbool( | |
2761 | b'experimental', b'bundle2lazylocking' |
|
2757 | b'experimental', b'bundle2lazylocking' | |
2762 | ): |
|
2758 | ): | |
2763 | gettransaction() |
|
2759 | gettransaction() | |
2764 |
|
2760 | |||
2765 | op = bundle2.bundleoperation( |
|
2761 | op = bundle2.bundleoperation( | |
2766 | repo, |
|
2762 | repo, | |
2767 | gettransaction, |
|
2763 | gettransaction, | |
2768 | captureoutput=captureoutput, |
|
2764 | captureoutput=captureoutput, | |
2769 | source=b'push', |
|
2765 | source=b'push', | |
2770 | ) |
|
2766 | ) | |
2771 | try: |
|
2767 | try: | |
2772 | op = bundle2.processbundle(repo, cg, op=op) |
|
2768 | op = bundle2.processbundle(repo, cg, op=op) | |
2773 | finally: |
|
2769 | finally: | |
2774 | r = op.reply |
|
2770 | r = op.reply | |
2775 | if captureoutput and r is not None: |
|
2771 | if captureoutput and r is not None: | |
2776 | repo.ui.pushbuffer(error=True, subproc=True) |
|
2772 | repo.ui.pushbuffer(error=True, subproc=True) | |
2777 |
|
2773 | |||
2778 | def recordout(output): |
|
2774 | def recordout(output): | |
2779 | r.newpart(b'output', data=output, mandatory=False) |
|
2775 | r.newpart(b'output', data=output, mandatory=False) | |
2780 |
|
2776 | |||
2781 | if lockandtr[2] is not None: |
|
2777 | if lockandtr[2] is not None: | |
2782 | lockandtr[2].close() |
|
2778 | lockandtr[2].close() | |
2783 | except BaseException as exc: |
|
2779 | except BaseException as exc: | |
2784 | exc.duringunbundle2 = True |
|
2780 | exc.duringunbundle2 = True | |
2785 | if captureoutput and r is not None: |
|
2781 | if captureoutput and r is not None: | |
2786 | parts = exc._bundle2salvagedoutput = r.salvageoutput() |
|
2782 | parts = exc._bundle2salvagedoutput = r.salvageoutput() | |
2787 |
|
2783 | |||
2788 | def recordout(output): |
|
2784 | def recordout(output): | |
2789 | part = bundle2.bundlepart( |
|
2785 | part = bundle2.bundlepart( | |
2790 | b'output', data=output, mandatory=False |
|
2786 | b'output', data=output, mandatory=False | |
2791 | ) |
|
2787 | ) | |
2792 | parts.append(part) |
|
2788 | parts.append(part) | |
2793 |
|
2789 | |||
2794 | raise |
|
2790 | raise | |
2795 | finally: |
|
2791 | finally: | |
2796 | lockmod.release(lockandtr[2], lockandtr[1], lockandtr[0]) |
|
2792 | lockmod.release(lockandtr[2], lockandtr[1], lockandtr[0]) | |
2797 | if recordout is not None: |
|
2793 | if recordout is not None: | |
2798 | recordout(repo.ui.popbuffer()) |
|
2794 | recordout(repo.ui.popbuffer()) | |
2799 | return r |
|
2795 | return r | |
2800 |
|
2796 | |||
2801 |
|
2797 | |||
2802 | def _maybeapplyclonebundle(pullop): |
|
2798 | def _maybeapplyclonebundle(pullop): | |
2803 | """Apply a clone bundle from a remote, if possible.""" |
|
2799 | """Apply a clone bundle from a remote, if possible.""" | |
2804 |
|
2800 | |||
2805 | repo = pullop.repo |
|
2801 | repo = pullop.repo | |
2806 | remote = pullop.remote |
|
2802 | remote = pullop.remote | |
2807 |
|
2803 | |||
2808 | if not repo.ui.configbool(b'ui', b'clonebundles'): |
|
2804 | if not repo.ui.configbool(b'ui', b'clonebundles'): | |
2809 | return |
|
2805 | return | |
2810 |
|
2806 | |||
2811 | # Only run if local repo is empty. |
|
2807 | # Only run if local repo is empty. | |
2812 | if len(repo): |
|
2808 | if len(repo): | |
2813 | return |
|
2809 | return | |
2814 |
|
2810 | |||
2815 | if pullop.heads: |
|
2811 | if pullop.heads: | |
2816 | return |
|
2812 | return | |
2817 |
|
2813 | |||
2818 | if not remote.capable(b'clonebundles'): |
|
2814 | if not remote.capable(b'clonebundles'): | |
2819 | return |
|
2815 | return | |
2820 |
|
2816 | |||
2821 | with remote.commandexecutor() as e: |
|
2817 | with remote.commandexecutor() as e: | |
2822 | res = e.callcommand(b'clonebundles', {}).result() |
|
2818 | res = e.callcommand(b'clonebundles', {}).result() | |
2823 |
|
2819 | |||
2824 | # If we call the wire protocol command, that's good enough to record the |
|
2820 | # If we call the wire protocol command, that's good enough to record the | |
2825 | # attempt. |
|
2821 | # attempt. | |
2826 | pullop.clonebundleattempted = True |
|
2822 | pullop.clonebundleattempted = True | |
2827 |
|
2823 | |||
2828 | entries = parseclonebundlesmanifest(repo, res) |
|
2824 | entries = parseclonebundlesmanifest(repo, res) | |
2829 | if not entries: |
|
2825 | if not entries: | |
2830 | repo.ui.note( |
|
2826 | repo.ui.note( | |
2831 | _( |
|
2827 | _( | |
2832 | b'no clone bundles available on remote; ' |
|
2828 | b'no clone bundles available on remote; ' | |
2833 | b'falling back to regular clone\n' |
|
2829 | b'falling back to regular clone\n' | |
2834 | ) |
|
2830 | ) | |
2835 | ) |
|
2831 | ) | |
2836 | return |
|
2832 | return | |
2837 |
|
2833 | |||
2838 | entries = filterclonebundleentries( |
|
2834 | entries = filterclonebundleentries( | |
2839 | repo, entries, streamclonerequested=pullop.streamclonerequested |
|
2835 | repo, entries, streamclonerequested=pullop.streamclonerequested | |
2840 | ) |
|
2836 | ) | |
2841 |
|
2837 | |||
2842 | if not entries: |
|
2838 | if not entries: | |
2843 | # There is a thundering herd concern here. However, if a server |
|
2839 | # There is a thundering herd concern here. However, if a server | |
2844 | # operator doesn't advertise bundles appropriate for its clients, |
|
2840 | # operator doesn't advertise bundles appropriate for its clients, | |
2845 | # they deserve what's coming. Furthermore, from a client's |
|
2841 | # they deserve what's coming. Furthermore, from a client's | |
2846 | # perspective, no automatic fallback would mean not being able to |
|
2842 | # perspective, no automatic fallback would mean not being able to | |
2847 | # clone! |
|
2843 | # clone! | |
2848 | repo.ui.warn( |
|
2844 | repo.ui.warn( | |
2849 | _( |
|
2845 | _( | |
2850 | b'no compatible clone bundles available on server; ' |
|
2846 | b'no compatible clone bundles available on server; ' | |
2851 | b'falling back to regular clone\n' |
|
2847 | b'falling back to regular clone\n' | |
2852 | ) |
|
2848 | ) | |
2853 | ) |
|
2849 | ) | |
2854 | repo.ui.warn( |
|
2850 | repo.ui.warn( | |
2855 | _(b'(you may want to report this to the server operator)\n') |
|
2851 | _(b'(you may want to report this to the server operator)\n') | |
2856 | ) |
|
2852 | ) | |
2857 | return |
|
2853 | return | |
2858 |
|
2854 | |||
2859 | entries = sortclonebundleentries(repo.ui, entries) |
|
2855 | entries = sortclonebundleentries(repo.ui, entries) | |
2860 |
|
2856 | |||
2861 | url = entries[0][b'URL'] |
|
2857 | url = entries[0][b'URL'] | |
2862 | repo.ui.status(_(b'applying clone bundle from %s\n') % url) |
|
2858 | repo.ui.status(_(b'applying clone bundle from %s\n') % url) | |
2863 | if trypullbundlefromurl(repo.ui, repo, url): |
|
2859 | if trypullbundlefromurl(repo.ui, repo, url): | |
2864 | repo.ui.status(_(b'finished applying clone bundle\n')) |
|
2860 | repo.ui.status(_(b'finished applying clone bundle\n')) | |
2865 | # Bundle failed. |
|
2861 | # Bundle failed. | |
2866 | # |
|
2862 | # | |
2867 | # We abort by default to avoid the thundering herd of |
|
2863 | # We abort by default to avoid the thundering herd of | |
2868 | # clients flooding a server that was expecting expensive |
|
2864 | # clients flooding a server that was expecting expensive | |
2869 | # clone load to be offloaded. |
|
2865 | # clone load to be offloaded. | |
2870 | elif repo.ui.configbool(b'ui', b'clonebundlefallback'): |
|
2866 | elif repo.ui.configbool(b'ui', b'clonebundlefallback'): | |
2871 | repo.ui.warn(_(b'falling back to normal clone\n')) |
|
2867 | repo.ui.warn(_(b'falling back to normal clone\n')) | |
2872 | else: |
|
2868 | else: | |
2873 | raise error.Abort( |
|
2869 | raise error.Abort( | |
2874 | _(b'error applying bundle'), |
|
2870 | _(b'error applying bundle'), | |
2875 | hint=_( |
|
2871 | hint=_( | |
2876 | b'if this error persists, consider contacting ' |
|
2872 | b'if this error persists, consider contacting ' | |
2877 | b'the server operator or disable clone ' |
|
2873 | b'the server operator or disable clone ' | |
2878 | b'bundles via ' |
|
2874 | b'bundles via ' | |
2879 | b'"--config ui.clonebundles=false"' |
|
2875 | b'"--config ui.clonebundles=false"' | |
2880 | ), |
|
2876 | ), | |
2881 | ) |
|
2877 | ) | |
2882 |
|
2878 | |||
2883 |
|
2879 | |||
2884 | def parseclonebundlesmanifest(repo, s): |
|
2880 | def parseclonebundlesmanifest(repo, s): | |
2885 | """Parses the raw text of a clone bundles manifest. |
|
2881 | """Parses the raw text of a clone bundles manifest. | |
2886 |
|
2882 | |||
2887 | Returns a list of dicts. The dicts have a ``URL`` key corresponding |
|
2883 | Returns a list of dicts. The dicts have a ``URL`` key corresponding | |
2888 | to the URL and other keys are the attributes for the entry. |
|
2884 | to the URL and other keys are the attributes for the entry. | |
2889 | """ |
|
2885 | """ | |
2890 | m = [] |
|
2886 | m = [] | |
2891 | for line in s.splitlines(): |
|
2887 | for line in s.splitlines(): | |
2892 | fields = line.split() |
|
2888 | fields = line.split() | |
2893 | if not fields: |
|
2889 | if not fields: | |
2894 | continue |
|
2890 | continue | |
2895 | attrs = {b'URL': fields[0]} |
|
2891 | attrs = {b'URL': fields[0]} | |
2896 | for rawattr in fields[1:]: |
|
2892 | for rawattr in fields[1:]: | |
2897 | key, value = rawattr.split(b'=', 1) |
|
2893 | key, value = rawattr.split(b'=', 1) | |
2898 | key = urlreq.unquote(key) |
|
2894 | key = urlreq.unquote(key) | |
2899 | value = urlreq.unquote(value) |
|
2895 | value = urlreq.unquote(value) | |
2900 | attrs[key] = value |
|
2896 | attrs[key] = value | |
2901 |
|
2897 | |||
2902 | # Parse BUNDLESPEC into components. This makes client-side |
|
2898 | # Parse BUNDLESPEC into components. This makes client-side | |
2903 | # preferences easier to specify since you can prefer a single |
|
2899 | # preferences easier to specify since you can prefer a single | |
2904 | # component of the BUNDLESPEC. |
|
2900 | # component of the BUNDLESPEC. | |
2905 | if key == b'BUNDLESPEC': |
|
2901 | if key == b'BUNDLESPEC': | |
2906 | try: |
|
2902 | try: | |
2907 | bundlespec = parsebundlespec(repo, value) |
|
2903 | bundlespec = parsebundlespec(repo, value) | |
2908 | attrs[b'COMPRESSION'] = bundlespec.compression |
|
2904 | attrs[b'COMPRESSION'] = bundlespec.compression | |
2909 | attrs[b'VERSION'] = bundlespec.version |
|
2905 | attrs[b'VERSION'] = bundlespec.version | |
2910 | except error.InvalidBundleSpecification: |
|
2906 | except error.InvalidBundleSpecification: | |
2911 | pass |
|
2907 | pass | |
2912 | except error.UnsupportedBundleSpecification: |
|
2908 | except error.UnsupportedBundleSpecification: | |
2913 | pass |
|
2909 | pass | |
2914 |
|
2910 | |||
2915 | m.append(attrs) |
|
2911 | m.append(attrs) | |
2916 |
|
2912 | |||
2917 | return m |
|
2913 | return m | |
2918 |
|
2914 | |||
2919 |
|
2915 | |||
2920 | def isstreamclonespec(bundlespec): |
|
2916 | def isstreamclonespec(bundlespec): | |
2921 | # Stream clone v1 |
|
2917 | # Stream clone v1 | |
2922 | if bundlespec.wirecompression == b'UN' and bundlespec.wireversion == b's1': |
|
2918 | if bundlespec.wirecompression == b'UN' and bundlespec.wireversion == b's1': | |
2923 | return True |
|
2919 | return True | |
2924 |
|
2920 | |||
2925 | # Stream clone v2 |
|
2921 | # Stream clone v2 | |
2926 | if ( |
|
2922 | if ( | |
2927 | bundlespec.wirecompression == b'UN' |
|
2923 | bundlespec.wirecompression == b'UN' | |
2928 | and bundlespec.wireversion == b'02' |
|
2924 | and bundlespec.wireversion == b'02' | |
2929 | and bundlespec.contentopts.get(b'streamv2') |
|
2925 | and bundlespec.contentopts.get(b'streamv2') | |
2930 | ): |
|
2926 | ): | |
2931 | return True |
|
2927 | return True | |
2932 |
|
2928 | |||
2933 | return False |
|
2929 | return False | |
2934 |
|
2930 | |||
2935 |
|
2931 | |||
2936 | def filterclonebundleentries(repo, entries, streamclonerequested=False): |
|
2932 | def filterclonebundleentries(repo, entries, streamclonerequested=False): | |
2937 | """Remove incompatible clone bundle manifest entries. |
|
2933 | """Remove incompatible clone bundle manifest entries. | |
2938 |
|
2934 | |||
2939 | Accepts a list of entries parsed with ``parseclonebundlesmanifest`` |
|
2935 | Accepts a list of entries parsed with ``parseclonebundlesmanifest`` | |
2940 | and returns a new list consisting of only the entries that this client |
|
2936 | and returns a new list consisting of only the entries that this client | |
2941 | should be able to apply. |
|
2937 | should be able to apply. | |
2942 |
|
2938 | |||
2943 | There is no guarantee we'll be able to apply all returned entries because |
|
2939 | There is no guarantee we'll be able to apply all returned entries because | |
2944 | the metadata we use to filter on may be missing or wrong. |
|
2940 | the metadata we use to filter on may be missing or wrong. | |
2945 | """ |
|
2941 | """ | |
2946 | newentries = [] |
|
2942 | newentries = [] | |
2947 | for entry in entries: |
|
2943 | for entry in entries: | |
2948 | spec = entry.get(b'BUNDLESPEC') |
|
2944 | spec = entry.get(b'BUNDLESPEC') | |
2949 | if spec: |
|
2945 | if spec: | |
2950 | try: |
|
2946 | try: | |
2951 | bundlespec = parsebundlespec(repo, spec, strict=True) |
|
2947 | bundlespec = parsebundlespec(repo, spec, strict=True) | |
2952 |
|
2948 | |||
2953 | # If a stream clone was requested, filter out non-streamclone |
|
2949 | # If a stream clone was requested, filter out non-streamclone | |
2954 | # entries. |
|
2950 | # entries. | |
2955 | if streamclonerequested and not isstreamclonespec(bundlespec): |
|
2951 | if streamclonerequested and not isstreamclonespec(bundlespec): | |
2956 | repo.ui.debug( |
|
2952 | repo.ui.debug( | |
2957 | b'filtering %s because not a stream clone\n' |
|
2953 | b'filtering %s because not a stream clone\n' | |
2958 | % entry[b'URL'] |
|
2954 | % entry[b'URL'] | |
2959 | ) |
|
2955 | ) | |
2960 | continue |
|
2956 | continue | |
2961 |
|
2957 | |||
2962 | except error.InvalidBundleSpecification as e: |
|
2958 | except error.InvalidBundleSpecification as e: | |
2963 | repo.ui.debug(stringutil.forcebytestr(e) + b'\n') |
|
2959 | repo.ui.debug(stringutil.forcebytestr(e) + b'\n') | |
2964 | continue |
|
2960 | continue | |
2965 | except error.UnsupportedBundleSpecification as e: |
|
2961 | except error.UnsupportedBundleSpecification as e: | |
2966 | repo.ui.debug( |
|
2962 | repo.ui.debug( | |
2967 | b'filtering %s because unsupported bundle ' |
|
2963 | b'filtering %s because unsupported bundle ' | |
2968 | b'spec: %s\n' % (entry[b'URL'], stringutil.forcebytestr(e)) |
|
2964 | b'spec: %s\n' % (entry[b'URL'], stringutil.forcebytestr(e)) | |
2969 | ) |
|
2965 | ) | |
2970 | continue |
|
2966 | continue | |
2971 | # If we don't have a spec and requested a stream clone, we don't know |
|
2967 | # If we don't have a spec and requested a stream clone, we don't know | |
2972 | # what the entry is so don't attempt to apply it. |
|
2968 | # what the entry is so don't attempt to apply it. | |
2973 | elif streamclonerequested: |
|
2969 | elif streamclonerequested: | |
2974 | repo.ui.debug( |
|
2970 | repo.ui.debug( | |
2975 | b'filtering %s because cannot determine if a stream ' |
|
2971 | b'filtering %s because cannot determine if a stream ' | |
2976 | b'clone bundle\n' % entry[b'URL'] |
|
2972 | b'clone bundle\n' % entry[b'URL'] | |
2977 | ) |
|
2973 | ) | |
2978 | continue |
|
2974 | continue | |
2979 |
|
2975 | |||
2980 | if b'REQUIRESNI' in entry and not sslutil.hassni: |
|
2976 | if b'REQUIRESNI' in entry and not sslutil.hassni: | |
2981 | repo.ui.debug( |
|
2977 | repo.ui.debug( | |
2982 | b'filtering %s because SNI not supported\n' % entry[b'URL'] |
|
2978 | b'filtering %s because SNI not supported\n' % entry[b'URL'] | |
2983 | ) |
|
2979 | ) | |
2984 | continue |
|
2980 | continue | |
2985 |
|
2981 | |||
2986 | newentries.append(entry) |
|
2982 | newentries.append(entry) | |
2987 |
|
2983 | |||
2988 | return newentries |
|
2984 | return newentries | |
2989 |
|
2985 | |||
2990 |
|
2986 | |||
2991 | class clonebundleentry(object): |
|
2987 | class clonebundleentry(object): | |
2992 | """Represents an item in a clone bundles manifest. |
|
2988 | """Represents an item in a clone bundles manifest. | |
2993 |
|
2989 | |||
2994 | This rich class is needed to support sorting since sorted() in Python 3 |
|
2990 | This rich class is needed to support sorting since sorted() in Python 3 | |
2995 | doesn't support ``cmp`` and our comparison is complex enough that ``key=`` |
|
2991 | doesn't support ``cmp`` and our comparison is complex enough that ``key=`` | |
2996 | won't work. |
|
2992 | won't work. | |
2997 | """ |
|
2993 | """ | |
2998 |
|
2994 | |||
2999 | def __init__(self, value, prefers): |
|
2995 | def __init__(self, value, prefers): | |
3000 | self.value = value |
|
2996 | self.value = value | |
3001 | self.prefers = prefers |
|
2997 | self.prefers = prefers | |
3002 |
|
2998 | |||
3003 | def _cmp(self, other): |
|
2999 | def _cmp(self, other): | |
3004 | for prefkey, prefvalue in self.prefers: |
|
3000 | for prefkey, prefvalue in self.prefers: | |
3005 | avalue = self.value.get(prefkey) |
|
3001 | avalue = self.value.get(prefkey) | |
3006 | bvalue = other.value.get(prefkey) |
|
3002 | bvalue = other.value.get(prefkey) | |
3007 |
|
3003 | |||
3008 | # Special case for b missing attribute and a matches exactly. |
|
3004 | # Special case for b missing attribute and a matches exactly. | |
3009 | if avalue is not None and bvalue is None and avalue == prefvalue: |
|
3005 | if avalue is not None and bvalue is None and avalue == prefvalue: | |
3010 | return -1 |
|
3006 | return -1 | |
3011 |
|
3007 | |||
3012 | # Special case for a missing attribute and b matches exactly. |
|
3008 | # Special case for a missing attribute and b matches exactly. | |
3013 | if bvalue is not None and avalue is None and bvalue == prefvalue: |
|
3009 | if bvalue is not None and avalue is None and bvalue == prefvalue: | |
3014 | return 1 |
|
3010 | return 1 | |
3015 |
|
3011 | |||
3016 | # We can't compare unless attribute present on both. |
|
3012 | # We can't compare unless attribute present on both. | |
3017 | if avalue is None or bvalue is None: |
|
3013 | if avalue is None or bvalue is None: | |
3018 | continue |
|
3014 | continue | |
3019 |
|
3015 | |||
3020 | # Same values should fall back to next attribute. |
|
3016 | # Same values should fall back to next attribute. | |
3021 | if avalue == bvalue: |
|
3017 | if avalue == bvalue: | |
3022 | continue |
|
3018 | continue | |
3023 |
|
3019 | |||
3024 | # Exact matches come first. |
|
3020 | # Exact matches come first. | |
3025 | if avalue == prefvalue: |
|
3021 | if avalue == prefvalue: | |
3026 | return -1 |
|
3022 | return -1 | |
3027 | if bvalue == prefvalue: |
|
3023 | if bvalue == prefvalue: | |
3028 | return 1 |
|
3024 | return 1 | |
3029 |
|
3025 | |||
3030 | # Fall back to next attribute. |
|
3026 | # Fall back to next attribute. | |
3031 | continue |
|
3027 | continue | |
3032 |
|
3028 | |||
3033 | # If we got here we couldn't sort by attributes and prefers. Fall |
|
3029 | # If we got here we couldn't sort by attributes and prefers. Fall | |
3034 | # back to index order. |
|
3030 | # back to index order. | |
3035 | return 0 |
|
3031 | return 0 | |
3036 |
|
3032 | |||
3037 | def __lt__(self, other): |
|
3033 | def __lt__(self, other): | |
3038 | return self._cmp(other) < 0 |
|
3034 | return self._cmp(other) < 0 | |
3039 |
|
3035 | |||
3040 | def __gt__(self, other): |
|
3036 | def __gt__(self, other): | |
3041 | return self._cmp(other) > 0 |
|
3037 | return self._cmp(other) > 0 | |
3042 |
|
3038 | |||
3043 | def __eq__(self, other): |
|
3039 | def __eq__(self, other): | |
3044 | return self._cmp(other) == 0 |
|
3040 | return self._cmp(other) == 0 | |
3045 |
|
3041 | |||
3046 | def __le__(self, other): |
|
3042 | def __le__(self, other): | |
3047 | return self._cmp(other) <= 0 |
|
3043 | return self._cmp(other) <= 0 | |
3048 |
|
3044 | |||
3049 | def __ge__(self, other): |
|
3045 | def __ge__(self, other): | |
3050 | return self._cmp(other) >= 0 |
|
3046 | return self._cmp(other) >= 0 | |
3051 |
|
3047 | |||
3052 | def __ne__(self, other): |
|
3048 | def __ne__(self, other): | |
3053 | return self._cmp(other) != 0 |
|
3049 | return self._cmp(other) != 0 | |
3054 |
|
3050 | |||
3055 |
|
3051 | |||
3056 | def sortclonebundleentries(ui, entries): |
|
3052 | def sortclonebundleentries(ui, entries): | |
3057 | prefers = ui.configlist(b'ui', b'clonebundleprefers') |
|
3053 | prefers = ui.configlist(b'ui', b'clonebundleprefers') | |
3058 | if not prefers: |
|
3054 | if not prefers: | |
3059 | return list(entries) |
|
3055 | return list(entries) | |
3060 |
|
3056 | |||
3061 | prefers = [p.split(b'=', 1) for p in prefers] |
|
3057 | prefers = [p.split(b'=', 1) for p in prefers] | |
3062 |
|
3058 | |||
3063 | items = sorted(clonebundleentry(v, prefers) for v in entries) |
|
3059 | items = sorted(clonebundleentry(v, prefers) for v in entries) | |
3064 | return [i.value for i in items] |
|
3060 | return [i.value for i in items] | |
3065 |
|
3061 | |||
3066 |
|
3062 | |||
3067 | def trypullbundlefromurl(ui, repo, url): |
|
3063 | def trypullbundlefromurl(ui, repo, url): | |
3068 | """Attempt to apply a bundle from a URL.""" |
|
3064 | """Attempt to apply a bundle from a URL.""" | |
3069 | with repo.lock(), repo.transaction(b'bundleurl') as tr: |
|
3065 | with repo.lock(), repo.transaction(b'bundleurl') as tr: | |
3070 | try: |
|
3066 | try: | |
3071 | fh = urlmod.open(ui, url) |
|
3067 | fh = urlmod.open(ui, url) | |
3072 | cg = readbundle(ui, fh, b'stream') |
|
3068 | cg = readbundle(ui, fh, b'stream') | |
3073 |
|
3069 | |||
3074 | if isinstance(cg, streamclone.streamcloneapplier): |
|
3070 | if isinstance(cg, streamclone.streamcloneapplier): | |
3075 | cg.apply(repo) |
|
3071 | cg.apply(repo) | |
3076 | else: |
|
3072 | else: | |
3077 | bundle2.applybundle(repo, cg, tr, b'clonebundles', url) |
|
3073 | bundle2.applybundle(repo, cg, tr, b'clonebundles', url) | |
3078 | return True |
|
3074 | return True | |
3079 | except urlerr.httperror as e: |
|
3075 | except urlerr.httperror as e: | |
3080 | ui.warn( |
|
3076 | ui.warn( | |
3081 | _(b'HTTP error fetching bundle: %s\n') |
|
3077 | _(b'HTTP error fetching bundle: %s\n') | |
3082 | % stringutil.forcebytestr(e) |
|
3078 | % stringutil.forcebytestr(e) | |
3083 | ) |
|
3079 | ) | |
3084 | except urlerr.urlerror as e: |
|
3080 | except urlerr.urlerror as e: | |
3085 | ui.warn( |
|
3081 | ui.warn( | |
3086 | _(b'error fetching bundle: %s\n') |
|
3082 | _(b'error fetching bundle: %s\n') | |
3087 | % stringutil.forcebytestr(e.reason) |
|
3083 | % stringutil.forcebytestr(e.reason) | |
3088 | ) |
|
3084 | ) | |
3089 |
|
3085 | |||
3090 | return False |
|
3086 | return False |
@@ -1,1035 +1,1040 b'' | |||||
1 | # obsutil.py - utility functions for obsolescence |
|
1 | # obsutil.py - utility functions for obsolescence | |
2 | # |
|
2 | # | |
3 | # Copyright 2017 Boris Feld <boris.feld@octobus.net> |
|
3 | # Copyright 2017 Boris Feld <boris.feld@octobus.net> | |
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 | import re |
|
10 | import re | |
11 |
|
11 | |||
12 | from .i18n import _ |
|
12 | from .i18n import _ | |
13 | from . import ( |
|
13 | from . import ( | |
14 | diffutil, |
|
14 | diffutil, | |
15 | encoding, |
|
15 | encoding, | |
16 | node as nodemod, |
|
16 | node as nodemod, | |
17 | phases, |
|
17 | phases, | |
18 | pycompat, |
|
18 | pycompat, | |
19 | util, |
|
19 | util, | |
20 | ) |
|
20 | ) | |
21 | from .utils import dateutil |
|
21 | from .utils import dateutil | |
22 |
|
22 | |||
23 | ### obsolescence marker flag |
|
23 | ### obsolescence marker flag | |
24 |
|
24 | |||
25 | ## bumpedfix flag |
|
25 | ## bumpedfix flag | |
26 | # |
|
26 | # | |
27 | # When a changeset A' succeed to a changeset A which became public, we call A' |
|
27 | # When a changeset A' succeed to a changeset A which became public, we call A' | |
28 | # "bumped" because it's a successors of a public changesets |
|
28 | # "bumped" because it's a successors of a public changesets | |
29 | # |
|
29 | # | |
30 | # o A' (bumped) |
|
30 | # o A' (bumped) | |
31 | # |`: |
|
31 | # |`: | |
32 | # | o A |
|
32 | # | o A | |
33 | # |/ |
|
33 | # |/ | |
34 | # o Z |
|
34 | # o Z | |
35 | # |
|
35 | # | |
36 | # The way to solve this situation is to create a new changeset Ad as children |
|
36 | # The way to solve this situation is to create a new changeset Ad as children | |
37 | # of A. This changeset have the same content than A'. So the diff from A to A' |
|
37 | # of A. This changeset have the same content than A'. So the diff from A to A' | |
38 | # is the same than the diff from A to Ad. Ad is marked as a successors of A' |
|
38 | # is the same than the diff from A to Ad. Ad is marked as a successors of A' | |
39 | # |
|
39 | # | |
40 | # o Ad |
|
40 | # o Ad | |
41 | # |`: |
|
41 | # |`: | |
42 | # | x A' |
|
42 | # | x A' | |
43 | # |'| |
|
43 | # |'| | |
44 | # o | A |
|
44 | # o | A | |
45 | # |/ |
|
45 | # |/ | |
46 | # o Z |
|
46 | # o Z | |
47 | # |
|
47 | # | |
48 | # But by transitivity Ad is also a successors of A. To avoid having Ad marked |
|
48 | # But by transitivity Ad is also a successors of A. To avoid having Ad marked | |
49 | # as bumped too, we add the `bumpedfix` flag to the marker. <A', (Ad,)>. |
|
49 | # as bumped too, we add the `bumpedfix` flag to the marker. <A', (Ad,)>. | |
50 | # This flag mean that the successors express the changes between the public and |
|
50 | # This flag mean that the successors express the changes between the public and | |
51 | # bumped version and fix the situation, breaking the transitivity of |
|
51 | # bumped version and fix the situation, breaking the transitivity of | |
52 | # "bumped" here. |
|
52 | # "bumped" here. | |
53 | bumpedfix = 1 |
|
53 | bumpedfix = 1 | |
54 | usingsha256 = 2 |
|
54 | usingsha256 = 2 | |
55 |
|
55 | |||
56 |
|
56 | |||
57 | class marker(object): |
|
57 | class marker(object): | |
58 | """Wrap obsolete marker raw data""" |
|
58 | """Wrap obsolete marker raw data""" | |
59 |
|
59 | |||
60 | def __init__(self, repo, data): |
|
60 | def __init__(self, repo, data): | |
61 | # the repo argument will be used to create changectx in later version |
|
61 | # the repo argument will be used to create changectx in later version | |
62 | self._repo = repo |
|
62 | self._repo = repo | |
63 | self._data = data |
|
63 | self._data = data | |
64 | self._decodedmeta = None |
|
64 | self._decodedmeta = None | |
65 |
|
65 | |||
66 | def __hash__(self): |
|
66 | def __hash__(self): | |
67 | return hash(self._data) |
|
67 | return hash(self._data) | |
68 |
|
68 | |||
69 | def __eq__(self, other): |
|
69 | def __eq__(self, other): | |
70 | if type(other) != type(self): |
|
70 | if type(other) != type(self): | |
71 | return False |
|
71 | return False | |
72 | return self._data == other._data |
|
72 | return self._data == other._data | |
73 |
|
73 | |||
74 | def prednode(self): |
|
74 | def prednode(self): | |
75 | """Predecessor changeset node identifier""" |
|
75 | """Predecessor changeset node identifier""" | |
76 | return self._data[0] |
|
76 | return self._data[0] | |
77 |
|
77 | |||
78 | def succnodes(self): |
|
78 | def succnodes(self): | |
79 | """List of successor changesets node identifiers""" |
|
79 | """List of successor changesets node identifiers""" | |
80 | return self._data[1] |
|
80 | return self._data[1] | |
81 |
|
81 | |||
82 | def parentnodes(self): |
|
82 | def parentnodes(self): | |
83 | """Parents of the predecessors (None if not recorded)""" |
|
83 | """Parents of the predecessors (None if not recorded)""" | |
84 | return self._data[5] |
|
84 | return self._data[5] | |
85 |
|
85 | |||
86 | def metadata(self): |
|
86 | def metadata(self): | |
87 | """Decoded metadata dictionary""" |
|
87 | """Decoded metadata dictionary""" | |
88 | return dict(self._data[3]) |
|
88 | return dict(self._data[3]) | |
89 |
|
89 | |||
90 | def date(self): |
|
90 | def date(self): | |
91 | """Creation date as (unixtime, offset)""" |
|
91 | """Creation date as (unixtime, offset)""" | |
92 | return self._data[4] |
|
92 | return self._data[4] | |
93 |
|
93 | |||
94 | def flags(self): |
|
94 | def flags(self): | |
95 | """The flags field of the marker""" |
|
95 | """The flags field of the marker""" | |
96 | return self._data[2] |
|
96 | return self._data[2] | |
97 |
|
97 | |||
98 |
|
98 | |||
99 | def getmarkers(repo, nodes=None, exclusive=False): |
|
99 | def getmarkers(repo, nodes=None, exclusive=False): | |
100 | """returns markers known in a repository |
|
100 | """returns markers known in a repository | |
101 |
|
101 | |||
102 | If <nodes> is specified, only markers "relevant" to those nodes are are |
|
102 | If <nodes> is specified, only markers "relevant" to those nodes are are | |
103 | returned""" |
|
103 | returned""" | |
104 | if nodes is None: |
|
104 | if nodes is None: | |
105 | rawmarkers = repo.obsstore |
|
105 | rawmarkers = repo.obsstore | |
106 | elif exclusive: |
|
106 | elif exclusive: | |
107 | rawmarkers = exclusivemarkers(repo, nodes) |
|
107 | rawmarkers = exclusivemarkers(repo, nodes) | |
108 | else: |
|
108 | else: | |
109 | rawmarkers = repo.obsstore.relevantmarkers(nodes) |
|
109 | rawmarkers = repo.obsstore.relevantmarkers(nodes) | |
110 |
|
110 | |||
111 | for markerdata in rawmarkers: |
|
111 | for markerdata in rawmarkers: | |
112 | yield marker(repo, markerdata) |
|
112 | yield marker(repo, markerdata) | |
113 |
|
113 | |||
114 |
|
114 | |||
|
115 | def sortedmarkers(markers): | |||
|
116 | # last item of marker tuple ('parents') may be None or a tuple | |||
|
117 | return sorted(markers, key=lambda m: m[:-1] + (m[-1] or (),)) | |||
|
118 | ||||
|
119 | ||||
115 | def closestpredecessors(repo, nodeid): |
|
120 | def closestpredecessors(repo, nodeid): | |
116 | """yield the list of next predecessors pointing on visible changectx nodes |
|
121 | """yield the list of next predecessors pointing on visible changectx nodes | |
117 |
|
122 | |||
118 | This function respect the repoview filtering, filtered revision will be |
|
123 | This function respect the repoview filtering, filtered revision will be | |
119 | considered missing. |
|
124 | considered missing. | |
120 | """ |
|
125 | """ | |
121 |
|
126 | |||
122 | precursors = repo.obsstore.predecessors |
|
127 | precursors = repo.obsstore.predecessors | |
123 | stack = [nodeid] |
|
128 | stack = [nodeid] | |
124 | seen = set(stack) |
|
129 | seen = set(stack) | |
125 |
|
130 | |||
126 | while stack: |
|
131 | while stack: | |
127 | current = stack.pop() |
|
132 | current = stack.pop() | |
128 | currentpreccs = precursors.get(current, ()) |
|
133 | currentpreccs = precursors.get(current, ()) | |
129 |
|
134 | |||
130 | for prec in currentpreccs: |
|
135 | for prec in currentpreccs: | |
131 | precnodeid = prec[0] |
|
136 | precnodeid = prec[0] | |
132 |
|
137 | |||
133 | # Basic cycle protection |
|
138 | # Basic cycle protection | |
134 | if precnodeid in seen: |
|
139 | if precnodeid in seen: | |
135 | continue |
|
140 | continue | |
136 | seen.add(precnodeid) |
|
141 | seen.add(precnodeid) | |
137 |
|
142 | |||
138 | if precnodeid in repo: |
|
143 | if precnodeid in repo: | |
139 | yield precnodeid |
|
144 | yield precnodeid | |
140 | else: |
|
145 | else: | |
141 | stack.append(precnodeid) |
|
146 | stack.append(precnodeid) | |
142 |
|
147 | |||
143 |
|
148 | |||
144 | def allpredecessors(obsstore, nodes, ignoreflags=0): |
|
149 | def allpredecessors(obsstore, nodes, ignoreflags=0): | |
145 | """Yield node for every precursors of <nodes>. |
|
150 | """Yield node for every precursors of <nodes>. | |
146 |
|
151 | |||
147 | Some precursors may be unknown locally. |
|
152 | Some precursors may be unknown locally. | |
148 |
|
153 | |||
149 | This is a linear yield unsuited to detecting folded changesets. It includes |
|
154 | This is a linear yield unsuited to detecting folded changesets. It includes | |
150 | initial nodes too.""" |
|
155 | initial nodes too.""" | |
151 |
|
156 | |||
152 | remaining = set(nodes) |
|
157 | remaining = set(nodes) | |
153 | seen = set(remaining) |
|
158 | seen = set(remaining) | |
154 | prec = obsstore.predecessors.get |
|
159 | prec = obsstore.predecessors.get | |
155 | while remaining: |
|
160 | while remaining: | |
156 | current = remaining.pop() |
|
161 | current = remaining.pop() | |
157 | yield current |
|
162 | yield current | |
158 | for mark in prec(current, ()): |
|
163 | for mark in prec(current, ()): | |
159 | # ignore marker flagged with specified flag |
|
164 | # ignore marker flagged with specified flag | |
160 | if mark[2] & ignoreflags: |
|
165 | if mark[2] & ignoreflags: | |
161 | continue |
|
166 | continue | |
162 | suc = mark[0] |
|
167 | suc = mark[0] | |
163 | if suc not in seen: |
|
168 | if suc not in seen: | |
164 | seen.add(suc) |
|
169 | seen.add(suc) | |
165 | remaining.add(suc) |
|
170 | remaining.add(suc) | |
166 |
|
171 | |||
167 |
|
172 | |||
168 | def allsuccessors(obsstore, nodes, ignoreflags=0): |
|
173 | def allsuccessors(obsstore, nodes, ignoreflags=0): | |
169 | """Yield node for every successor of <nodes>. |
|
174 | """Yield node for every successor of <nodes>. | |
170 |
|
175 | |||
171 | Some successors may be unknown locally. |
|
176 | Some successors may be unknown locally. | |
172 |
|
177 | |||
173 | This is a linear yield unsuited to detecting split changesets. It includes |
|
178 | This is a linear yield unsuited to detecting split changesets. It includes | |
174 | initial nodes too.""" |
|
179 | initial nodes too.""" | |
175 | remaining = set(nodes) |
|
180 | remaining = set(nodes) | |
176 | seen = set(remaining) |
|
181 | seen = set(remaining) | |
177 | while remaining: |
|
182 | while remaining: | |
178 | current = remaining.pop() |
|
183 | current = remaining.pop() | |
179 | yield current |
|
184 | yield current | |
180 | for mark in obsstore.successors.get(current, ()): |
|
185 | for mark in obsstore.successors.get(current, ()): | |
181 | # ignore marker flagged with specified flag |
|
186 | # ignore marker flagged with specified flag | |
182 | if mark[2] & ignoreflags: |
|
187 | if mark[2] & ignoreflags: | |
183 | continue |
|
188 | continue | |
184 | for suc in mark[1]: |
|
189 | for suc in mark[1]: | |
185 | if suc not in seen: |
|
190 | if suc not in seen: | |
186 | seen.add(suc) |
|
191 | seen.add(suc) | |
187 | remaining.add(suc) |
|
192 | remaining.add(suc) | |
188 |
|
193 | |||
189 |
|
194 | |||
190 | def _filterprunes(markers): |
|
195 | def _filterprunes(markers): | |
191 | """return a set with no prune markers""" |
|
196 | """return a set with no prune markers""" | |
192 | return set(m for m in markers if m[1]) |
|
197 | return set(m for m in markers if m[1]) | |
193 |
|
198 | |||
194 |
|
199 | |||
195 | def exclusivemarkers(repo, nodes): |
|
200 | def exclusivemarkers(repo, nodes): | |
196 | """set of markers relevant to "nodes" but no other locally-known nodes |
|
201 | """set of markers relevant to "nodes" but no other locally-known nodes | |
197 |
|
202 | |||
198 | This function compute the set of markers "exclusive" to a locally-known |
|
203 | This function compute the set of markers "exclusive" to a locally-known | |
199 | node. This means we walk the markers starting from <nodes> until we reach a |
|
204 | node. This means we walk the markers starting from <nodes> until we reach a | |
200 | locally-known precursors outside of <nodes>. Element of <nodes> with |
|
205 | locally-known precursors outside of <nodes>. Element of <nodes> with | |
201 | locally-known successors outside of <nodes> are ignored (since their |
|
206 | locally-known successors outside of <nodes> are ignored (since their | |
202 | precursors markers are also relevant to these successors). |
|
207 | precursors markers are also relevant to these successors). | |
203 |
|
208 | |||
204 | For example: |
|
209 | For example: | |
205 |
|
210 | |||
206 | # (A0 rewritten as A1) |
|
211 | # (A0 rewritten as A1) | |
207 | # |
|
212 | # | |
208 | # A0 <-1- A1 # Marker "1" is exclusive to A1 |
|
213 | # A0 <-1- A1 # Marker "1" is exclusive to A1 | |
209 |
|
214 | |||
210 | or |
|
215 | or | |
211 |
|
216 | |||
212 | # (A0 rewritten as AX; AX rewritten as A1; AX is unkown locally) |
|
217 | # (A0 rewritten as AX; AX rewritten as A1; AX is unkown locally) | |
213 | # |
|
218 | # | |
214 | # <-1- A0 <-2- AX <-3- A1 # Marker "2,3" are exclusive to A1 |
|
219 | # <-1- A0 <-2- AX <-3- A1 # Marker "2,3" are exclusive to A1 | |
215 |
|
220 | |||
216 | or |
|
221 | or | |
217 |
|
222 | |||
218 | # (A0 has unknown precursors, A0 rewritten as A1 and A2 (divergence)) |
|
223 | # (A0 has unknown precursors, A0 rewritten as A1 and A2 (divergence)) | |
219 | # |
|
224 | # | |
220 | # <-2- A1 # Marker "2" is exclusive to A0,A1 |
|
225 | # <-2- A1 # Marker "2" is exclusive to A0,A1 | |
221 | # / |
|
226 | # / | |
222 | # <-1- A0 |
|
227 | # <-1- A0 | |
223 | # \ |
|
228 | # \ | |
224 | # <-3- A2 # Marker "3" is exclusive to A0,A2 |
|
229 | # <-3- A2 # Marker "3" is exclusive to A0,A2 | |
225 | # |
|
230 | # | |
226 | # in addition: |
|
231 | # in addition: | |
227 | # |
|
232 | # | |
228 | # Markers "2,3" are exclusive to A1,A2 |
|
233 | # Markers "2,3" are exclusive to A1,A2 | |
229 | # Markers "1,2,3" are exclusive to A0,A1,A2 |
|
234 | # Markers "1,2,3" are exclusive to A0,A1,A2 | |
230 |
|
235 | |||
231 | See test/test-obsolete-bundle-strip.t for more examples. |
|
236 | See test/test-obsolete-bundle-strip.t for more examples. | |
232 |
|
237 | |||
233 | An example usage is strip. When stripping a changeset, we also want to |
|
238 | An example usage is strip. When stripping a changeset, we also want to | |
234 | strip the markers exclusive to this changeset. Otherwise we would have |
|
239 | strip the markers exclusive to this changeset. Otherwise we would have | |
235 | "dangling"" obsolescence markers from its precursors: Obsolescence markers |
|
240 | "dangling"" obsolescence markers from its precursors: Obsolescence markers | |
236 | marking a node as obsolete without any successors available locally. |
|
241 | marking a node as obsolete without any successors available locally. | |
237 |
|
242 | |||
238 | As for relevant markers, the prune markers for children will be followed. |
|
243 | As for relevant markers, the prune markers for children will be followed. | |
239 | Of course, they will only be followed if the pruned children is |
|
244 | Of course, they will only be followed if the pruned children is | |
240 | locally-known. Since the prune markers are relevant to the pruned node. |
|
245 | locally-known. Since the prune markers are relevant to the pruned node. | |
241 | However, while prune markers are considered relevant to the parent of the |
|
246 | However, while prune markers are considered relevant to the parent of the | |
242 | pruned changesets, prune markers for locally-known changeset (with no |
|
247 | pruned changesets, prune markers for locally-known changeset (with no | |
243 | successors) are considered exclusive to the pruned nodes. This allows |
|
248 | successors) are considered exclusive to the pruned nodes. This allows | |
244 | to strip the prune markers (with the rest of the exclusive chain) alongside |
|
249 | to strip the prune markers (with the rest of the exclusive chain) alongside | |
245 | the pruned changesets. |
|
250 | the pruned changesets. | |
246 | """ |
|
251 | """ | |
247 | # running on a filtered repository would be dangerous as markers could be |
|
252 | # running on a filtered repository would be dangerous as markers could be | |
248 | # reported as exclusive when they are relevant for other filtered nodes. |
|
253 | # reported as exclusive when they are relevant for other filtered nodes. | |
249 | unfi = repo.unfiltered() |
|
254 | unfi = repo.unfiltered() | |
250 |
|
255 | |||
251 | # shortcut to various useful item |
|
256 | # shortcut to various useful item | |
252 | nm = unfi.changelog.nodemap |
|
257 | nm = unfi.changelog.nodemap | |
253 | precursorsmarkers = unfi.obsstore.predecessors |
|
258 | precursorsmarkers = unfi.obsstore.predecessors | |
254 | successormarkers = unfi.obsstore.successors |
|
259 | successormarkers = unfi.obsstore.successors | |
255 | childrenmarkers = unfi.obsstore.children |
|
260 | childrenmarkers = unfi.obsstore.children | |
256 |
|
261 | |||
257 | # exclusive markers (return of the function) |
|
262 | # exclusive markers (return of the function) | |
258 | exclmarkers = set() |
|
263 | exclmarkers = set() | |
259 | # we need fast membership testing |
|
264 | # we need fast membership testing | |
260 | nodes = set(nodes) |
|
265 | nodes = set(nodes) | |
261 | # looking for head in the obshistory |
|
266 | # looking for head in the obshistory | |
262 | # |
|
267 | # | |
263 | # XXX we are ignoring all issues in regard with cycle for now. |
|
268 | # XXX we are ignoring all issues in regard with cycle for now. | |
264 | stack = [n for n in nodes if not _filterprunes(successormarkers.get(n, ()))] |
|
269 | stack = [n for n in nodes if not _filterprunes(successormarkers.get(n, ()))] | |
265 | stack.sort() |
|
270 | stack.sort() | |
266 | # nodes already stacked |
|
271 | # nodes already stacked | |
267 | seennodes = set(stack) |
|
272 | seennodes = set(stack) | |
268 | while stack: |
|
273 | while stack: | |
269 | current = stack.pop() |
|
274 | current = stack.pop() | |
270 | # fetch precursors markers |
|
275 | # fetch precursors markers | |
271 | markers = list(precursorsmarkers.get(current, ())) |
|
276 | markers = list(precursorsmarkers.get(current, ())) | |
272 | # extend the list with prune markers |
|
277 | # extend the list with prune markers | |
273 | for mark in successormarkers.get(current, ()): |
|
278 | for mark in successormarkers.get(current, ()): | |
274 | if not mark[1]: |
|
279 | if not mark[1]: | |
275 | markers.append(mark) |
|
280 | markers.append(mark) | |
276 | # and markers from children (looking for prune) |
|
281 | # and markers from children (looking for prune) | |
277 | for mark in childrenmarkers.get(current, ()): |
|
282 | for mark in childrenmarkers.get(current, ()): | |
278 | if not mark[1]: |
|
283 | if not mark[1]: | |
279 | markers.append(mark) |
|
284 | markers.append(mark) | |
280 | # traverse the markers |
|
285 | # traverse the markers | |
281 | for mark in markers: |
|
286 | for mark in markers: | |
282 | if mark in exclmarkers: |
|
287 | if mark in exclmarkers: | |
283 | # markers already selected |
|
288 | # markers already selected | |
284 | continue |
|
289 | continue | |
285 |
|
290 | |||
286 | # If the markers is about the current node, select it |
|
291 | # If the markers is about the current node, select it | |
287 | # |
|
292 | # | |
288 | # (this delay the addition of markers from children) |
|
293 | # (this delay the addition of markers from children) | |
289 | if mark[1] or mark[0] == current: |
|
294 | if mark[1] or mark[0] == current: | |
290 | exclmarkers.add(mark) |
|
295 | exclmarkers.add(mark) | |
291 |
|
296 | |||
292 | # should we keep traversing through the precursors? |
|
297 | # should we keep traversing through the precursors? | |
293 | prec = mark[0] |
|
298 | prec = mark[0] | |
294 |
|
299 | |||
295 | # nodes in the stack or already processed |
|
300 | # nodes in the stack or already processed | |
296 | if prec in seennodes: |
|
301 | if prec in seennodes: | |
297 | continue |
|
302 | continue | |
298 |
|
303 | |||
299 | # is this a locally known node ? |
|
304 | # is this a locally known node ? | |
300 | known = prec in nm |
|
305 | known = prec in nm | |
301 | # if locally-known and not in the <nodes> set the traversal |
|
306 | # if locally-known and not in the <nodes> set the traversal | |
302 | # stop here. |
|
307 | # stop here. | |
303 | if known and prec not in nodes: |
|
308 | if known and prec not in nodes: | |
304 | continue |
|
309 | continue | |
305 |
|
310 | |||
306 | # do not keep going if there are unselected markers pointing to this |
|
311 | # do not keep going if there are unselected markers pointing to this | |
307 | # nodes. If we end up traversing these unselected markers later the |
|
312 | # nodes. If we end up traversing these unselected markers later the | |
308 | # node will be taken care of at that point. |
|
313 | # node will be taken care of at that point. | |
309 | precmarkers = _filterprunes(successormarkers.get(prec)) |
|
314 | precmarkers = _filterprunes(successormarkers.get(prec)) | |
310 | if precmarkers.issubset(exclmarkers): |
|
315 | if precmarkers.issubset(exclmarkers): | |
311 | seennodes.add(prec) |
|
316 | seennodes.add(prec) | |
312 | stack.append(prec) |
|
317 | stack.append(prec) | |
313 |
|
318 | |||
314 | return exclmarkers |
|
319 | return exclmarkers | |
315 |
|
320 | |||
316 |
|
321 | |||
317 | def foreground(repo, nodes): |
|
322 | def foreground(repo, nodes): | |
318 | """return all nodes in the "foreground" of other node |
|
323 | """return all nodes in the "foreground" of other node | |
319 |
|
324 | |||
320 | The foreground of a revision is anything reachable using parent -> children |
|
325 | The foreground of a revision is anything reachable using parent -> children | |
321 | or precursor -> successor relation. It is very similar to "descendant" but |
|
326 | or precursor -> successor relation. It is very similar to "descendant" but | |
322 | augmented with obsolescence information. |
|
327 | augmented with obsolescence information. | |
323 |
|
328 | |||
324 | Beware that possible obsolescence cycle may result if complex situation. |
|
329 | Beware that possible obsolescence cycle may result if complex situation. | |
325 | """ |
|
330 | """ | |
326 | repo = repo.unfiltered() |
|
331 | repo = repo.unfiltered() | |
327 | foreground = set(repo.set(b'%ln::', nodes)) |
|
332 | foreground = set(repo.set(b'%ln::', nodes)) | |
328 | if repo.obsstore: |
|
333 | if repo.obsstore: | |
329 | # We only need this complicated logic if there is obsolescence |
|
334 | # We only need this complicated logic if there is obsolescence | |
330 | # XXX will probably deserve an optimised revset. |
|
335 | # XXX will probably deserve an optimised revset. | |
331 | nm = repo.changelog.nodemap |
|
336 | nm = repo.changelog.nodemap | |
332 | plen = -1 |
|
337 | plen = -1 | |
333 | # compute the whole set of successors or descendants |
|
338 | # compute the whole set of successors or descendants | |
334 | while len(foreground) != plen: |
|
339 | while len(foreground) != plen: | |
335 | plen = len(foreground) |
|
340 | plen = len(foreground) | |
336 | succs = set(c.node() for c in foreground) |
|
341 | succs = set(c.node() for c in foreground) | |
337 | mutable = [c.node() for c in foreground if c.mutable()] |
|
342 | mutable = [c.node() for c in foreground if c.mutable()] | |
338 | succs.update(allsuccessors(repo.obsstore, mutable)) |
|
343 | succs.update(allsuccessors(repo.obsstore, mutable)) | |
339 | known = (n for n in succs if n in nm) |
|
344 | known = (n for n in succs if n in nm) | |
340 | foreground = set(repo.set(b'%ln::', known)) |
|
345 | foreground = set(repo.set(b'%ln::', known)) | |
341 | return set(c.node() for c in foreground) |
|
346 | return set(c.node() for c in foreground) | |
342 |
|
347 | |||
343 |
|
348 | |||
344 | # effectflag field |
|
349 | # effectflag field | |
345 | # |
|
350 | # | |
346 | # Effect-flag is a 1-byte bit field used to store what changed between a |
|
351 | # Effect-flag is a 1-byte bit field used to store what changed between a | |
347 | # changeset and its successor(s). |
|
352 | # changeset and its successor(s). | |
348 | # |
|
353 | # | |
349 | # The effect flag is stored in obs-markers metadata while we iterate on the |
|
354 | # The effect flag is stored in obs-markers metadata while we iterate on the | |
350 | # information design. That's why we have the EFFECTFLAGFIELD. If we come up |
|
355 | # information design. That's why we have the EFFECTFLAGFIELD. If we come up | |
351 | # with an incompatible design for effect flag, we can store a new design under |
|
356 | # with an incompatible design for effect flag, we can store a new design under | |
352 | # another field name so we don't break readers. We plan to extend the existing |
|
357 | # another field name so we don't break readers. We plan to extend the existing | |
353 | # obsmarkers bit-field when the effect flag design will be stabilized. |
|
358 | # obsmarkers bit-field when the effect flag design will be stabilized. | |
354 | # |
|
359 | # | |
355 | # The effect-flag is placed behind an experimental flag |
|
360 | # The effect-flag is placed behind an experimental flag | |
356 | # `effect-flags` set to off by default. |
|
361 | # `effect-flags` set to off by default. | |
357 | # |
|
362 | # | |
358 |
|
363 | |||
359 | EFFECTFLAGFIELD = b"ef1" |
|
364 | EFFECTFLAGFIELD = b"ef1" | |
360 |
|
365 | |||
361 | DESCCHANGED = 1 << 0 # action changed the description |
|
366 | DESCCHANGED = 1 << 0 # action changed the description | |
362 | METACHANGED = 1 << 1 # action change the meta |
|
367 | METACHANGED = 1 << 1 # action change the meta | |
363 | DIFFCHANGED = 1 << 3 # action change diff introduced by the changeset |
|
368 | DIFFCHANGED = 1 << 3 # action change diff introduced by the changeset | |
364 | PARENTCHANGED = 1 << 2 # action change the parent |
|
369 | PARENTCHANGED = 1 << 2 # action change the parent | |
365 | USERCHANGED = 1 << 4 # the user changed |
|
370 | USERCHANGED = 1 << 4 # the user changed | |
366 | DATECHANGED = 1 << 5 # the date changed |
|
371 | DATECHANGED = 1 << 5 # the date changed | |
367 | BRANCHCHANGED = 1 << 6 # the branch changed |
|
372 | BRANCHCHANGED = 1 << 6 # the branch changed | |
368 |
|
373 | |||
369 | METABLACKLIST = [ |
|
374 | METABLACKLIST = [ | |
370 | re.compile(b'^branch$'), |
|
375 | re.compile(b'^branch$'), | |
371 | re.compile(b'^.*-source$'), |
|
376 | re.compile(b'^.*-source$'), | |
372 | re.compile(b'^.*_source$'), |
|
377 | re.compile(b'^.*_source$'), | |
373 | re.compile(b'^source$'), |
|
378 | re.compile(b'^source$'), | |
374 | ] |
|
379 | ] | |
375 |
|
380 | |||
376 |
|
381 | |||
377 | def metanotblacklisted(metaitem): |
|
382 | def metanotblacklisted(metaitem): | |
378 | """ Check that the key of a meta item (extrakey, extravalue) does not |
|
383 | """ Check that the key of a meta item (extrakey, extravalue) does not | |
379 | match at least one of the blacklist pattern |
|
384 | match at least one of the blacklist pattern | |
380 | """ |
|
385 | """ | |
381 | metakey = metaitem[0] |
|
386 | metakey = metaitem[0] | |
382 |
|
387 | |||
383 | return not any(pattern.match(metakey) for pattern in METABLACKLIST) |
|
388 | return not any(pattern.match(metakey) for pattern in METABLACKLIST) | |
384 |
|
389 | |||
385 |
|
390 | |||
386 | def _prepare_hunk(hunk): |
|
391 | def _prepare_hunk(hunk): | |
387 | """Drop all information but the username and patch""" |
|
392 | """Drop all information but the username and patch""" | |
388 | cleanhunk = [] |
|
393 | cleanhunk = [] | |
389 | for line in hunk.splitlines(): |
|
394 | for line in hunk.splitlines(): | |
390 | if line.startswith(b'# User') or not line.startswith(b'#'): |
|
395 | if line.startswith(b'# User') or not line.startswith(b'#'): | |
391 | if line.startswith(b'@@'): |
|
396 | if line.startswith(b'@@'): | |
392 | line = b'@@\n' |
|
397 | line = b'@@\n' | |
393 | cleanhunk.append(line) |
|
398 | cleanhunk.append(line) | |
394 | return cleanhunk |
|
399 | return cleanhunk | |
395 |
|
400 | |||
396 |
|
401 | |||
397 | def _getdifflines(iterdiff): |
|
402 | def _getdifflines(iterdiff): | |
398 | """return a cleaned up lines""" |
|
403 | """return a cleaned up lines""" | |
399 | lines = next(iterdiff, None) |
|
404 | lines = next(iterdiff, None) | |
400 |
|
405 | |||
401 | if lines is None: |
|
406 | if lines is None: | |
402 | return lines |
|
407 | return lines | |
403 |
|
408 | |||
404 | return _prepare_hunk(lines) |
|
409 | return _prepare_hunk(lines) | |
405 |
|
410 | |||
406 |
|
411 | |||
407 | def _cmpdiff(leftctx, rightctx): |
|
412 | def _cmpdiff(leftctx, rightctx): | |
408 | """return True if both ctx introduce the "same diff" |
|
413 | """return True if both ctx introduce the "same diff" | |
409 |
|
414 | |||
410 | This is a first and basic implementation, with many shortcoming. |
|
415 | This is a first and basic implementation, with many shortcoming. | |
411 | """ |
|
416 | """ | |
412 | diffopts = diffutil.diffallopts(leftctx.repo().ui, {b'git': True}) |
|
417 | diffopts = diffutil.diffallopts(leftctx.repo().ui, {b'git': True}) | |
413 |
|
418 | |||
414 | # Leftctx or right ctx might be filtered, so we need to use the contexts |
|
419 | # Leftctx or right ctx might be filtered, so we need to use the contexts | |
415 | # with an unfiltered repository to safely compute the diff |
|
420 | # with an unfiltered repository to safely compute the diff | |
416 |
|
421 | |||
417 | # leftctx and rightctx can be from different repository views in case of |
|
422 | # leftctx and rightctx can be from different repository views in case of | |
418 | # hgsubversion, do don't try to access them from same repository |
|
423 | # hgsubversion, do don't try to access them from same repository | |
419 | # rightctx.repo() and leftctx.repo() are not always the same |
|
424 | # rightctx.repo() and leftctx.repo() are not always the same | |
420 | leftunfi = leftctx._repo.unfiltered()[leftctx.rev()] |
|
425 | leftunfi = leftctx._repo.unfiltered()[leftctx.rev()] | |
421 | leftdiff = leftunfi.diff(opts=diffopts) |
|
426 | leftdiff = leftunfi.diff(opts=diffopts) | |
422 | rightunfi = rightctx._repo.unfiltered()[rightctx.rev()] |
|
427 | rightunfi = rightctx._repo.unfiltered()[rightctx.rev()] | |
423 | rightdiff = rightunfi.diff(opts=diffopts) |
|
428 | rightdiff = rightunfi.diff(opts=diffopts) | |
424 |
|
429 | |||
425 | left, right = (0, 0) |
|
430 | left, right = (0, 0) | |
426 | while None not in (left, right): |
|
431 | while None not in (left, right): | |
427 | left = _getdifflines(leftdiff) |
|
432 | left = _getdifflines(leftdiff) | |
428 | right = _getdifflines(rightdiff) |
|
433 | right = _getdifflines(rightdiff) | |
429 |
|
434 | |||
430 | if left != right: |
|
435 | if left != right: | |
431 | return False |
|
436 | return False | |
432 | return True |
|
437 | return True | |
433 |
|
438 | |||
434 |
|
439 | |||
435 | def geteffectflag(source, successors): |
|
440 | def geteffectflag(source, successors): | |
436 | """ From an obs-marker relation, compute what changed between the |
|
441 | """ From an obs-marker relation, compute what changed between the | |
437 | predecessor and the successor. |
|
442 | predecessor and the successor. | |
438 | """ |
|
443 | """ | |
439 | effects = 0 |
|
444 | effects = 0 | |
440 |
|
445 | |||
441 | for changectx in successors: |
|
446 | for changectx in successors: | |
442 | # Check if description has changed |
|
447 | # Check if description has changed | |
443 | if changectx.description() != source.description(): |
|
448 | if changectx.description() != source.description(): | |
444 | effects |= DESCCHANGED |
|
449 | effects |= DESCCHANGED | |
445 |
|
450 | |||
446 | # Check if user has changed |
|
451 | # Check if user has changed | |
447 | if changectx.user() != source.user(): |
|
452 | if changectx.user() != source.user(): | |
448 | effects |= USERCHANGED |
|
453 | effects |= USERCHANGED | |
449 |
|
454 | |||
450 | # Check if date has changed |
|
455 | # Check if date has changed | |
451 | if changectx.date() != source.date(): |
|
456 | if changectx.date() != source.date(): | |
452 | effects |= DATECHANGED |
|
457 | effects |= DATECHANGED | |
453 |
|
458 | |||
454 | # Check if branch has changed |
|
459 | # Check if branch has changed | |
455 | if changectx.branch() != source.branch(): |
|
460 | if changectx.branch() != source.branch(): | |
456 | effects |= BRANCHCHANGED |
|
461 | effects |= BRANCHCHANGED | |
457 |
|
462 | |||
458 | # Check if at least one of the parent has changed |
|
463 | # Check if at least one of the parent has changed | |
459 | if changectx.parents() != source.parents(): |
|
464 | if changectx.parents() != source.parents(): | |
460 | effects |= PARENTCHANGED |
|
465 | effects |= PARENTCHANGED | |
461 |
|
466 | |||
462 | # Check if other meta has changed |
|
467 | # Check if other meta has changed | |
463 | changeextra = changectx.extra().items() |
|
468 | changeextra = changectx.extra().items() | |
464 | ctxmeta = list(filter(metanotblacklisted, changeextra)) |
|
469 | ctxmeta = list(filter(metanotblacklisted, changeextra)) | |
465 |
|
470 | |||
466 | sourceextra = source.extra().items() |
|
471 | sourceextra = source.extra().items() | |
467 | srcmeta = list(filter(metanotblacklisted, sourceextra)) |
|
472 | srcmeta = list(filter(metanotblacklisted, sourceextra)) | |
468 |
|
473 | |||
469 | if ctxmeta != srcmeta: |
|
474 | if ctxmeta != srcmeta: | |
470 | effects |= METACHANGED |
|
475 | effects |= METACHANGED | |
471 |
|
476 | |||
472 | # Check if the diff has changed |
|
477 | # Check if the diff has changed | |
473 | if not _cmpdiff(source, changectx): |
|
478 | if not _cmpdiff(source, changectx): | |
474 | effects |= DIFFCHANGED |
|
479 | effects |= DIFFCHANGED | |
475 |
|
480 | |||
476 | return effects |
|
481 | return effects | |
477 |
|
482 | |||
478 |
|
483 | |||
479 | def getobsoleted(repo, tr): |
|
484 | def getobsoleted(repo, tr): | |
480 | """return the set of pre-existing revisions obsoleted by a transaction""" |
|
485 | """return the set of pre-existing revisions obsoleted by a transaction""" | |
481 | torev = repo.unfiltered().changelog.nodemap.get |
|
486 | torev = repo.unfiltered().changelog.nodemap.get | |
482 | phase = repo._phasecache.phase |
|
487 | phase = repo._phasecache.phase | |
483 | succsmarkers = repo.obsstore.successors.get |
|
488 | succsmarkers = repo.obsstore.successors.get | |
484 | public = phases.public |
|
489 | public = phases.public | |
485 | addedmarkers = tr.changes[b'obsmarkers'] |
|
490 | addedmarkers = tr.changes[b'obsmarkers'] | |
486 | origrepolen = tr.changes[b'origrepolen'] |
|
491 | origrepolen = tr.changes[b'origrepolen'] | |
487 | seenrevs = set() |
|
492 | seenrevs = set() | |
488 | obsoleted = set() |
|
493 | obsoleted = set() | |
489 | for mark in addedmarkers: |
|
494 | for mark in addedmarkers: | |
490 | node = mark[0] |
|
495 | node = mark[0] | |
491 | rev = torev(node) |
|
496 | rev = torev(node) | |
492 | if rev is None or rev in seenrevs or rev >= origrepolen: |
|
497 | if rev is None or rev in seenrevs or rev >= origrepolen: | |
493 | continue |
|
498 | continue | |
494 | seenrevs.add(rev) |
|
499 | seenrevs.add(rev) | |
495 | if phase(repo, rev) == public: |
|
500 | if phase(repo, rev) == public: | |
496 | continue |
|
501 | continue | |
497 | if set(succsmarkers(node) or []).issubset(addedmarkers): |
|
502 | if set(succsmarkers(node) or []).issubset(addedmarkers): | |
498 | obsoleted.add(rev) |
|
503 | obsoleted.add(rev) | |
499 | return obsoleted |
|
504 | return obsoleted | |
500 |
|
505 | |||
501 |
|
506 | |||
502 | class _succs(list): |
|
507 | class _succs(list): | |
503 | """small class to represent a successors with some metadata about it""" |
|
508 | """small class to represent a successors with some metadata about it""" | |
504 |
|
509 | |||
505 | def __init__(self, *args, **kwargs): |
|
510 | def __init__(self, *args, **kwargs): | |
506 | super(_succs, self).__init__(*args, **kwargs) |
|
511 | super(_succs, self).__init__(*args, **kwargs) | |
507 | self.markers = set() |
|
512 | self.markers = set() | |
508 |
|
513 | |||
509 | def copy(self): |
|
514 | def copy(self): | |
510 | new = _succs(self) |
|
515 | new = _succs(self) | |
511 | new.markers = self.markers.copy() |
|
516 | new.markers = self.markers.copy() | |
512 | return new |
|
517 | return new | |
513 |
|
518 | |||
514 | @util.propertycache |
|
519 | @util.propertycache | |
515 | def _set(self): |
|
520 | def _set(self): | |
516 | # immutable |
|
521 | # immutable | |
517 | return set(self) |
|
522 | return set(self) | |
518 |
|
523 | |||
519 | def canmerge(self, other): |
|
524 | def canmerge(self, other): | |
520 | return self._set.issubset(other._set) |
|
525 | return self._set.issubset(other._set) | |
521 |
|
526 | |||
522 |
|
527 | |||
523 | def successorssets(repo, initialnode, closest=False, cache=None): |
|
528 | def successorssets(repo, initialnode, closest=False, cache=None): | |
524 | """Return set of all latest successors of initial nodes |
|
529 | """Return set of all latest successors of initial nodes | |
525 |
|
530 | |||
526 | The successors set of a changeset A are the group of revisions that succeed |
|
531 | The successors set of a changeset A are the group of revisions that succeed | |
527 | A. It succeeds A as a consistent whole, each revision being only a partial |
|
532 | A. It succeeds A as a consistent whole, each revision being only a partial | |
528 | replacement. By default, the successors set contains non-obsolete |
|
533 | replacement. By default, the successors set contains non-obsolete | |
529 | changesets only, walking the obsolescence graph until reaching a leaf. If |
|
534 | changesets only, walking the obsolescence graph until reaching a leaf. If | |
530 | 'closest' is set to True, closest successors-sets are return (the |
|
535 | 'closest' is set to True, closest successors-sets are return (the | |
531 | obsolescence walk stops on known changesets). |
|
536 | obsolescence walk stops on known changesets). | |
532 |
|
537 | |||
533 | This function returns the full list of successor sets which is why it |
|
538 | This function returns the full list of successor sets which is why it | |
534 | returns a list of tuples and not just a single tuple. Each tuple is a valid |
|
539 | returns a list of tuples and not just a single tuple. Each tuple is a valid | |
535 | successors set. Note that (A,) may be a valid successors set for changeset A |
|
540 | successors set. Note that (A,) may be a valid successors set for changeset A | |
536 | (see below). |
|
541 | (see below). | |
537 |
|
542 | |||
538 | In most cases, a changeset A will have a single element (e.g. the changeset |
|
543 | In most cases, a changeset A will have a single element (e.g. the changeset | |
539 | A is replaced by A') in its successors set. Though, it is also common for a |
|
544 | A is replaced by A') in its successors set. Though, it is also common for a | |
540 | changeset A to have no elements in its successor set (e.g. the changeset |
|
545 | changeset A to have no elements in its successor set (e.g. the changeset | |
541 | has been pruned). Therefore, the returned list of successors sets will be |
|
546 | has been pruned). Therefore, the returned list of successors sets will be | |
542 | [(A',)] or [], respectively. |
|
547 | [(A',)] or [], respectively. | |
543 |
|
548 | |||
544 | When a changeset A is split into A' and B', however, it will result in a |
|
549 | When a changeset A is split into A' and B', however, it will result in a | |
545 | successors set containing more than a single element, i.e. [(A',B')]. |
|
550 | successors set containing more than a single element, i.e. [(A',B')]. | |
546 | Divergent changesets will result in multiple successors sets, i.e. [(A',), |
|
551 | Divergent changesets will result in multiple successors sets, i.e. [(A',), | |
547 | (A'')]. |
|
552 | (A'')]. | |
548 |
|
553 | |||
549 | If a changeset A is not obsolete, then it will conceptually have no |
|
554 | If a changeset A is not obsolete, then it will conceptually have no | |
550 | successors set. To distinguish this from a pruned changeset, the successor |
|
555 | successors set. To distinguish this from a pruned changeset, the successor | |
551 | set will contain itself only, i.e. [(A,)]. |
|
556 | set will contain itself only, i.e. [(A,)]. | |
552 |
|
557 | |||
553 | Finally, final successors unknown locally are considered to be pruned |
|
558 | Finally, final successors unknown locally are considered to be pruned | |
554 | (pruned: obsoleted without any successors). (Final: successors not affected |
|
559 | (pruned: obsoleted without any successors). (Final: successors not affected | |
555 | by markers). |
|
560 | by markers). | |
556 |
|
561 | |||
557 | The 'closest' mode respect the repoview filtering. For example, without |
|
562 | The 'closest' mode respect the repoview filtering. For example, without | |
558 | filter it will stop at the first locally known changeset, with 'visible' |
|
563 | filter it will stop at the first locally known changeset, with 'visible' | |
559 | filter it will stop on visible changesets). |
|
564 | filter it will stop on visible changesets). | |
560 |
|
565 | |||
561 | The optional `cache` parameter is a dictionary that may contains |
|
566 | The optional `cache` parameter is a dictionary that may contains | |
562 | precomputed successors sets. It is meant to reuse the computation of a |
|
567 | precomputed successors sets. It is meant to reuse the computation of a | |
563 | previous call to `successorssets` when multiple calls are made at the same |
|
568 | previous call to `successorssets` when multiple calls are made at the same | |
564 | time. The cache dictionary is updated in place. The caller is responsible |
|
569 | time. The cache dictionary is updated in place. The caller is responsible | |
565 | for its life span. Code that makes multiple calls to `successorssets` |
|
570 | for its life span. Code that makes multiple calls to `successorssets` | |
566 | *should* use this cache mechanism or risk a performance hit. |
|
571 | *should* use this cache mechanism or risk a performance hit. | |
567 |
|
572 | |||
568 | Since results are different depending of the 'closest' most, the same cache |
|
573 | Since results are different depending of the 'closest' most, the same cache | |
569 | cannot be reused for both mode. |
|
574 | cannot be reused for both mode. | |
570 | """ |
|
575 | """ | |
571 |
|
576 | |||
572 | succmarkers = repo.obsstore.successors |
|
577 | succmarkers = repo.obsstore.successors | |
573 |
|
578 | |||
574 | # Stack of nodes we search successors sets for |
|
579 | # Stack of nodes we search successors sets for | |
575 | toproceed = [initialnode] |
|
580 | toproceed = [initialnode] | |
576 | # set version of above list for fast loop detection |
|
581 | # set version of above list for fast loop detection | |
577 | # element added to "toproceed" must be added here |
|
582 | # element added to "toproceed" must be added here | |
578 | stackedset = set(toproceed) |
|
583 | stackedset = set(toproceed) | |
579 | if cache is None: |
|
584 | if cache is None: | |
580 | cache = {} |
|
585 | cache = {} | |
581 |
|
586 | |||
582 | # This while loop is the flattened version of a recursive search for |
|
587 | # This while loop is the flattened version of a recursive search for | |
583 | # successors sets |
|
588 | # successors sets | |
584 | # |
|
589 | # | |
585 | # def successorssets(x): |
|
590 | # def successorssets(x): | |
586 | # successors = directsuccessors(x) |
|
591 | # successors = directsuccessors(x) | |
587 | # ss = [[]] |
|
592 | # ss = [[]] | |
588 | # for succ in directsuccessors(x): |
|
593 | # for succ in directsuccessors(x): | |
589 | # # product as in itertools cartesian product |
|
594 | # # product as in itertools cartesian product | |
590 | # ss = product(ss, successorssets(succ)) |
|
595 | # ss = product(ss, successorssets(succ)) | |
591 | # return ss |
|
596 | # return ss | |
592 | # |
|
597 | # | |
593 | # But we can not use plain recursive calls here: |
|
598 | # But we can not use plain recursive calls here: | |
594 | # - that would blow the python call stack |
|
599 | # - that would blow the python call stack | |
595 | # - obsolescence markers may have cycles, we need to handle them. |
|
600 | # - obsolescence markers may have cycles, we need to handle them. | |
596 | # |
|
601 | # | |
597 | # The `toproceed` list act as our call stack. Every node we search |
|
602 | # The `toproceed` list act as our call stack. Every node we search | |
598 | # successors set for are stacked there. |
|
603 | # successors set for are stacked there. | |
599 | # |
|
604 | # | |
600 | # The `stackedset` is set version of this stack used to check if a node is |
|
605 | # The `stackedset` is set version of this stack used to check if a node is | |
601 | # already stacked. This check is used to detect cycles and prevent infinite |
|
606 | # already stacked. This check is used to detect cycles and prevent infinite | |
602 | # loop. |
|
607 | # loop. | |
603 | # |
|
608 | # | |
604 | # successors set of all nodes are stored in the `cache` dictionary. |
|
609 | # successors set of all nodes are stored in the `cache` dictionary. | |
605 | # |
|
610 | # | |
606 | # After this while loop ends we use the cache to return the successors sets |
|
611 | # After this while loop ends we use the cache to return the successors sets | |
607 | # for the node requested by the caller. |
|
612 | # for the node requested by the caller. | |
608 | while toproceed: |
|
613 | while toproceed: | |
609 | # Every iteration tries to compute the successors sets of the topmost |
|
614 | # Every iteration tries to compute the successors sets of the topmost | |
610 | # node of the stack: CURRENT. |
|
615 | # node of the stack: CURRENT. | |
611 | # |
|
616 | # | |
612 | # There are four possible outcomes: |
|
617 | # There are four possible outcomes: | |
613 | # |
|
618 | # | |
614 | # 1) We already know the successors sets of CURRENT: |
|
619 | # 1) We already know the successors sets of CURRENT: | |
615 | # -> mission accomplished, pop it from the stack. |
|
620 | # -> mission accomplished, pop it from the stack. | |
616 | # 2) Stop the walk: |
|
621 | # 2) Stop the walk: | |
617 | # default case: Node is not obsolete |
|
622 | # default case: Node is not obsolete | |
618 | # closest case: Node is known at this repo filter level |
|
623 | # closest case: Node is known at this repo filter level | |
619 | # -> the node is its own successors sets. Add it to the cache. |
|
624 | # -> the node is its own successors sets. Add it to the cache. | |
620 | # 3) We do not know successors set of direct successors of CURRENT: |
|
625 | # 3) We do not know successors set of direct successors of CURRENT: | |
621 | # -> We add those successors to the stack. |
|
626 | # -> We add those successors to the stack. | |
622 | # 4) We know successors sets of all direct successors of CURRENT: |
|
627 | # 4) We know successors sets of all direct successors of CURRENT: | |
623 | # -> We can compute CURRENT successors set and add it to the |
|
628 | # -> We can compute CURRENT successors set and add it to the | |
624 | # cache. |
|
629 | # cache. | |
625 | # |
|
630 | # | |
626 | current = toproceed[-1] |
|
631 | current = toproceed[-1] | |
627 |
|
632 | |||
628 | # case 2 condition is a bit hairy because of closest, |
|
633 | # case 2 condition is a bit hairy because of closest, | |
629 | # we compute it on its own |
|
634 | # we compute it on its own | |
630 | case2condition = (current not in succmarkers) or ( |
|
635 | case2condition = (current not in succmarkers) or ( | |
631 | closest and current != initialnode and current in repo |
|
636 | closest and current != initialnode and current in repo | |
632 | ) |
|
637 | ) | |
633 |
|
638 | |||
634 | if current in cache: |
|
639 | if current in cache: | |
635 | # case (1): We already know the successors sets |
|
640 | # case (1): We already know the successors sets | |
636 | stackedset.remove(toproceed.pop()) |
|
641 | stackedset.remove(toproceed.pop()) | |
637 | elif case2condition: |
|
642 | elif case2condition: | |
638 | # case (2): end of walk. |
|
643 | # case (2): end of walk. | |
639 | if current in repo: |
|
644 | if current in repo: | |
640 | # We have a valid successors. |
|
645 | # We have a valid successors. | |
641 | cache[current] = [_succs((current,))] |
|
646 | cache[current] = [_succs((current,))] | |
642 | else: |
|
647 | else: | |
643 | # Final obsolete version is unknown locally. |
|
648 | # Final obsolete version is unknown locally. | |
644 | # Do not count that as a valid successors |
|
649 | # Do not count that as a valid successors | |
645 | cache[current] = [] |
|
650 | cache[current] = [] | |
646 | else: |
|
651 | else: | |
647 | # cases (3) and (4) |
|
652 | # cases (3) and (4) | |
648 | # |
|
653 | # | |
649 | # We proceed in two phases. Phase 1 aims to distinguish case (3) |
|
654 | # We proceed in two phases. Phase 1 aims to distinguish case (3) | |
650 | # from case (4): |
|
655 | # from case (4): | |
651 | # |
|
656 | # | |
652 | # For each direct successors of CURRENT, we check whether its |
|
657 | # For each direct successors of CURRENT, we check whether its | |
653 | # successors sets are known. If they are not, we stack the |
|
658 | # successors sets are known. If they are not, we stack the | |
654 | # unknown node and proceed to the next iteration of the while |
|
659 | # unknown node and proceed to the next iteration of the while | |
655 | # loop. (case 3) |
|
660 | # loop. (case 3) | |
656 | # |
|
661 | # | |
657 | # During this step, we may detect obsolescence cycles: a node |
|
662 | # During this step, we may detect obsolescence cycles: a node | |
658 | # with unknown successors sets but already in the call stack. |
|
663 | # with unknown successors sets but already in the call stack. | |
659 | # In such a situation, we arbitrary set the successors sets of |
|
664 | # In such a situation, we arbitrary set the successors sets of | |
660 | # the node to nothing (node pruned) to break the cycle. |
|
665 | # the node to nothing (node pruned) to break the cycle. | |
661 | # |
|
666 | # | |
662 | # If no break was encountered we proceed to phase 2. |
|
667 | # If no break was encountered we proceed to phase 2. | |
663 | # |
|
668 | # | |
664 | # Phase 2 computes successors sets of CURRENT (case 4); see details |
|
669 | # Phase 2 computes successors sets of CURRENT (case 4); see details | |
665 | # in phase 2 itself. |
|
670 | # in phase 2 itself. | |
666 | # |
|
671 | # | |
667 | # Note the two levels of iteration in each phase. |
|
672 | # Note the two levels of iteration in each phase. | |
668 | # - The first one handles obsolescence markers using CURRENT as |
|
673 | # - The first one handles obsolescence markers using CURRENT as | |
669 | # precursor (successors markers of CURRENT). |
|
674 | # precursor (successors markers of CURRENT). | |
670 | # |
|
675 | # | |
671 | # Having multiple entry here means divergence. |
|
676 | # Having multiple entry here means divergence. | |
672 | # |
|
677 | # | |
673 | # - The second one handles successors defined in each marker. |
|
678 | # - The second one handles successors defined in each marker. | |
674 | # |
|
679 | # | |
675 | # Having none means pruned node, multiple successors means split, |
|
680 | # Having none means pruned node, multiple successors means split, | |
676 | # single successors are standard replacement. |
|
681 | # single successors are standard replacement. | |
677 | # |
|
682 | # | |
678 | for mark in sorted(succmarkers[current]): |
|
683 | for mark in sortedmarkers(succmarkers[current]): | |
679 | for suc in mark[1]: |
|
684 | for suc in mark[1]: | |
680 | if suc not in cache: |
|
685 | if suc not in cache: | |
681 | if suc in stackedset: |
|
686 | if suc in stackedset: | |
682 | # cycle breaking |
|
687 | # cycle breaking | |
683 | cache[suc] = [] |
|
688 | cache[suc] = [] | |
684 | else: |
|
689 | else: | |
685 | # case (3) If we have not computed successors sets |
|
690 | # case (3) If we have not computed successors sets | |
686 | # of one of those successors we add it to the |
|
691 | # of one of those successors we add it to the | |
687 | # `toproceed` stack and stop all work for this |
|
692 | # `toproceed` stack and stop all work for this | |
688 | # iteration. |
|
693 | # iteration. | |
689 | toproceed.append(suc) |
|
694 | toproceed.append(suc) | |
690 | stackedset.add(suc) |
|
695 | stackedset.add(suc) | |
691 | break |
|
696 | break | |
692 | else: |
|
697 | else: | |
693 | continue |
|
698 | continue | |
694 | break |
|
699 | break | |
695 | else: |
|
700 | else: | |
696 | # case (4): we know all successors sets of all direct |
|
701 | # case (4): we know all successors sets of all direct | |
697 | # successors |
|
702 | # successors | |
698 | # |
|
703 | # | |
699 | # Successors set contributed by each marker depends on the |
|
704 | # Successors set contributed by each marker depends on the | |
700 | # successors sets of all its "successors" node. |
|
705 | # successors sets of all its "successors" node. | |
701 | # |
|
706 | # | |
702 | # Each different marker is a divergence in the obsolescence |
|
707 | # Each different marker is a divergence in the obsolescence | |
703 | # history. It contributes successors sets distinct from other |
|
708 | # history. It contributes successors sets distinct from other | |
704 | # markers. |
|
709 | # markers. | |
705 | # |
|
710 | # | |
706 | # Within a marker, a successor may have divergent successors |
|
711 | # Within a marker, a successor may have divergent successors | |
707 | # sets. In such a case, the marker will contribute multiple |
|
712 | # sets. In such a case, the marker will contribute multiple | |
708 | # divergent successors sets. If multiple successors have |
|
713 | # divergent successors sets. If multiple successors have | |
709 | # divergent successors sets, a Cartesian product is used. |
|
714 | # divergent successors sets, a Cartesian product is used. | |
710 | # |
|
715 | # | |
711 | # At the end we post-process successors sets to remove |
|
716 | # At the end we post-process successors sets to remove | |
712 | # duplicated entry and successors set that are strict subset of |
|
717 | # duplicated entry and successors set that are strict subset of | |
713 | # another one. |
|
718 | # another one. | |
714 | succssets = [] |
|
719 | succssets = [] | |
715 | for mark in sorted(succmarkers[current]): |
|
720 | for mark in sortedmarkers(succmarkers[current]): | |
716 | # successors sets contributed by this marker |
|
721 | # successors sets contributed by this marker | |
717 | base = _succs() |
|
722 | base = _succs() | |
718 | base.markers.add(mark) |
|
723 | base.markers.add(mark) | |
719 | markss = [base] |
|
724 | markss = [base] | |
720 | for suc in mark[1]: |
|
725 | for suc in mark[1]: | |
721 | # cardinal product with previous successors |
|
726 | # cardinal product with previous successors | |
722 | productresult = [] |
|
727 | productresult = [] | |
723 | for prefix in markss: |
|
728 | for prefix in markss: | |
724 | for suffix in cache[suc]: |
|
729 | for suffix in cache[suc]: | |
725 | newss = prefix.copy() |
|
730 | newss = prefix.copy() | |
726 | newss.markers.update(suffix.markers) |
|
731 | newss.markers.update(suffix.markers) | |
727 | for part in suffix: |
|
732 | for part in suffix: | |
728 | # do not duplicated entry in successors set |
|
733 | # do not duplicated entry in successors set | |
729 | # first entry wins. |
|
734 | # first entry wins. | |
730 | if part not in newss: |
|
735 | if part not in newss: | |
731 | newss.append(part) |
|
736 | newss.append(part) | |
732 | productresult.append(newss) |
|
737 | productresult.append(newss) | |
733 | if productresult: |
|
738 | if productresult: | |
734 | markss = productresult |
|
739 | markss = productresult | |
735 | succssets.extend(markss) |
|
740 | succssets.extend(markss) | |
736 | # remove duplicated and subset |
|
741 | # remove duplicated and subset | |
737 | seen = [] |
|
742 | seen = [] | |
738 | final = [] |
|
743 | final = [] | |
739 | candidates = sorted( |
|
744 | candidates = sorted( | |
740 | (s for s in succssets if s), key=len, reverse=True |
|
745 | (s for s in succssets if s), key=len, reverse=True | |
741 | ) |
|
746 | ) | |
742 | for cand in candidates: |
|
747 | for cand in candidates: | |
743 | for seensuccs in seen: |
|
748 | for seensuccs in seen: | |
744 | if cand.canmerge(seensuccs): |
|
749 | if cand.canmerge(seensuccs): | |
745 | seensuccs.markers.update(cand.markers) |
|
750 | seensuccs.markers.update(cand.markers) | |
746 | break |
|
751 | break | |
747 | else: |
|
752 | else: | |
748 | final.append(cand) |
|
753 | final.append(cand) | |
749 | seen.append(cand) |
|
754 | seen.append(cand) | |
750 | final.reverse() # put small successors set first |
|
755 | final.reverse() # put small successors set first | |
751 | cache[current] = final |
|
756 | cache[current] = final | |
752 | return cache[initialnode] |
|
757 | return cache[initialnode] | |
753 |
|
758 | |||
754 |
|
759 | |||
755 | def successorsandmarkers(repo, ctx): |
|
760 | def successorsandmarkers(repo, ctx): | |
756 | """compute the raw data needed for computing obsfate |
|
761 | """compute the raw data needed for computing obsfate | |
757 | Returns a list of dict, one dict per successors set |
|
762 | Returns a list of dict, one dict per successors set | |
758 | """ |
|
763 | """ | |
759 | if not ctx.obsolete(): |
|
764 | if not ctx.obsolete(): | |
760 | return None |
|
765 | return None | |
761 |
|
766 | |||
762 | ssets = successorssets(repo, ctx.node(), closest=True) |
|
767 | ssets = successorssets(repo, ctx.node(), closest=True) | |
763 |
|
768 | |||
764 | # closestsuccessors returns an empty list for pruned revisions, remap it |
|
769 | # closestsuccessors returns an empty list for pruned revisions, remap it | |
765 | # into a list containing an empty list for future processing |
|
770 | # into a list containing an empty list for future processing | |
766 | if ssets == []: |
|
771 | if ssets == []: | |
767 | ssets = [[]] |
|
772 | ssets = [[]] | |
768 |
|
773 | |||
769 | # Try to recover pruned markers |
|
774 | # Try to recover pruned markers | |
770 | succsmap = repo.obsstore.successors |
|
775 | succsmap = repo.obsstore.successors | |
771 | fullsuccessorsets = [] # successor set + markers |
|
776 | fullsuccessorsets = [] # successor set + markers | |
772 | for sset in ssets: |
|
777 | for sset in ssets: | |
773 | if sset: |
|
778 | if sset: | |
774 | fullsuccessorsets.append(sset) |
|
779 | fullsuccessorsets.append(sset) | |
775 | else: |
|
780 | else: | |
776 | # successorsset return an empty set() when ctx or one of its |
|
781 | # successorsset return an empty set() when ctx or one of its | |
777 | # successors is pruned. |
|
782 | # successors is pruned. | |
778 | # In this case, walk the obs-markers tree again starting with ctx |
|
783 | # In this case, walk the obs-markers tree again starting with ctx | |
779 | # and find the relevant pruning obs-makers, the ones without |
|
784 | # and find the relevant pruning obs-makers, the ones without | |
780 | # successors. |
|
785 | # successors. | |
781 | # Having these markers allow us to compute some information about |
|
786 | # Having these markers allow us to compute some information about | |
782 | # its fate, like who pruned this changeset and when. |
|
787 | # its fate, like who pruned this changeset and when. | |
783 |
|
788 | |||
784 | # XXX we do not catch all prune markers (eg rewritten then pruned) |
|
789 | # XXX we do not catch all prune markers (eg rewritten then pruned) | |
785 | # (fix me later) |
|
790 | # (fix me later) | |
786 | foundany = False |
|
791 | foundany = False | |
787 | for mark in succsmap.get(ctx.node(), ()): |
|
792 | for mark in succsmap.get(ctx.node(), ()): | |
788 | if not mark[1]: |
|
793 | if not mark[1]: | |
789 | foundany = True |
|
794 | foundany = True | |
790 | sset = _succs() |
|
795 | sset = _succs() | |
791 | sset.markers.add(mark) |
|
796 | sset.markers.add(mark) | |
792 | fullsuccessorsets.append(sset) |
|
797 | fullsuccessorsets.append(sset) | |
793 | if not foundany: |
|
798 | if not foundany: | |
794 | fullsuccessorsets.append(_succs()) |
|
799 | fullsuccessorsets.append(_succs()) | |
795 |
|
800 | |||
796 | values = [] |
|
801 | values = [] | |
797 | for sset in fullsuccessorsets: |
|
802 | for sset in fullsuccessorsets: | |
798 | values.append({b'successors': sset, b'markers': sset.markers}) |
|
803 | values.append({b'successors': sset, b'markers': sset.markers}) | |
799 |
|
804 | |||
800 | return values |
|
805 | return values | |
801 |
|
806 | |||
802 |
|
807 | |||
803 | def _getobsfate(successorssets): |
|
808 | def _getobsfate(successorssets): | |
804 | """ Compute a changeset obsolescence fate based on its successorssets. |
|
809 | """ Compute a changeset obsolescence fate based on its successorssets. | |
805 | Successors can be the tipmost ones or the immediate ones. This function |
|
810 | Successors can be the tipmost ones or the immediate ones. This function | |
806 | return values are not meant to be shown directly to users, it is meant to |
|
811 | return values are not meant to be shown directly to users, it is meant to | |
807 | be used by internal functions only. |
|
812 | be used by internal functions only. | |
808 | Returns one fate from the following values: |
|
813 | Returns one fate from the following values: | |
809 | - pruned |
|
814 | - pruned | |
810 | - diverged |
|
815 | - diverged | |
811 | - superseded |
|
816 | - superseded | |
812 | - superseded_split |
|
817 | - superseded_split | |
813 | """ |
|
818 | """ | |
814 |
|
819 | |||
815 | if len(successorssets) == 0: |
|
820 | if len(successorssets) == 0: | |
816 | # The commit has been pruned |
|
821 | # The commit has been pruned | |
817 | return b'pruned' |
|
822 | return b'pruned' | |
818 | elif len(successorssets) > 1: |
|
823 | elif len(successorssets) > 1: | |
819 | return b'diverged' |
|
824 | return b'diverged' | |
820 | else: |
|
825 | else: | |
821 | # No divergence, only one set of successors |
|
826 | # No divergence, only one set of successors | |
822 | successors = successorssets[0] |
|
827 | successors = successorssets[0] | |
823 |
|
828 | |||
824 | if len(successors) == 1: |
|
829 | if len(successors) == 1: | |
825 | return b'superseded' |
|
830 | return b'superseded' | |
826 | else: |
|
831 | else: | |
827 | return b'superseded_split' |
|
832 | return b'superseded_split' | |
828 |
|
833 | |||
829 |
|
834 | |||
830 | def obsfateverb(successorset, markers): |
|
835 | def obsfateverb(successorset, markers): | |
831 | """ Return the verb summarizing the successorset and potentially using |
|
836 | """ Return the verb summarizing the successorset and potentially using | |
832 | information from the markers |
|
837 | information from the markers | |
833 | """ |
|
838 | """ | |
834 | if not successorset: |
|
839 | if not successorset: | |
835 | verb = b'pruned' |
|
840 | verb = b'pruned' | |
836 | elif len(successorset) == 1: |
|
841 | elif len(successorset) == 1: | |
837 | verb = b'rewritten' |
|
842 | verb = b'rewritten' | |
838 | else: |
|
843 | else: | |
839 | verb = b'split' |
|
844 | verb = b'split' | |
840 | return verb |
|
845 | return verb | |
841 |
|
846 | |||
842 |
|
847 | |||
843 | def markersdates(markers): |
|
848 | def markersdates(markers): | |
844 | """returns the list of dates for a list of markers |
|
849 | """returns the list of dates for a list of markers | |
845 | """ |
|
850 | """ | |
846 | return [m[4] for m in markers] |
|
851 | return [m[4] for m in markers] | |
847 |
|
852 | |||
848 |
|
853 | |||
849 | def markersusers(markers): |
|
854 | def markersusers(markers): | |
850 | """ Returns a sorted list of markers users without duplicates |
|
855 | """ Returns a sorted list of markers users without duplicates | |
851 | """ |
|
856 | """ | |
852 | markersmeta = [dict(m[3]) for m in markers] |
|
857 | markersmeta = [dict(m[3]) for m in markers] | |
853 | users = set( |
|
858 | users = set( | |
854 | encoding.tolocal(meta[b'user']) |
|
859 | encoding.tolocal(meta[b'user']) | |
855 | for meta in markersmeta |
|
860 | for meta in markersmeta | |
856 | if meta.get(b'user') |
|
861 | if meta.get(b'user') | |
857 | ) |
|
862 | ) | |
858 |
|
863 | |||
859 | return sorted(users) |
|
864 | return sorted(users) | |
860 |
|
865 | |||
861 |
|
866 | |||
862 | def markersoperations(markers): |
|
867 | def markersoperations(markers): | |
863 | """ Returns a sorted list of markers operations without duplicates |
|
868 | """ Returns a sorted list of markers operations without duplicates | |
864 | """ |
|
869 | """ | |
865 | markersmeta = [dict(m[3]) for m in markers] |
|
870 | markersmeta = [dict(m[3]) for m in markers] | |
866 | operations = set( |
|
871 | operations = set( | |
867 | meta.get(b'operation') for meta in markersmeta if meta.get(b'operation') |
|
872 | meta.get(b'operation') for meta in markersmeta if meta.get(b'operation') | |
868 | ) |
|
873 | ) | |
869 |
|
874 | |||
870 | return sorted(operations) |
|
875 | return sorted(operations) | |
871 |
|
876 | |||
872 |
|
877 | |||
873 | def obsfateprinter(ui, repo, successors, markers, formatctx): |
|
878 | def obsfateprinter(ui, repo, successors, markers, formatctx): | |
874 | """ Build a obsfate string for a single successorset using all obsfate |
|
879 | """ Build a obsfate string for a single successorset using all obsfate | |
875 | related function defined in obsutil |
|
880 | related function defined in obsutil | |
876 | """ |
|
881 | """ | |
877 | quiet = ui.quiet |
|
882 | quiet = ui.quiet | |
878 | verbose = ui.verbose |
|
883 | verbose = ui.verbose | |
879 | normal = not verbose and not quiet |
|
884 | normal = not verbose and not quiet | |
880 |
|
885 | |||
881 | line = [] |
|
886 | line = [] | |
882 |
|
887 | |||
883 | # Verb |
|
888 | # Verb | |
884 | line.append(obsfateverb(successors, markers)) |
|
889 | line.append(obsfateverb(successors, markers)) | |
885 |
|
890 | |||
886 | # Operations |
|
891 | # Operations | |
887 | operations = markersoperations(markers) |
|
892 | operations = markersoperations(markers) | |
888 | if operations: |
|
893 | if operations: | |
889 | line.append(b" using %s" % b", ".join(operations)) |
|
894 | line.append(b" using %s" % b", ".join(operations)) | |
890 |
|
895 | |||
891 | # Successors |
|
896 | # Successors | |
892 | if successors: |
|
897 | if successors: | |
893 | fmtsuccessors = [formatctx(repo[succ]) for succ in successors] |
|
898 | fmtsuccessors = [formatctx(repo[succ]) for succ in successors] | |
894 | line.append(b" as %s" % b", ".join(fmtsuccessors)) |
|
899 | line.append(b" as %s" % b", ".join(fmtsuccessors)) | |
895 |
|
900 | |||
896 | # Users |
|
901 | # Users | |
897 | users = markersusers(markers) |
|
902 | users = markersusers(markers) | |
898 | # Filter out current user in not verbose mode to reduce amount of |
|
903 | # Filter out current user in not verbose mode to reduce amount of | |
899 | # information |
|
904 | # information | |
900 | if not verbose: |
|
905 | if not verbose: | |
901 | currentuser = ui.username(acceptempty=True) |
|
906 | currentuser = ui.username(acceptempty=True) | |
902 | if len(users) == 1 and currentuser in users: |
|
907 | if len(users) == 1 and currentuser in users: | |
903 | users = None |
|
908 | users = None | |
904 |
|
909 | |||
905 | if (verbose or normal) and users: |
|
910 | if (verbose or normal) and users: | |
906 | line.append(b" by %s" % b", ".join(users)) |
|
911 | line.append(b" by %s" % b", ".join(users)) | |
907 |
|
912 | |||
908 | # Date |
|
913 | # Date | |
909 | dates = markersdates(markers) |
|
914 | dates = markersdates(markers) | |
910 |
|
915 | |||
911 | if dates and verbose: |
|
916 | if dates and verbose: | |
912 | min_date = min(dates) |
|
917 | min_date = min(dates) | |
913 | max_date = max(dates) |
|
918 | max_date = max(dates) | |
914 |
|
919 | |||
915 | if min_date == max_date: |
|
920 | if min_date == max_date: | |
916 | fmtmin_date = dateutil.datestr(min_date, b'%Y-%m-%d %H:%M %1%2') |
|
921 | fmtmin_date = dateutil.datestr(min_date, b'%Y-%m-%d %H:%M %1%2') | |
917 | line.append(b" (at %s)" % fmtmin_date) |
|
922 | line.append(b" (at %s)" % fmtmin_date) | |
918 | else: |
|
923 | else: | |
919 | fmtmin_date = dateutil.datestr(min_date, b'%Y-%m-%d %H:%M %1%2') |
|
924 | fmtmin_date = dateutil.datestr(min_date, b'%Y-%m-%d %H:%M %1%2') | |
920 | fmtmax_date = dateutil.datestr(max_date, b'%Y-%m-%d %H:%M %1%2') |
|
925 | fmtmax_date = dateutil.datestr(max_date, b'%Y-%m-%d %H:%M %1%2') | |
921 | line.append(b" (between %s and %s)" % (fmtmin_date, fmtmax_date)) |
|
926 | line.append(b" (between %s and %s)" % (fmtmin_date, fmtmax_date)) | |
922 |
|
927 | |||
923 | return b"".join(line) |
|
928 | return b"".join(line) | |
924 |
|
929 | |||
925 |
|
930 | |||
926 | filteredmsgtable = { |
|
931 | filteredmsgtable = { | |
927 | b"pruned": _(b"hidden revision '%s' is pruned"), |
|
932 | b"pruned": _(b"hidden revision '%s' is pruned"), | |
928 | b"diverged": _(b"hidden revision '%s' has diverged"), |
|
933 | b"diverged": _(b"hidden revision '%s' has diverged"), | |
929 | b"superseded": _(b"hidden revision '%s' was rewritten as: %s"), |
|
934 | b"superseded": _(b"hidden revision '%s' was rewritten as: %s"), | |
930 | b"superseded_split": _(b"hidden revision '%s' was split as: %s"), |
|
935 | b"superseded_split": _(b"hidden revision '%s' was split as: %s"), | |
931 | b"superseded_split_several": _( |
|
936 | b"superseded_split_several": _( | |
932 | b"hidden revision '%s' was split as: %s and %d more" |
|
937 | b"hidden revision '%s' was split as: %s and %d more" | |
933 | ), |
|
938 | ), | |
934 | } |
|
939 | } | |
935 |
|
940 | |||
936 |
|
941 | |||
937 | def _getfilteredreason(repo, changeid, ctx): |
|
942 | def _getfilteredreason(repo, changeid, ctx): | |
938 | """return a human-friendly string on why a obsolete changeset is hidden |
|
943 | """return a human-friendly string on why a obsolete changeset is hidden | |
939 | """ |
|
944 | """ | |
940 | successors = successorssets(repo, ctx.node()) |
|
945 | successors = successorssets(repo, ctx.node()) | |
941 | fate = _getobsfate(successors) |
|
946 | fate = _getobsfate(successors) | |
942 |
|
947 | |||
943 | # Be more precise in case the revision is superseded |
|
948 | # Be more precise in case the revision is superseded | |
944 | if fate == b'pruned': |
|
949 | if fate == b'pruned': | |
945 | return filteredmsgtable[b'pruned'] % changeid |
|
950 | return filteredmsgtable[b'pruned'] % changeid | |
946 | elif fate == b'diverged': |
|
951 | elif fate == b'diverged': | |
947 | return filteredmsgtable[b'diverged'] % changeid |
|
952 | return filteredmsgtable[b'diverged'] % changeid | |
948 | elif fate == b'superseded': |
|
953 | elif fate == b'superseded': | |
949 | single_successor = nodemod.short(successors[0][0]) |
|
954 | single_successor = nodemod.short(successors[0][0]) | |
950 | return filteredmsgtable[b'superseded'] % (changeid, single_successor) |
|
955 | return filteredmsgtable[b'superseded'] % (changeid, single_successor) | |
951 | elif fate == b'superseded_split': |
|
956 | elif fate == b'superseded_split': | |
952 |
|
957 | |||
953 | succs = [] |
|
958 | succs = [] | |
954 | for node_id in successors[0]: |
|
959 | for node_id in successors[0]: | |
955 | succs.append(nodemod.short(node_id)) |
|
960 | succs.append(nodemod.short(node_id)) | |
956 |
|
961 | |||
957 | if len(succs) <= 2: |
|
962 | if len(succs) <= 2: | |
958 | fmtsuccs = b', '.join(succs) |
|
963 | fmtsuccs = b', '.join(succs) | |
959 | return filteredmsgtable[b'superseded_split'] % (changeid, fmtsuccs) |
|
964 | return filteredmsgtable[b'superseded_split'] % (changeid, fmtsuccs) | |
960 | else: |
|
965 | else: | |
961 | firstsuccessors = b', '.join(succs[:2]) |
|
966 | firstsuccessors = b', '.join(succs[:2]) | |
962 | remainingnumber = len(succs) - 2 |
|
967 | remainingnumber = len(succs) - 2 | |
963 |
|
968 | |||
964 | args = (changeid, firstsuccessors, remainingnumber) |
|
969 | args = (changeid, firstsuccessors, remainingnumber) | |
965 | return filteredmsgtable[b'superseded_split_several'] % args |
|
970 | return filteredmsgtable[b'superseded_split_several'] % args | |
966 |
|
971 | |||
967 |
|
972 | |||
968 | def divergentsets(repo, ctx): |
|
973 | def divergentsets(repo, ctx): | |
969 | """Compute sets of commits divergent with a given one""" |
|
974 | """Compute sets of commits divergent with a given one""" | |
970 | cache = {} |
|
975 | cache = {} | |
971 | base = {} |
|
976 | base = {} | |
972 | for n in allpredecessors(repo.obsstore, [ctx.node()]): |
|
977 | for n in allpredecessors(repo.obsstore, [ctx.node()]): | |
973 | if n == ctx.node(): |
|
978 | if n == ctx.node(): | |
974 | # a node can't be a base for divergence with itself |
|
979 | # a node can't be a base for divergence with itself | |
975 | continue |
|
980 | continue | |
976 | nsuccsets = successorssets(repo, n, cache) |
|
981 | nsuccsets = successorssets(repo, n, cache) | |
977 | for nsuccset in nsuccsets: |
|
982 | for nsuccset in nsuccsets: | |
978 | if ctx.node() in nsuccset: |
|
983 | if ctx.node() in nsuccset: | |
979 | # we are only interested in *other* successor sets |
|
984 | # we are only interested in *other* successor sets | |
980 | continue |
|
985 | continue | |
981 | if tuple(nsuccset) in base: |
|
986 | if tuple(nsuccset) in base: | |
982 | # we already know the latest base for this divergency |
|
987 | # we already know the latest base for this divergency | |
983 | continue |
|
988 | continue | |
984 | base[tuple(nsuccset)] = n |
|
989 | base[tuple(nsuccset)] = n | |
985 | return [ |
|
990 | return [ | |
986 | {b'divergentnodes': divset, b'commonpredecessor': b} |
|
991 | {b'divergentnodes': divset, b'commonpredecessor': b} | |
987 | for divset, b in pycompat.iteritems(base) |
|
992 | for divset, b in pycompat.iteritems(base) | |
988 | ] |
|
993 | ] | |
989 |
|
994 | |||
990 |
|
995 | |||
991 | def whyunstable(repo, ctx): |
|
996 | def whyunstable(repo, ctx): | |
992 | result = [] |
|
997 | result = [] | |
993 | if ctx.orphan(): |
|
998 | if ctx.orphan(): | |
994 | for parent in ctx.parents(): |
|
999 | for parent in ctx.parents(): | |
995 | kind = None |
|
1000 | kind = None | |
996 | if parent.orphan(): |
|
1001 | if parent.orphan(): | |
997 | kind = b'orphan' |
|
1002 | kind = b'orphan' | |
998 | elif parent.obsolete(): |
|
1003 | elif parent.obsolete(): | |
999 | kind = b'obsolete' |
|
1004 | kind = b'obsolete' | |
1000 | if kind is not None: |
|
1005 | if kind is not None: | |
1001 | result.append( |
|
1006 | result.append( | |
1002 | { |
|
1007 | { | |
1003 | b'instability': b'orphan', |
|
1008 | b'instability': b'orphan', | |
1004 | b'reason': b'%s parent' % kind, |
|
1009 | b'reason': b'%s parent' % kind, | |
1005 | b'node': parent.hex(), |
|
1010 | b'node': parent.hex(), | |
1006 | } |
|
1011 | } | |
1007 | ) |
|
1012 | ) | |
1008 | if ctx.phasedivergent(): |
|
1013 | if ctx.phasedivergent(): | |
1009 | predecessors = allpredecessors( |
|
1014 | predecessors = allpredecessors( | |
1010 | repo.obsstore, [ctx.node()], ignoreflags=bumpedfix |
|
1015 | repo.obsstore, [ctx.node()], ignoreflags=bumpedfix | |
1011 | ) |
|
1016 | ) | |
1012 | immutable = [ |
|
1017 | immutable = [ | |
1013 | repo[p] for p in predecessors if p in repo and not repo[p].mutable() |
|
1018 | repo[p] for p in predecessors if p in repo and not repo[p].mutable() | |
1014 | ] |
|
1019 | ] | |
1015 | for predecessor in immutable: |
|
1020 | for predecessor in immutable: | |
1016 | result.append( |
|
1021 | result.append( | |
1017 | { |
|
1022 | { | |
1018 | b'instability': b'phase-divergent', |
|
1023 | b'instability': b'phase-divergent', | |
1019 | b'reason': b'immutable predecessor', |
|
1024 | b'reason': b'immutable predecessor', | |
1020 | b'node': predecessor.hex(), |
|
1025 | b'node': predecessor.hex(), | |
1021 | } |
|
1026 | } | |
1022 | ) |
|
1027 | ) | |
1023 | if ctx.contentdivergent(): |
|
1028 | if ctx.contentdivergent(): | |
1024 | dsets = divergentsets(repo, ctx) |
|
1029 | dsets = divergentsets(repo, ctx) | |
1025 | for dset in dsets: |
|
1030 | for dset in dsets: | |
1026 | divnodes = [repo[n] for n in dset[b'divergentnodes']] |
|
1031 | divnodes = [repo[n] for n in dset[b'divergentnodes']] | |
1027 | result.append( |
|
1032 | result.append( | |
1028 | { |
|
1033 | { | |
1029 | b'instability': b'content-divergent', |
|
1034 | b'instability': b'content-divergent', | |
1030 | b'divergentnodes': divnodes, |
|
1035 | b'divergentnodes': divnodes, | |
1031 | b'reason': b'predecessor', |
|
1036 | b'reason': b'predecessor', | |
1032 | b'node': nodemod.hex(dset[b'commonpredecessor']), |
|
1037 | b'node': nodemod.hex(dset[b'commonpredecessor']), | |
1033 | } |
|
1038 | } | |
1034 | ) |
|
1039 | ) | |
1035 | return result |
|
1040 | return result |
General Comments 0
You need to be logged in to leave comments.
Login now