Show More
@@ -1,1057 +1,1059 b'' | |||
|
1 | 1 | # Mercurial bookmark support code |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2008 David Soria Parra <dsp@php.net> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from __future__ import absolute_import |
|
9 | 9 | |
|
10 | 10 | import errno |
|
11 | 11 | import struct |
|
12 | 12 | |
|
13 | 13 | from .i18n import _ |
|
14 | 14 | from .node import ( |
|
15 | 15 | bin, |
|
16 | 16 | hex, |
|
17 | 17 | short, |
|
18 | 18 | wdirid, |
|
19 | 19 | ) |
|
20 | 20 | from .pycompat import getattr |
|
21 | 21 | from . import ( |
|
22 | 22 | encoding, |
|
23 | 23 | error, |
|
24 | 24 | obsutil, |
|
25 | 25 | pycompat, |
|
26 | 26 | scmutil, |
|
27 | 27 | txnutil, |
|
28 | 28 | util, |
|
29 | 29 | ) |
|
30 | 30 | |
|
31 | 31 | # label constants |
|
32 | 32 | # until 3.5, bookmarks.current was the advertised name, not |
|
33 | 33 | # bookmarks.active, so we must use both to avoid breaking old |
|
34 | 34 | # custom styles |
|
35 | 35 | activebookmarklabel = b'bookmarks.active bookmarks.current' |
|
36 | 36 | |
|
37 | 37 | BOOKMARKS_IN_STORE_REQUIREMENT = b'bookmarksinstore' |
|
38 | 38 | |
|
39 | 39 | |
|
40 | 40 | def bookmarksinstore(repo): |
|
41 | 41 | return BOOKMARKS_IN_STORE_REQUIREMENT in repo.requirements |
|
42 | 42 | |
|
43 | 43 | |
|
44 | 44 | def bookmarksvfs(repo): |
|
45 | 45 | return repo.svfs if bookmarksinstore(repo) else repo.vfs |
|
46 | 46 | |
|
47 | 47 | |
|
48 | 48 | def _getbkfile(repo): |
|
49 | 49 | """Hook so that extensions that mess with the store can hook bm storage. |
|
50 | 50 | |
|
51 | 51 | For core, this just handles wether we should see pending |
|
52 | 52 | bookmarks or the committed ones. Other extensions (like share) |
|
53 | 53 | may need to tweak this behavior further. |
|
54 | 54 | """ |
|
55 | 55 | fp, pending = txnutil.trypending( |
|
56 | 56 | repo.root, bookmarksvfs(repo), b'bookmarks' |
|
57 | 57 | ) |
|
58 | 58 | return fp |
|
59 | 59 | |
|
60 | 60 | |
|
61 | 61 | class bmstore(object): |
|
62 | 62 | r"""Storage for bookmarks. |
|
63 | 63 | |
|
64 | 64 | This object should do all bookmark-related reads and writes, so |
|
65 | 65 | that it's fairly simple to replace the storage underlying |
|
66 | 66 | bookmarks without having to clone the logic surrounding |
|
67 | 67 | bookmarks. This type also should manage the active bookmark, if |
|
68 | 68 | any. |
|
69 | 69 | |
|
70 | 70 | This particular bmstore implementation stores bookmarks as |
|
71 | 71 | {hash}\s{name}\n (the same format as localtags) in |
|
72 | 72 | .hg/bookmarks. The mapping is stored as {name: nodeid}. |
|
73 | 73 | """ |
|
74 | 74 | |
|
75 | 75 | def __init__(self, repo): |
|
76 | 76 | self._repo = repo |
|
77 | 77 | self._refmap = refmap = {} # refspec: node |
|
78 | 78 | self._nodemap = nodemap = {} # node: sorted([refspec, ...]) |
|
79 | 79 | self._clean = True |
|
80 | 80 | self._aclean = True |
|
81 | 81 | has_node = repo.changelog.index.has_node |
|
82 | 82 | tonode = bin # force local lookup |
|
83 | 83 | try: |
|
84 | 84 | with _getbkfile(repo) as bkfile: |
|
85 | 85 | for line in bkfile: |
|
86 | 86 | line = line.strip() |
|
87 | 87 | if not line: |
|
88 | 88 | continue |
|
89 | 89 | try: |
|
90 | 90 | sha, refspec = line.split(b' ', 1) |
|
91 | 91 | node = tonode(sha) |
|
92 | 92 | if has_node(node): |
|
93 | 93 | refspec = encoding.tolocal(refspec) |
|
94 | 94 | refmap[refspec] = node |
|
95 | 95 | nrefs = nodemap.get(node) |
|
96 | 96 | if nrefs is None: |
|
97 | 97 | nodemap[node] = [refspec] |
|
98 | 98 | else: |
|
99 | 99 | nrefs.append(refspec) |
|
100 | 100 | if nrefs[-2] > refspec: |
|
101 | 101 | # bookmarks weren't sorted before 4.5 |
|
102 | 102 | nrefs.sort() |
|
103 | 103 | except (TypeError, ValueError): |
|
104 | 104 | # TypeError: |
|
105 | 105 | # - bin(...) |
|
106 | 106 | # ValueError: |
|
107 | 107 | # - node in nm, for non-20-bytes entry |
|
108 | 108 | # - split(...), for string without ' ' |
|
109 | 109 | bookmarkspath = b'.hg/bookmarks' |
|
110 | 110 | if bookmarksinstore(repo): |
|
111 | 111 | bookmarkspath = b'.hg/store/bookmarks' |
|
112 | 112 | repo.ui.warn( |
|
113 | 113 | _(b'malformed line in %s: %r\n') |
|
114 | 114 | % (bookmarkspath, pycompat.bytestr(line)) |
|
115 | 115 | ) |
|
116 | 116 | except IOError as inst: |
|
117 | 117 | if inst.errno != errno.ENOENT: |
|
118 | 118 | raise |
|
119 | 119 | self._active = _readactive(repo, self) |
|
120 | 120 | |
|
121 | 121 | @property |
|
122 | 122 | def active(self): |
|
123 | 123 | return self._active |
|
124 | 124 | |
|
125 | 125 | @active.setter |
|
126 | 126 | def active(self, mark): |
|
127 | 127 | if mark is not None and mark not in self._refmap: |
|
128 | 128 | raise AssertionError(b'bookmark %s does not exist!' % mark) |
|
129 | 129 | |
|
130 | 130 | self._active = mark |
|
131 | 131 | self._aclean = False |
|
132 | 132 | |
|
133 | 133 | def __len__(self): |
|
134 | 134 | return len(self._refmap) |
|
135 | 135 | |
|
136 | 136 | def __iter__(self): |
|
137 | 137 | return iter(self._refmap) |
|
138 | 138 | |
|
139 | 139 | def iteritems(self): |
|
140 | 140 | return pycompat.iteritems(self._refmap) |
|
141 | 141 | |
|
142 | 142 | def items(self): |
|
143 | 143 | return self._refmap.items() |
|
144 | 144 | |
|
145 | 145 | # TODO: maybe rename to allnames()? |
|
146 | 146 | def keys(self): |
|
147 | 147 | return self._refmap.keys() |
|
148 | 148 | |
|
149 | 149 | # TODO: maybe rename to allnodes()? but nodes would have to be deduplicated |
|
150 | 150 | # could be self._nodemap.keys() |
|
151 | 151 | def values(self): |
|
152 | 152 | return self._refmap.values() |
|
153 | 153 | |
|
154 | 154 | def __contains__(self, mark): |
|
155 | 155 | return mark in self._refmap |
|
156 | 156 | |
|
157 | 157 | def __getitem__(self, mark): |
|
158 | 158 | return self._refmap[mark] |
|
159 | 159 | |
|
160 | 160 | def get(self, mark, default=None): |
|
161 | 161 | return self._refmap.get(mark, default) |
|
162 | 162 | |
|
163 | 163 | def _set(self, mark, node): |
|
164 | 164 | self._clean = False |
|
165 | 165 | if mark in self._refmap: |
|
166 | 166 | self._del(mark) |
|
167 | 167 | self._refmap[mark] = node |
|
168 | 168 | nrefs = self._nodemap.get(node) |
|
169 | 169 | if nrefs is None: |
|
170 | 170 | self._nodemap[node] = [mark] |
|
171 | 171 | else: |
|
172 | 172 | nrefs.append(mark) |
|
173 | 173 | nrefs.sort() |
|
174 | 174 | |
|
175 | 175 | def _del(self, mark): |
|
176 | 176 | if mark not in self._refmap: |
|
177 | 177 | return |
|
178 | 178 | self._clean = False |
|
179 | 179 | node = self._refmap.pop(mark) |
|
180 | 180 | nrefs = self._nodemap[node] |
|
181 | 181 | if len(nrefs) == 1: |
|
182 | 182 | assert nrefs[0] == mark |
|
183 | 183 | del self._nodemap[node] |
|
184 | 184 | else: |
|
185 | 185 | nrefs.remove(mark) |
|
186 | 186 | |
|
187 | 187 | def names(self, node): |
|
188 | 188 | """Return a sorted list of bookmarks pointing to the specified node""" |
|
189 | 189 | return self._nodemap.get(node, []) |
|
190 | 190 | |
|
191 | 191 | def applychanges(self, repo, tr, changes): |
|
192 | 192 | """Apply a list of changes to bookmarks |
|
193 | 193 | """ |
|
194 | 194 | bmchanges = tr.changes.get(b'bookmarks') |
|
195 | 195 | for name, node in changes: |
|
196 | 196 | old = self._refmap.get(name) |
|
197 | 197 | if node is None: |
|
198 | 198 | self._del(name) |
|
199 | 199 | else: |
|
200 | 200 | self._set(name, node) |
|
201 | 201 | if bmchanges is not None: |
|
202 | 202 | # if a previous value exist preserve the "initial" value |
|
203 | 203 | previous = bmchanges.get(name) |
|
204 | 204 | if previous is not None: |
|
205 | 205 | old = previous[0] |
|
206 | 206 | bmchanges[name] = (old, node) |
|
207 | 207 | self._recordchange(tr) |
|
208 | 208 | |
|
209 | 209 | def _recordchange(self, tr): |
|
210 | 210 | """record that bookmarks have been changed in a transaction |
|
211 | 211 | |
|
212 | 212 | The transaction is then responsible for updating the file content.""" |
|
213 | 213 | location = b'' if bookmarksinstore(self._repo) else b'plain' |
|
214 | 214 | tr.addfilegenerator( |
|
215 | 215 | b'bookmarks', (b'bookmarks',), self._write, location=location |
|
216 | 216 | ) |
|
217 | 217 | tr.hookargs[b'bookmark_moved'] = b'1' |
|
218 | 218 | |
|
219 | 219 | def _writerepo(self, repo): |
|
220 | 220 | """Factored out for extensibility""" |
|
221 | 221 | rbm = repo._bookmarks |
|
222 | 222 | if rbm.active not in self._refmap: |
|
223 | 223 | rbm.active = None |
|
224 | 224 | rbm._writeactive() |
|
225 | 225 | |
|
226 | 226 | if bookmarksinstore(repo): |
|
227 | 227 | vfs = repo.svfs |
|
228 | 228 | lock = repo.lock() |
|
229 | 229 | else: |
|
230 | 230 | vfs = repo.vfs |
|
231 | 231 | lock = repo.wlock() |
|
232 | 232 | with lock: |
|
233 | 233 | with vfs(b'bookmarks', b'w', atomictemp=True, checkambig=True) as f: |
|
234 | 234 | self._write(f) |
|
235 | 235 | |
|
236 | 236 | def _writeactive(self): |
|
237 | 237 | if self._aclean: |
|
238 | 238 | return |
|
239 | 239 | with self._repo.wlock(): |
|
240 | 240 | if self._active is not None: |
|
241 | 241 | with self._repo.vfs( |
|
242 | 242 | b'bookmarks.current', b'w', atomictemp=True, checkambig=True |
|
243 | 243 | ) as f: |
|
244 | 244 | f.write(encoding.fromlocal(self._active)) |
|
245 | 245 | else: |
|
246 | 246 | self._repo.vfs.tryunlink(b'bookmarks.current') |
|
247 | 247 | self._aclean = True |
|
248 | 248 | |
|
249 | 249 | def _write(self, fp): |
|
250 | 250 | for name, node in sorted(pycompat.iteritems(self._refmap)): |
|
251 | 251 | fp.write(b"%s %s\n" % (hex(node), encoding.fromlocal(name))) |
|
252 | 252 | self._clean = True |
|
253 | 253 | self._repo.invalidatevolatilesets() |
|
254 | 254 | |
|
255 | 255 | def expandname(self, bname): |
|
256 | 256 | if bname == b'.': |
|
257 | 257 | if self.active: |
|
258 | 258 | return self.active |
|
259 | 259 | else: |
|
260 | 260 | raise error.RepoLookupError(_(b"no active bookmark")) |
|
261 | 261 | return bname |
|
262 | 262 | |
|
263 | 263 | def checkconflict(self, mark, force=False, target=None): |
|
264 | 264 | """check repo for a potential clash of mark with an existing bookmark, |
|
265 | 265 | branch, or hash |
|
266 | 266 | |
|
267 | 267 | If target is supplied, then check that we are moving the bookmark |
|
268 | 268 | forward. |
|
269 | 269 | |
|
270 | 270 | If force is supplied, then forcibly move the bookmark to a new commit |
|
271 | 271 | regardless if it is a move forward. |
|
272 | 272 | |
|
273 | 273 | If divergent bookmark are to be deleted, they will be returned as list. |
|
274 | 274 | """ |
|
275 | 275 | cur = self._repo[b'.'].node() |
|
276 | 276 | if mark in self._refmap and not force: |
|
277 | 277 | if target: |
|
278 | 278 | if self._refmap[mark] == target and target == cur: |
|
279 | 279 | # re-activating a bookmark |
|
280 | 280 | return [] |
|
281 | 281 | rev = self._repo[target].rev() |
|
282 | 282 | anc = self._repo.changelog.ancestors([rev]) |
|
283 | 283 | bmctx = self._repo[self[mark]] |
|
284 | 284 | divs = [ |
|
285 | 285 | self._refmap[b] |
|
286 | 286 | for b in self._refmap |
|
287 | 287 | if b.split(b'@', 1)[0] == mark.split(b'@', 1)[0] |
|
288 | 288 | ] |
|
289 | 289 | |
|
290 | 290 | # allow resolving a single divergent bookmark even if moving |
|
291 | 291 | # the bookmark across branches when a revision is specified |
|
292 | 292 | # that contains a divergent bookmark |
|
293 | 293 | if bmctx.rev() not in anc and target in divs: |
|
294 | 294 | return divergent2delete(self._repo, [target], mark) |
|
295 | 295 | |
|
296 | 296 | deletefrom = [ |
|
297 | 297 | b for b in divs if self._repo[b].rev() in anc or b == target |
|
298 | 298 | ] |
|
299 | 299 | delbms = divergent2delete(self._repo, deletefrom, mark) |
|
300 | 300 | if validdest(self._repo, bmctx, self._repo[target]): |
|
301 | 301 | self._repo.ui.status( |
|
302 | 302 | _(b"moving bookmark '%s' forward from %s\n") |
|
303 | 303 | % (mark, short(bmctx.node())) |
|
304 | 304 | ) |
|
305 | 305 | return delbms |
|
306 | 306 | raise error.Abort( |
|
307 | 307 | _(b"bookmark '%s' already exists (use -f to force)") % mark |
|
308 | 308 | ) |
|
309 | 309 | if ( |
|
310 | 310 | mark in self._repo.branchmap() |
|
311 | 311 | or mark == self._repo.dirstate.branch() |
|
312 | 312 | ) and not force: |
|
313 | 313 | raise error.Abort( |
|
314 | 314 | _(b"a bookmark cannot have the name of an existing branch") |
|
315 | 315 | ) |
|
316 | 316 | if len(mark) > 3 and not force: |
|
317 | 317 | try: |
|
318 | 318 | shadowhash = scmutil.isrevsymbol(self._repo, mark) |
|
319 | 319 | except error.LookupError: # ambiguous identifier |
|
320 | 320 | shadowhash = False |
|
321 | 321 | if shadowhash: |
|
322 | 322 | self._repo.ui.warn( |
|
323 | 323 | _( |
|
324 | 324 | b"bookmark %s matches a changeset hash\n" |
|
325 | 325 | b"(did you leave a -r out of an 'hg bookmark' " |
|
326 | 326 | b"command?)\n" |
|
327 | 327 | ) |
|
328 | 328 | % mark |
|
329 | 329 | ) |
|
330 | 330 | return [] |
|
331 | 331 | |
|
332 | 332 | |
|
333 | 333 | def _readactive(repo, marks): |
|
334 | 334 | """ |
|
335 | 335 | Get the active bookmark. We can have an active bookmark that updates |
|
336 | 336 | itself as we commit. This function returns the name of that bookmark. |
|
337 | 337 | It is stored in .hg/bookmarks.current |
|
338 | 338 | """ |
|
339 | 339 | # No readline() in osutil.posixfile, reading everything is |
|
340 | 340 | # cheap. |
|
341 | 341 | content = repo.vfs.tryread(b'bookmarks.current') |
|
342 | 342 | mark = encoding.tolocal((content.splitlines() or [b''])[0]) |
|
343 | 343 | if mark == b'' or mark not in marks: |
|
344 | 344 | mark = None |
|
345 | 345 | return mark |
|
346 | 346 | |
|
347 | 347 | |
|
348 | 348 | def activate(repo, mark): |
|
349 | 349 | """ |
|
350 | 350 | Set the given bookmark to be 'active', meaning that this bookmark will |
|
351 | 351 | follow new commits that are made. |
|
352 | 352 | The name is recorded in .hg/bookmarks.current |
|
353 | 353 | """ |
|
354 | 354 | repo._bookmarks.active = mark |
|
355 | 355 | repo._bookmarks._writeactive() |
|
356 | 356 | |
|
357 | 357 | |
|
358 | 358 | def deactivate(repo): |
|
359 | 359 | """ |
|
360 | 360 | Unset the active bookmark in this repository. |
|
361 | 361 | """ |
|
362 | 362 | repo._bookmarks.active = None |
|
363 | 363 | repo._bookmarks._writeactive() |
|
364 | 364 | |
|
365 | 365 | |
|
366 | 366 | def isactivewdirparent(repo): |
|
367 | 367 | """ |
|
368 | 368 | Tell whether the 'active' bookmark (the one that follows new commits) |
|
369 | 369 | points to one of the parents of the current working directory (wdir). |
|
370 | 370 | |
|
371 | 371 | While this is normally the case, it can on occasion be false; for example, |
|
372 | 372 | immediately after a pull, the active bookmark can be moved to point |
|
373 | 373 | to a place different than the wdir. This is solved by running `hg update`. |
|
374 | 374 | """ |
|
375 | 375 | mark = repo._activebookmark |
|
376 | 376 | marks = repo._bookmarks |
|
377 | 377 | parents = [p.node() for p in repo[None].parents()] |
|
378 | 378 | return mark in marks and marks[mark] in parents |
|
379 | 379 | |
|
380 | 380 | |
|
381 | 381 | def divergent2delete(repo, deletefrom, bm): |
|
382 | 382 | """find divergent versions of bm on nodes in deletefrom. |
|
383 | 383 | |
|
384 | 384 | the list of bookmark to delete.""" |
|
385 | 385 | todelete = [] |
|
386 | 386 | marks = repo._bookmarks |
|
387 | 387 | divergent = [ |
|
388 | 388 | b for b in marks if b.split(b'@', 1)[0] == bm.split(b'@', 1)[0] |
|
389 | 389 | ] |
|
390 | 390 | for mark in divergent: |
|
391 | 391 | if mark == b'@' or b'@' not in mark: |
|
392 | 392 | # can't be divergent by definition |
|
393 | 393 | continue |
|
394 | 394 | if mark and marks[mark] in deletefrom: |
|
395 | 395 | if mark != bm: |
|
396 | 396 | todelete.append(mark) |
|
397 | 397 | return todelete |
|
398 | 398 | |
|
399 | 399 | |
|
400 | 400 | def headsforactive(repo): |
|
401 | 401 | """Given a repo with an active bookmark, return divergent bookmark nodes. |
|
402 | 402 | |
|
403 | 403 | Args: |
|
404 | 404 | repo: A repository with an active bookmark. |
|
405 | 405 | |
|
406 | 406 | Returns: |
|
407 | 407 | A list of binary node ids that is the full list of other |
|
408 | 408 | revisions with bookmarks divergent from the active bookmark. If |
|
409 | 409 | there were no divergent bookmarks, then this list will contain |
|
410 | 410 | only one entry. |
|
411 | 411 | """ |
|
412 | 412 | if not repo._activebookmark: |
|
413 | 413 | raise ValueError( |
|
414 | 414 | b'headsforactive() only makes sense with an active bookmark' |
|
415 | 415 | ) |
|
416 | 416 | name = repo._activebookmark.split(b'@', 1)[0] |
|
417 | 417 | heads = [] |
|
418 | 418 | for mark, n in pycompat.iteritems(repo._bookmarks): |
|
419 | 419 | if mark.split(b'@', 1)[0] == name: |
|
420 | 420 | heads.append(n) |
|
421 | 421 | return heads |
|
422 | 422 | |
|
423 | 423 | |
|
424 | 424 | def calculateupdate(ui, repo): |
|
425 | 425 | '''Return a tuple (activemark, movemarkfrom) indicating the active bookmark |
|
426 | 426 | and where to move the active bookmark from, if needed.''' |
|
427 | 427 | checkout, movemarkfrom = None, None |
|
428 | 428 | activemark = repo._activebookmark |
|
429 | 429 | if isactivewdirparent(repo): |
|
430 | 430 | movemarkfrom = repo[b'.'].node() |
|
431 | 431 | elif activemark: |
|
432 | 432 | ui.status(_(b"updating to active bookmark %s\n") % activemark) |
|
433 | 433 | checkout = activemark |
|
434 | 434 | return (checkout, movemarkfrom) |
|
435 | 435 | |
|
436 | 436 | |
|
437 | 437 | def update(repo, parents, node): |
|
438 | 438 | deletefrom = parents |
|
439 | 439 | marks = repo._bookmarks |
|
440 | 440 | active = marks.active |
|
441 | 441 | if not active: |
|
442 | 442 | return False |
|
443 | 443 | |
|
444 | 444 | bmchanges = [] |
|
445 | 445 | if marks[active] in parents: |
|
446 | 446 | new = repo[node] |
|
447 | 447 | divs = [ |
|
448 | 448 | repo[marks[b]] |
|
449 | 449 | for b in marks |
|
450 | 450 | if b.split(b'@', 1)[0] == active.split(b'@', 1)[0] |
|
451 | 451 | ] |
|
452 | 452 | anc = repo.changelog.ancestors([new.rev()]) |
|
453 | 453 | deletefrom = [b.node() for b in divs if b.rev() in anc or b == new] |
|
454 | 454 | if validdest(repo, repo[marks[active]], new): |
|
455 | 455 | bmchanges.append((active, new.node())) |
|
456 | 456 | |
|
457 | 457 | for bm in divergent2delete(repo, deletefrom, active): |
|
458 | 458 | bmchanges.append((bm, None)) |
|
459 | 459 | |
|
460 | 460 | if bmchanges: |
|
461 | 461 | with repo.lock(), repo.transaction(b'bookmark') as tr: |
|
462 | 462 | marks.applychanges(repo, tr, bmchanges) |
|
463 | 463 | return bool(bmchanges) |
|
464 | 464 | |
|
465 | 465 | |
|
466 | 466 | def isdivergent(b): |
|
467 | 467 | return b'@' in b and not b.endswith(b'@') |
|
468 | 468 | |
|
469 | 469 | |
|
470 | 470 | def listbinbookmarks(repo): |
|
471 | 471 | # We may try to list bookmarks on a repo type that does not |
|
472 | 472 | # support it (e.g., statichttprepository). |
|
473 | 473 | marks = getattr(repo, '_bookmarks', {}) |
|
474 | 474 | |
|
475 | 475 | hasnode = repo.changelog.hasnode |
|
476 | 476 | for k, v in pycompat.iteritems(marks): |
|
477 | 477 | # don't expose local divergent bookmarks |
|
478 | 478 | if hasnode(v) and not isdivergent(k): |
|
479 | 479 | yield k, v |
|
480 | 480 | |
|
481 | 481 | |
|
482 | 482 | def listbookmarks(repo): |
|
483 | 483 | d = {} |
|
484 | 484 | for book, node in listbinbookmarks(repo): |
|
485 | 485 | d[book] = hex(node) |
|
486 | 486 | return d |
|
487 | 487 | |
|
488 | 488 | |
|
489 | 489 | def pushbookmark(repo, key, old, new): |
|
490 | if isdivergent(key): | |
|
491 | return False | |
|
490 | 492 | if bookmarksinstore(repo): |
|
491 | 493 | wlock = util.nullcontextmanager() |
|
492 | 494 | else: |
|
493 | 495 | wlock = repo.wlock() |
|
494 | 496 | with wlock, repo.lock(), repo.transaction(b'bookmarks') as tr: |
|
495 | 497 | marks = repo._bookmarks |
|
496 | 498 | existing = hex(marks.get(key, b'')) |
|
497 | 499 | if existing != old and existing != new: |
|
498 | 500 | return False |
|
499 | 501 | if new == b'': |
|
500 | 502 | changes = [(key, None)] |
|
501 | 503 | else: |
|
502 | 504 | if new not in repo: |
|
503 | 505 | return False |
|
504 | 506 | changes = [(key, repo[new].node())] |
|
505 | 507 | marks.applychanges(repo, tr, changes) |
|
506 | 508 | return True |
|
507 | 509 | |
|
508 | 510 | |
|
509 | 511 | def comparebookmarks(repo, srcmarks, dstmarks, targets=None): |
|
510 | 512 | '''Compare bookmarks between srcmarks and dstmarks |
|
511 | 513 | |
|
512 | 514 | This returns tuple "(addsrc, adddst, advsrc, advdst, diverge, |
|
513 | 515 | differ, invalid)", each are list of bookmarks below: |
|
514 | 516 | |
|
515 | 517 | :addsrc: added on src side (removed on dst side, perhaps) |
|
516 | 518 | :adddst: added on dst side (removed on src side, perhaps) |
|
517 | 519 | :advsrc: advanced on src side |
|
518 | 520 | :advdst: advanced on dst side |
|
519 | 521 | :diverge: diverge |
|
520 | 522 | :differ: changed, but changeset referred on src is unknown on dst |
|
521 | 523 | :invalid: unknown on both side |
|
522 | 524 | :same: same on both side |
|
523 | 525 | |
|
524 | 526 | Each elements of lists in result tuple is tuple "(bookmark name, |
|
525 | 527 | changeset ID on source side, changeset ID on destination |
|
526 | 528 | side)". Each changeset ID is a binary node or None. |
|
527 | 529 | |
|
528 | 530 | Changeset IDs of tuples in "addsrc", "adddst", "differ" or |
|
529 | 531 | "invalid" list may be unknown for repo. |
|
530 | 532 | |
|
531 | 533 | If "targets" is specified, only bookmarks listed in it are |
|
532 | 534 | examined. |
|
533 | 535 | ''' |
|
534 | 536 | |
|
535 | 537 | if targets: |
|
536 | 538 | bset = set(targets) |
|
537 | 539 | else: |
|
538 | 540 | srcmarkset = set(srcmarks) |
|
539 | 541 | dstmarkset = set(dstmarks) |
|
540 | 542 | bset = srcmarkset | dstmarkset |
|
541 | 543 | |
|
542 | 544 | results = ([], [], [], [], [], [], [], []) |
|
543 | 545 | addsrc = results[0].append |
|
544 | 546 | adddst = results[1].append |
|
545 | 547 | advsrc = results[2].append |
|
546 | 548 | advdst = results[3].append |
|
547 | 549 | diverge = results[4].append |
|
548 | 550 | differ = results[5].append |
|
549 | 551 | invalid = results[6].append |
|
550 | 552 | same = results[7].append |
|
551 | 553 | |
|
552 | 554 | for b in sorted(bset): |
|
553 | 555 | if b not in srcmarks: |
|
554 | 556 | if b in dstmarks: |
|
555 | 557 | adddst((b, None, dstmarks[b])) |
|
556 | 558 | else: |
|
557 | 559 | invalid((b, None, None)) |
|
558 | 560 | elif b not in dstmarks: |
|
559 | 561 | addsrc((b, srcmarks[b], None)) |
|
560 | 562 | else: |
|
561 | 563 | scid = srcmarks[b] |
|
562 | 564 | dcid = dstmarks[b] |
|
563 | 565 | if scid == dcid: |
|
564 | 566 | same((b, scid, dcid)) |
|
565 | 567 | elif scid in repo and dcid in repo: |
|
566 | 568 | sctx = repo[scid] |
|
567 | 569 | dctx = repo[dcid] |
|
568 | 570 | if sctx.rev() < dctx.rev(): |
|
569 | 571 | if validdest(repo, sctx, dctx): |
|
570 | 572 | advdst((b, scid, dcid)) |
|
571 | 573 | else: |
|
572 | 574 | diverge((b, scid, dcid)) |
|
573 | 575 | else: |
|
574 | 576 | if validdest(repo, dctx, sctx): |
|
575 | 577 | advsrc((b, scid, dcid)) |
|
576 | 578 | else: |
|
577 | 579 | diverge((b, scid, dcid)) |
|
578 | 580 | else: |
|
579 | 581 | # it is too expensive to examine in detail, in this case |
|
580 | 582 | differ((b, scid, dcid)) |
|
581 | 583 | |
|
582 | 584 | return results |
|
583 | 585 | |
|
584 | 586 | |
|
585 | 587 | def _diverge(ui, b, path, localmarks, remotenode): |
|
586 | 588 | '''Return appropriate diverged bookmark for specified ``path`` |
|
587 | 589 | |
|
588 | 590 | This returns None, if it is failed to assign any divergent |
|
589 | 591 | bookmark name. |
|
590 | 592 | |
|
591 | 593 | This reuses already existing one with "@number" suffix, if it |
|
592 | 594 | refers ``remotenode``. |
|
593 | 595 | ''' |
|
594 | 596 | if b == b'@': |
|
595 | 597 | b = b'' |
|
596 | 598 | # try to use an @pathalias suffix |
|
597 | 599 | # if an @pathalias already exists, we overwrite (update) it |
|
598 | 600 | if path.startswith(b"file:"): |
|
599 | 601 | path = util.url(path).path |
|
600 | 602 | for p, u in ui.configitems(b"paths"): |
|
601 | 603 | if u.startswith(b"file:"): |
|
602 | 604 | u = util.url(u).path |
|
603 | 605 | if path == u: |
|
604 | 606 | return b'%s@%s' % (b, p) |
|
605 | 607 | |
|
606 | 608 | # assign a unique "@number" suffix newly |
|
607 | 609 | for x in range(1, 100): |
|
608 | 610 | n = b'%s@%d' % (b, x) |
|
609 | 611 | if n not in localmarks or localmarks[n] == remotenode: |
|
610 | 612 | return n |
|
611 | 613 | |
|
612 | 614 | return None |
|
613 | 615 | |
|
614 | 616 | |
|
615 | 617 | def unhexlifybookmarks(marks): |
|
616 | 618 | binremotemarks = {} |
|
617 | 619 | for name, node in marks.items(): |
|
618 | 620 | binremotemarks[name] = bin(node) |
|
619 | 621 | return binremotemarks |
|
620 | 622 | |
|
621 | 623 | |
|
622 | 624 | _binaryentry = struct.Struct(b'>20sH') |
|
623 | 625 | |
|
624 | 626 | |
|
625 | 627 | def binaryencode(bookmarks): |
|
626 | 628 | """encode a '(bookmark, node)' iterable into a binary stream |
|
627 | 629 | |
|
628 | 630 | the binary format is: |
|
629 | 631 | |
|
630 | 632 | <node><bookmark-length><bookmark-name> |
|
631 | 633 | |
|
632 | 634 | :node: is a 20 bytes binary node, |
|
633 | 635 | :bookmark-length: an unsigned short, |
|
634 | 636 | :bookmark-name: the name of the bookmark (of length <bookmark-length>) |
|
635 | 637 | |
|
636 | 638 | wdirid (all bits set) will be used as a special value for "missing" |
|
637 | 639 | """ |
|
638 | 640 | binarydata = [] |
|
639 | 641 | for book, node in bookmarks: |
|
640 | 642 | if not node: # None or '' |
|
641 | 643 | node = wdirid |
|
642 | 644 | binarydata.append(_binaryentry.pack(node, len(book))) |
|
643 | 645 | binarydata.append(book) |
|
644 | 646 | return b''.join(binarydata) |
|
645 | 647 | |
|
646 | 648 | |
|
647 | 649 | def binarydecode(stream): |
|
648 | 650 | """decode a binary stream into an '(bookmark, node)' iterable |
|
649 | 651 | |
|
650 | 652 | the binary format is: |
|
651 | 653 | |
|
652 | 654 | <node><bookmark-length><bookmark-name> |
|
653 | 655 | |
|
654 | 656 | :node: is a 20 bytes binary node, |
|
655 | 657 | :bookmark-length: an unsigned short, |
|
656 | 658 | :bookmark-name: the name of the bookmark (of length <bookmark-length>)) |
|
657 | 659 | |
|
658 | 660 | wdirid (all bits set) will be used as a special value for "missing" |
|
659 | 661 | """ |
|
660 | 662 | entrysize = _binaryentry.size |
|
661 | 663 | books = [] |
|
662 | 664 | while True: |
|
663 | 665 | entry = stream.read(entrysize) |
|
664 | 666 | if len(entry) < entrysize: |
|
665 | 667 | if entry: |
|
666 | 668 | raise error.Abort(_(b'bad bookmark stream')) |
|
667 | 669 | break |
|
668 | 670 | node, length = _binaryentry.unpack(entry) |
|
669 | 671 | bookmark = stream.read(length) |
|
670 | 672 | if len(bookmark) < length: |
|
671 | 673 | if entry: |
|
672 | 674 | raise error.Abort(_(b'bad bookmark stream')) |
|
673 | 675 | if node == wdirid: |
|
674 | 676 | node = None |
|
675 | 677 | books.append((bookmark, node)) |
|
676 | 678 | return books |
|
677 | 679 | |
|
678 | 680 | |
|
679 | 681 | def updatefromremote(ui, repo, remotemarks, path, trfunc, explicit=()): |
|
680 | 682 | ui.debug(b"checking for updated bookmarks\n") |
|
681 | 683 | localmarks = repo._bookmarks |
|
682 | 684 | ( |
|
683 | 685 | addsrc, |
|
684 | 686 | adddst, |
|
685 | 687 | advsrc, |
|
686 | 688 | advdst, |
|
687 | 689 | diverge, |
|
688 | 690 | differ, |
|
689 | 691 | invalid, |
|
690 | 692 | same, |
|
691 | 693 | ) = comparebookmarks(repo, remotemarks, localmarks) |
|
692 | 694 | |
|
693 | 695 | status = ui.status |
|
694 | 696 | warn = ui.warn |
|
695 | 697 | if ui.configbool(b'ui', b'quietbookmarkmove'): |
|
696 | 698 | status = warn = ui.debug |
|
697 | 699 | |
|
698 | 700 | explicit = set(explicit) |
|
699 | 701 | changed = [] |
|
700 | 702 | for b, scid, dcid in addsrc: |
|
701 | 703 | if scid in repo: # add remote bookmarks for changes we already have |
|
702 | 704 | changed.append( |
|
703 | 705 | (b, scid, status, _(b"adding remote bookmark %s\n") % b) |
|
704 | 706 | ) |
|
705 | 707 | elif b in explicit: |
|
706 | 708 | explicit.remove(b) |
|
707 | 709 | ui.warn( |
|
708 | 710 | _(b"remote bookmark %s points to locally missing %s\n") |
|
709 | 711 | % (b, hex(scid)[:12]) |
|
710 | 712 | ) |
|
711 | 713 | |
|
712 | 714 | for b, scid, dcid in advsrc: |
|
713 | 715 | changed.append((b, scid, status, _(b"updating bookmark %s\n") % b)) |
|
714 | 716 | # remove normal movement from explicit set |
|
715 | 717 | explicit.difference_update(d[0] for d in changed) |
|
716 | 718 | |
|
717 | 719 | for b, scid, dcid in diverge: |
|
718 | 720 | if b in explicit: |
|
719 | 721 | explicit.discard(b) |
|
720 | 722 | changed.append((b, scid, status, _(b"importing bookmark %s\n") % b)) |
|
721 | 723 | else: |
|
722 | 724 | db = _diverge(ui, b, path, localmarks, scid) |
|
723 | 725 | if db: |
|
724 | 726 | changed.append( |
|
725 | 727 | ( |
|
726 | 728 | db, |
|
727 | 729 | scid, |
|
728 | 730 | warn, |
|
729 | 731 | _(b"divergent bookmark %s stored as %s\n") % (b, db), |
|
730 | 732 | ) |
|
731 | 733 | ) |
|
732 | 734 | else: |
|
733 | 735 | warn( |
|
734 | 736 | _( |
|
735 | 737 | b"warning: failed to assign numbered name " |
|
736 | 738 | b"to divergent bookmark %s\n" |
|
737 | 739 | ) |
|
738 | 740 | % b |
|
739 | 741 | ) |
|
740 | 742 | for b, scid, dcid in adddst + advdst: |
|
741 | 743 | if b in explicit: |
|
742 | 744 | explicit.discard(b) |
|
743 | 745 | changed.append((b, scid, status, _(b"importing bookmark %s\n") % b)) |
|
744 | 746 | for b, scid, dcid in differ: |
|
745 | 747 | if b in explicit: |
|
746 | 748 | explicit.remove(b) |
|
747 | 749 | ui.warn( |
|
748 | 750 | _(b"remote bookmark %s points to locally missing %s\n") |
|
749 | 751 | % (b, hex(scid)[:12]) |
|
750 | 752 | ) |
|
751 | 753 | |
|
752 | 754 | if changed: |
|
753 | 755 | tr = trfunc() |
|
754 | 756 | changes = [] |
|
755 | 757 | for b, node, writer, msg in sorted(changed): |
|
756 | 758 | changes.append((b, node)) |
|
757 | 759 | writer(msg) |
|
758 | 760 | localmarks.applychanges(repo, tr, changes) |
|
759 | 761 | |
|
760 | 762 | |
|
761 | 763 | def incoming(ui, repo, peer): |
|
762 | 764 | '''Show bookmarks incoming from other to repo |
|
763 | 765 | ''' |
|
764 | 766 | ui.status(_(b"searching for changed bookmarks\n")) |
|
765 | 767 | |
|
766 | 768 | with peer.commandexecutor() as e: |
|
767 | 769 | remotemarks = unhexlifybookmarks( |
|
768 | 770 | e.callcommand(b'listkeys', {b'namespace': b'bookmarks',}).result() |
|
769 | 771 | ) |
|
770 | 772 | |
|
771 | 773 | r = comparebookmarks(repo, remotemarks, repo._bookmarks) |
|
772 | 774 | addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r |
|
773 | 775 | |
|
774 | 776 | incomings = [] |
|
775 | 777 | if ui.debugflag: |
|
776 | 778 | getid = lambda id: id |
|
777 | 779 | else: |
|
778 | 780 | getid = lambda id: id[:12] |
|
779 | 781 | if ui.verbose: |
|
780 | 782 | |
|
781 | 783 | def add(b, id, st): |
|
782 | 784 | incomings.append(b" %-25s %s %s\n" % (b, getid(id), st)) |
|
783 | 785 | |
|
784 | 786 | else: |
|
785 | 787 | |
|
786 | 788 | def add(b, id, st): |
|
787 | 789 | incomings.append(b" %-25s %s\n" % (b, getid(id))) |
|
788 | 790 | |
|
789 | 791 | for b, scid, dcid in addsrc: |
|
790 | 792 | # i18n: "added" refers to a bookmark |
|
791 | 793 | add(b, hex(scid), _(b'added')) |
|
792 | 794 | for b, scid, dcid in advsrc: |
|
793 | 795 | # i18n: "advanced" refers to a bookmark |
|
794 | 796 | add(b, hex(scid), _(b'advanced')) |
|
795 | 797 | for b, scid, dcid in diverge: |
|
796 | 798 | # i18n: "diverged" refers to a bookmark |
|
797 | 799 | add(b, hex(scid), _(b'diverged')) |
|
798 | 800 | for b, scid, dcid in differ: |
|
799 | 801 | # i18n: "changed" refers to a bookmark |
|
800 | 802 | add(b, hex(scid), _(b'changed')) |
|
801 | 803 | |
|
802 | 804 | if not incomings: |
|
803 | 805 | ui.status(_(b"no changed bookmarks found\n")) |
|
804 | 806 | return 1 |
|
805 | 807 | |
|
806 | 808 | for s in sorted(incomings): |
|
807 | 809 | ui.write(s) |
|
808 | 810 | |
|
809 | 811 | return 0 |
|
810 | 812 | |
|
811 | 813 | |
|
812 | 814 | def outgoing(ui, repo, other): |
|
813 | 815 | '''Show bookmarks outgoing from repo to other |
|
814 | 816 | ''' |
|
815 | 817 | ui.status(_(b"searching for changed bookmarks\n")) |
|
816 | 818 | |
|
817 | 819 | remotemarks = unhexlifybookmarks(other.listkeys(b'bookmarks')) |
|
818 | 820 | r = comparebookmarks(repo, repo._bookmarks, remotemarks) |
|
819 | 821 | addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r |
|
820 | 822 | |
|
821 | 823 | outgoings = [] |
|
822 | 824 | if ui.debugflag: |
|
823 | 825 | getid = lambda id: id |
|
824 | 826 | else: |
|
825 | 827 | getid = lambda id: id[:12] |
|
826 | 828 | if ui.verbose: |
|
827 | 829 | |
|
828 | 830 | def add(b, id, st): |
|
829 | 831 | outgoings.append(b" %-25s %s %s\n" % (b, getid(id), st)) |
|
830 | 832 | |
|
831 | 833 | else: |
|
832 | 834 | |
|
833 | 835 | def add(b, id, st): |
|
834 | 836 | outgoings.append(b" %-25s %s\n" % (b, getid(id))) |
|
835 | 837 | |
|
836 | 838 | for b, scid, dcid in addsrc: |
|
837 | 839 | # i18n: "added refers to a bookmark |
|
838 | 840 | add(b, hex(scid), _(b'added')) |
|
839 | 841 | for b, scid, dcid in adddst: |
|
840 | 842 | # i18n: "deleted" refers to a bookmark |
|
841 | 843 | add(b, b' ' * 40, _(b'deleted')) |
|
842 | 844 | for b, scid, dcid in advsrc: |
|
843 | 845 | # i18n: "advanced" refers to a bookmark |
|
844 | 846 | add(b, hex(scid), _(b'advanced')) |
|
845 | 847 | for b, scid, dcid in diverge: |
|
846 | 848 | # i18n: "diverged" refers to a bookmark |
|
847 | 849 | add(b, hex(scid), _(b'diverged')) |
|
848 | 850 | for b, scid, dcid in differ: |
|
849 | 851 | # i18n: "changed" refers to a bookmark |
|
850 | 852 | add(b, hex(scid), _(b'changed')) |
|
851 | 853 | |
|
852 | 854 | if not outgoings: |
|
853 | 855 | ui.status(_(b"no changed bookmarks found\n")) |
|
854 | 856 | return 1 |
|
855 | 857 | |
|
856 | 858 | for s in sorted(outgoings): |
|
857 | 859 | ui.write(s) |
|
858 | 860 | |
|
859 | 861 | return 0 |
|
860 | 862 | |
|
861 | 863 | |
|
862 | 864 | def summary(repo, peer): |
|
863 | 865 | '''Compare bookmarks between repo and other for "hg summary" output |
|
864 | 866 | |
|
865 | 867 | This returns "(# of incoming, # of outgoing)" tuple. |
|
866 | 868 | ''' |
|
867 | 869 | with peer.commandexecutor() as e: |
|
868 | 870 | remotemarks = unhexlifybookmarks( |
|
869 | 871 | e.callcommand(b'listkeys', {b'namespace': b'bookmarks',}).result() |
|
870 | 872 | ) |
|
871 | 873 | |
|
872 | 874 | r = comparebookmarks(repo, remotemarks, repo._bookmarks) |
|
873 | 875 | addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r |
|
874 | 876 | return (len(addsrc), len(adddst)) |
|
875 | 877 | |
|
876 | 878 | |
|
877 | 879 | def validdest(repo, old, new): |
|
878 | 880 | """Is the new bookmark destination a valid update from the old one""" |
|
879 | 881 | repo = repo.unfiltered() |
|
880 | 882 | if old == new: |
|
881 | 883 | # Old == new -> nothing to update. |
|
882 | 884 | return False |
|
883 | 885 | elif not old: |
|
884 | 886 | # old is nullrev, anything is valid. |
|
885 | 887 | # (new != nullrev has been excluded by the previous check) |
|
886 | 888 | return True |
|
887 | 889 | elif repo.obsstore: |
|
888 | 890 | return new.node() in obsutil.foreground(repo, [old.node()]) |
|
889 | 891 | else: |
|
890 | 892 | # still an independent clause as it is lazier (and therefore faster) |
|
891 | 893 | return old.isancestorof(new) |
|
892 | 894 | |
|
893 | 895 | |
|
894 | 896 | def checkformat(repo, mark): |
|
895 | 897 | """return a valid version of a potential bookmark name |
|
896 | 898 | |
|
897 | 899 | Raises an abort error if the bookmark name is not valid. |
|
898 | 900 | """ |
|
899 | 901 | mark = mark.strip() |
|
900 | 902 | if not mark: |
|
901 | 903 | raise error.Abort( |
|
902 | 904 | _(b"bookmark names cannot consist entirely of whitespace") |
|
903 | 905 | ) |
|
904 | 906 | scmutil.checknewlabel(repo, mark, b'bookmark') |
|
905 | 907 | return mark |
|
906 | 908 | |
|
907 | 909 | |
|
908 | 910 | def delete(repo, tr, names): |
|
909 | 911 | """remove a mark from the bookmark store |
|
910 | 912 | |
|
911 | 913 | Raises an abort error if mark does not exist. |
|
912 | 914 | """ |
|
913 | 915 | marks = repo._bookmarks |
|
914 | 916 | changes = [] |
|
915 | 917 | for mark in names: |
|
916 | 918 | if mark not in marks: |
|
917 | 919 | raise error.Abort(_(b"bookmark '%s' does not exist") % mark) |
|
918 | 920 | if mark == repo._activebookmark: |
|
919 | 921 | deactivate(repo) |
|
920 | 922 | changes.append((mark, None)) |
|
921 | 923 | marks.applychanges(repo, tr, changes) |
|
922 | 924 | |
|
923 | 925 | |
|
924 | 926 | def rename(repo, tr, old, new, force=False, inactive=False): |
|
925 | 927 | """rename a bookmark from old to new |
|
926 | 928 | |
|
927 | 929 | If force is specified, then the new name can overwrite an existing |
|
928 | 930 | bookmark. |
|
929 | 931 | |
|
930 | 932 | If inactive is specified, then do not activate the new bookmark. |
|
931 | 933 | |
|
932 | 934 | Raises an abort error if old is not in the bookmark store. |
|
933 | 935 | """ |
|
934 | 936 | marks = repo._bookmarks |
|
935 | 937 | mark = checkformat(repo, new) |
|
936 | 938 | if old not in marks: |
|
937 | 939 | raise error.Abort(_(b"bookmark '%s' does not exist") % old) |
|
938 | 940 | changes = [] |
|
939 | 941 | for bm in marks.checkconflict(mark, force): |
|
940 | 942 | changes.append((bm, None)) |
|
941 | 943 | changes.extend([(mark, marks[old]), (old, None)]) |
|
942 | 944 | marks.applychanges(repo, tr, changes) |
|
943 | 945 | if repo._activebookmark == old and not inactive: |
|
944 | 946 | activate(repo, mark) |
|
945 | 947 | |
|
946 | 948 | |
|
947 | 949 | def addbookmarks(repo, tr, names, rev=None, force=False, inactive=False): |
|
948 | 950 | """add a list of bookmarks |
|
949 | 951 | |
|
950 | 952 | If force is specified, then the new name can overwrite an existing |
|
951 | 953 | bookmark. |
|
952 | 954 | |
|
953 | 955 | If inactive is specified, then do not activate any bookmark. Otherwise, the |
|
954 | 956 | first bookmark is activated. |
|
955 | 957 | |
|
956 | 958 | Raises an abort error if old is not in the bookmark store. |
|
957 | 959 | """ |
|
958 | 960 | marks = repo._bookmarks |
|
959 | 961 | cur = repo[b'.'].node() |
|
960 | 962 | newact = None |
|
961 | 963 | changes = [] |
|
962 | 964 | |
|
963 | 965 | # unhide revs if any |
|
964 | 966 | if rev: |
|
965 | 967 | repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn') |
|
966 | 968 | |
|
967 | 969 | ctx = scmutil.revsingle(repo, rev, None) |
|
968 | 970 | # bookmarking wdir means creating a bookmark on p1 and activating it |
|
969 | 971 | activatenew = not inactive and ctx.rev() is None |
|
970 | 972 | if ctx.node() is None: |
|
971 | 973 | ctx = ctx.p1() |
|
972 | 974 | tgt = ctx.node() |
|
973 | 975 | assert tgt |
|
974 | 976 | |
|
975 | 977 | for mark in names: |
|
976 | 978 | mark = checkformat(repo, mark) |
|
977 | 979 | if newact is None: |
|
978 | 980 | newact = mark |
|
979 | 981 | if inactive and mark == repo._activebookmark: |
|
980 | 982 | deactivate(repo) |
|
981 | 983 | continue |
|
982 | 984 | for bm in marks.checkconflict(mark, force, tgt): |
|
983 | 985 | changes.append((bm, None)) |
|
984 | 986 | changes.append((mark, tgt)) |
|
985 | 987 | |
|
986 | 988 | # nothing changed but for the one deactivated above |
|
987 | 989 | if not changes: |
|
988 | 990 | return |
|
989 | 991 | |
|
990 | 992 | if ctx.hidden(): |
|
991 | 993 | repo.ui.warn(_(b"bookmarking hidden changeset %s\n") % ctx.hex()[:12]) |
|
992 | 994 | |
|
993 | 995 | if ctx.obsolete(): |
|
994 | 996 | msg = obsutil._getfilteredreason(repo, ctx.hex()[:12], ctx) |
|
995 | 997 | repo.ui.warn(b"(%s)\n" % msg) |
|
996 | 998 | |
|
997 | 999 | marks.applychanges(repo, tr, changes) |
|
998 | 1000 | if activatenew and cur == marks[newact]: |
|
999 | 1001 | activate(repo, newact) |
|
1000 | 1002 | elif cur != tgt and newact == repo._activebookmark: |
|
1001 | 1003 | deactivate(repo) |
|
1002 | 1004 | |
|
1003 | 1005 | |
|
1004 | 1006 | def _printbookmarks(ui, repo, fm, bmarks): |
|
1005 | 1007 | """private method to print bookmarks |
|
1006 | 1008 | |
|
1007 | 1009 | Provides a way for extensions to control how bookmarks are printed (e.g. |
|
1008 | 1010 | prepend or postpend names) |
|
1009 | 1011 | """ |
|
1010 | 1012 | hexfn = fm.hexfunc |
|
1011 | 1013 | if len(bmarks) == 0 and fm.isplain(): |
|
1012 | 1014 | ui.status(_(b"no bookmarks set\n")) |
|
1013 | 1015 | for bmark, (n, prefix, label) in sorted(pycompat.iteritems(bmarks)): |
|
1014 | 1016 | fm.startitem() |
|
1015 | 1017 | fm.context(repo=repo) |
|
1016 | 1018 | if not ui.quiet: |
|
1017 | 1019 | fm.plain(b' %s ' % prefix, label=label) |
|
1018 | 1020 | fm.write(b'bookmark', b'%s', bmark, label=label) |
|
1019 | 1021 | pad = b" " * (25 - encoding.colwidth(bmark)) |
|
1020 | 1022 | fm.condwrite( |
|
1021 | 1023 | not ui.quiet, |
|
1022 | 1024 | b'rev node', |
|
1023 | 1025 | pad + b' %d:%s', |
|
1024 | 1026 | repo.changelog.rev(n), |
|
1025 | 1027 | hexfn(n), |
|
1026 | 1028 | label=label, |
|
1027 | 1029 | ) |
|
1028 | 1030 | fm.data(active=(activebookmarklabel in label)) |
|
1029 | 1031 | fm.plain(b'\n') |
|
1030 | 1032 | |
|
1031 | 1033 | |
|
1032 | 1034 | def printbookmarks(ui, repo, fm, names=None): |
|
1033 | 1035 | """print bookmarks by the given formatter |
|
1034 | 1036 | |
|
1035 | 1037 | Provides a way for extensions to control how bookmarks are printed. |
|
1036 | 1038 | """ |
|
1037 | 1039 | marks = repo._bookmarks |
|
1038 | 1040 | bmarks = {} |
|
1039 | 1041 | for bmark in names or marks: |
|
1040 | 1042 | if bmark not in marks: |
|
1041 | 1043 | raise error.Abort(_(b"bookmark '%s' does not exist") % bmark) |
|
1042 | 1044 | active = repo._activebookmark |
|
1043 | 1045 | if bmark == active: |
|
1044 | 1046 | prefix, label = b'*', activebookmarklabel |
|
1045 | 1047 | else: |
|
1046 | 1048 | prefix, label = b' ', b'' |
|
1047 | 1049 | |
|
1048 | 1050 | bmarks[bmark] = (marks[bmark], prefix, label) |
|
1049 | 1051 | _printbookmarks(ui, repo, fm, bmarks) |
|
1050 | 1052 | |
|
1051 | 1053 | |
|
1052 | 1054 | def preparehookargs(name, old, new): |
|
1053 | 1055 | if new is None: |
|
1054 | 1056 | new = b'' |
|
1055 | 1057 | if old is None: |
|
1056 | 1058 | old = b'' |
|
1057 | 1059 | return {b'bookmark': name, b'node': hex(new), b'oldnode': hex(old)} |
@@ -1,2578 +1,2583 b'' | |||
|
1 | 1 | # bundle2.py - generic container format to transmit arbitrary data. |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2013 Facebook, Inc. |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | """Handling of the new bundle2 format |
|
8 | 8 | |
|
9 | 9 | The goal of bundle2 is to act as an atomically packet to transmit a set of |
|
10 | 10 | payloads in an application agnostic way. It consist in a sequence of "parts" |
|
11 | 11 | that will be handed to and processed by the application layer. |
|
12 | 12 | |
|
13 | 13 | |
|
14 | 14 | General format architecture |
|
15 | 15 | =========================== |
|
16 | 16 | |
|
17 | 17 | The format is architectured as follow |
|
18 | 18 | |
|
19 | 19 | - magic string |
|
20 | 20 | - stream level parameters |
|
21 | 21 | - payload parts (any number) |
|
22 | 22 | - end of stream marker. |
|
23 | 23 | |
|
24 | 24 | the Binary format |
|
25 | 25 | ============================ |
|
26 | 26 | |
|
27 | 27 | All numbers are unsigned and big-endian. |
|
28 | 28 | |
|
29 | 29 | stream level parameters |
|
30 | 30 | ------------------------ |
|
31 | 31 | |
|
32 | 32 | Binary format is as follow |
|
33 | 33 | |
|
34 | 34 | :params size: int32 |
|
35 | 35 | |
|
36 | 36 | The total number of Bytes used by the parameters |
|
37 | 37 | |
|
38 | 38 | :params value: arbitrary number of Bytes |
|
39 | 39 | |
|
40 | 40 | A blob of `params size` containing the serialized version of all stream level |
|
41 | 41 | parameters. |
|
42 | 42 | |
|
43 | 43 | The blob contains a space separated list of parameters. Parameters with value |
|
44 | 44 | are stored in the form `<name>=<value>`. Both name and value are urlquoted. |
|
45 | 45 | |
|
46 | 46 | Empty name are obviously forbidden. |
|
47 | 47 | |
|
48 | 48 | Name MUST start with a letter. If this first letter is lower case, the |
|
49 | 49 | parameter is advisory and can be safely ignored. However when the first |
|
50 | 50 | letter is capital, the parameter is mandatory and the bundling process MUST |
|
51 | 51 | stop if he is not able to proceed it. |
|
52 | 52 | |
|
53 | 53 | Stream parameters use a simple textual format for two main reasons: |
|
54 | 54 | |
|
55 | 55 | - Stream level parameters should remain simple and we want to discourage any |
|
56 | 56 | crazy usage. |
|
57 | 57 | - Textual data allow easy human inspection of a bundle2 header in case of |
|
58 | 58 | troubles. |
|
59 | 59 | |
|
60 | 60 | Any Applicative level options MUST go into a bundle2 part instead. |
|
61 | 61 | |
|
62 | 62 | Payload part |
|
63 | 63 | ------------------------ |
|
64 | 64 | |
|
65 | 65 | Binary format is as follow |
|
66 | 66 | |
|
67 | 67 | :header size: int32 |
|
68 | 68 | |
|
69 | 69 | The total number of Bytes used by the part header. When the header is empty |
|
70 | 70 | (size = 0) this is interpreted as the end of stream marker. |
|
71 | 71 | |
|
72 | 72 | :header: |
|
73 | 73 | |
|
74 | 74 | The header defines how to interpret the part. It contains two piece of |
|
75 | 75 | data: the part type, and the part parameters. |
|
76 | 76 | |
|
77 | 77 | The part type is used to route an application level handler, that can |
|
78 | 78 | interpret payload. |
|
79 | 79 | |
|
80 | 80 | Part parameters are passed to the application level handler. They are |
|
81 | 81 | meant to convey information that will help the application level object to |
|
82 | 82 | interpret the part payload. |
|
83 | 83 | |
|
84 | 84 | The binary format of the header is has follow |
|
85 | 85 | |
|
86 | 86 | :typesize: (one byte) |
|
87 | 87 | |
|
88 | 88 | :parttype: alphanumerical part name (restricted to [a-zA-Z0-9_:-]*) |
|
89 | 89 | |
|
90 | 90 | :partid: A 32bits integer (unique in the bundle) that can be used to refer |
|
91 | 91 | to this part. |
|
92 | 92 | |
|
93 | 93 | :parameters: |
|
94 | 94 | |
|
95 | 95 | Part's parameter may have arbitrary content, the binary structure is:: |
|
96 | 96 | |
|
97 | 97 | <mandatory-count><advisory-count><param-sizes><param-data> |
|
98 | 98 | |
|
99 | 99 | :mandatory-count: 1 byte, number of mandatory parameters |
|
100 | 100 | |
|
101 | 101 | :advisory-count: 1 byte, number of advisory parameters |
|
102 | 102 | |
|
103 | 103 | :param-sizes: |
|
104 | 104 | |
|
105 | 105 | N couple of bytes, where N is the total number of parameters. Each |
|
106 | 106 | couple contains (<size-of-key>, <size-of-value) for one parameter. |
|
107 | 107 | |
|
108 | 108 | :param-data: |
|
109 | 109 | |
|
110 | 110 | A blob of bytes from which each parameter key and value can be |
|
111 | 111 | retrieved using the list of size couples stored in the previous |
|
112 | 112 | field. |
|
113 | 113 | |
|
114 | 114 | Mandatory parameters comes first, then the advisory ones. |
|
115 | 115 | |
|
116 | 116 | Each parameter's key MUST be unique within the part. |
|
117 | 117 | |
|
118 | 118 | :payload: |
|
119 | 119 | |
|
120 | 120 | payload is a series of `<chunksize><chunkdata>`. |
|
121 | 121 | |
|
122 | 122 | `chunksize` is an int32, `chunkdata` are plain bytes (as much as |
|
123 | 123 | `chunksize` says)` The payload part is concluded by a zero size chunk. |
|
124 | 124 | |
|
125 | 125 | The current implementation always produces either zero or one chunk. |
|
126 | 126 | This is an implementation limitation that will ultimately be lifted. |
|
127 | 127 | |
|
128 | 128 | `chunksize` can be negative to trigger special case processing. No such |
|
129 | 129 | processing is in place yet. |
|
130 | 130 | |
|
131 | 131 | Bundle processing |
|
132 | 132 | ============================ |
|
133 | 133 | |
|
134 | 134 | Each part is processed in order using a "part handler". Handler are registered |
|
135 | 135 | for a certain part type. |
|
136 | 136 | |
|
137 | 137 | The matching of a part to its handler is case insensitive. The case of the |
|
138 | 138 | part type is used to know if a part is mandatory or advisory. If the Part type |
|
139 | 139 | contains any uppercase char it is considered mandatory. When no handler is |
|
140 | 140 | known for a Mandatory part, the process is aborted and an exception is raised. |
|
141 | 141 | If the part is advisory and no handler is known, the part is ignored. When the |
|
142 | 142 | process is aborted, the full bundle is still read from the stream to keep the |
|
143 | 143 | channel usable. But none of the part read from an abort are processed. In the |
|
144 | 144 | future, dropping the stream may become an option for channel we do not care to |
|
145 | 145 | preserve. |
|
146 | 146 | """ |
|
147 | 147 | |
|
148 | 148 | from __future__ import absolute_import, division |
|
149 | 149 | |
|
150 | 150 | import collections |
|
151 | 151 | import errno |
|
152 | 152 | import os |
|
153 | 153 | import re |
|
154 | 154 | import string |
|
155 | 155 | import struct |
|
156 | 156 | import sys |
|
157 | 157 | |
|
158 | 158 | from .i18n import _ |
|
159 | 159 | from . import ( |
|
160 | 160 | bookmarks, |
|
161 | 161 | changegroup, |
|
162 | 162 | encoding, |
|
163 | 163 | error, |
|
164 | 164 | node as nodemod, |
|
165 | 165 | obsolete, |
|
166 | 166 | phases, |
|
167 | 167 | pushkey, |
|
168 | 168 | pycompat, |
|
169 | 169 | streamclone, |
|
170 | 170 | tags, |
|
171 | 171 | url, |
|
172 | 172 | util, |
|
173 | 173 | ) |
|
174 | 174 | from .utils import stringutil |
|
175 | 175 | |
|
176 | 176 | urlerr = util.urlerr |
|
177 | 177 | urlreq = util.urlreq |
|
178 | 178 | |
|
179 | 179 | _pack = struct.pack |
|
180 | 180 | _unpack = struct.unpack |
|
181 | 181 | |
|
182 | 182 | _fstreamparamsize = b'>i' |
|
183 | 183 | _fpartheadersize = b'>i' |
|
184 | 184 | _fparttypesize = b'>B' |
|
185 | 185 | _fpartid = b'>I' |
|
186 | 186 | _fpayloadsize = b'>i' |
|
187 | 187 | _fpartparamcount = b'>BB' |
|
188 | 188 | |
|
189 | 189 | preferedchunksize = 32768 |
|
190 | 190 | |
|
191 | 191 | _parttypeforbidden = re.compile(b'[^a-zA-Z0-9_:-]') |
|
192 | 192 | |
|
193 | 193 | |
|
194 | 194 | def outdebug(ui, message): |
|
195 | 195 | """debug regarding output stream (bundling)""" |
|
196 | 196 | if ui.configbool(b'devel', b'bundle2.debug'): |
|
197 | 197 | ui.debug(b'bundle2-output: %s\n' % message) |
|
198 | 198 | |
|
199 | 199 | |
|
200 | 200 | def indebug(ui, message): |
|
201 | 201 | """debug on input stream (unbundling)""" |
|
202 | 202 | if ui.configbool(b'devel', b'bundle2.debug'): |
|
203 | 203 | ui.debug(b'bundle2-input: %s\n' % message) |
|
204 | 204 | |
|
205 | 205 | |
|
206 | 206 | def validateparttype(parttype): |
|
207 | 207 | """raise ValueError if a parttype contains invalid character""" |
|
208 | 208 | if _parttypeforbidden.search(parttype): |
|
209 | 209 | raise ValueError(parttype) |
|
210 | 210 | |
|
211 | 211 | |
|
212 | 212 | def _makefpartparamsizes(nbparams): |
|
213 | 213 | """return a struct format to read part parameter sizes |
|
214 | 214 | |
|
215 | 215 | The number parameters is variable so we need to build that format |
|
216 | 216 | dynamically. |
|
217 | 217 | """ |
|
218 | 218 | return b'>' + (b'BB' * nbparams) |
|
219 | 219 | |
|
220 | 220 | |
|
221 | 221 | parthandlermapping = {} |
|
222 | 222 | |
|
223 | 223 | |
|
224 | 224 | def parthandler(parttype, params=()): |
|
225 | 225 | """decorator that register a function as a bundle2 part handler |
|
226 | 226 | |
|
227 | 227 | eg:: |
|
228 | 228 | |
|
229 | 229 | @parthandler('myparttype', ('mandatory', 'param', 'handled')) |
|
230 | 230 | def myparttypehandler(...): |
|
231 | 231 | '''process a part of type "my part".''' |
|
232 | 232 | ... |
|
233 | 233 | """ |
|
234 | 234 | validateparttype(parttype) |
|
235 | 235 | |
|
236 | 236 | def _decorator(func): |
|
237 | 237 | lparttype = parttype.lower() # enforce lower case matching. |
|
238 | 238 | assert lparttype not in parthandlermapping |
|
239 | 239 | parthandlermapping[lparttype] = func |
|
240 | 240 | func.params = frozenset(params) |
|
241 | 241 | return func |
|
242 | 242 | |
|
243 | 243 | return _decorator |
|
244 | 244 | |
|
245 | 245 | |
|
246 | 246 | class unbundlerecords(object): |
|
247 | 247 | """keep record of what happens during and unbundle |
|
248 | 248 | |
|
249 | 249 | New records are added using `records.add('cat', obj)`. Where 'cat' is a |
|
250 | 250 | category of record and obj is an arbitrary object. |
|
251 | 251 | |
|
252 | 252 | `records['cat']` will return all entries of this category 'cat'. |
|
253 | 253 | |
|
254 | 254 | Iterating on the object itself will yield `('category', obj)` tuples |
|
255 | 255 | for all entries. |
|
256 | 256 | |
|
257 | 257 | All iterations happens in chronological order. |
|
258 | 258 | """ |
|
259 | 259 | |
|
260 | 260 | def __init__(self): |
|
261 | 261 | self._categories = {} |
|
262 | 262 | self._sequences = [] |
|
263 | 263 | self._replies = {} |
|
264 | 264 | |
|
265 | 265 | def add(self, category, entry, inreplyto=None): |
|
266 | 266 | """add a new record of a given category. |
|
267 | 267 | |
|
268 | 268 | The entry can then be retrieved in the list returned by |
|
269 | 269 | self['category'].""" |
|
270 | 270 | self._categories.setdefault(category, []).append(entry) |
|
271 | 271 | self._sequences.append((category, entry)) |
|
272 | 272 | if inreplyto is not None: |
|
273 | 273 | self.getreplies(inreplyto).add(category, entry) |
|
274 | 274 | |
|
275 | 275 | def getreplies(self, partid): |
|
276 | 276 | """get the records that are replies to a specific part""" |
|
277 | 277 | return self._replies.setdefault(partid, unbundlerecords()) |
|
278 | 278 | |
|
279 | 279 | def __getitem__(self, cat): |
|
280 | 280 | return tuple(self._categories.get(cat, ())) |
|
281 | 281 | |
|
282 | 282 | def __iter__(self): |
|
283 | 283 | return iter(self._sequences) |
|
284 | 284 | |
|
285 | 285 | def __len__(self): |
|
286 | 286 | return len(self._sequences) |
|
287 | 287 | |
|
288 | 288 | def __nonzero__(self): |
|
289 | 289 | return bool(self._sequences) |
|
290 | 290 | |
|
291 | 291 | __bool__ = __nonzero__ |
|
292 | 292 | |
|
293 | 293 | |
|
294 | 294 | class bundleoperation(object): |
|
295 | 295 | """an object that represents a single bundling process |
|
296 | 296 | |
|
297 | 297 | Its purpose is to carry unbundle-related objects and states. |
|
298 | 298 | |
|
299 | 299 | A new object should be created at the beginning of each bundle processing. |
|
300 | 300 | The object is to be returned by the processing function. |
|
301 | 301 | |
|
302 | 302 | The object has very little content now it will ultimately contain: |
|
303 | 303 | * an access to the repo the bundle is applied to, |
|
304 | 304 | * a ui object, |
|
305 | 305 | * a way to retrieve a transaction to add changes to the repo, |
|
306 | 306 | * a way to record the result of processing each part, |
|
307 | 307 | * a way to construct a bundle response when applicable. |
|
308 | 308 | """ |
|
309 | 309 | |
|
310 | 310 | def __init__(self, repo, transactiongetter, captureoutput=True, source=b''): |
|
311 | 311 | self.repo = repo |
|
312 | 312 | self.ui = repo.ui |
|
313 | 313 | self.records = unbundlerecords() |
|
314 | 314 | self.reply = None |
|
315 | 315 | self.captureoutput = captureoutput |
|
316 | 316 | self.hookargs = {} |
|
317 | 317 | self._gettransaction = transactiongetter |
|
318 | 318 | # carries value that can modify part behavior |
|
319 | 319 | self.modes = {} |
|
320 | 320 | self.source = source |
|
321 | 321 | |
|
322 | 322 | def gettransaction(self): |
|
323 | 323 | transaction = self._gettransaction() |
|
324 | 324 | |
|
325 | 325 | if self.hookargs: |
|
326 | 326 | # the ones added to the transaction supercede those added |
|
327 | 327 | # to the operation. |
|
328 | 328 | self.hookargs.update(transaction.hookargs) |
|
329 | 329 | transaction.hookargs = self.hookargs |
|
330 | 330 | |
|
331 | 331 | # mark the hookargs as flushed. further attempts to add to |
|
332 | 332 | # hookargs will result in an abort. |
|
333 | 333 | self.hookargs = None |
|
334 | 334 | |
|
335 | 335 | return transaction |
|
336 | 336 | |
|
337 | 337 | def addhookargs(self, hookargs): |
|
338 | 338 | if self.hookargs is None: |
|
339 | 339 | raise error.ProgrammingError( |
|
340 | 340 | b'attempted to add hookargs to ' |
|
341 | 341 | b'operation after transaction started' |
|
342 | 342 | ) |
|
343 | 343 | self.hookargs.update(hookargs) |
|
344 | 344 | |
|
345 | 345 | |
|
346 | 346 | class TransactionUnavailable(RuntimeError): |
|
347 | 347 | pass |
|
348 | 348 | |
|
349 | 349 | |
|
350 | 350 | def _notransaction(): |
|
351 | 351 | """default method to get a transaction while processing a bundle |
|
352 | 352 | |
|
353 | 353 | Raise an exception to highlight the fact that no transaction was expected |
|
354 | 354 | to be created""" |
|
355 | 355 | raise TransactionUnavailable() |
|
356 | 356 | |
|
357 | 357 | |
|
358 | 358 | def applybundle(repo, unbundler, tr, source, url=None, **kwargs): |
|
359 | 359 | # transform me into unbundler.apply() as soon as the freeze is lifted |
|
360 | 360 | if isinstance(unbundler, unbundle20): |
|
361 | 361 | tr.hookargs[b'bundle2'] = b'1' |
|
362 | 362 | if source is not None and b'source' not in tr.hookargs: |
|
363 | 363 | tr.hookargs[b'source'] = source |
|
364 | 364 | if url is not None and b'url' not in tr.hookargs: |
|
365 | 365 | tr.hookargs[b'url'] = url |
|
366 | 366 | return processbundle(repo, unbundler, lambda: tr, source=source) |
|
367 | 367 | else: |
|
368 | 368 | # the transactiongetter won't be used, but we might as well set it |
|
369 | 369 | op = bundleoperation(repo, lambda: tr, source=source) |
|
370 | 370 | _processchangegroup(op, unbundler, tr, source, url, **kwargs) |
|
371 | 371 | return op |
|
372 | 372 | |
|
373 | 373 | |
|
374 | 374 | class partiterator(object): |
|
375 | 375 | def __init__(self, repo, op, unbundler): |
|
376 | 376 | self.repo = repo |
|
377 | 377 | self.op = op |
|
378 | 378 | self.unbundler = unbundler |
|
379 | 379 | self.iterator = None |
|
380 | 380 | self.count = 0 |
|
381 | 381 | self.current = None |
|
382 | 382 | |
|
383 | 383 | def __enter__(self): |
|
384 | 384 | def func(): |
|
385 | 385 | itr = enumerate(self.unbundler.iterparts(), 1) |
|
386 | 386 | for count, p in itr: |
|
387 | 387 | self.count = count |
|
388 | 388 | self.current = p |
|
389 | 389 | yield p |
|
390 | 390 | p.consume() |
|
391 | 391 | self.current = None |
|
392 | 392 | |
|
393 | 393 | self.iterator = func() |
|
394 | 394 | return self.iterator |
|
395 | 395 | |
|
396 | 396 | def __exit__(self, type, exc, tb): |
|
397 | 397 | if not self.iterator: |
|
398 | 398 | return |
|
399 | 399 | |
|
400 | 400 | # Only gracefully abort in a normal exception situation. User aborts |
|
401 | 401 | # like Ctrl+C throw a KeyboardInterrupt which is not a base Exception, |
|
402 | 402 | # and should not gracefully cleanup. |
|
403 | 403 | if isinstance(exc, Exception): |
|
404 | 404 | # Any exceptions seeking to the end of the bundle at this point are |
|
405 | 405 | # almost certainly related to the underlying stream being bad. |
|
406 | 406 | # And, chances are that the exception we're handling is related to |
|
407 | 407 | # getting in that bad state. So, we swallow the seeking error and |
|
408 | 408 | # re-raise the original error. |
|
409 | 409 | seekerror = False |
|
410 | 410 | try: |
|
411 | 411 | if self.current: |
|
412 | 412 | # consume the part content to not corrupt the stream. |
|
413 | 413 | self.current.consume() |
|
414 | 414 | |
|
415 | 415 | for part in self.iterator: |
|
416 | 416 | # consume the bundle content |
|
417 | 417 | part.consume() |
|
418 | 418 | except Exception: |
|
419 | 419 | seekerror = True |
|
420 | 420 | |
|
421 | 421 | # Small hack to let caller code distinguish exceptions from bundle2 |
|
422 | 422 | # processing from processing the old format. This is mostly needed |
|
423 | 423 | # to handle different return codes to unbundle according to the type |
|
424 | 424 | # of bundle. We should probably clean up or drop this return code |
|
425 | 425 | # craziness in a future version. |
|
426 | 426 | exc.duringunbundle2 = True |
|
427 | 427 | salvaged = [] |
|
428 | 428 | replycaps = None |
|
429 | 429 | if self.op.reply is not None: |
|
430 | 430 | salvaged = self.op.reply.salvageoutput() |
|
431 | 431 | replycaps = self.op.reply.capabilities |
|
432 | 432 | exc._replycaps = replycaps |
|
433 | 433 | exc._bundle2salvagedoutput = salvaged |
|
434 | 434 | |
|
435 | 435 | # Re-raising from a variable loses the original stack. So only use |
|
436 | 436 | # that form if we need to. |
|
437 | 437 | if seekerror: |
|
438 | 438 | raise exc |
|
439 | 439 | |
|
440 | 440 | self.repo.ui.debug( |
|
441 | 441 | b'bundle2-input-bundle: %i parts total\n' % self.count |
|
442 | 442 | ) |
|
443 | 443 | |
|
444 | 444 | |
|
445 | 445 | def processbundle(repo, unbundler, transactiongetter=None, op=None, source=b''): |
|
446 | 446 | """This function process a bundle, apply effect to/from a repo |
|
447 | 447 | |
|
448 | 448 | It iterates over each part then searches for and uses the proper handling |
|
449 | 449 | code to process the part. Parts are processed in order. |
|
450 | 450 | |
|
451 | 451 | Unknown Mandatory part will abort the process. |
|
452 | 452 | |
|
453 | 453 | It is temporarily possible to provide a prebuilt bundleoperation to the |
|
454 | 454 | function. This is used to ensure output is properly propagated in case of |
|
455 | 455 | an error during the unbundling. This output capturing part will likely be |
|
456 | 456 | reworked and this ability will probably go away in the process. |
|
457 | 457 | """ |
|
458 | 458 | if op is None: |
|
459 | 459 | if transactiongetter is None: |
|
460 | 460 | transactiongetter = _notransaction |
|
461 | 461 | op = bundleoperation(repo, transactiongetter, source=source) |
|
462 | 462 | # todo: |
|
463 | 463 | # - replace this is a init function soon. |
|
464 | 464 | # - exception catching |
|
465 | 465 | unbundler.params |
|
466 | 466 | if repo.ui.debugflag: |
|
467 | 467 | msg = [b'bundle2-input-bundle:'] |
|
468 | 468 | if unbundler.params: |
|
469 | 469 | msg.append(b' %i params' % len(unbundler.params)) |
|
470 | 470 | if op._gettransaction is None or op._gettransaction is _notransaction: |
|
471 | 471 | msg.append(b' no-transaction') |
|
472 | 472 | else: |
|
473 | 473 | msg.append(b' with-transaction') |
|
474 | 474 | msg.append(b'\n') |
|
475 | 475 | repo.ui.debug(b''.join(msg)) |
|
476 | 476 | |
|
477 | 477 | processparts(repo, op, unbundler) |
|
478 | 478 | |
|
479 | 479 | return op |
|
480 | 480 | |
|
481 | 481 | |
|
482 | 482 | def processparts(repo, op, unbundler): |
|
483 | 483 | with partiterator(repo, op, unbundler) as parts: |
|
484 | 484 | for part in parts: |
|
485 | 485 | _processpart(op, part) |
|
486 | 486 | |
|
487 | 487 | |
|
488 | 488 | def _processchangegroup(op, cg, tr, source, url, **kwargs): |
|
489 | 489 | ret = cg.apply(op.repo, tr, source, url, **kwargs) |
|
490 | 490 | op.records.add(b'changegroup', {b'return': ret,}) |
|
491 | 491 | return ret |
|
492 | 492 | |
|
493 | 493 | |
|
494 | 494 | def _gethandler(op, part): |
|
495 | 495 | status = b'unknown' # used by debug output |
|
496 | 496 | try: |
|
497 | 497 | handler = parthandlermapping.get(part.type) |
|
498 | 498 | if handler is None: |
|
499 | 499 | status = b'unsupported-type' |
|
500 | 500 | raise error.BundleUnknownFeatureError(parttype=part.type) |
|
501 | 501 | indebug(op.ui, b'found a handler for part %s' % part.type) |
|
502 | 502 | unknownparams = part.mandatorykeys - handler.params |
|
503 | 503 | if unknownparams: |
|
504 | 504 | unknownparams = list(unknownparams) |
|
505 | 505 | unknownparams.sort() |
|
506 | 506 | status = b'unsupported-params (%s)' % b', '.join(unknownparams) |
|
507 | 507 | raise error.BundleUnknownFeatureError( |
|
508 | 508 | parttype=part.type, params=unknownparams |
|
509 | 509 | ) |
|
510 | 510 | status = b'supported' |
|
511 | 511 | except error.BundleUnknownFeatureError as exc: |
|
512 | 512 | if part.mandatory: # mandatory parts |
|
513 | 513 | raise |
|
514 | 514 | indebug(op.ui, b'ignoring unsupported advisory part %s' % exc) |
|
515 | 515 | return # skip to part processing |
|
516 | 516 | finally: |
|
517 | 517 | if op.ui.debugflag: |
|
518 | 518 | msg = [b'bundle2-input-part: "%s"' % part.type] |
|
519 | 519 | if not part.mandatory: |
|
520 | 520 | msg.append(b' (advisory)') |
|
521 | 521 | nbmp = len(part.mandatorykeys) |
|
522 | 522 | nbap = len(part.params) - nbmp |
|
523 | 523 | if nbmp or nbap: |
|
524 | 524 | msg.append(b' (params:') |
|
525 | 525 | if nbmp: |
|
526 | 526 | msg.append(b' %i mandatory' % nbmp) |
|
527 | 527 | if nbap: |
|
528 | 528 | msg.append(b' %i advisory' % nbmp) |
|
529 | 529 | msg.append(b')') |
|
530 | 530 | msg.append(b' %s\n' % status) |
|
531 | 531 | op.ui.debug(b''.join(msg)) |
|
532 | 532 | |
|
533 | 533 | return handler |
|
534 | 534 | |
|
535 | 535 | |
|
536 | 536 | def _processpart(op, part): |
|
537 | 537 | """process a single part from a bundle |
|
538 | 538 | |
|
539 | 539 | The part is guaranteed to have been fully consumed when the function exits |
|
540 | 540 | (even if an exception is raised).""" |
|
541 | 541 | handler = _gethandler(op, part) |
|
542 | 542 | if handler is None: |
|
543 | 543 | return |
|
544 | 544 | |
|
545 | 545 | # handler is called outside the above try block so that we don't |
|
546 | 546 | # risk catching KeyErrors from anything other than the |
|
547 | 547 | # parthandlermapping lookup (any KeyError raised by handler() |
|
548 | 548 | # itself represents a defect of a different variety). |
|
549 | 549 | output = None |
|
550 | 550 | if op.captureoutput and op.reply is not None: |
|
551 | 551 | op.ui.pushbuffer(error=True, subproc=True) |
|
552 | 552 | output = b'' |
|
553 | 553 | try: |
|
554 | 554 | handler(op, part) |
|
555 | 555 | finally: |
|
556 | 556 | if output is not None: |
|
557 | 557 | output = op.ui.popbuffer() |
|
558 | 558 | if output: |
|
559 | 559 | outpart = op.reply.newpart(b'output', data=output, mandatory=False) |
|
560 | 560 | outpart.addparam( |
|
561 | 561 | b'in-reply-to', pycompat.bytestr(part.id), mandatory=False |
|
562 | 562 | ) |
|
563 | 563 | |
|
564 | 564 | |
|
565 | 565 | def decodecaps(blob): |
|
566 | 566 | """decode a bundle2 caps bytes blob into a dictionary |
|
567 | 567 | |
|
568 | 568 | The blob is a list of capabilities (one per line) |
|
569 | 569 | Capabilities may have values using a line of the form:: |
|
570 | 570 | |
|
571 | 571 | capability=value1,value2,value3 |
|
572 | 572 | |
|
573 | 573 | The values are always a list.""" |
|
574 | 574 | caps = {} |
|
575 | 575 | for line in blob.splitlines(): |
|
576 | 576 | if not line: |
|
577 | 577 | continue |
|
578 | 578 | if b'=' not in line: |
|
579 | 579 | key, vals = line, () |
|
580 | 580 | else: |
|
581 | 581 | key, vals = line.split(b'=', 1) |
|
582 | 582 | vals = vals.split(b',') |
|
583 | 583 | key = urlreq.unquote(key) |
|
584 | 584 | vals = [urlreq.unquote(v) for v in vals] |
|
585 | 585 | caps[key] = vals |
|
586 | 586 | return caps |
|
587 | 587 | |
|
588 | 588 | |
|
589 | 589 | def encodecaps(caps): |
|
590 | 590 | """encode a bundle2 caps dictionary into a bytes blob""" |
|
591 | 591 | chunks = [] |
|
592 | 592 | for ca in sorted(caps): |
|
593 | 593 | vals = caps[ca] |
|
594 | 594 | ca = urlreq.quote(ca) |
|
595 | 595 | vals = [urlreq.quote(v) for v in vals] |
|
596 | 596 | if vals: |
|
597 | 597 | ca = b"%s=%s" % (ca, b','.join(vals)) |
|
598 | 598 | chunks.append(ca) |
|
599 | 599 | return b'\n'.join(chunks) |
|
600 | 600 | |
|
601 | 601 | |
|
602 | 602 | bundletypes = { |
|
603 | 603 | b"": (b"", b'UN'), # only when using unbundle on ssh and old http servers |
|
604 | 604 | # since the unification ssh accepts a header but there |
|
605 | 605 | # is no capability signaling it. |
|
606 | 606 | b"HG20": (), # special-cased below |
|
607 | 607 | b"HG10UN": (b"HG10UN", b'UN'), |
|
608 | 608 | b"HG10BZ": (b"HG10", b'BZ'), |
|
609 | 609 | b"HG10GZ": (b"HG10GZ", b'GZ'), |
|
610 | 610 | } |
|
611 | 611 | |
|
612 | 612 | # hgweb uses this list to communicate its preferred type |
|
613 | 613 | bundlepriority = [b'HG10GZ', b'HG10BZ', b'HG10UN'] |
|
614 | 614 | |
|
615 | 615 | |
|
616 | 616 | class bundle20(object): |
|
617 | 617 | """represent an outgoing bundle2 container |
|
618 | 618 | |
|
619 | 619 | Use the `addparam` method to add stream level parameter. and `newpart` to |
|
620 | 620 | populate it. Then call `getchunks` to retrieve all the binary chunks of |
|
621 | 621 | data that compose the bundle2 container.""" |
|
622 | 622 | |
|
623 | 623 | _magicstring = b'HG20' |
|
624 | 624 | |
|
625 | 625 | def __init__(self, ui, capabilities=()): |
|
626 | 626 | self.ui = ui |
|
627 | 627 | self._params = [] |
|
628 | 628 | self._parts = [] |
|
629 | 629 | self.capabilities = dict(capabilities) |
|
630 | 630 | self._compengine = util.compengines.forbundletype(b'UN') |
|
631 | 631 | self._compopts = None |
|
632 | 632 | # If compression is being handled by a consumer of the raw |
|
633 | 633 | # data (e.g. the wire protocol), unsetting this flag tells |
|
634 | 634 | # consumers that the bundle is best left uncompressed. |
|
635 | 635 | self.prefercompressed = True |
|
636 | 636 | |
|
637 | 637 | def setcompression(self, alg, compopts=None): |
|
638 | 638 | """setup core part compression to <alg>""" |
|
639 | 639 | if alg in (None, b'UN'): |
|
640 | 640 | return |
|
641 | 641 | assert not any(n.lower() == b'compression' for n, v in self._params) |
|
642 | 642 | self.addparam(b'Compression', alg) |
|
643 | 643 | self._compengine = util.compengines.forbundletype(alg) |
|
644 | 644 | self._compopts = compopts |
|
645 | 645 | |
|
646 | 646 | @property |
|
647 | 647 | def nbparts(self): |
|
648 | 648 | """total number of parts added to the bundler""" |
|
649 | 649 | return len(self._parts) |
|
650 | 650 | |
|
651 | 651 | # methods used to defines the bundle2 content |
|
652 | 652 | def addparam(self, name, value=None): |
|
653 | 653 | """add a stream level parameter""" |
|
654 | 654 | if not name: |
|
655 | 655 | raise error.ProgrammingError(b'empty parameter name') |
|
656 | 656 | if name[0:1] not in pycompat.bytestr( |
|
657 | 657 | string.ascii_letters # pytype: disable=wrong-arg-types |
|
658 | 658 | ): |
|
659 | 659 | raise error.ProgrammingError( |
|
660 | 660 | b'non letter first character: %s' % name |
|
661 | 661 | ) |
|
662 | 662 | self._params.append((name, value)) |
|
663 | 663 | |
|
664 | 664 | def addpart(self, part): |
|
665 | 665 | """add a new part to the bundle2 container |
|
666 | 666 | |
|
667 | 667 | Parts contains the actual applicative payload.""" |
|
668 | 668 | assert part.id is None |
|
669 | 669 | part.id = len(self._parts) # very cheap counter |
|
670 | 670 | self._parts.append(part) |
|
671 | 671 | |
|
672 | 672 | def newpart(self, typeid, *args, **kwargs): |
|
673 | 673 | """create a new part and add it to the containers |
|
674 | 674 | |
|
675 | 675 | As the part is directly added to the containers. For now, this means |
|
676 | 676 | that any failure to properly initialize the part after calling |
|
677 | 677 | ``newpart`` should result in a failure of the whole bundling process. |
|
678 | 678 | |
|
679 | 679 | You can still fall back to manually create and add if you need better |
|
680 | 680 | control.""" |
|
681 | 681 | part = bundlepart(typeid, *args, **kwargs) |
|
682 | 682 | self.addpart(part) |
|
683 | 683 | return part |
|
684 | 684 | |
|
685 | 685 | # methods used to generate the bundle2 stream |
|
686 | 686 | def getchunks(self): |
|
687 | 687 | if self.ui.debugflag: |
|
688 | 688 | msg = [b'bundle2-output-bundle: "%s",' % self._magicstring] |
|
689 | 689 | if self._params: |
|
690 | 690 | msg.append(b' (%i params)' % len(self._params)) |
|
691 | 691 | msg.append(b' %i parts total\n' % len(self._parts)) |
|
692 | 692 | self.ui.debug(b''.join(msg)) |
|
693 | 693 | outdebug(self.ui, b'start emission of %s stream' % self._magicstring) |
|
694 | 694 | yield self._magicstring |
|
695 | 695 | param = self._paramchunk() |
|
696 | 696 | outdebug(self.ui, b'bundle parameter: %s' % param) |
|
697 | 697 | yield _pack(_fstreamparamsize, len(param)) |
|
698 | 698 | if param: |
|
699 | 699 | yield param |
|
700 | 700 | for chunk in self._compengine.compressstream( |
|
701 | 701 | self._getcorechunk(), self._compopts |
|
702 | 702 | ): |
|
703 | 703 | yield chunk |
|
704 | 704 | |
|
705 | 705 | def _paramchunk(self): |
|
706 | 706 | """return a encoded version of all stream parameters""" |
|
707 | 707 | blocks = [] |
|
708 | 708 | for par, value in self._params: |
|
709 | 709 | par = urlreq.quote(par) |
|
710 | 710 | if value is not None: |
|
711 | 711 | value = urlreq.quote(value) |
|
712 | 712 | par = b'%s=%s' % (par, value) |
|
713 | 713 | blocks.append(par) |
|
714 | 714 | return b' '.join(blocks) |
|
715 | 715 | |
|
716 | 716 | def _getcorechunk(self): |
|
717 | 717 | """yield chunk for the core part of the bundle |
|
718 | 718 | |
|
719 | 719 | (all but headers and parameters)""" |
|
720 | 720 | outdebug(self.ui, b'start of parts') |
|
721 | 721 | for part in self._parts: |
|
722 | 722 | outdebug(self.ui, b'bundle part: "%s"' % part.type) |
|
723 | 723 | for chunk in part.getchunks(ui=self.ui): |
|
724 | 724 | yield chunk |
|
725 | 725 | outdebug(self.ui, b'end of bundle') |
|
726 | 726 | yield _pack(_fpartheadersize, 0) |
|
727 | 727 | |
|
728 | 728 | def salvageoutput(self): |
|
729 | 729 | """return a list with a copy of all output parts in the bundle |
|
730 | 730 | |
|
731 | 731 | This is meant to be used during error handling to make sure we preserve |
|
732 | 732 | server output""" |
|
733 | 733 | salvaged = [] |
|
734 | 734 | for part in self._parts: |
|
735 | 735 | if part.type.startswith(b'output'): |
|
736 | 736 | salvaged.append(part.copy()) |
|
737 | 737 | return salvaged |
|
738 | 738 | |
|
739 | 739 | |
|
740 | 740 | class unpackermixin(object): |
|
741 | 741 | """A mixin to extract bytes and struct data from a stream""" |
|
742 | 742 | |
|
743 | 743 | def __init__(self, fp): |
|
744 | 744 | self._fp = fp |
|
745 | 745 | |
|
746 | 746 | def _unpack(self, format): |
|
747 | 747 | """unpack this struct format from the stream |
|
748 | 748 | |
|
749 | 749 | This method is meant for internal usage by the bundle2 protocol only. |
|
750 | 750 | They directly manipulate the low level stream including bundle2 level |
|
751 | 751 | instruction. |
|
752 | 752 | |
|
753 | 753 | Do not use it to implement higher-level logic or methods.""" |
|
754 | 754 | data = self._readexact(struct.calcsize(format)) |
|
755 | 755 | return _unpack(format, data) |
|
756 | 756 | |
|
757 | 757 | def _readexact(self, size): |
|
758 | 758 | """read exactly <size> bytes from the stream |
|
759 | 759 | |
|
760 | 760 | This method is meant for internal usage by the bundle2 protocol only. |
|
761 | 761 | They directly manipulate the low level stream including bundle2 level |
|
762 | 762 | instruction. |
|
763 | 763 | |
|
764 | 764 | Do not use it to implement higher-level logic or methods.""" |
|
765 | 765 | return changegroup.readexactly(self._fp, size) |
|
766 | 766 | |
|
767 | 767 | |
|
768 | 768 | def getunbundler(ui, fp, magicstring=None): |
|
769 | 769 | """return a valid unbundler object for a given magicstring""" |
|
770 | 770 | if magicstring is None: |
|
771 | 771 | magicstring = changegroup.readexactly(fp, 4) |
|
772 | 772 | magic, version = magicstring[0:2], magicstring[2:4] |
|
773 | 773 | if magic != b'HG': |
|
774 | 774 | ui.debug( |
|
775 | 775 | b"error: invalid magic: %r (version %r), should be 'HG'\n" |
|
776 | 776 | % (magic, version) |
|
777 | 777 | ) |
|
778 | 778 | raise error.Abort(_(b'not a Mercurial bundle')) |
|
779 | 779 | unbundlerclass = formatmap.get(version) |
|
780 | 780 | if unbundlerclass is None: |
|
781 | 781 | raise error.Abort(_(b'unknown bundle version %s') % version) |
|
782 | 782 | unbundler = unbundlerclass(ui, fp) |
|
783 | 783 | indebug(ui, b'start processing of %s stream' % magicstring) |
|
784 | 784 | return unbundler |
|
785 | 785 | |
|
786 | 786 | |
|
787 | 787 | class unbundle20(unpackermixin): |
|
788 | 788 | """interpret a bundle2 stream |
|
789 | 789 | |
|
790 | 790 | This class is fed with a binary stream and yields parts through its |
|
791 | 791 | `iterparts` methods.""" |
|
792 | 792 | |
|
793 | 793 | _magicstring = b'HG20' |
|
794 | 794 | |
|
795 | 795 | def __init__(self, ui, fp): |
|
796 | 796 | """If header is specified, we do not read it out of the stream.""" |
|
797 | 797 | self.ui = ui |
|
798 | 798 | self._compengine = util.compengines.forbundletype(b'UN') |
|
799 | 799 | self._compressed = None |
|
800 | 800 | super(unbundle20, self).__init__(fp) |
|
801 | 801 | |
|
802 | 802 | @util.propertycache |
|
803 | 803 | def params(self): |
|
804 | 804 | """dictionary of stream level parameters""" |
|
805 | 805 | indebug(self.ui, b'reading bundle2 stream parameters') |
|
806 | 806 | params = {} |
|
807 | 807 | paramssize = self._unpack(_fstreamparamsize)[0] |
|
808 | 808 | if paramssize < 0: |
|
809 | 809 | raise error.BundleValueError( |
|
810 | 810 | b'negative bundle param size: %i' % paramssize |
|
811 | 811 | ) |
|
812 | 812 | if paramssize: |
|
813 | 813 | params = self._readexact(paramssize) |
|
814 | 814 | params = self._processallparams(params) |
|
815 | 815 | return params |
|
816 | 816 | |
|
817 | 817 | def _processallparams(self, paramsblock): |
|
818 | 818 | """""" |
|
819 | 819 | params = util.sortdict() |
|
820 | 820 | for p in paramsblock.split(b' '): |
|
821 | 821 | p = p.split(b'=', 1) |
|
822 | 822 | p = [urlreq.unquote(i) for i in p] |
|
823 | 823 | if len(p) < 2: |
|
824 | 824 | p.append(None) |
|
825 | 825 | self._processparam(*p) |
|
826 | 826 | params[p[0]] = p[1] |
|
827 | 827 | return params |
|
828 | 828 | |
|
829 | 829 | def _processparam(self, name, value): |
|
830 | 830 | """process a parameter, applying its effect if needed |
|
831 | 831 | |
|
832 | 832 | Parameter starting with a lower case letter are advisory and will be |
|
833 | 833 | ignored when unknown. Those starting with an upper case letter are |
|
834 | 834 | mandatory and will this function will raise a KeyError when unknown. |
|
835 | 835 | |
|
836 | 836 | Note: no option are currently supported. Any input will be either |
|
837 | 837 | ignored or failing. |
|
838 | 838 | """ |
|
839 | 839 | if not name: |
|
840 | 840 | raise ValueError('empty parameter name') |
|
841 | 841 | if name[0:1] not in pycompat.bytestr( |
|
842 | 842 | string.ascii_letters # pytype: disable=wrong-arg-types |
|
843 | 843 | ): |
|
844 | 844 | raise ValueError('non letter first character: %s' % name) |
|
845 | 845 | try: |
|
846 | 846 | handler = b2streamparamsmap[name.lower()] |
|
847 | 847 | except KeyError: |
|
848 | 848 | if name[0:1].islower(): |
|
849 | 849 | indebug(self.ui, b"ignoring unknown parameter %s" % name) |
|
850 | 850 | else: |
|
851 | 851 | raise error.BundleUnknownFeatureError(params=(name,)) |
|
852 | 852 | else: |
|
853 | 853 | handler(self, name, value) |
|
854 | 854 | |
|
855 | 855 | def _forwardchunks(self): |
|
856 | 856 | """utility to transfer a bundle2 as binary |
|
857 | 857 | |
|
858 | 858 | This is made necessary by the fact the 'getbundle' command over 'ssh' |
|
859 | 859 | have no way to know then the reply end, relying on the bundle to be |
|
860 | 860 | interpreted to know its end. This is terrible and we are sorry, but we |
|
861 | 861 | needed to move forward to get general delta enabled. |
|
862 | 862 | """ |
|
863 | 863 | yield self._magicstring |
|
864 | 864 | assert 'params' not in vars(self) |
|
865 | 865 | paramssize = self._unpack(_fstreamparamsize)[0] |
|
866 | 866 | if paramssize < 0: |
|
867 | 867 | raise error.BundleValueError( |
|
868 | 868 | b'negative bundle param size: %i' % paramssize |
|
869 | 869 | ) |
|
870 | 870 | if paramssize: |
|
871 | 871 | params = self._readexact(paramssize) |
|
872 | 872 | self._processallparams(params) |
|
873 | 873 | # The payload itself is decompressed below, so drop |
|
874 | 874 | # the compression parameter passed down to compensate. |
|
875 | 875 | outparams = [] |
|
876 | 876 | for p in params.split(b' '): |
|
877 | 877 | k, v = p.split(b'=', 1) |
|
878 | 878 | if k.lower() != b'compression': |
|
879 | 879 | outparams.append(p) |
|
880 | 880 | outparams = b' '.join(outparams) |
|
881 | 881 | yield _pack(_fstreamparamsize, len(outparams)) |
|
882 | 882 | yield outparams |
|
883 | 883 | else: |
|
884 | 884 | yield _pack(_fstreamparamsize, paramssize) |
|
885 | 885 | # From there, payload might need to be decompressed |
|
886 | 886 | self._fp = self._compengine.decompressorreader(self._fp) |
|
887 | 887 | emptycount = 0 |
|
888 | 888 | while emptycount < 2: |
|
889 | 889 | # so we can brainlessly loop |
|
890 | 890 | assert _fpartheadersize == _fpayloadsize |
|
891 | 891 | size = self._unpack(_fpartheadersize)[0] |
|
892 | 892 | yield _pack(_fpartheadersize, size) |
|
893 | 893 | if size: |
|
894 | 894 | emptycount = 0 |
|
895 | 895 | else: |
|
896 | 896 | emptycount += 1 |
|
897 | 897 | continue |
|
898 | 898 | if size == flaginterrupt: |
|
899 | 899 | continue |
|
900 | 900 | elif size < 0: |
|
901 | 901 | raise error.BundleValueError(b'negative chunk size: %i') |
|
902 | 902 | yield self._readexact(size) |
|
903 | 903 | |
|
904 | 904 | def iterparts(self, seekable=False): |
|
905 | 905 | """yield all parts contained in the stream""" |
|
906 | 906 | cls = seekableunbundlepart if seekable else unbundlepart |
|
907 | 907 | # make sure param have been loaded |
|
908 | 908 | self.params |
|
909 | 909 | # From there, payload need to be decompressed |
|
910 | 910 | self._fp = self._compengine.decompressorreader(self._fp) |
|
911 | 911 | indebug(self.ui, b'start extraction of bundle2 parts') |
|
912 | 912 | headerblock = self._readpartheader() |
|
913 | 913 | while headerblock is not None: |
|
914 | 914 | part = cls(self.ui, headerblock, self._fp) |
|
915 | 915 | yield part |
|
916 | 916 | # Ensure part is fully consumed so we can start reading the next |
|
917 | 917 | # part. |
|
918 | 918 | part.consume() |
|
919 | 919 | |
|
920 | 920 | headerblock = self._readpartheader() |
|
921 | 921 | indebug(self.ui, b'end of bundle2 stream') |
|
922 | 922 | |
|
923 | 923 | def _readpartheader(self): |
|
924 | 924 | """reads a part header size and return the bytes blob |
|
925 | 925 | |
|
926 | 926 | returns None if empty""" |
|
927 | 927 | headersize = self._unpack(_fpartheadersize)[0] |
|
928 | 928 | if headersize < 0: |
|
929 | 929 | raise error.BundleValueError( |
|
930 | 930 | b'negative part header size: %i' % headersize |
|
931 | 931 | ) |
|
932 | 932 | indebug(self.ui, b'part header size: %i' % headersize) |
|
933 | 933 | if headersize: |
|
934 | 934 | return self._readexact(headersize) |
|
935 | 935 | return None |
|
936 | 936 | |
|
937 | 937 | def compressed(self): |
|
938 | 938 | self.params # load params |
|
939 | 939 | return self._compressed |
|
940 | 940 | |
|
941 | 941 | def close(self): |
|
942 | 942 | """close underlying file""" |
|
943 | 943 | if util.safehasattr(self._fp, 'close'): |
|
944 | 944 | return self._fp.close() |
|
945 | 945 | |
|
946 | 946 | |
|
947 | 947 | formatmap = {b'20': unbundle20} |
|
948 | 948 | |
|
949 | 949 | b2streamparamsmap = {} |
|
950 | 950 | |
|
951 | 951 | |
|
952 | 952 | def b2streamparamhandler(name): |
|
953 | 953 | """register a handler for a stream level parameter""" |
|
954 | 954 | |
|
955 | 955 | def decorator(func): |
|
956 | 956 | assert name not in formatmap |
|
957 | 957 | b2streamparamsmap[name] = func |
|
958 | 958 | return func |
|
959 | 959 | |
|
960 | 960 | return decorator |
|
961 | 961 | |
|
962 | 962 | |
|
963 | 963 | @b2streamparamhandler(b'compression') |
|
964 | 964 | def processcompression(unbundler, param, value): |
|
965 | 965 | """read compression parameter and install payload decompression""" |
|
966 | 966 | if value not in util.compengines.supportedbundletypes: |
|
967 | 967 | raise error.BundleUnknownFeatureError(params=(param,), values=(value,)) |
|
968 | 968 | unbundler._compengine = util.compengines.forbundletype(value) |
|
969 | 969 | if value is not None: |
|
970 | 970 | unbundler._compressed = True |
|
971 | 971 | |
|
972 | 972 | |
|
973 | 973 | class bundlepart(object): |
|
974 | 974 | """A bundle2 part contains application level payload |
|
975 | 975 | |
|
976 | 976 | The part `type` is used to route the part to the application level |
|
977 | 977 | handler. |
|
978 | 978 | |
|
979 | 979 | The part payload is contained in ``part.data``. It could be raw bytes or a |
|
980 | 980 | generator of byte chunks. |
|
981 | 981 | |
|
982 | 982 | You can add parameters to the part using the ``addparam`` method. |
|
983 | 983 | Parameters can be either mandatory (default) or advisory. Remote side |
|
984 | 984 | should be able to safely ignore the advisory ones. |
|
985 | 985 | |
|
986 | 986 | Both data and parameters cannot be modified after the generation has begun. |
|
987 | 987 | """ |
|
988 | 988 | |
|
989 | 989 | def __init__( |
|
990 | 990 | self, |
|
991 | 991 | parttype, |
|
992 | 992 | mandatoryparams=(), |
|
993 | 993 | advisoryparams=(), |
|
994 | 994 | data=b'', |
|
995 | 995 | mandatory=True, |
|
996 | 996 | ): |
|
997 | 997 | validateparttype(parttype) |
|
998 | 998 | self.id = None |
|
999 | 999 | self.type = parttype |
|
1000 | 1000 | self._data = data |
|
1001 | 1001 | self._mandatoryparams = list(mandatoryparams) |
|
1002 | 1002 | self._advisoryparams = list(advisoryparams) |
|
1003 | 1003 | # checking for duplicated entries |
|
1004 | 1004 | self._seenparams = set() |
|
1005 | 1005 | for pname, __ in self._mandatoryparams + self._advisoryparams: |
|
1006 | 1006 | if pname in self._seenparams: |
|
1007 | 1007 | raise error.ProgrammingError(b'duplicated params: %s' % pname) |
|
1008 | 1008 | self._seenparams.add(pname) |
|
1009 | 1009 | # status of the part's generation: |
|
1010 | 1010 | # - None: not started, |
|
1011 | 1011 | # - False: currently generated, |
|
1012 | 1012 | # - True: generation done. |
|
1013 | 1013 | self._generated = None |
|
1014 | 1014 | self.mandatory = mandatory |
|
1015 | 1015 | |
|
1016 | 1016 | def __repr__(self): |
|
1017 | 1017 | cls = "%s.%s" % (self.__class__.__module__, self.__class__.__name__) |
|
1018 | 1018 | return '<%s object at %x; id: %s; type: %s; mandatory: %s>' % ( |
|
1019 | 1019 | cls, |
|
1020 | 1020 | id(self), |
|
1021 | 1021 | self.id, |
|
1022 | 1022 | self.type, |
|
1023 | 1023 | self.mandatory, |
|
1024 | 1024 | ) |
|
1025 | 1025 | |
|
1026 | 1026 | def copy(self): |
|
1027 | 1027 | """return a copy of the part |
|
1028 | 1028 | |
|
1029 | 1029 | The new part have the very same content but no partid assigned yet. |
|
1030 | 1030 | Parts with generated data cannot be copied.""" |
|
1031 | 1031 | assert not util.safehasattr(self.data, 'next') |
|
1032 | 1032 | return self.__class__( |
|
1033 | 1033 | self.type, |
|
1034 | 1034 | self._mandatoryparams, |
|
1035 | 1035 | self._advisoryparams, |
|
1036 | 1036 | self._data, |
|
1037 | 1037 | self.mandatory, |
|
1038 | 1038 | ) |
|
1039 | 1039 | |
|
1040 | 1040 | # methods used to defines the part content |
|
1041 | 1041 | @property |
|
1042 | 1042 | def data(self): |
|
1043 | 1043 | return self._data |
|
1044 | 1044 | |
|
1045 | 1045 | @data.setter |
|
1046 | 1046 | def data(self, data): |
|
1047 | 1047 | if self._generated is not None: |
|
1048 | 1048 | raise error.ReadOnlyPartError(b'part is being generated') |
|
1049 | 1049 | self._data = data |
|
1050 | 1050 | |
|
1051 | 1051 | @property |
|
1052 | 1052 | def mandatoryparams(self): |
|
1053 | 1053 | # make it an immutable tuple to force people through ``addparam`` |
|
1054 | 1054 | return tuple(self._mandatoryparams) |
|
1055 | 1055 | |
|
1056 | 1056 | @property |
|
1057 | 1057 | def advisoryparams(self): |
|
1058 | 1058 | # make it an immutable tuple to force people through ``addparam`` |
|
1059 | 1059 | return tuple(self._advisoryparams) |
|
1060 | 1060 | |
|
1061 | 1061 | def addparam(self, name, value=b'', mandatory=True): |
|
1062 | 1062 | """add a parameter to the part |
|
1063 | 1063 | |
|
1064 | 1064 | If 'mandatory' is set to True, the remote handler must claim support |
|
1065 | 1065 | for this parameter or the unbundling will be aborted. |
|
1066 | 1066 | |
|
1067 | 1067 | The 'name' and 'value' cannot exceed 255 bytes each. |
|
1068 | 1068 | """ |
|
1069 | 1069 | if self._generated is not None: |
|
1070 | 1070 | raise error.ReadOnlyPartError(b'part is being generated') |
|
1071 | 1071 | if name in self._seenparams: |
|
1072 | 1072 | raise ValueError(b'duplicated params: %s' % name) |
|
1073 | 1073 | self._seenparams.add(name) |
|
1074 | 1074 | params = self._advisoryparams |
|
1075 | 1075 | if mandatory: |
|
1076 | 1076 | params = self._mandatoryparams |
|
1077 | 1077 | params.append((name, value)) |
|
1078 | 1078 | |
|
1079 | 1079 | # methods used to generates the bundle2 stream |
|
1080 | 1080 | def getchunks(self, ui): |
|
1081 | 1081 | if self._generated is not None: |
|
1082 | 1082 | raise error.ProgrammingError(b'part can only be consumed once') |
|
1083 | 1083 | self._generated = False |
|
1084 | 1084 | |
|
1085 | 1085 | if ui.debugflag: |
|
1086 | 1086 | msg = [b'bundle2-output-part: "%s"' % self.type] |
|
1087 | 1087 | if not self.mandatory: |
|
1088 | 1088 | msg.append(b' (advisory)') |
|
1089 | 1089 | nbmp = len(self.mandatoryparams) |
|
1090 | 1090 | nbap = len(self.advisoryparams) |
|
1091 | 1091 | if nbmp or nbap: |
|
1092 | 1092 | msg.append(b' (params:') |
|
1093 | 1093 | if nbmp: |
|
1094 | 1094 | msg.append(b' %i mandatory' % nbmp) |
|
1095 | 1095 | if nbap: |
|
1096 | 1096 | msg.append(b' %i advisory' % nbmp) |
|
1097 | 1097 | msg.append(b')') |
|
1098 | 1098 | if not self.data: |
|
1099 | 1099 | msg.append(b' empty payload') |
|
1100 | 1100 | elif util.safehasattr(self.data, 'next') or util.safehasattr( |
|
1101 | 1101 | self.data, b'__next__' |
|
1102 | 1102 | ): |
|
1103 | 1103 | msg.append(b' streamed payload') |
|
1104 | 1104 | else: |
|
1105 | 1105 | msg.append(b' %i bytes payload' % len(self.data)) |
|
1106 | 1106 | msg.append(b'\n') |
|
1107 | 1107 | ui.debug(b''.join(msg)) |
|
1108 | 1108 | |
|
1109 | 1109 | #### header |
|
1110 | 1110 | if self.mandatory: |
|
1111 | 1111 | parttype = self.type.upper() |
|
1112 | 1112 | else: |
|
1113 | 1113 | parttype = self.type.lower() |
|
1114 | 1114 | outdebug(ui, b'part %s: "%s"' % (pycompat.bytestr(self.id), parttype)) |
|
1115 | 1115 | ## parttype |
|
1116 | 1116 | header = [ |
|
1117 | 1117 | _pack(_fparttypesize, len(parttype)), |
|
1118 | 1118 | parttype, |
|
1119 | 1119 | _pack(_fpartid, self.id), |
|
1120 | 1120 | ] |
|
1121 | 1121 | ## parameters |
|
1122 | 1122 | # count |
|
1123 | 1123 | manpar = self.mandatoryparams |
|
1124 | 1124 | advpar = self.advisoryparams |
|
1125 | 1125 | header.append(_pack(_fpartparamcount, len(manpar), len(advpar))) |
|
1126 | 1126 | # size |
|
1127 | 1127 | parsizes = [] |
|
1128 | 1128 | for key, value in manpar: |
|
1129 | 1129 | parsizes.append(len(key)) |
|
1130 | 1130 | parsizes.append(len(value)) |
|
1131 | 1131 | for key, value in advpar: |
|
1132 | 1132 | parsizes.append(len(key)) |
|
1133 | 1133 | parsizes.append(len(value)) |
|
1134 | 1134 | paramsizes = _pack(_makefpartparamsizes(len(parsizes) // 2), *parsizes) |
|
1135 | 1135 | header.append(paramsizes) |
|
1136 | 1136 | # key, value |
|
1137 | 1137 | for key, value in manpar: |
|
1138 | 1138 | header.append(key) |
|
1139 | 1139 | header.append(value) |
|
1140 | 1140 | for key, value in advpar: |
|
1141 | 1141 | header.append(key) |
|
1142 | 1142 | header.append(value) |
|
1143 | 1143 | ## finalize header |
|
1144 | 1144 | try: |
|
1145 | 1145 | headerchunk = b''.join(header) |
|
1146 | 1146 | except TypeError: |
|
1147 | 1147 | raise TypeError( |
|
1148 | 1148 | 'Found a non-bytes trying to ' |
|
1149 | 1149 | 'build bundle part header: %r' % header |
|
1150 | 1150 | ) |
|
1151 | 1151 | outdebug(ui, b'header chunk size: %i' % len(headerchunk)) |
|
1152 | 1152 | yield _pack(_fpartheadersize, len(headerchunk)) |
|
1153 | 1153 | yield headerchunk |
|
1154 | 1154 | ## payload |
|
1155 | 1155 | try: |
|
1156 | 1156 | for chunk in self._payloadchunks(): |
|
1157 | 1157 | outdebug(ui, b'payload chunk size: %i' % len(chunk)) |
|
1158 | 1158 | yield _pack(_fpayloadsize, len(chunk)) |
|
1159 | 1159 | yield chunk |
|
1160 | 1160 | except GeneratorExit: |
|
1161 | 1161 | # GeneratorExit means that nobody is listening for our |
|
1162 | 1162 | # results anyway, so just bail quickly rather than trying |
|
1163 | 1163 | # to produce an error part. |
|
1164 | 1164 | ui.debug(b'bundle2-generatorexit\n') |
|
1165 | 1165 | raise |
|
1166 | 1166 | except BaseException as exc: |
|
1167 | 1167 | bexc = stringutil.forcebytestr(exc) |
|
1168 | 1168 | # backup exception data for later |
|
1169 | 1169 | ui.debug( |
|
1170 | 1170 | b'bundle2-input-stream-interrupt: encoding exception %s' % bexc |
|
1171 | 1171 | ) |
|
1172 | 1172 | tb = sys.exc_info()[2] |
|
1173 | 1173 | msg = b'unexpected error: %s' % bexc |
|
1174 | 1174 | interpart = bundlepart( |
|
1175 | 1175 | b'error:abort', [(b'message', msg)], mandatory=False |
|
1176 | 1176 | ) |
|
1177 | 1177 | interpart.id = 0 |
|
1178 | 1178 | yield _pack(_fpayloadsize, -1) |
|
1179 | 1179 | for chunk in interpart.getchunks(ui=ui): |
|
1180 | 1180 | yield chunk |
|
1181 | 1181 | outdebug(ui, b'closing payload chunk') |
|
1182 | 1182 | # abort current part payload |
|
1183 | 1183 | yield _pack(_fpayloadsize, 0) |
|
1184 | 1184 | pycompat.raisewithtb(exc, tb) |
|
1185 | 1185 | # end of payload |
|
1186 | 1186 | outdebug(ui, b'closing payload chunk') |
|
1187 | 1187 | yield _pack(_fpayloadsize, 0) |
|
1188 | 1188 | self._generated = True |
|
1189 | 1189 | |
|
1190 | 1190 | def _payloadchunks(self): |
|
1191 | 1191 | """yield chunks of a the part payload |
|
1192 | 1192 | |
|
1193 | 1193 | Exists to handle the different methods to provide data to a part.""" |
|
1194 | 1194 | # we only support fixed size data now. |
|
1195 | 1195 | # This will be improved in the future. |
|
1196 | 1196 | if util.safehasattr(self.data, 'next') or util.safehasattr( |
|
1197 | 1197 | self.data, b'__next__' |
|
1198 | 1198 | ): |
|
1199 | 1199 | buff = util.chunkbuffer(self.data) |
|
1200 | 1200 | chunk = buff.read(preferedchunksize) |
|
1201 | 1201 | while chunk: |
|
1202 | 1202 | yield chunk |
|
1203 | 1203 | chunk = buff.read(preferedchunksize) |
|
1204 | 1204 | elif len(self.data): |
|
1205 | 1205 | yield self.data |
|
1206 | 1206 | |
|
1207 | 1207 | |
|
1208 | 1208 | flaginterrupt = -1 |
|
1209 | 1209 | |
|
1210 | 1210 | |
|
1211 | 1211 | class interrupthandler(unpackermixin): |
|
1212 | 1212 | """read one part and process it with restricted capability |
|
1213 | 1213 | |
|
1214 | 1214 | This allows to transmit exception raised on the producer size during part |
|
1215 | 1215 | iteration while the consumer is reading a part. |
|
1216 | 1216 | |
|
1217 | 1217 | Part processed in this manner only have access to a ui object,""" |
|
1218 | 1218 | |
|
1219 | 1219 | def __init__(self, ui, fp): |
|
1220 | 1220 | super(interrupthandler, self).__init__(fp) |
|
1221 | 1221 | self.ui = ui |
|
1222 | 1222 | |
|
1223 | 1223 | def _readpartheader(self): |
|
1224 | 1224 | """reads a part header size and return the bytes blob |
|
1225 | 1225 | |
|
1226 | 1226 | returns None if empty""" |
|
1227 | 1227 | headersize = self._unpack(_fpartheadersize)[0] |
|
1228 | 1228 | if headersize < 0: |
|
1229 | 1229 | raise error.BundleValueError( |
|
1230 | 1230 | b'negative part header size: %i' % headersize |
|
1231 | 1231 | ) |
|
1232 | 1232 | indebug(self.ui, b'part header size: %i\n' % headersize) |
|
1233 | 1233 | if headersize: |
|
1234 | 1234 | return self._readexact(headersize) |
|
1235 | 1235 | return None |
|
1236 | 1236 | |
|
1237 | 1237 | def __call__(self): |
|
1238 | 1238 | |
|
1239 | 1239 | self.ui.debug( |
|
1240 | 1240 | b'bundle2-input-stream-interrupt: opening out of band context\n' |
|
1241 | 1241 | ) |
|
1242 | 1242 | indebug(self.ui, b'bundle2 stream interruption, looking for a part.') |
|
1243 | 1243 | headerblock = self._readpartheader() |
|
1244 | 1244 | if headerblock is None: |
|
1245 | 1245 | indebug(self.ui, b'no part found during interruption.') |
|
1246 | 1246 | return |
|
1247 | 1247 | part = unbundlepart(self.ui, headerblock, self._fp) |
|
1248 | 1248 | op = interruptoperation(self.ui) |
|
1249 | 1249 | hardabort = False |
|
1250 | 1250 | try: |
|
1251 | 1251 | _processpart(op, part) |
|
1252 | 1252 | except (SystemExit, KeyboardInterrupt): |
|
1253 | 1253 | hardabort = True |
|
1254 | 1254 | raise |
|
1255 | 1255 | finally: |
|
1256 | 1256 | if not hardabort: |
|
1257 | 1257 | part.consume() |
|
1258 | 1258 | self.ui.debug( |
|
1259 | 1259 | b'bundle2-input-stream-interrupt: closing out of band context\n' |
|
1260 | 1260 | ) |
|
1261 | 1261 | |
|
1262 | 1262 | |
|
1263 | 1263 | class interruptoperation(object): |
|
1264 | 1264 | """A limited operation to be use by part handler during interruption |
|
1265 | 1265 | |
|
1266 | 1266 | It only have access to an ui object. |
|
1267 | 1267 | """ |
|
1268 | 1268 | |
|
1269 | 1269 | def __init__(self, ui): |
|
1270 | 1270 | self.ui = ui |
|
1271 | 1271 | self.reply = None |
|
1272 | 1272 | self.captureoutput = False |
|
1273 | 1273 | |
|
1274 | 1274 | @property |
|
1275 | 1275 | def repo(self): |
|
1276 | 1276 | raise error.ProgrammingError(b'no repo access from stream interruption') |
|
1277 | 1277 | |
|
1278 | 1278 | def gettransaction(self): |
|
1279 | 1279 | raise TransactionUnavailable(b'no repo access from stream interruption') |
|
1280 | 1280 | |
|
1281 | 1281 | |
|
1282 | 1282 | def decodepayloadchunks(ui, fh): |
|
1283 | 1283 | """Reads bundle2 part payload data into chunks. |
|
1284 | 1284 | |
|
1285 | 1285 | Part payload data consists of framed chunks. This function takes |
|
1286 | 1286 | a file handle and emits those chunks. |
|
1287 | 1287 | """ |
|
1288 | 1288 | dolog = ui.configbool(b'devel', b'bundle2.debug') |
|
1289 | 1289 | debug = ui.debug |
|
1290 | 1290 | |
|
1291 | 1291 | headerstruct = struct.Struct(_fpayloadsize) |
|
1292 | 1292 | headersize = headerstruct.size |
|
1293 | 1293 | unpack = headerstruct.unpack |
|
1294 | 1294 | |
|
1295 | 1295 | readexactly = changegroup.readexactly |
|
1296 | 1296 | read = fh.read |
|
1297 | 1297 | |
|
1298 | 1298 | chunksize = unpack(readexactly(fh, headersize))[0] |
|
1299 | 1299 | indebug(ui, b'payload chunk size: %i' % chunksize) |
|
1300 | 1300 | |
|
1301 | 1301 | # changegroup.readexactly() is inlined below for performance. |
|
1302 | 1302 | while chunksize: |
|
1303 | 1303 | if chunksize >= 0: |
|
1304 | 1304 | s = read(chunksize) |
|
1305 | 1305 | if len(s) < chunksize: |
|
1306 | 1306 | raise error.Abort( |
|
1307 | 1307 | _( |
|
1308 | 1308 | b'stream ended unexpectedly ' |
|
1309 | 1309 | b' (got %d bytes, expected %d)' |
|
1310 | 1310 | ) |
|
1311 | 1311 | % (len(s), chunksize) |
|
1312 | 1312 | ) |
|
1313 | 1313 | |
|
1314 | 1314 | yield s |
|
1315 | 1315 | elif chunksize == flaginterrupt: |
|
1316 | 1316 | # Interrupt "signal" detected. The regular stream is interrupted |
|
1317 | 1317 | # and a bundle2 part follows. Consume it. |
|
1318 | 1318 | interrupthandler(ui, fh)() |
|
1319 | 1319 | else: |
|
1320 | 1320 | raise error.BundleValueError( |
|
1321 | 1321 | b'negative payload chunk size: %s' % chunksize |
|
1322 | 1322 | ) |
|
1323 | 1323 | |
|
1324 | 1324 | s = read(headersize) |
|
1325 | 1325 | if len(s) < headersize: |
|
1326 | 1326 | raise error.Abort( |
|
1327 | 1327 | _(b'stream ended unexpectedly (got %d bytes, expected %d)') |
|
1328 | 1328 | % (len(s), chunksize) |
|
1329 | 1329 | ) |
|
1330 | 1330 | |
|
1331 | 1331 | chunksize = unpack(s)[0] |
|
1332 | 1332 | |
|
1333 | 1333 | # indebug() inlined for performance. |
|
1334 | 1334 | if dolog: |
|
1335 | 1335 | debug(b'bundle2-input: payload chunk size: %i\n' % chunksize) |
|
1336 | 1336 | |
|
1337 | 1337 | |
|
1338 | 1338 | class unbundlepart(unpackermixin): |
|
1339 | 1339 | """a bundle part read from a bundle""" |
|
1340 | 1340 | |
|
1341 | 1341 | def __init__(self, ui, header, fp): |
|
1342 | 1342 | super(unbundlepart, self).__init__(fp) |
|
1343 | 1343 | self._seekable = util.safehasattr(fp, 'seek') and util.safehasattr( |
|
1344 | 1344 | fp, b'tell' |
|
1345 | 1345 | ) |
|
1346 | 1346 | self.ui = ui |
|
1347 | 1347 | # unbundle state attr |
|
1348 | 1348 | self._headerdata = header |
|
1349 | 1349 | self._headeroffset = 0 |
|
1350 | 1350 | self._initialized = False |
|
1351 | 1351 | self.consumed = False |
|
1352 | 1352 | # part data |
|
1353 | 1353 | self.id = None |
|
1354 | 1354 | self.type = None |
|
1355 | 1355 | self.mandatoryparams = None |
|
1356 | 1356 | self.advisoryparams = None |
|
1357 | 1357 | self.params = None |
|
1358 | 1358 | self.mandatorykeys = () |
|
1359 | 1359 | self._readheader() |
|
1360 | 1360 | self._mandatory = None |
|
1361 | 1361 | self._pos = 0 |
|
1362 | 1362 | |
|
1363 | 1363 | def _fromheader(self, size): |
|
1364 | 1364 | """return the next <size> byte from the header""" |
|
1365 | 1365 | offset = self._headeroffset |
|
1366 | 1366 | data = self._headerdata[offset : (offset + size)] |
|
1367 | 1367 | self._headeroffset = offset + size |
|
1368 | 1368 | return data |
|
1369 | 1369 | |
|
1370 | 1370 | def _unpackheader(self, format): |
|
1371 | 1371 | """read given format from header |
|
1372 | 1372 | |
|
1373 | 1373 | This automatically compute the size of the format to read.""" |
|
1374 | 1374 | data = self._fromheader(struct.calcsize(format)) |
|
1375 | 1375 | return _unpack(format, data) |
|
1376 | 1376 | |
|
1377 | 1377 | def _initparams(self, mandatoryparams, advisoryparams): |
|
1378 | 1378 | """internal function to setup all logic related parameters""" |
|
1379 | 1379 | # make it read only to prevent people touching it by mistake. |
|
1380 | 1380 | self.mandatoryparams = tuple(mandatoryparams) |
|
1381 | 1381 | self.advisoryparams = tuple(advisoryparams) |
|
1382 | 1382 | # user friendly UI |
|
1383 | 1383 | self.params = util.sortdict(self.mandatoryparams) |
|
1384 | 1384 | self.params.update(self.advisoryparams) |
|
1385 | 1385 | self.mandatorykeys = frozenset(p[0] for p in mandatoryparams) |
|
1386 | 1386 | |
|
1387 | 1387 | def _readheader(self): |
|
1388 | 1388 | """read the header and setup the object""" |
|
1389 | 1389 | typesize = self._unpackheader(_fparttypesize)[0] |
|
1390 | 1390 | self.type = self._fromheader(typesize) |
|
1391 | 1391 | indebug(self.ui, b'part type: "%s"' % self.type) |
|
1392 | 1392 | self.id = self._unpackheader(_fpartid)[0] |
|
1393 | 1393 | indebug(self.ui, b'part id: "%s"' % pycompat.bytestr(self.id)) |
|
1394 | 1394 | # extract mandatory bit from type |
|
1395 | 1395 | self.mandatory = self.type != self.type.lower() |
|
1396 | 1396 | self.type = self.type.lower() |
|
1397 | 1397 | ## reading parameters |
|
1398 | 1398 | # param count |
|
1399 | 1399 | mancount, advcount = self._unpackheader(_fpartparamcount) |
|
1400 | 1400 | indebug(self.ui, b'part parameters: %i' % (mancount + advcount)) |
|
1401 | 1401 | # param size |
|
1402 | 1402 | fparamsizes = _makefpartparamsizes(mancount + advcount) |
|
1403 | 1403 | paramsizes = self._unpackheader(fparamsizes) |
|
1404 | 1404 | # make it a list of couple again |
|
1405 | 1405 | paramsizes = list(zip(paramsizes[::2], paramsizes[1::2])) |
|
1406 | 1406 | # split mandatory from advisory |
|
1407 | 1407 | mansizes = paramsizes[:mancount] |
|
1408 | 1408 | advsizes = paramsizes[mancount:] |
|
1409 | 1409 | # retrieve param value |
|
1410 | 1410 | manparams = [] |
|
1411 | 1411 | for key, value in mansizes: |
|
1412 | 1412 | manparams.append((self._fromheader(key), self._fromheader(value))) |
|
1413 | 1413 | advparams = [] |
|
1414 | 1414 | for key, value in advsizes: |
|
1415 | 1415 | advparams.append((self._fromheader(key), self._fromheader(value))) |
|
1416 | 1416 | self._initparams(manparams, advparams) |
|
1417 | 1417 | ## part payload |
|
1418 | 1418 | self._payloadstream = util.chunkbuffer(self._payloadchunks()) |
|
1419 | 1419 | # we read the data, tell it |
|
1420 | 1420 | self._initialized = True |
|
1421 | 1421 | |
|
1422 | 1422 | def _payloadchunks(self): |
|
1423 | 1423 | """Generator of decoded chunks in the payload.""" |
|
1424 | 1424 | return decodepayloadchunks(self.ui, self._fp) |
|
1425 | 1425 | |
|
1426 | 1426 | def consume(self): |
|
1427 | 1427 | """Read the part payload until completion. |
|
1428 | 1428 | |
|
1429 | 1429 | By consuming the part data, the underlying stream read offset will |
|
1430 | 1430 | be advanced to the next part (or end of stream). |
|
1431 | 1431 | """ |
|
1432 | 1432 | if self.consumed: |
|
1433 | 1433 | return |
|
1434 | 1434 | |
|
1435 | 1435 | chunk = self.read(32768) |
|
1436 | 1436 | while chunk: |
|
1437 | 1437 | self._pos += len(chunk) |
|
1438 | 1438 | chunk = self.read(32768) |
|
1439 | 1439 | |
|
1440 | 1440 | def read(self, size=None): |
|
1441 | 1441 | """read payload data""" |
|
1442 | 1442 | if not self._initialized: |
|
1443 | 1443 | self._readheader() |
|
1444 | 1444 | if size is None: |
|
1445 | 1445 | data = self._payloadstream.read() |
|
1446 | 1446 | else: |
|
1447 | 1447 | data = self._payloadstream.read(size) |
|
1448 | 1448 | self._pos += len(data) |
|
1449 | 1449 | if size is None or len(data) < size: |
|
1450 | 1450 | if not self.consumed and self._pos: |
|
1451 | 1451 | self.ui.debug( |
|
1452 | 1452 | b'bundle2-input-part: total payload size %i\n' % self._pos |
|
1453 | 1453 | ) |
|
1454 | 1454 | self.consumed = True |
|
1455 | 1455 | return data |
|
1456 | 1456 | |
|
1457 | 1457 | |
|
1458 | 1458 | class seekableunbundlepart(unbundlepart): |
|
1459 | 1459 | """A bundle2 part in a bundle that is seekable. |
|
1460 | 1460 | |
|
1461 | 1461 | Regular ``unbundlepart`` instances can only be read once. This class |
|
1462 | 1462 | extends ``unbundlepart`` to enable bi-directional seeking within the |
|
1463 | 1463 | part. |
|
1464 | 1464 | |
|
1465 | 1465 | Bundle2 part data consists of framed chunks. Offsets when seeking |
|
1466 | 1466 | refer to the decoded data, not the offsets in the underlying bundle2 |
|
1467 | 1467 | stream. |
|
1468 | 1468 | |
|
1469 | 1469 | To facilitate quickly seeking within the decoded data, instances of this |
|
1470 | 1470 | class maintain a mapping between offsets in the underlying stream and |
|
1471 | 1471 | the decoded payload. This mapping will consume memory in proportion |
|
1472 | 1472 | to the number of chunks within the payload (which almost certainly |
|
1473 | 1473 | increases in proportion with the size of the part). |
|
1474 | 1474 | """ |
|
1475 | 1475 | |
|
1476 | 1476 | def __init__(self, ui, header, fp): |
|
1477 | 1477 | # (payload, file) offsets for chunk starts. |
|
1478 | 1478 | self._chunkindex = [] |
|
1479 | 1479 | |
|
1480 | 1480 | super(seekableunbundlepart, self).__init__(ui, header, fp) |
|
1481 | 1481 | |
|
1482 | 1482 | def _payloadchunks(self, chunknum=0): |
|
1483 | 1483 | '''seek to specified chunk and start yielding data''' |
|
1484 | 1484 | if len(self._chunkindex) == 0: |
|
1485 | 1485 | assert chunknum == 0, b'Must start with chunk 0' |
|
1486 | 1486 | self._chunkindex.append((0, self._tellfp())) |
|
1487 | 1487 | else: |
|
1488 | 1488 | assert chunknum < len(self._chunkindex), ( |
|
1489 | 1489 | b'Unknown chunk %d' % chunknum |
|
1490 | 1490 | ) |
|
1491 | 1491 | self._seekfp(self._chunkindex[chunknum][1]) |
|
1492 | 1492 | |
|
1493 | 1493 | pos = self._chunkindex[chunknum][0] |
|
1494 | 1494 | |
|
1495 | 1495 | for chunk in decodepayloadchunks(self.ui, self._fp): |
|
1496 | 1496 | chunknum += 1 |
|
1497 | 1497 | pos += len(chunk) |
|
1498 | 1498 | if chunknum == len(self._chunkindex): |
|
1499 | 1499 | self._chunkindex.append((pos, self._tellfp())) |
|
1500 | 1500 | |
|
1501 | 1501 | yield chunk |
|
1502 | 1502 | |
|
1503 | 1503 | def _findchunk(self, pos): |
|
1504 | 1504 | '''for a given payload position, return a chunk number and offset''' |
|
1505 | 1505 | for chunk, (ppos, fpos) in enumerate(self._chunkindex): |
|
1506 | 1506 | if ppos == pos: |
|
1507 | 1507 | return chunk, 0 |
|
1508 | 1508 | elif ppos > pos: |
|
1509 | 1509 | return chunk - 1, pos - self._chunkindex[chunk - 1][0] |
|
1510 | 1510 | raise ValueError(b'Unknown chunk') |
|
1511 | 1511 | |
|
1512 | 1512 | def tell(self): |
|
1513 | 1513 | return self._pos |
|
1514 | 1514 | |
|
1515 | 1515 | def seek(self, offset, whence=os.SEEK_SET): |
|
1516 | 1516 | if whence == os.SEEK_SET: |
|
1517 | 1517 | newpos = offset |
|
1518 | 1518 | elif whence == os.SEEK_CUR: |
|
1519 | 1519 | newpos = self._pos + offset |
|
1520 | 1520 | elif whence == os.SEEK_END: |
|
1521 | 1521 | if not self.consumed: |
|
1522 | 1522 | # Can't use self.consume() here because it advances self._pos. |
|
1523 | 1523 | chunk = self.read(32768) |
|
1524 | 1524 | while chunk: |
|
1525 | 1525 | chunk = self.read(32768) |
|
1526 | 1526 | newpos = self._chunkindex[-1][0] - offset |
|
1527 | 1527 | else: |
|
1528 | 1528 | raise ValueError(b'Unknown whence value: %r' % (whence,)) |
|
1529 | 1529 | |
|
1530 | 1530 | if newpos > self._chunkindex[-1][0] and not self.consumed: |
|
1531 | 1531 | # Can't use self.consume() here because it advances self._pos. |
|
1532 | 1532 | chunk = self.read(32768) |
|
1533 | 1533 | while chunk: |
|
1534 | 1534 | chunk = self.read(32668) |
|
1535 | 1535 | |
|
1536 | 1536 | if not 0 <= newpos <= self._chunkindex[-1][0]: |
|
1537 | 1537 | raise ValueError(b'Offset out of range') |
|
1538 | 1538 | |
|
1539 | 1539 | if self._pos != newpos: |
|
1540 | 1540 | chunk, internaloffset = self._findchunk(newpos) |
|
1541 | 1541 | self._payloadstream = util.chunkbuffer(self._payloadchunks(chunk)) |
|
1542 | 1542 | adjust = self.read(internaloffset) |
|
1543 | 1543 | if len(adjust) != internaloffset: |
|
1544 | 1544 | raise error.Abort(_(b'Seek failed\n')) |
|
1545 | 1545 | self._pos = newpos |
|
1546 | 1546 | |
|
1547 | 1547 | def _seekfp(self, offset, whence=0): |
|
1548 | 1548 | """move the underlying file pointer |
|
1549 | 1549 | |
|
1550 | 1550 | This method is meant for internal usage by the bundle2 protocol only. |
|
1551 | 1551 | They directly manipulate the low level stream including bundle2 level |
|
1552 | 1552 | instruction. |
|
1553 | 1553 | |
|
1554 | 1554 | Do not use it to implement higher-level logic or methods.""" |
|
1555 | 1555 | if self._seekable: |
|
1556 | 1556 | return self._fp.seek(offset, whence) |
|
1557 | 1557 | else: |
|
1558 | 1558 | raise NotImplementedError(_(b'File pointer is not seekable')) |
|
1559 | 1559 | |
|
1560 | 1560 | def _tellfp(self): |
|
1561 | 1561 | """return the file offset, or None if file is not seekable |
|
1562 | 1562 | |
|
1563 | 1563 | This method is meant for internal usage by the bundle2 protocol only. |
|
1564 | 1564 | They directly manipulate the low level stream including bundle2 level |
|
1565 | 1565 | instruction. |
|
1566 | 1566 | |
|
1567 | 1567 | Do not use it to implement higher-level logic or methods.""" |
|
1568 | 1568 | if self._seekable: |
|
1569 | 1569 | try: |
|
1570 | 1570 | return self._fp.tell() |
|
1571 | 1571 | except IOError as e: |
|
1572 | 1572 | if e.errno == errno.ESPIPE: |
|
1573 | 1573 | self._seekable = False |
|
1574 | 1574 | else: |
|
1575 | 1575 | raise |
|
1576 | 1576 | return None |
|
1577 | 1577 | |
|
1578 | 1578 | |
|
1579 | 1579 | # These are only the static capabilities. |
|
1580 | 1580 | # Check the 'getrepocaps' function for the rest. |
|
1581 | 1581 | capabilities = { |
|
1582 | 1582 | b'HG20': (), |
|
1583 | 1583 | b'bookmarks': (), |
|
1584 | 1584 | b'error': (b'abort', b'unsupportedcontent', b'pushraced', b'pushkey'), |
|
1585 | 1585 | b'listkeys': (), |
|
1586 | 1586 | b'pushkey': (), |
|
1587 | 1587 | b'digests': tuple(sorted(util.DIGESTS.keys())), |
|
1588 | 1588 | b'remote-changegroup': (b'http', b'https'), |
|
1589 | 1589 | b'hgtagsfnodes': (), |
|
1590 | 1590 | b'rev-branch-cache': (), |
|
1591 | 1591 | b'phases': (b'heads',), |
|
1592 | 1592 | b'stream': (b'v2',), |
|
1593 | 1593 | } |
|
1594 | 1594 | |
|
1595 | 1595 | |
|
1596 | 1596 | def getrepocaps(repo, allowpushback=False, role=None): |
|
1597 | 1597 | """return the bundle2 capabilities for a given repo |
|
1598 | 1598 | |
|
1599 | 1599 | Exists to allow extensions (like evolution) to mutate the capabilities. |
|
1600 | 1600 | |
|
1601 | 1601 | The returned value is used for servers advertising their capabilities as |
|
1602 | 1602 | well as clients advertising their capabilities to servers as part of |
|
1603 | 1603 | bundle2 requests. The ``role`` argument specifies which is which. |
|
1604 | 1604 | """ |
|
1605 | 1605 | if role not in (b'client', b'server'): |
|
1606 | 1606 | raise error.ProgrammingError(b'role argument must be client or server') |
|
1607 | 1607 | |
|
1608 | 1608 | caps = capabilities.copy() |
|
1609 | 1609 | caps[b'changegroup'] = tuple( |
|
1610 | 1610 | sorted(changegroup.supportedincomingversions(repo)) |
|
1611 | 1611 | ) |
|
1612 | 1612 | if obsolete.isenabled(repo, obsolete.exchangeopt): |
|
1613 | 1613 | supportedformat = tuple(b'V%i' % v for v in obsolete.formats) |
|
1614 | 1614 | caps[b'obsmarkers'] = supportedformat |
|
1615 | 1615 | if allowpushback: |
|
1616 | 1616 | caps[b'pushback'] = () |
|
1617 | 1617 | cpmode = repo.ui.config(b'server', b'concurrent-push-mode') |
|
1618 | 1618 | if cpmode == b'check-related': |
|
1619 | 1619 | caps[b'checkheads'] = (b'related',) |
|
1620 | 1620 | if b'phases' in repo.ui.configlist(b'devel', b'legacy.exchange'): |
|
1621 | 1621 | caps.pop(b'phases') |
|
1622 | 1622 | |
|
1623 | 1623 | # Don't advertise stream clone support in server mode if not configured. |
|
1624 | 1624 | if role == b'server': |
|
1625 | 1625 | streamsupported = repo.ui.configbool( |
|
1626 | 1626 | b'server', b'uncompressed', untrusted=True |
|
1627 | 1627 | ) |
|
1628 | 1628 | featuresupported = repo.ui.configbool(b'server', b'bundle2.stream') |
|
1629 | 1629 | |
|
1630 | 1630 | if not streamsupported or not featuresupported: |
|
1631 | 1631 | caps.pop(b'stream') |
|
1632 | 1632 | # Else always advertise support on client, because payload support |
|
1633 | 1633 | # should always be advertised. |
|
1634 | 1634 | |
|
1635 | 1635 | return caps |
|
1636 | 1636 | |
|
1637 | 1637 | |
|
1638 | 1638 | def bundle2caps(remote): |
|
1639 | 1639 | """return the bundle capabilities of a peer as dict""" |
|
1640 | 1640 | raw = remote.capable(b'bundle2') |
|
1641 | 1641 | if not raw and raw != b'': |
|
1642 | 1642 | return {} |
|
1643 | 1643 | capsblob = urlreq.unquote(remote.capable(b'bundle2')) |
|
1644 | 1644 | return decodecaps(capsblob) |
|
1645 | 1645 | |
|
1646 | 1646 | |
|
1647 | 1647 | def obsmarkersversion(caps): |
|
1648 | 1648 | """extract the list of supported obsmarkers versions from a bundle2caps dict |
|
1649 | 1649 | """ |
|
1650 | 1650 | obscaps = caps.get(b'obsmarkers', ()) |
|
1651 | 1651 | return [int(c[1:]) for c in obscaps if c.startswith(b'V')] |
|
1652 | 1652 | |
|
1653 | 1653 | |
|
1654 | 1654 | def writenewbundle( |
|
1655 | 1655 | ui, |
|
1656 | 1656 | repo, |
|
1657 | 1657 | source, |
|
1658 | 1658 | filename, |
|
1659 | 1659 | bundletype, |
|
1660 | 1660 | outgoing, |
|
1661 | 1661 | opts, |
|
1662 | 1662 | vfs=None, |
|
1663 | 1663 | compression=None, |
|
1664 | 1664 | compopts=None, |
|
1665 | 1665 | ): |
|
1666 | 1666 | if bundletype.startswith(b'HG10'): |
|
1667 | 1667 | cg = changegroup.makechangegroup(repo, outgoing, b'01', source) |
|
1668 | 1668 | return writebundle( |
|
1669 | 1669 | ui, |
|
1670 | 1670 | cg, |
|
1671 | 1671 | filename, |
|
1672 | 1672 | bundletype, |
|
1673 | 1673 | vfs=vfs, |
|
1674 | 1674 | compression=compression, |
|
1675 | 1675 | compopts=compopts, |
|
1676 | 1676 | ) |
|
1677 | 1677 | elif not bundletype.startswith(b'HG20'): |
|
1678 | 1678 | raise error.ProgrammingError(b'unknown bundle type: %s' % bundletype) |
|
1679 | 1679 | |
|
1680 | 1680 | caps = {} |
|
1681 | 1681 | if b'obsolescence' in opts: |
|
1682 | 1682 | caps[b'obsmarkers'] = (b'V1',) |
|
1683 | 1683 | bundle = bundle20(ui, caps) |
|
1684 | 1684 | bundle.setcompression(compression, compopts) |
|
1685 | 1685 | _addpartsfromopts(ui, repo, bundle, source, outgoing, opts) |
|
1686 | 1686 | chunkiter = bundle.getchunks() |
|
1687 | 1687 | |
|
1688 | 1688 | return changegroup.writechunks(ui, chunkiter, filename, vfs=vfs) |
|
1689 | 1689 | |
|
1690 | 1690 | |
|
1691 | 1691 | def _addpartsfromopts(ui, repo, bundler, source, outgoing, opts): |
|
1692 | 1692 | # We should eventually reconcile this logic with the one behind |
|
1693 | 1693 | # 'exchange.getbundle2partsgenerator'. |
|
1694 | 1694 | # |
|
1695 | 1695 | # The type of input from 'getbundle' and 'writenewbundle' are a bit |
|
1696 | 1696 | # different right now. So we keep them separated for now for the sake of |
|
1697 | 1697 | # simplicity. |
|
1698 | 1698 | |
|
1699 | 1699 | # we might not always want a changegroup in such bundle, for example in |
|
1700 | 1700 | # stream bundles |
|
1701 | 1701 | if opts.get(b'changegroup', True): |
|
1702 | 1702 | cgversion = opts.get(b'cg.version') |
|
1703 | 1703 | if cgversion is None: |
|
1704 | 1704 | cgversion = changegroup.safeversion(repo) |
|
1705 | 1705 | cg = changegroup.makechangegroup(repo, outgoing, cgversion, source) |
|
1706 | 1706 | part = bundler.newpart(b'changegroup', data=cg.getchunks()) |
|
1707 | 1707 | part.addparam(b'version', cg.version) |
|
1708 | 1708 | if b'clcount' in cg.extras: |
|
1709 | 1709 | part.addparam( |
|
1710 | 1710 | b'nbchanges', b'%d' % cg.extras[b'clcount'], mandatory=False |
|
1711 | 1711 | ) |
|
1712 | 1712 | if opts.get(b'phases') and repo.revs( |
|
1713 | 1713 | b'%ln and secret()', outgoing.missingheads |
|
1714 | 1714 | ): |
|
1715 | 1715 | part.addparam( |
|
1716 | 1716 | b'targetphase', b'%d' % phases.secret, mandatory=False |
|
1717 | 1717 | ) |
|
1718 | 1718 | if b'exp-sidedata-flag' in repo.requirements: |
|
1719 | 1719 | part.addparam(b'exp-sidedata', b'1') |
|
1720 | 1720 | |
|
1721 | 1721 | if opts.get(b'streamv2', False): |
|
1722 | 1722 | addpartbundlestream2(bundler, repo, stream=True) |
|
1723 | 1723 | |
|
1724 | 1724 | if opts.get(b'tagsfnodescache', True): |
|
1725 | 1725 | addparttagsfnodescache(repo, bundler, outgoing) |
|
1726 | 1726 | |
|
1727 | 1727 | if opts.get(b'revbranchcache', True): |
|
1728 | 1728 | addpartrevbranchcache(repo, bundler, outgoing) |
|
1729 | 1729 | |
|
1730 | 1730 | if opts.get(b'obsolescence', False): |
|
1731 | 1731 | obsmarkers = repo.obsstore.relevantmarkers(outgoing.missing) |
|
1732 | 1732 | buildobsmarkerspart(bundler, obsmarkers) |
|
1733 | 1733 | |
|
1734 | 1734 | if opts.get(b'phases', False): |
|
1735 | 1735 | headsbyphase = phases.subsetphaseheads(repo, outgoing.missing) |
|
1736 | 1736 | phasedata = phases.binaryencode(headsbyphase) |
|
1737 | 1737 | bundler.newpart(b'phase-heads', data=phasedata) |
|
1738 | 1738 | |
|
1739 | 1739 | |
|
1740 | 1740 | def addparttagsfnodescache(repo, bundler, outgoing): |
|
1741 | 1741 | # we include the tags fnode cache for the bundle changeset |
|
1742 | 1742 | # (as an optional parts) |
|
1743 | 1743 | cache = tags.hgtagsfnodescache(repo.unfiltered()) |
|
1744 | 1744 | chunks = [] |
|
1745 | 1745 | |
|
1746 | 1746 | # .hgtags fnodes are only relevant for head changesets. While we could |
|
1747 | 1747 | # transfer values for all known nodes, there will likely be little to |
|
1748 | 1748 | # no benefit. |
|
1749 | 1749 | # |
|
1750 | 1750 | # We don't bother using a generator to produce output data because |
|
1751 | 1751 | # a) we only have 40 bytes per head and even esoteric numbers of heads |
|
1752 | 1752 | # consume little memory (1M heads is 40MB) b) we don't want to send the |
|
1753 | 1753 | # part if we don't have entries and knowing if we have entries requires |
|
1754 | 1754 | # cache lookups. |
|
1755 | 1755 | for node in outgoing.missingheads: |
|
1756 | 1756 | # Don't compute missing, as this may slow down serving. |
|
1757 | 1757 | fnode = cache.getfnode(node, computemissing=False) |
|
1758 | 1758 | if fnode is not None: |
|
1759 | 1759 | chunks.extend([node, fnode]) |
|
1760 | 1760 | |
|
1761 | 1761 | if chunks: |
|
1762 | 1762 | bundler.newpart(b'hgtagsfnodes', data=b''.join(chunks)) |
|
1763 | 1763 | |
|
1764 | 1764 | |
|
1765 | 1765 | def addpartrevbranchcache(repo, bundler, outgoing): |
|
1766 | 1766 | # we include the rev branch cache for the bundle changeset |
|
1767 | 1767 | # (as an optional parts) |
|
1768 | 1768 | cache = repo.revbranchcache() |
|
1769 | 1769 | cl = repo.unfiltered().changelog |
|
1770 | 1770 | branchesdata = collections.defaultdict(lambda: (set(), set())) |
|
1771 | 1771 | for node in outgoing.missing: |
|
1772 | 1772 | branch, close = cache.branchinfo(cl.rev(node)) |
|
1773 | 1773 | branchesdata[branch][close].add(node) |
|
1774 | 1774 | |
|
1775 | 1775 | def generate(): |
|
1776 | 1776 | for branch, (nodes, closed) in sorted(branchesdata.items()): |
|
1777 | 1777 | utf8branch = encoding.fromlocal(branch) |
|
1778 | 1778 | yield rbcstruct.pack(len(utf8branch), len(nodes), len(closed)) |
|
1779 | 1779 | yield utf8branch |
|
1780 | 1780 | for n in sorted(nodes): |
|
1781 | 1781 | yield n |
|
1782 | 1782 | for n in sorted(closed): |
|
1783 | 1783 | yield n |
|
1784 | 1784 | |
|
1785 | 1785 | bundler.newpart(b'cache:rev-branch-cache', data=generate(), mandatory=False) |
|
1786 | 1786 | |
|
1787 | 1787 | |
|
1788 | 1788 | def _formatrequirementsspec(requirements): |
|
1789 | 1789 | requirements = [req for req in requirements if req != b"shared"] |
|
1790 | 1790 | return urlreq.quote(b','.join(sorted(requirements))) |
|
1791 | 1791 | |
|
1792 | 1792 | |
|
1793 | 1793 | def _formatrequirementsparams(requirements): |
|
1794 | 1794 | requirements = _formatrequirementsspec(requirements) |
|
1795 | 1795 | params = b"%s%s" % (urlreq.quote(b"requirements="), requirements) |
|
1796 | 1796 | return params |
|
1797 | 1797 | |
|
1798 | 1798 | |
|
1799 | 1799 | def addpartbundlestream2(bundler, repo, **kwargs): |
|
1800 | 1800 | if not kwargs.get('stream', False): |
|
1801 | 1801 | return |
|
1802 | 1802 | |
|
1803 | 1803 | if not streamclone.allowservergeneration(repo): |
|
1804 | 1804 | raise error.Abort( |
|
1805 | 1805 | _( |
|
1806 | 1806 | b'stream data requested but server does not allow ' |
|
1807 | 1807 | b'this feature' |
|
1808 | 1808 | ), |
|
1809 | 1809 | hint=_( |
|
1810 | 1810 | b'well-behaved clients should not be ' |
|
1811 | 1811 | b'requesting stream data from servers not ' |
|
1812 | 1812 | b'advertising it; the client may be buggy' |
|
1813 | 1813 | ), |
|
1814 | 1814 | ) |
|
1815 | 1815 | |
|
1816 | 1816 | # Stream clones don't compress well. And compression undermines a |
|
1817 | 1817 | # goal of stream clones, which is to be fast. Communicate the desire |
|
1818 | 1818 | # to avoid compression to consumers of the bundle. |
|
1819 | 1819 | bundler.prefercompressed = False |
|
1820 | 1820 | |
|
1821 | 1821 | # get the includes and excludes |
|
1822 | 1822 | includepats = kwargs.get('includepats') |
|
1823 | 1823 | excludepats = kwargs.get('excludepats') |
|
1824 | 1824 | |
|
1825 | 1825 | narrowstream = repo.ui.configbool( |
|
1826 | 1826 | b'experimental', b'server.stream-narrow-clones' |
|
1827 | 1827 | ) |
|
1828 | 1828 | |
|
1829 | 1829 | if (includepats or excludepats) and not narrowstream: |
|
1830 | 1830 | raise error.Abort(_(b'server does not support narrow stream clones')) |
|
1831 | 1831 | |
|
1832 | 1832 | includeobsmarkers = False |
|
1833 | 1833 | if repo.obsstore: |
|
1834 | 1834 | remoteversions = obsmarkersversion(bundler.capabilities) |
|
1835 | 1835 | if not remoteversions: |
|
1836 | 1836 | raise error.Abort( |
|
1837 | 1837 | _( |
|
1838 | 1838 | b'server has obsolescence markers, but client ' |
|
1839 | 1839 | b'cannot receive them via stream clone' |
|
1840 | 1840 | ) |
|
1841 | 1841 | ) |
|
1842 | 1842 | elif repo.obsstore._version in remoteversions: |
|
1843 | 1843 | includeobsmarkers = True |
|
1844 | 1844 | |
|
1845 | 1845 | filecount, bytecount, it = streamclone.generatev2( |
|
1846 | 1846 | repo, includepats, excludepats, includeobsmarkers |
|
1847 | 1847 | ) |
|
1848 | 1848 | requirements = _formatrequirementsspec(repo.requirements) |
|
1849 | 1849 | part = bundler.newpart(b'stream2', data=it) |
|
1850 | 1850 | part.addparam(b'bytecount', b'%d' % bytecount, mandatory=True) |
|
1851 | 1851 | part.addparam(b'filecount', b'%d' % filecount, mandatory=True) |
|
1852 | 1852 | part.addparam(b'requirements', requirements, mandatory=True) |
|
1853 | 1853 | |
|
1854 | 1854 | |
|
1855 | 1855 | def buildobsmarkerspart(bundler, markers): |
|
1856 | 1856 | """add an obsmarker part to the bundler with <markers> |
|
1857 | 1857 | |
|
1858 | 1858 | No part is created if markers is empty. |
|
1859 | 1859 | Raises ValueError if the bundler doesn't support any known obsmarker format. |
|
1860 | 1860 | """ |
|
1861 | 1861 | if not markers: |
|
1862 | 1862 | return None |
|
1863 | 1863 | |
|
1864 | 1864 | remoteversions = obsmarkersversion(bundler.capabilities) |
|
1865 | 1865 | version = obsolete.commonversion(remoteversions) |
|
1866 | 1866 | if version is None: |
|
1867 | 1867 | raise ValueError(b'bundler does not support common obsmarker format') |
|
1868 | 1868 | stream = obsolete.encodemarkers(markers, True, version=version) |
|
1869 | 1869 | return bundler.newpart(b'obsmarkers', data=stream) |
|
1870 | 1870 | |
|
1871 | 1871 | |
|
1872 | 1872 | def writebundle( |
|
1873 | 1873 | ui, cg, filename, bundletype, vfs=None, compression=None, compopts=None |
|
1874 | 1874 | ): |
|
1875 | 1875 | """Write a bundle file and return its filename. |
|
1876 | 1876 | |
|
1877 | 1877 | Existing files will not be overwritten. |
|
1878 | 1878 | If no filename is specified, a temporary file is created. |
|
1879 | 1879 | bz2 compression can be turned off. |
|
1880 | 1880 | The bundle file will be deleted in case of errors. |
|
1881 | 1881 | """ |
|
1882 | 1882 | |
|
1883 | 1883 | if bundletype == b"HG20": |
|
1884 | 1884 | bundle = bundle20(ui) |
|
1885 | 1885 | bundle.setcompression(compression, compopts) |
|
1886 | 1886 | part = bundle.newpart(b'changegroup', data=cg.getchunks()) |
|
1887 | 1887 | part.addparam(b'version', cg.version) |
|
1888 | 1888 | if b'clcount' in cg.extras: |
|
1889 | 1889 | part.addparam( |
|
1890 | 1890 | b'nbchanges', b'%d' % cg.extras[b'clcount'], mandatory=False |
|
1891 | 1891 | ) |
|
1892 | 1892 | chunkiter = bundle.getchunks() |
|
1893 | 1893 | else: |
|
1894 | 1894 | # compression argument is only for the bundle2 case |
|
1895 | 1895 | assert compression is None |
|
1896 | 1896 | if cg.version != b'01': |
|
1897 | 1897 | raise error.Abort( |
|
1898 | 1898 | _(b'old bundle types only supports v1 changegroups') |
|
1899 | 1899 | ) |
|
1900 | 1900 | header, comp = bundletypes[bundletype] |
|
1901 | 1901 | if comp not in util.compengines.supportedbundletypes: |
|
1902 | 1902 | raise error.Abort(_(b'unknown stream compression type: %s') % comp) |
|
1903 | 1903 | compengine = util.compengines.forbundletype(comp) |
|
1904 | 1904 | |
|
1905 | 1905 | def chunkiter(): |
|
1906 | 1906 | yield header |
|
1907 | 1907 | for chunk in compengine.compressstream(cg.getchunks(), compopts): |
|
1908 | 1908 | yield chunk |
|
1909 | 1909 | |
|
1910 | 1910 | chunkiter = chunkiter() |
|
1911 | 1911 | |
|
1912 | 1912 | # parse the changegroup data, otherwise we will block |
|
1913 | 1913 | # in case of sshrepo because we don't know the end of the stream |
|
1914 | 1914 | return changegroup.writechunks(ui, chunkiter, filename, vfs=vfs) |
|
1915 | 1915 | |
|
1916 | 1916 | |
|
1917 | 1917 | def combinechangegroupresults(op): |
|
1918 | 1918 | """logic to combine 0 or more addchangegroup results into one""" |
|
1919 | 1919 | results = [r.get(b'return', 0) for r in op.records[b'changegroup']] |
|
1920 | 1920 | changedheads = 0 |
|
1921 | 1921 | result = 1 |
|
1922 | 1922 | for ret in results: |
|
1923 | 1923 | # If any changegroup result is 0, return 0 |
|
1924 | 1924 | if ret == 0: |
|
1925 | 1925 | result = 0 |
|
1926 | 1926 | break |
|
1927 | 1927 | if ret < -1: |
|
1928 | 1928 | changedheads += ret + 1 |
|
1929 | 1929 | elif ret > 1: |
|
1930 | 1930 | changedheads += ret - 1 |
|
1931 | 1931 | if changedheads > 0: |
|
1932 | 1932 | result = 1 + changedheads |
|
1933 | 1933 | elif changedheads < 0: |
|
1934 | 1934 | result = -1 + changedheads |
|
1935 | 1935 | return result |
|
1936 | 1936 | |
|
1937 | 1937 | |
|
1938 | 1938 | @parthandler( |
|
1939 | 1939 | b'changegroup', |
|
1940 | 1940 | ( |
|
1941 | 1941 | b'version', |
|
1942 | 1942 | b'nbchanges', |
|
1943 | 1943 | b'exp-sidedata', |
|
1944 | 1944 | b'treemanifest', |
|
1945 | 1945 | b'targetphase', |
|
1946 | 1946 | ), |
|
1947 | 1947 | ) |
|
1948 | 1948 | def handlechangegroup(op, inpart): |
|
1949 | 1949 | """apply a changegroup part on the repo |
|
1950 | 1950 | |
|
1951 | 1951 | This is a very early implementation that will massive rework before being |
|
1952 | 1952 | inflicted to any end-user. |
|
1953 | 1953 | """ |
|
1954 | 1954 | from . import localrepo |
|
1955 | 1955 | |
|
1956 | 1956 | tr = op.gettransaction() |
|
1957 | 1957 | unpackerversion = inpart.params.get(b'version', b'01') |
|
1958 | 1958 | # We should raise an appropriate exception here |
|
1959 | 1959 | cg = changegroup.getunbundler(unpackerversion, inpart, None) |
|
1960 | 1960 | # the source and url passed here are overwritten by the one contained in |
|
1961 | 1961 | # the transaction.hookargs argument. So 'bundle2' is a placeholder |
|
1962 | 1962 | nbchangesets = None |
|
1963 | 1963 | if b'nbchanges' in inpart.params: |
|
1964 | 1964 | nbchangesets = int(inpart.params.get(b'nbchanges')) |
|
1965 | 1965 | if ( |
|
1966 | 1966 | b'treemanifest' in inpart.params |
|
1967 | 1967 | and b'treemanifest' not in op.repo.requirements |
|
1968 | 1968 | ): |
|
1969 | 1969 | if len(op.repo.changelog) != 0: |
|
1970 | 1970 | raise error.Abort( |
|
1971 | 1971 | _( |
|
1972 | 1972 | b"bundle contains tree manifests, but local repo is " |
|
1973 | 1973 | b"non-empty and does not use tree manifests" |
|
1974 | 1974 | ) |
|
1975 | 1975 | ) |
|
1976 | 1976 | op.repo.requirements.add(b'treemanifest') |
|
1977 | 1977 | op.repo.svfs.options = localrepo.resolvestorevfsoptions( |
|
1978 | 1978 | op.repo.ui, op.repo.requirements, op.repo.features |
|
1979 | 1979 | ) |
|
1980 | 1980 | op.repo._writerequirements() |
|
1981 | 1981 | |
|
1982 | 1982 | bundlesidedata = bool(b'exp-sidedata' in inpart.params) |
|
1983 | 1983 | reposidedata = bool(b'exp-sidedata-flag' in op.repo.requirements) |
|
1984 | 1984 | if reposidedata and not bundlesidedata: |
|
1985 | 1985 | msg = b"repository is using sidedata but the bundle source do not" |
|
1986 | 1986 | hint = b'this is currently unsupported' |
|
1987 | 1987 | raise error.Abort(msg, hint=hint) |
|
1988 | 1988 | |
|
1989 | 1989 | extrakwargs = {} |
|
1990 | 1990 | targetphase = inpart.params.get(b'targetphase') |
|
1991 | 1991 | if targetphase is not None: |
|
1992 | 1992 | extrakwargs['targetphase'] = int(targetphase) |
|
1993 | 1993 | ret = _processchangegroup( |
|
1994 | 1994 | op, |
|
1995 | 1995 | cg, |
|
1996 | 1996 | tr, |
|
1997 | 1997 | b'bundle2', |
|
1998 | 1998 | b'bundle2', |
|
1999 | 1999 | expectedtotal=nbchangesets, |
|
2000 | 2000 | **extrakwargs |
|
2001 | 2001 | ) |
|
2002 | 2002 | if op.reply is not None: |
|
2003 | 2003 | # This is definitely not the final form of this |
|
2004 | 2004 | # return. But one need to start somewhere. |
|
2005 | 2005 | part = op.reply.newpart(b'reply:changegroup', mandatory=False) |
|
2006 | 2006 | part.addparam( |
|
2007 | 2007 | b'in-reply-to', pycompat.bytestr(inpart.id), mandatory=False |
|
2008 | 2008 | ) |
|
2009 | 2009 | part.addparam(b'return', b'%i' % ret, mandatory=False) |
|
2010 | 2010 | assert not inpart.read() |
|
2011 | 2011 | |
|
2012 | 2012 | |
|
2013 | 2013 | _remotechangegroupparams = tuple( |
|
2014 | 2014 | [b'url', b'size', b'digests'] |
|
2015 | 2015 | + [b'digest:%s' % k for k in util.DIGESTS.keys()] |
|
2016 | 2016 | ) |
|
2017 | 2017 | |
|
2018 | 2018 | |
|
2019 | 2019 | @parthandler(b'remote-changegroup', _remotechangegroupparams) |
|
2020 | 2020 | def handleremotechangegroup(op, inpart): |
|
2021 | 2021 | """apply a bundle10 on the repo, given an url and validation information |
|
2022 | 2022 | |
|
2023 | 2023 | All the information about the remote bundle to import are given as |
|
2024 | 2024 | parameters. The parameters include: |
|
2025 | 2025 | - url: the url to the bundle10. |
|
2026 | 2026 | - size: the bundle10 file size. It is used to validate what was |
|
2027 | 2027 | retrieved by the client matches the server knowledge about the bundle. |
|
2028 | 2028 | - digests: a space separated list of the digest types provided as |
|
2029 | 2029 | parameters. |
|
2030 | 2030 | - digest:<digest-type>: the hexadecimal representation of the digest with |
|
2031 | 2031 | that name. Like the size, it is used to validate what was retrieved by |
|
2032 | 2032 | the client matches what the server knows about the bundle. |
|
2033 | 2033 | |
|
2034 | 2034 | When multiple digest types are given, all of them are checked. |
|
2035 | 2035 | """ |
|
2036 | 2036 | try: |
|
2037 | 2037 | raw_url = inpart.params[b'url'] |
|
2038 | 2038 | except KeyError: |
|
2039 | 2039 | raise error.Abort(_(b'remote-changegroup: missing "%s" param') % b'url') |
|
2040 | 2040 | parsed_url = util.url(raw_url) |
|
2041 | 2041 | if parsed_url.scheme not in capabilities[b'remote-changegroup']: |
|
2042 | 2042 | raise error.Abort( |
|
2043 | 2043 | _(b'remote-changegroup does not support %s urls') |
|
2044 | 2044 | % parsed_url.scheme |
|
2045 | 2045 | ) |
|
2046 | 2046 | |
|
2047 | 2047 | try: |
|
2048 | 2048 | size = int(inpart.params[b'size']) |
|
2049 | 2049 | except ValueError: |
|
2050 | 2050 | raise error.Abort( |
|
2051 | 2051 | _(b'remote-changegroup: invalid value for param "%s"') % b'size' |
|
2052 | 2052 | ) |
|
2053 | 2053 | except KeyError: |
|
2054 | 2054 | raise error.Abort( |
|
2055 | 2055 | _(b'remote-changegroup: missing "%s" param') % b'size' |
|
2056 | 2056 | ) |
|
2057 | 2057 | |
|
2058 | 2058 | digests = {} |
|
2059 | 2059 | for typ in inpart.params.get(b'digests', b'').split(): |
|
2060 | 2060 | param = b'digest:%s' % typ |
|
2061 | 2061 | try: |
|
2062 | 2062 | value = inpart.params[param] |
|
2063 | 2063 | except KeyError: |
|
2064 | 2064 | raise error.Abort( |
|
2065 | 2065 | _(b'remote-changegroup: missing "%s" param') % param |
|
2066 | 2066 | ) |
|
2067 | 2067 | digests[typ] = value |
|
2068 | 2068 | |
|
2069 | 2069 | real_part = util.digestchecker(url.open(op.ui, raw_url), size, digests) |
|
2070 | 2070 | |
|
2071 | 2071 | tr = op.gettransaction() |
|
2072 | 2072 | from . import exchange |
|
2073 | 2073 | |
|
2074 | 2074 | cg = exchange.readbundle(op.repo.ui, real_part, raw_url) |
|
2075 | 2075 | if not isinstance(cg, changegroup.cg1unpacker): |
|
2076 | 2076 | raise error.Abort( |
|
2077 | 2077 | _(b'%s: not a bundle version 1.0') % util.hidepassword(raw_url) |
|
2078 | 2078 | ) |
|
2079 | 2079 | ret = _processchangegroup(op, cg, tr, b'bundle2', b'bundle2') |
|
2080 | 2080 | if op.reply is not None: |
|
2081 | 2081 | # This is definitely not the final form of this |
|
2082 | 2082 | # return. But one need to start somewhere. |
|
2083 | 2083 | part = op.reply.newpart(b'reply:changegroup') |
|
2084 | 2084 | part.addparam( |
|
2085 | 2085 | b'in-reply-to', pycompat.bytestr(inpart.id), mandatory=False |
|
2086 | 2086 | ) |
|
2087 | 2087 | part.addparam(b'return', b'%i' % ret, mandatory=False) |
|
2088 | 2088 | try: |
|
2089 | 2089 | real_part.validate() |
|
2090 | 2090 | except error.Abort as e: |
|
2091 | 2091 | raise error.Abort( |
|
2092 | 2092 | _(b'bundle at %s is corrupted:\n%s') |
|
2093 | 2093 | % (util.hidepassword(raw_url), bytes(e)) |
|
2094 | 2094 | ) |
|
2095 | 2095 | assert not inpart.read() |
|
2096 | 2096 | |
|
2097 | 2097 | |
|
2098 | 2098 | @parthandler(b'reply:changegroup', (b'return', b'in-reply-to')) |
|
2099 | 2099 | def handlereplychangegroup(op, inpart): |
|
2100 | 2100 | ret = int(inpart.params[b'return']) |
|
2101 | 2101 | replyto = int(inpart.params[b'in-reply-to']) |
|
2102 | 2102 | op.records.add(b'changegroup', {b'return': ret}, replyto) |
|
2103 | 2103 | |
|
2104 | 2104 | |
|
2105 | 2105 | @parthandler(b'check:bookmarks') |
|
2106 | 2106 | def handlecheckbookmarks(op, inpart): |
|
2107 | 2107 | """check location of bookmarks |
|
2108 | 2108 | |
|
2109 | 2109 | This part is to be used to detect push race regarding bookmark, it |
|
2110 | 2110 | contains binary encoded (bookmark, node) tuple. If the local state does |
|
2111 | 2111 | not marks the one in the part, a PushRaced exception is raised |
|
2112 | 2112 | """ |
|
2113 | 2113 | bookdata = bookmarks.binarydecode(inpart) |
|
2114 | 2114 | |
|
2115 | 2115 | msgstandard = ( |
|
2116 | 2116 | b'remote repository changed while pushing - please try again ' |
|
2117 | 2117 | b'(bookmark "%s" move from %s to %s)' |
|
2118 | 2118 | ) |
|
2119 | 2119 | msgmissing = ( |
|
2120 | 2120 | b'remote repository changed while pushing - please try again ' |
|
2121 | 2121 | b'(bookmark "%s" is missing, expected %s)' |
|
2122 | 2122 | ) |
|
2123 | 2123 | msgexist = ( |
|
2124 | 2124 | b'remote repository changed while pushing - please try again ' |
|
2125 | 2125 | b'(bookmark "%s" set on %s, expected missing)' |
|
2126 | 2126 | ) |
|
2127 | 2127 | for book, node in bookdata: |
|
2128 | 2128 | currentnode = op.repo._bookmarks.get(book) |
|
2129 | 2129 | if currentnode != node: |
|
2130 | 2130 | if node is None: |
|
2131 | 2131 | finalmsg = msgexist % (book, nodemod.short(currentnode)) |
|
2132 | 2132 | elif currentnode is None: |
|
2133 | 2133 | finalmsg = msgmissing % (book, nodemod.short(node)) |
|
2134 | 2134 | else: |
|
2135 | 2135 | finalmsg = msgstandard % ( |
|
2136 | 2136 | book, |
|
2137 | 2137 | nodemod.short(node), |
|
2138 | 2138 | nodemod.short(currentnode), |
|
2139 | 2139 | ) |
|
2140 | 2140 | raise error.PushRaced(finalmsg) |
|
2141 | 2141 | |
|
2142 | 2142 | |
|
2143 | 2143 | @parthandler(b'check:heads') |
|
2144 | 2144 | def handlecheckheads(op, inpart): |
|
2145 | 2145 | """check that head of the repo did not change |
|
2146 | 2146 | |
|
2147 | 2147 | This is used to detect a push race when using unbundle. |
|
2148 | 2148 | This replaces the "heads" argument of unbundle.""" |
|
2149 | 2149 | h = inpart.read(20) |
|
2150 | 2150 | heads = [] |
|
2151 | 2151 | while len(h) == 20: |
|
2152 | 2152 | heads.append(h) |
|
2153 | 2153 | h = inpart.read(20) |
|
2154 | 2154 | assert not h |
|
2155 | 2155 | # Trigger a transaction so that we are guaranteed to have the lock now. |
|
2156 | 2156 | if op.ui.configbool(b'experimental', b'bundle2lazylocking'): |
|
2157 | 2157 | op.gettransaction() |
|
2158 | 2158 | if sorted(heads) != sorted(op.repo.heads()): |
|
2159 | 2159 | raise error.PushRaced( |
|
2160 | 2160 | b'remote repository changed while pushing - please try again' |
|
2161 | 2161 | ) |
|
2162 | 2162 | |
|
2163 | 2163 | |
|
2164 | 2164 | @parthandler(b'check:updated-heads') |
|
2165 | 2165 | def handlecheckupdatedheads(op, inpart): |
|
2166 | 2166 | """check for race on the heads touched by a push |
|
2167 | 2167 | |
|
2168 | 2168 | This is similar to 'check:heads' but focus on the heads actually updated |
|
2169 | 2169 | during the push. If other activities happen on unrelated heads, it is |
|
2170 | 2170 | ignored. |
|
2171 | 2171 | |
|
2172 | 2172 | This allow server with high traffic to avoid push contention as long as |
|
2173 | 2173 | unrelated parts of the graph are involved.""" |
|
2174 | 2174 | h = inpart.read(20) |
|
2175 | 2175 | heads = [] |
|
2176 | 2176 | while len(h) == 20: |
|
2177 | 2177 | heads.append(h) |
|
2178 | 2178 | h = inpart.read(20) |
|
2179 | 2179 | assert not h |
|
2180 | 2180 | # trigger a transaction so that we are guaranteed to have the lock now. |
|
2181 | 2181 | if op.ui.configbool(b'experimental', b'bundle2lazylocking'): |
|
2182 | 2182 | op.gettransaction() |
|
2183 | 2183 | |
|
2184 | 2184 | currentheads = set() |
|
2185 | 2185 | for ls in op.repo.branchmap().iterheads(): |
|
2186 | 2186 | currentheads.update(ls) |
|
2187 | 2187 | |
|
2188 | 2188 | for h in heads: |
|
2189 | 2189 | if h not in currentheads: |
|
2190 | 2190 | raise error.PushRaced( |
|
2191 | 2191 | b'remote repository changed while pushing - ' |
|
2192 | 2192 | b'please try again' |
|
2193 | 2193 | ) |
|
2194 | 2194 | |
|
2195 | 2195 | |
|
2196 | 2196 | @parthandler(b'check:phases') |
|
2197 | 2197 | def handlecheckphases(op, inpart): |
|
2198 | 2198 | """check that phase boundaries of the repository did not change |
|
2199 | 2199 | |
|
2200 | 2200 | This is used to detect a push race. |
|
2201 | 2201 | """ |
|
2202 | 2202 | phasetonodes = phases.binarydecode(inpart) |
|
2203 | 2203 | unfi = op.repo.unfiltered() |
|
2204 | 2204 | cl = unfi.changelog |
|
2205 | 2205 | phasecache = unfi._phasecache |
|
2206 | 2206 | msg = ( |
|
2207 | 2207 | b'remote repository changed while pushing - please try again ' |
|
2208 | 2208 | b'(%s is %s expected %s)' |
|
2209 | 2209 | ) |
|
2210 | 2210 | for expectedphase, nodes in enumerate(phasetonodes): |
|
2211 | 2211 | for n in nodes: |
|
2212 | 2212 | actualphase = phasecache.phase(unfi, cl.rev(n)) |
|
2213 | 2213 | if actualphase != expectedphase: |
|
2214 | 2214 | finalmsg = msg % ( |
|
2215 | 2215 | nodemod.short(n), |
|
2216 | 2216 | phases.phasenames[actualphase], |
|
2217 | 2217 | phases.phasenames[expectedphase], |
|
2218 | 2218 | ) |
|
2219 | 2219 | raise error.PushRaced(finalmsg) |
|
2220 | 2220 | |
|
2221 | 2221 | |
|
2222 | 2222 | @parthandler(b'output') |
|
2223 | 2223 | def handleoutput(op, inpart): |
|
2224 | 2224 | """forward output captured on the server to the client""" |
|
2225 | 2225 | for line in inpart.read().splitlines(): |
|
2226 | 2226 | op.ui.status(_(b'remote: %s\n') % line) |
|
2227 | 2227 | |
|
2228 | 2228 | |
|
2229 | 2229 | @parthandler(b'replycaps') |
|
2230 | 2230 | def handlereplycaps(op, inpart): |
|
2231 | 2231 | """Notify that a reply bundle should be created |
|
2232 | 2232 | |
|
2233 | 2233 | The payload contains the capabilities information for the reply""" |
|
2234 | 2234 | caps = decodecaps(inpart.read()) |
|
2235 | 2235 | if op.reply is None: |
|
2236 | 2236 | op.reply = bundle20(op.ui, caps) |
|
2237 | 2237 | |
|
2238 | 2238 | |
|
2239 | 2239 | class AbortFromPart(error.Abort): |
|
2240 | 2240 | """Sub-class of Abort that denotes an error from a bundle2 part.""" |
|
2241 | 2241 | |
|
2242 | 2242 | |
|
2243 | 2243 | @parthandler(b'error:abort', (b'message', b'hint')) |
|
2244 | 2244 | def handleerrorabort(op, inpart): |
|
2245 | 2245 | """Used to transmit abort error over the wire""" |
|
2246 | 2246 | raise AbortFromPart( |
|
2247 | 2247 | inpart.params[b'message'], hint=inpart.params.get(b'hint') |
|
2248 | 2248 | ) |
|
2249 | 2249 | |
|
2250 | 2250 | |
|
2251 | 2251 | @parthandler( |
|
2252 | 2252 | b'error:pushkey', |
|
2253 | 2253 | (b'namespace', b'key', b'new', b'old', b'ret', b'in-reply-to'), |
|
2254 | 2254 | ) |
|
2255 | 2255 | def handleerrorpushkey(op, inpart): |
|
2256 | 2256 | """Used to transmit failure of a mandatory pushkey over the wire""" |
|
2257 | 2257 | kwargs = {} |
|
2258 | 2258 | for name in (b'namespace', b'key', b'new', b'old', b'ret'): |
|
2259 | 2259 | value = inpart.params.get(name) |
|
2260 | 2260 | if value is not None: |
|
2261 | 2261 | kwargs[name] = value |
|
2262 | 2262 | raise error.PushkeyFailed( |
|
2263 | 2263 | inpart.params[b'in-reply-to'], **pycompat.strkwargs(kwargs) |
|
2264 | 2264 | ) |
|
2265 | 2265 | |
|
2266 | 2266 | |
|
2267 | 2267 | @parthandler(b'error:unsupportedcontent', (b'parttype', b'params')) |
|
2268 | 2268 | def handleerrorunsupportedcontent(op, inpart): |
|
2269 | 2269 | """Used to transmit unknown content error over the wire""" |
|
2270 | 2270 | kwargs = {} |
|
2271 | 2271 | parttype = inpart.params.get(b'parttype') |
|
2272 | 2272 | if parttype is not None: |
|
2273 | 2273 | kwargs[b'parttype'] = parttype |
|
2274 | 2274 | params = inpart.params.get(b'params') |
|
2275 | 2275 | if params is not None: |
|
2276 | 2276 | kwargs[b'params'] = params.split(b'\0') |
|
2277 | 2277 | |
|
2278 | 2278 | raise error.BundleUnknownFeatureError(**pycompat.strkwargs(kwargs)) |
|
2279 | 2279 | |
|
2280 | 2280 | |
|
2281 | 2281 | @parthandler(b'error:pushraced', (b'message',)) |
|
2282 | 2282 | def handleerrorpushraced(op, inpart): |
|
2283 | 2283 | """Used to transmit push race error over the wire""" |
|
2284 | 2284 | raise error.ResponseError(_(b'push failed:'), inpart.params[b'message']) |
|
2285 | 2285 | |
|
2286 | 2286 | |
|
2287 | 2287 | @parthandler(b'listkeys', (b'namespace',)) |
|
2288 | 2288 | def handlelistkeys(op, inpart): |
|
2289 | 2289 | """retrieve pushkey namespace content stored in a bundle2""" |
|
2290 | 2290 | namespace = inpart.params[b'namespace'] |
|
2291 | 2291 | r = pushkey.decodekeys(inpart.read()) |
|
2292 | 2292 | op.records.add(b'listkeys', (namespace, r)) |
|
2293 | 2293 | |
|
2294 | 2294 | |
|
2295 | 2295 | @parthandler(b'pushkey', (b'namespace', b'key', b'old', b'new')) |
|
2296 | 2296 | def handlepushkey(op, inpart): |
|
2297 | 2297 | """process a pushkey request""" |
|
2298 | 2298 | dec = pushkey.decode |
|
2299 | 2299 | namespace = dec(inpart.params[b'namespace']) |
|
2300 | 2300 | key = dec(inpart.params[b'key']) |
|
2301 | 2301 | old = dec(inpart.params[b'old']) |
|
2302 | 2302 | new = dec(inpart.params[b'new']) |
|
2303 | 2303 | # Grab the transaction to ensure that we have the lock before performing the |
|
2304 | 2304 | # pushkey. |
|
2305 | 2305 | if op.ui.configbool(b'experimental', b'bundle2lazylocking'): |
|
2306 | 2306 | op.gettransaction() |
|
2307 | 2307 | ret = op.repo.pushkey(namespace, key, old, new) |
|
2308 | 2308 | record = {b'namespace': namespace, b'key': key, b'old': old, b'new': new} |
|
2309 | 2309 | op.records.add(b'pushkey', record) |
|
2310 | 2310 | if op.reply is not None: |
|
2311 | 2311 | rpart = op.reply.newpart(b'reply:pushkey') |
|
2312 | 2312 | rpart.addparam( |
|
2313 | 2313 | b'in-reply-to', pycompat.bytestr(inpart.id), mandatory=False |
|
2314 | 2314 | ) |
|
2315 | 2315 | rpart.addparam(b'return', b'%i' % ret, mandatory=False) |
|
2316 | 2316 | if inpart.mandatory and not ret: |
|
2317 | 2317 | kwargs = {} |
|
2318 | 2318 | for key in (b'namespace', b'key', b'new', b'old', b'ret'): |
|
2319 | 2319 | if key in inpart.params: |
|
2320 | 2320 | kwargs[key] = inpart.params[key] |
|
2321 | 2321 | raise error.PushkeyFailed( |
|
2322 | 2322 | partid=b'%d' % inpart.id, **pycompat.strkwargs(kwargs) |
|
2323 | 2323 | ) |
|
2324 | 2324 | |
|
2325 | 2325 | |
|
2326 | 2326 | @parthandler(b'bookmarks') |
|
2327 | 2327 | def handlebookmark(op, inpart): |
|
2328 | 2328 | """transmit bookmark information |
|
2329 | 2329 | |
|
2330 | 2330 | The part contains binary encoded bookmark information. |
|
2331 | 2331 | |
|
2332 | 2332 | The exact behavior of this part can be controlled by the 'bookmarks' mode |
|
2333 | 2333 | on the bundle operation. |
|
2334 | 2334 | |
|
2335 | 2335 | When mode is 'apply' (the default) the bookmark information is applied as |
|
2336 | 2336 | is to the unbundling repository. Make sure a 'check:bookmarks' part is |
|
2337 | 2337 | issued earlier to check for push races in such update. This behavior is |
|
2338 | 2338 | suitable for pushing. |
|
2339 | 2339 | |
|
2340 | 2340 | When mode is 'records', the information is recorded into the 'bookmarks' |
|
2341 | 2341 | records of the bundle operation. This behavior is suitable for pulling. |
|
2342 | 2342 | """ |
|
2343 | 2343 | changes = bookmarks.binarydecode(inpart) |
|
2344 | 2344 | |
|
2345 | 2345 | pushkeycompat = op.repo.ui.configbool( |
|
2346 | 2346 | b'server', b'bookmarks-pushkey-compat' |
|
2347 | 2347 | ) |
|
2348 | 2348 | bookmarksmode = op.modes.get(b'bookmarks', b'apply') |
|
2349 | 2349 | |
|
2350 | 2350 | if bookmarksmode == b'apply': |
|
2351 | 2351 | tr = op.gettransaction() |
|
2352 | 2352 | bookstore = op.repo._bookmarks |
|
2353 | 2353 | if pushkeycompat: |
|
2354 | 2354 | allhooks = [] |
|
2355 | 2355 | for book, node in changes: |
|
2356 | 2356 | hookargs = tr.hookargs.copy() |
|
2357 | 2357 | hookargs[b'pushkeycompat'] = b'1' |
|
2358 | 2358 | hookargs[b'namespace'] = b'bookmarks' |
|
2359 | 2359 | hookargs[b'key'] = book |
|
2360 | 2360 | hookargs[b'old'] = nodemod.hex(bookstore.get(book, b'')) |
|
2361 | 2361 | hookargs[b'new'] = nodemod.hex( |
|
2362 | 2362 | node if node is not None else b'' |
|
2363 | 2363 | ) |
|
2364 | 2364 | allhooks.append(hookargs) |
|
2365 | 2365 | |
|
2366 | 2366 | for hookargs in allhooks: |
|
2367 | 2367 | op.repo.hook( |
|
2368 | 2368 | b'prepushkey', throw=True, **pycompat.strkwargs(hookargs) |
|
2369 | 2369 | ) |
|
2370 | 2370 | |
|
2371 | for book, node in changes: | |
|
2372 | if bookmarks.isdivergent(book): | |
|
2373 | msg = _(b'cannot accept divergent bookmark %s!') % book | |
|
2374 | raise error.Abort(msg) | |
|
2375 | ||
|
2371 | 2376 | bookstore.applychanges(op.repo, op.gettransaction(), changes) |
|
2372 | 2377 | |
|
2373 | 2378 | if pushkeycompat: |
|
2374 | 2379 | |
|
2375 | 2380 | def runhook(unused_success): |
|
2376 | 2381 | for hookargs in allhooks: |
|
2377 | 2382 | op.repo.hook(b'pushkey', **pycompat.strkwargs(hookargs)) |
|
2378 | 2383 | |
|
2379 | 2384 | op.repo._afterlock(runhook) |
|
2380 | 2385 | |
|
2381 | 2386 | elif bookmarksmode == b'records': |
|
2382 | 2387 | for book, node in changes: |
|
2383 | 2388 | record = {b'bookmark': book, b'node': node} |
|
2384 | 2389 | op.records.add(b'bookmarks', record) |
|
2385 | 2390 | else: |
|
2386 | 2391 | raise error.ProgrammingError( |
|
2387 | 2392 | b'unkown bookmark mode: %s' % bookmarksmode |
|
2388 | 2393 | ) |
|
2389 | 2394 | |
|
2390 | 2395 | |
|
2391 | 2396 | @parthandler(b'phase-heads') |
|
2392 | 2397 | def handlephases(op, inpart): |
|
2393 | 2398 | """apply phases from bundle part to repo""" |
|
2394 | 2399 | headsbyphase = phases.binarydecode(inpart) |
|
2395 | 2400 | phases.updatephases(op.repo.unfiltered(), op.gettransaction, headsbyphase) |
|
2396 | 2401 | |
|
2397 | 2402 | |
|
2398 | 2403 | @parthandler(b'reply:pushkey', (b'return', b'in-reply-to')) |
|
2399 | 2404 | def handlepushkeyreply(op, inpart): |
|
2400 | 2405 | """retrieve the result of a pushkey request""" |
|
2401 | 2406 | ret = int(inpart.params[b'return']) |
|
2402 | 2407 | partid = int(inpart.params[b'in-reply-to']) |
|
2403 | 2408 | op.records.add(b'pushkey', {b'return': ret}, partid) |
|
2404 | 2409 | |
|
2405 | 2410 | |
|
2406 | 2411 | @parthandler(b'obsmarkers') |
|
2407 | 2412 | def handleobsmarker(op, inpart): |
|
2408 | 2413 | """add a stream of obsmarkers to the repo""" |
|
2409 | 2414 | tr = op.gettransaction() |
|
2410 | 2415 | markerdata = inpart.read() |
|
2411 | 2416 | if op.ui.config(b'experimental', b'obsmarkers-exchange-debug'): |
|
2412 | 2417 | op.ui.writenoi18n( |
|
2413 | 2418 | b'obsmarker-exchange: %i bytes received\n' % len(markerdata) |
|
2414 | 2419 | ) |
|
2415 | 2420 | # The mergemarkers call will crash if marker creation is not enabled. |
|
2416 | 2421 | # we want to avoid this if the part is advisory. |
|
2417 | 2422 | if not inpart.mandatory and op.repo.obsstore.readonly: |
|
2418 | 2423 | op.repo.ui.debug( |
|
2419 | 2424 | b'ignoring obsolescence markers, feature not enabled\n' |
|
2420 | 2425 | ) |
|
2421 | 2426 | return |
|
2422 | 2427 | new = op.repo.obsstore.mergemarkers(tr, markerdata) |
|
2423 | 2428 | op.repo.invalidatevolatilesets() |
|
2424 | 2429 | op.records.add(b'obsmarkers', {b'new': new}) |
|
2425 | 2430 | if op.reply is not None: |
|
2426 | 2431 | rpart = op.reply.newpart(b'reply:obsmarkers') |
|
2427 | 2432 | rpart.addparam( |
|
2428 | 2433 | b'in-reply-to', pycompat.bytestr(inpart.id), mandatory=False |
|
2429 | 2434 | ) |
|
2430 | 2435 | rpart.addparam(b'new', b'%i' % new, mandatory=False) |
|
2431 | 2436 | |
|
2432 | 2437 | |
|
2433 | 2438 | @parthandler(b'reply:obsmarkers', (b'new', b'in-reply-to')) |
|
2434 | 2439 | def handleobsmarkerreply(op, inpart): |
|
2435 | 2440 | """retrieve the result of a pushkey request""" |
|
2436 | 2441 | ret = int(inpart.params[b'new']) |
|
2437 | 2442 | partid = int(inpart.params[b'in-reply-to']) |
|
2438 | 2443 | op.records.add(b'obsmarkers', {b'new': ret}, partid) |
|
2439 | 2444 | |
|
2440 | 2445 | |
|
2441 | 2446 | @parthandler(b'hgtagsfnodes') |
|
2442 | 2447 | def handlehgtagsfnodes(op, inpart): |
|
2443 | 2448 | """Applies .hgtags fnodes cache entries to the local repo. |
|
2444 | 2449 | |
|
2445 | 2450 | Payload is pairs of 20 byte changeset nodes and filenodes. |
|
2446 | 2451 | """ |
|
2447 | 2452 | # Grab the transaction so we ensure that we have the lock at this point. |
|
2448 | 2453 | if op.ui.configbool(b'experimental', b'bundle2lazylocking'): |
|
2449 | 2454 | op.gettransaction() |
|
2450 | 2455 | cache = tags.hgtagsfnodescache(op.repo.unfiltered()) |
|
2451 | 2456 | |
|
2452 | 2457 | count = 0 |
|
2453 | 2458 | while True: |
|
2454 | 2459 | node = inpart.read(20) |
|
2455 | 2460 | fnode = inpart.read(20) |
|
2456 | 2461 | if len(node) < 20 or len(fnode) < 20: |
|
2457 | 2462 | op.ui.debug(b'ignoring incomplete received .hgtags fnodes data\n') |
|
2458 | 2463 | break |
|
2459 | 2464 | cache.setfnode(node, fnode) |
|
2460 | 2465 | count += 1 |
|
2461 | 2466 | |
|
2462 | 2467 | cache.write() |
|
2463 | 2468 | op.ui.debug(b'applied %i hgtags fnodes cache entries\n' % count) |
|
2464 | 2469 | |
|
2465 | 2470 | |
|
2466 | 2471 | rbcstruct = struct.Struct(b'>III') |
|
2467 | 2472 | |
|
2468 | 2473 | |
|
2469 | 2474 | @parthandler(b'cache:rev-branch-cache') |
|
2470 | 2475 | def handlerbc(op, inpart): |
|
2471 | 2476 | """receive a rev-branch-cache payload and update the local cache |
|
2472 | 2477 | |
|
2473 | 2478 | The payload is a series of data related to each branch |
|
2474 | 2479 | |
|
2475 | 2480 | 1) branch name length |
|
2476 | 2481 | 2) number of open heads |
|
2477 | 2482 | 3) number of closed heads |
|
2478 | 2483 | 4) open heads nodes |
|
2479 | 2484 | 5) closed heads nodes |
|
2480 | 2485 | """ |
|
2481 | 2486 | total = 0 |
|
2482 | 2487 | rawheader = inpart.read(rbcstruct.size) |
|
2483 | 2488 | cache = op.repo.revbranchcache() |
|
2484 | 2489 | cl = op.repo.unfiltered().changelog |
|
2485 | 2490 | while rawheader: |
|
2486 | 2491 | header = rbcstruct.unpack(rawheader) |
|
2487 | 2492 | total += header[1] + header[2] |
|
2488 | 2493 | utf8branch = inpart.read(header[0]) |
|
2489 | 2494 | branch = encoding.tolocal(utf8branch) |
|
2490 | 2495 | for x in pycompat.xrange(header[1]): |
|
2491 | 2496 | node = inpart.read(20) |
|
2492 | 2497 | rev = cl.rev(node) |
|
2493 | 2498 | cache.setdata(branch, rev, node, False) |
|
2494 | 2499 | for x in pycompat.xrange(header[2]): |
|
2495 | 2500 | node = inpart.read(20) |
|
2496 | 2501 | rev = cl.rev(node) |
|
2497 | 2502 | cache.setdata(branch, rev, node, True) |
|
2498 | 2503 | rawheader = inpart.read(rbcstruct.size) |
|
2499 | 2504 | cache.write() |
|
2500 | 2505 | |
|
2501 | 2506 | |
|
2502 | 2507 | @parthandler(b'pushvars') |
|
2503 | 2508 | def bundle2getvars(op, part): |
|
2504 | 2509 | '''unbundle a bundle2 containing shellvars on the server''' |
|
2505 | 2510 | # An option to disable unbundling on server-side for security reasons |
|
2506 | 2511 | if op.ui.configbool(b'push', b'pushvars.server'): |
|
2507 | 2512 | hookargs = {} |
|
2508 | 2513 | for key, value in part.advisoryparams: |
|
2509 | 2514 | key = key.upper() |
|
2510 | 2515 | # We want pushed variables to have USERVAR_ prepended so we know |
|
2511 | 2516 | # they came from the --pushvar flag. |
|
2512 | 2517 | key = b"USERVAR_" + key |
|
2513 | 2518 | hookargs[key] = value |
|
2514 | 2519 | op.addhookargs(hookargs) |
|
2515 | 2520 | |
|
2516 | 2521 | |
|
2517 | 2522 | @parthandler(b'stream2', (b'requirements', b'filecount', b'bytecount')) |
|
2518 | 2523 | def handlestreamv2bundle(op, part): |
|
2519 | 2524 | |
|
2520 | 2525 | requirements = urlreq.unquote(part.params[b'requirements']).split(b',') |
|
2521 | 2526 | filecount = int(part.params[b'filecount']) |
|
2522 | 2527 | bytecount = int(part.params[b'bytecount']) |
|
2523 | 2528 | |
|
2524 | 2529 | repo = op.repo |
|
2525 | 2530 | if len(repo): |
|
2526 | 2531 | msg = _(b'cannot apply stream clone to non empty repository') |
|
2527 | 2532 | raise error.Abort(msg) |
|
2528 | 2533 | |
|
2529 | 2534 | repo.ui.debug(b'applying stream bundle\n') |
|
2530 | 2535 | streamclone.applybundlev2(repo, part, filecount, bytecount, requirements) |
|
2531 | 2536 | |
|
2532 | 2537 | |
|
2533 | 2538 | def widen_bundle( |
|
2534 | 2539 | bundler, repo, oldmatcher, newmatcher, common, known, cgversion, ellipses |
|
2535 | 2540 | ): |
|
2536 | 2541 | """generates bundle2 for widening a narrow clone |
|
2537 | 2542 | |
|
2538 | 2543 | bundler is the bundle to which data should be added |
|
2539 | 2544 | repo is the localrepository instance |
|
2540 | 2545 | oldmatcher matches what the client already has |
|
2541 | 2546 | newmatcher matches what the client needs (including what it already has) |
|
2542 | 2547 | common is set of common heads between server and client |
|
2543 | 2548 | known is a set of revs known on the client side (used in ellipses) |
|
2544 | 2549 | cgversion is the changegroup version to send |
|
2545 | 2550 | ellipses is boolean value telling whether to send ellipses data or not |
|
2546 | 2551 | |
|
2547 | 2552 | returns bundle2 of the data required for extending |
|
2548 | 2553 | """ |
|
2549 | 2554 | commonnodes = set() |
|
2550 | 2555 | cl = repo.changelog |
|
2551 | 2556 | for r in repo.revs(b"::%ln", common): |
|
2552 | 2557 | commonnodes.add(cl.node(r)) |
|
2553 | 2558 | if commonnodes: |
|
2554 | 2559 | # XXX: we should only send the filelogs (and treemanifest). user |
|
2555 | 2560 | # already has the changelog and manifest |
|
2556 | 2561 | packer = changegroup.getbundler( |
|
2557 | 2562 | cgversion, |
|
2558 | 2563 | repo, |
|
2559 | 2564 | oldmatcher=oldmatcher, |
|
2560 | 2565 | matcher=newmatcher, |
|
2561 | 2566 | fullnodes=commonnodes, |
|
2562 | 2567 | ) |
|
2563 | 2568 | cgdata = packer.generate( |
|
2564 | 2569 | {nodemod.nullid}, |
|
2565 | 2570 | list(commonnodes), |
|
2566 | 2571 | False, |
|
2567 | 2572 | b'narrow_widen', |
|
2568 | 2573 | changelog=False, |
|
2569 | 2574 | ) |
|
2570 | 2575 | |
|
2571 | 2576 | part = bundler.newpart(b'changegroup', data=cgdata) |
|
2572 | 2577 | part.addparam(b'version', cgversion) |
|
2573 | 2578 | if b'treemanifest' in repo.requirements: |
|
2574 | 2579 | part.addparam(b'treemanifest', b'1') |
|
2575 | 2580 | if b'exp-sidedata-flag' in repo.requirements: |
|
2576 | 2581 | part.addparam(b'exp-sidedata', b'1') |
|
2577 | 2582 | |
|
2578 | 2583 | return bundler |
@@ -1,3108 +1,3112 b'' | |||
|
1 | 1 | # exchange.py - utility to exchange data between repos. |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from __future__ import absolute_import |
|
9 | 9 | |
|
10 | 10 | import collections |
|
11 | 11 | |
|
12 | 12 | from .i18n import _ |
|
13 | 13 | from .node import ( |
|
14 | 14 | hex, |
|
15 | 15 | nullid, |
|
16 | 16 | nullrev, |
|
17 | 17 | ) |
|
18 | 18 | from .thirdparty import attr |
|
19 | 19 | from . import ( |
|
20 | 20 | bookmarks as bookmod, |
|
21 | 21 | bundle2, |
|
22 | 22 | changegroup, |
|
23 | 23 | discovery, |
|
24 | 24 | error, |
|
25 | 25 | exchangev2, |
|
26 | 26 | lock as lockmod, |
|
27 | 27 | logexchange, |
|
28 | 28 | narrowspec, |
|
29 | 29 | obsolete, |
|
30 | 30 | obsutil, |
|
31 | 31 | phases, |
|
32 | 32 | pushkey, |
|
33 | 33 | pycompat, |
|
34 | 34 | scmutil, |
|
35 | 35 | sslutil, |
|
36 | 36 | streamclone, |
|
37 | 37 | url as urlmod, |
|
38 | 38 | util, |
|
39 | 39 | wireprototypes, |
|
40 | 40 | ) |
|
41 | 41 | from .interfaces import repository |
|
42 | 42 | from .utils import ( |
|
43 | 43 | hashutil, |
|
44 | 44 | stringutil, |
|
45 | 45 | ) |
|
46 | 46 | |
|
47 | 47 | urlerr = util.urlerr |
|
48 | 48 | urlreq = util.urlreq |
|
49 | 49 | |
|
50 | 50 | _NARROWACL_SECTION = b'narrowacl' |
|
51 | 51 | |
|
52 | 52 | # Maps bundle version human names to changegroup versions. |
|
53 | 53 | _bundlespeccgversions = { |
|
54 | 54 | b'v1': b'01', |
|
55 | 55 | b'v2': b'02', |
|
56 | 56 | b'packed1': b's1', |
|
57 | 57 | b'bundle2': b'02', # legacy |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | # Maps bundle version with content opts to choose which part to bundle |
|
61 | 61 | _bundlespeccontentopts = { |
|
62 | 62 | b'v1': { |
|
63 | 63 | b'changegroup': True, |
|
64 | 64 | b'cg.version': b'01', |
|
65 | 65 | b'obsolescence': False, |
|
66 | 66 | b'phases': False, |
|
67 | 67 | b'tagsfnodescache': False, |
|
68 | 68 | b'revbranchcache': False, |
|
69 | 69 | }, |
|
70 | 70 | b'v2': { |
|
71 | 71 | b'changegroup': True, |
|
72 | 72 | b'cg.version': b'02', |
|
73 | 73 | b'obsolescence': False, |
|
74 | 74 | b'phases': False, |
|
75 | 75 | b'tagsfnodescache': True, |
|
76 | 76 | b'revbranchcache': True, |
|
77 | 77 | }, |
|
78 | 78 | b'packed1': {b'cg.version': b's1'}, |
|
79 | 79 | } |
|
80 | 80 | _bundlespeccontentopts[b'bundle2'] = _bundlespeccontentopts[b'v2'] |
|
81 | 81 | |
|
82 | 82 | _bundlespecvariants = { |
|
83 | 83 | b"streamv2": { |
|
84 | 84 | b"changegroup": False, |
|
85 | 85 | b"streamv2": True, |
|
86 | 86 | b"tagsfnodescache": False, |
|
87 | 87 | b"revbranchcache": False, |
|
88 | 88 | } |
|
89 | 89 | } |
|
90 | 90 | |
|
91 | 91 | # Compression engines allowed in version 1. THIS SHOULD NEVER CHANGE. |
|
92 | 92 | _bundlespecv1compengines = {b'gzip', b'bzip2', b'none'} |
|
93 | 93 | |
|
94 | 94 | |
|
95 | 95 | @attr.s |
|
96 | 96 | class bundlespec(object): |
|
97 | 97 | compression = attr.ib() |
|
98 | 98 | wirecompression = attr.ib() |
|
99 | 99 | version = attr.ib() |
|
100 | 100 | wireversion = attr.ib() |
|
101 | 101 | params = attr.ib() |
|
102 | 102 | contentopts = attr.ib() |
|
103 | 103 | |
|
104 | 104 | |
|
105 | 105 | def parsebundlespec(repo, spec, strict=True): |
|
106 | 106 | """Parse a bundle string specification into parts. |
|
107 | 107 | |
|
108 | 108 | Bundle specifications denote a well-defined bundle/exchange format. |
|
109 | 109 | The content of a given specification should not change over time in |
|
110 | 110 | order to ensure that bundles produced by a newer version of Mercurial are |
|
111 | 111 | readable from an older version. |
|
112 | 112 | |
|
113 | 113 | The string currently has the form: |
|
114 | 114 | |
|
115 | 115 | <compression>-<type>[;<parameter0>[;<parameter1>]] |
|
116 | 116 | |
|
117 | 117 | Where <compression> is one of the supported compression formats |
|
118 | 118 | and <type> is (currently) a version string. A ";" can follow the type and |
|
119 | 119 | all text afterwards is interpreted as URI encoded, ";" delimited key=value |
|
120 | 120 | pairs. |
|
121 | 121 | |
|
122 | 122 | If ``strict`` is True (the default) <compression> is required. Otherwise, |
|
123 | 123 | it is optional. |
|
124 | 124 | |
|
125 | 125 | Returns a bundlespec object of (compression, version, parameters). |
|
126 | 126 | Compression will be ``None`` if not in strict mode and a compression isn't |
|
127 | 127 | defined. |
|
128 | 128 | |
|
129 | 129 | An ``InvalidBundleSpecification`` is raised when the specification is |
|
130 | 130 | not syntactically well formed. |
|
131 | 131 | |
|
132 | 132 | An ``UnsupportedBundleSpecification`` is raised when the compression or |
|
133 | 133 | bundle type/version is not recognized. |
|
134 | 134 | |
|
135 | 135 | Note: this function will likely eventually return a more complex data |
|
136 | 136 | structure, including bundle2 part information. |
|
137 | 137 | """ |
|
138 | 138 | |
|
139 | 139 | def parseparams(s): |
|
140 | 140 | if b';' not in s: |
|
141 | 141 | return s, {} |
|
142 | 142 | |
|
143 | 143 | params = {} |
|
144 | 144 | version, paramstr = s.split(b';', 1) |
|
145 | 145 | |
|
146 | 146 | for p in paramstr.split(b';'): |
|
147 | 147 | if b'=' not in p: |
|
148 | 148 | raise error.InvalidBundleSpecification( |
|
149 | 149 | _( |
|
150 | 150 | b'invalid bundle specification: ' |
|
151 | 151 | b'missing "=" in parameter: %s' |
|
152 | 152 | ) |
|
153 | 153 | % p |
|
154 | 154 | ) |
|
155 | 155 | |
|
156 | 156 | key, value = p.split(b'=', 1) |
|
157 | 157 | key = urlreq.unquote(key) |
|
158 | 158 | value = urlreq.unquote(value) |
|
159 | 159 | params[key] = value |
|
160 | 160 | |
|
161 | 161 | return version, params |
|
162 | 162 | |
|
163 | 163 | if strict and b'-' not in spec: |
|
164 | 164 | raise error.InvalidBundleSpecification( |
|
165 | 165 | _( |
|
166 | 166 | b'invalid bundle specification; ' |
|
167 | 167 | b'must be prefixed with compression: %s' |
|
168 | 168 | ) |
|
169 | 169 | % spec |
|
170 | 170 | ) |
|
171 | 171 | |
|
172 | 172 | if b'-' in spec: |
|
173 | 173 | compression, version = spec.split(b'-', 1) |
|
174 | 174 | |
|
175 | 175 | if compression not in util.compengines.supportedbundlenames: |
|
176 | 176 | raise error.UnsupportedBundleSpecification( |
|
177 | 177 | _(b'%s compression is not supported') % compression |
|
178 | 178 | ) |
|
179 | 179 | |
|
180 | 180 | version, params = parseparams(version) |
|
181 | 181 | |
|
182 | 182 | if version not in _bundlespeccgversions: |
|
183 | 183 | raise error.UnsupportedBundleSpecification( |
|
184 | 184 | _(b'%s is not a recognized bundle version') % version |
|
185 | 185 | ) |
|
186 | 186 | else: |
|
187 | 187 | # Value could be just the compression or just the version, in which |
|
188 | 188 | # case some defaults are assumed (but only when not in strict mode). |
|
189 | 189 | assert not strict |
|
190 | 190 | |
|
191 | 191 | spec, params = parseparams(spec) |
|
192 | 192 | |
|
193 | 193 | if spec in util.compengines.supportedbundlenames: |
|
194 | 194 | compression = spec |
|
195 | 195 | version = b'v1' |
|
196 | 196 | # Generaldelta repos require v2. |
|
197 | 197 | if b'generaldelta' in repo.requirements: |
|
198 | 198 | version = b'v2' |
|
199 | 199 | # Modern compression engines require v2. |
|
200 | 200 | if compression not in _bundlespecv1compengines: |
|
201 | 201 | version = b'v2' |
|
202 | 202 | elif spec in _bundlespeccgversions: |
|
203 | 203 | if spec == b'packed1': |
|
204 | 204 | compression = b'none' |
|
205 | 205 | else: |
|
206 | 206 | compression = b'bzip2' |
|
207 | 207 | version = spec |
|
208 | 208 | else: |
|
209 | 209 | raise error.UnsupportedBundleSpecification( |
|
210 | 210 | _(b'%s is not a recognized bundle specification') % spec |
|
211 | 211 | ) |
|
212 | 212 | |
|
213 | 213 | # Bundle version 1 only supports a known set of compression engines. |
|
214 | 214 | if version == b'v1' and compression not in _bundlespecv1compengines: |
|
215 | 215 | raise error.UnsupportedBundleSpecification( |
|
216 | 216 | _(b'compression engine %s is not supported on v1 bundles') |
|
217 | 217 | % compression |
|
218 | 218 | ) |
|
219 | 219 | |
|
220 | 220 | # The specification for packed1 can optionally declare the data formats |
|
221 | 221 | # required to apply it. If we see this metadata, compare against what the |
|
222 | 222 | # repo supports and error if the bundle isn't compatible. |
|
223 | 223 | if version == b'packed1' and b'requirements' in params: |
|
224 | 224 | requirements = set(params[b'requirements'].split(b',')) |
|
225 | 225 | missingreqs = requirements - repo.supportedformats |
|
226 | 226 | if missingreqs: |
|
227 | 227 | raise error.UnsupportedBundleSpecification( |
|
228 | 228 | _(b'missing support for repository features: %s') |
|
229 | 229 | % b', '.join(sorted(missingreqs)) |
|
230 | 230 | ) |
|
231 | 231 | |
|
232 | 232 | # Compute contentopts based on the version |
|
233 | 233 | contentopts = _bundlespeccontentopts.get(version, {}).copy() |
|
234 | 234 | |
|
235 | 235 | # Process the variants |
|
236 | 236 | if b"stream" in params and params[b"stream"] == b"v2": |
|
237 | 237 | variant = _bundlespecvariants[b"streamv2"] |
|
238 | 238 | contentopts.update(variant) |
|
239 | 239 | |
|
240 | 240 | engine = util.compengines.forbundlename(compression) |
|
241 | 241 | compression, wirecompression = engine.bundletype() |
|
242 | 242 | wireversion = _bundlespeccgversions[version] |
|
243 | 243 | |
|
244 | 244 | return bundlespec( |
|
245 | 245 | compression, wirecompression, version, wireversion, params, contentopts |
|
246 | 246 | ) |
|
247 | 247 | |
|
248 | 248 | |
|
249 | 249 | def readbundle(ui, fh, fname, vfs=None): |
|
250 | 250 | header = changegroup.readexactly(fh, 4) |
|
251 | 251 | |
|
252 | 252 | alg = None |
|
253 | 253 | if not fname: |
|
254 | 254 | fname = b"stream" |
|
255 | 255 | if not header.startswith(b'HG') and header.startswith(b'\0'): |
|
256 | 256 | fh = changegroup.headerlessfixup(fh, header) |
|
257 | 257 | header = b"HG10" |
|
258 | 258 | alg = b'UN' |
|
259 | 259 | elif vfs: |
|
260 | 260 | fname = vfs.join(fname) |
|
261 | 261 | |
|
262 | 262 | magic, version = header[0:2], header[2:4] |
|
263 | 263 | |
|
264 | 264 | if magic != b'HG': |
|
265 | 265 | raise error.Abort(_(b'%s: not a Mercurial bundle') % fname) |
|
266 | 266 | if version == b'10': |
|
267 | 267 | if alg is None: |
|
268 | 268 | alg = changegroup.readexactly(fh, 2) |
|
269 | 269 | return changegroup.cg1unpacker(fh, alg) |
|
270 | 270 | elif version.startswith(b'2'): |
|
271 | 271 | return bundle2.getunbundler(ui, fh, magicstring=magic + version) |
|
272 | 272 | elif version == b'S1': |
|
273 | 273 | return streamclone.streamcloneapplier(fh) |
|
274 | 274 | else: |
|
275 | 275 | raise error.Abort( |
|
276 | 276 | _(b'%s: unknown bundle version %s') % (fname, version) |
|
277 | 277 | ) |
|
278 | 278 | |
|
279 | 279 | |
|
280 | 280 | def getbundlespec(ui, fh): |
|
281 | 281 | """Infer the bundlespec from a bundle file handle. |
|
282 | 282 | |
|
283 | 283 | The input file handle is seeked and the original seek position is not |
|
284 | 284 | restored. |
|
285 | 285 | """ |
|
286 | 286 | |
|
287 | 287 | def speccompression(alg): |
|
288 | 288 | try: |
|
289 | 289 | return util.compengines.forbundletype(alg).bundletype()[0] |
|
290 | 290 | except KeyError: |
|
291 | 291 | return None |
|
292 | 292 | |
|
293 | 293 | b = readbundle(ui, fh, None) |
|
294 | 294 | if isinstance(b, changegroup.cg1unpacker): |
|
295 | 295 | alg = b._type |
|
296 | 296 | if alg == b'_truncatedBZ': |
|
297 | 297 | alg = b'BZ' |
|
298 | 298 | comp = speccompression(alg) |
|
299 | 299 | if not comp: |
|
300 | 300 | raise error.Abort(_(b'unknown compression algorithm: %s') % alg) |
|
301 | 301 | return b'%s-v1' % comp |
|
302 | 302 | elif isinstance(b, bundle2.unbundle20): |
|
303 | 303 | if b'Compression' in b.params: |
|
304 | 304 | comp = speccompression(b.params[b'Compression']) |
|
305 | 305 | if not comp: |
|
306 | 306 | raise error.Abort( |
|
307 | 307 | _(b'unknown compression algorithm: %s') % comp |
|
308 | 308 | ) |
|
309 | 309 | else: |
|
310 | 310 | comp = b'none' |
|
311 | 311 | |
|
312 | 312 | version = None |
|
313 | 313 | for part in b.iterparts(): |
|
314 | 314 | if part.type == b'changegroup': |
|
315 | 315 | version = part.params[b'version'] |
|
316 | 316 | if version in (b'01', b'02'): |
|
317 | 317 | version = b'v2' |
|
318 | 318 | else: |
|
319 | 319 | raise error.Abort( |
|
320 | 320 | _( |
|
321 | 321 | b'changegroup version %s does not have ' |
|
322 | 322 | b'a known bundlespec' |
|
323 | 323 | ) |
|
324 | 324 | % version, |
|
325 | 325 | hint=_(b'try upgrading your Mercurial client'), |
|
326 | 326 | ) |
|
327 | 327 | elif part.type == b'stream2' and version is None: |
|
328 | 328 | # A stream2 part requires to be part of a v2 bundle |
|
329 | 329 | requirements = urlreq.unquote(part.params[b'requirements']) |
|
330 | 330 | splitted = requirements.split() |
|
331 | 331 | params = bundle2._formatrequirementsparams(splitted) |
|
332 | 332 | return b'none-v2;stream=v2;%s' % params |
|
333 | 333 | |
|
334 | 334 | if not version: |
|
335 | 335 | raise error.Abort( |
|
336 | 336 | _(b'could not identify changegroup version in bundle') |
|
337 | 337 | ) |
|
338 | 338 | |
|
339 | 339 | return b'%s-%s' % (comp, version) |
|
340 | 340 | elif isinstance(b, streamclone.streamcloneapplier): |
|
341 | 341 | requirements = streamclone.readbundle1header(fh)[2] |
|
342 | 342 | formatted = bundle2._formatrequirementsparams(requirements) |
|
343 | 343 | return b'none-packed1;%s' % formatted |
|
344 | 344 | else: |
|
345 | 345 | raise error.Abort(_(b'unknown bundle type: %s') % b) |
|
346 | 346 | |
|
347 | 347 | |
|
348 | 348 | def _computeoutgoing(repo, heads, common): |
|
349 | 349 | """Computes which revs are outgoing given a set of common |
|
350 | 350 | and a set of heads. |
|
351 | 351 | |
|
352 | 352 | This is a separate function so extensions can have access to |
|
353 | 353 | the logic. |
|
354 | 354 | |
|
355 | 355 | Returns a discovery.outgoing object. |
|
356 | 356 | """ |
|
357 | 357 | cl = repo.changelog |
|
358 | 358 | if common: |
|
359 | 359 | hasnode = cl.hasnode |
|
360 | 360 | common = [n for n in common if hasnode(n)] |
|
361 | 361 | else: |
|
362 | 362 | common = [nullid] |
|
363 | 363 | if not heads: |
|
364 | 364 | heads = cl.heads() |
|
365 | 365 | return discovery.outgoing(repo, common, heads) |
|
366 | 366 | |
|
367 | 367 | |
|
368 | 368 | def _checkpublish(pushop): |
|
369 | 369 | repo = pushop.repo |
|
370 | 370 | ui = repo.ui |
|
371 | 371 | behavior = ui.config(b'experimental', b'auto-publish') |
|
372 | 372 | if pushop.publish or behavior not in (b'warn', b'confirm', b'abort'): |
|
373 | 373 | return |
|
374 | 374 | remotephases = listkeys(pushop.remote, b'phases') |
|
375 | 375 | if not remotephases.get(b'publishing', False): |
|
376 | 376 | return |
|
377 | 377 | |
|
378 | 378 | if pushop.revs is None: |
|
379 | 379 | published = repo.filtered(b'served').revs(b'not public()') |
|
380 | 380 | else: |
|
381 | 381 | published = repo.revs(b'::%ln - public()', pushop.revs) |
|
382 | 382 | if published: |
|
383 | 383 | if behavior == b'warn': |
|
384 | 384 | ui.warn( |
|
385 | 385 | _(b'%i changesets about to be published\n') % len(published) |
|
386 | 386 | ) |
|
387 | 387 | elif behavior == b'confirm': |
|
388 | 388 | if ui.promptchoice( |
|
389 | 389 | _(b'push and publish %i changesets (yn)?$$ &Yes $$ &No') |
|
390 | 390 | % len(published) |
|
391 | 391 | ): |
|
392 | 392 | raise error.Abort(_(b'user quit')) |
|
393 | 393 | elif behavior == b'abort': |
|
394 | 394 | msg = _(b'push would publish %i changesets') % len(published) |
|
395 | 395 | hint = _( |
|
396 | 396 | b"use --publish or adjust 'experimental.auto-publish'" |
|
397 | 397 | b" config" |
|
398 | 398 | ) |
|
399 | 399 | raise error.Abort(msg, hint=hint) |
|
400 | 400 | |
|
401 | 401 | |
|
402 | 402 | def _forcebundle1(op): |
|
403 | 403 | """return true if a pull/push must use bundle1 |
|
404 | 404 | |
|
405 | 405 | This function is used to allow testing of the older bundle version""" |
|
406 | 406 | ui = op.repo.ui |
|
407 | 407 | # The goal is this config is to allow developer to choose the bundle |
|
408 | 408 | # version used during exchanged. This is especially handy during test. |
|
409 | 409 | # Value is a list of bundle version to be picked from, highest version |
|
410 | 410 | # should be used. |
|
411 | 411 | # |
|
412 | 412 | # developer config: devel.legacy.exchange |
|
413 | 413 | exchange = ui.configlist(b'devel', b'legacy.exchange') |
|
414 | 414 | forcebundle1 = b'bundle2' not in exchange and b'bundle1' in exchange |
|
415 | 415 | return forcebundle1 or not op.remote.capable(b'bundle2') |
|
416 | 416 | |
|
417 | 417 | |
|
418 | 418 | class pushoperation(object): |
|
419 | 419 | """A object that represent a single push operation |
|
420 | 420 | |
|
421 | 421 | Its purpose is to carry push related state and very common operations. |
|
422 | 422 | |
|
423 | 423 | A new pushoperation should be created at the beginning of each push and |
|
424 | 424 | discarded afterward. |
|
425 | 425 | """ |
|
426 | 426 | |
|
427 | 427 | def __init__( |
|
428 | 428 | self, |
|
429 | 429 | repo, |
|
430 | 430 | remote, |
|
431 | 431 | force=False, |
|
432 | 432 | revs=None, |
|
433 | 433 | newbranch=False, |
|
434 | 434 | bookmarks=(), |
|
435 | 435 | publish=False, |
|
436 | 436 | pushvars=None, |
|
437 | 437 | ): |
|
438 | 438 | # repo we push from |
|
439 | 439 | self.repo = repo |
|
440 | 440 | self.ui = repo.ui |
|
441 | 441 | # repo we push to |
|
442 | 442 | self.remote = remote |
|
443 | 443 | # force option provided |
|
444 | 444 | self.force = force |
|
445 | 445 | # revs to be pushed (None is "all") |
|
446 | 446 | self.revs = revs |
|
447 | 447 | # bookmark explicitly pushed |
|
448 | 448 | self.bookmarks = bookmarks |
|
449 | 449 | # allow push of new branch |
|
450 | 450 | self.newbranch = newbranch |
|
451 | 451 | # step already performed |
|
452 | 452 | # (used to check what steps have been already performed through bundle2) |
|
453 | 453 | self.stepsdone = set() |
|
454 | 454 | # Integer version of the changegroup push result |
|
455 | 455 | # - None means nothing to push |
|
456 | 456 | # - 0 means HTTP error |
|
457 | 457 | # - 1 means we pushed and remote head count is unchanged *or* |
|
458 | 458 | # we have outgoing changesets but refused to push |
|
459 | 459 | # - other values as described by addchangegroup() |
|
460 | 460 | self.cgresult = None |
|
461 | 461 | # Boolean value for the bookmark push |
|
462 | 462 | self.bkresult = None |
|
463 | 463 | # discover.outgoing object (contains common and outgoing data) |
|
464 | 464 | self.outgoing = None |
|
465 | 465 | # all remote topological heads before the push |
|
466 | 466 | self.remoteheads = None |
|
467 | 467 | # Details of the remote branch pre and post push |
|
468 | 468 | # |
|
469 | 469 | # mapping: {'branch': ([remoteheads], |
|
470 | 470 | # [newheads], |
|
471 | 471 | # [unsyncedheads], |
|
472 | 472 | # [discardedheads])} |
|
473 | 473 | # - branch: the branch name |
|
474 | 474 | # - remoteheads: the list of remote heads known locally |
|
475 | 475 | # None if the branch is new |
|
476 | 476 | # - newheads: the new remote heads (known locally) with outgoing pushed |
|
477 | 477 | # - unsyncedheads: the list of remote heads unknown locally. |
|
478 | 478 | # - discardedheads: the list of remote heads made obsolete by the push |
|
479 | 479 | self.pushbranchmap = None |
|
480 | 480 | # testable as a boolean indicating if any nodes are missing locally. |
|
481 | 481 | self.incoming = None |
|
482 | 482 | # summary of the remote phase situation |
|
483 | 483 | self.remotephases = None |
|
484 | 484 | # phases changes that must be pushed along side the changesets |
|
485 | 485 | self.outdatedphases = None |
|
486 | 486 | # phases changes that must be pushed if changeset push fails |
|
487 | 487 | self.fallbackoutdatedphases = None |
|
488 | 488 | # outgoing obsmarkers |
|
489 | 489 | self.outobsmarkers = set() |
|
490 | 490 | # outgoing bookmarks, list of (bm, oldnode | '', newnode | '') |
|
491 | 491 | self.outbookmarks = [] |
|
492 | 492 | # transaction manager |
|
493 | 493 | self.trmanager = None |
|
494 | 494 | # map { pushkey partid -> callback handling failure} |
|
495 | 495 | # used to handle exception from mandatory pushkey part failure |
|
496 | 496 | self.pkfailcb = {} |
|
497 | 497 | # an iterable of pushvars or None |
|
498 | 498 | self.pushvars = pushvars |
|
499 | 499 | # publish pushed changesets |
|
500 | 500 | self.publish = publish |
|
501 | 501 | |
|
502 | 502 | @util.propertycache |
|
503 | 503 | def futureheads(self): |
|
504 | 504 | """future remote heads if the changeset push succeeds""" |
|
505 | 505 | return self.outgoing.missingheads |
|
506 | 506 | |
|
507 | 507 | @util.propertycache |
|
508 | 508 | def fallbackheads(self): |
|
509 | 509 | """future remote heads if the changeset push fails""" |
|
510 | 510 | if self.revs is None: |
|
511 | 511 | # not target to push, all common are relevant |
|
512 | 512 | return self.outgoing.commonheads |
|
513 | 513 | unfi = self.repo.unfiltered() |
|
514 | 514 | # I want cheads = heads(::missingheads and ::commonheads) |
|
515 | 515 | # (missingheads is revs with secret changeset filtered out) |
|
516 | 516 | # |
|
517 | 517 | # This can be expressed as: |
|
518 | 518 | # cheads = ( (missingheads and ::commonheads) |
|
519 | 519 | # + (commonheads and ::missingheads))" |
|
520 | 520 | # ) |
|
521 | 521 | # |
|
522 | 522 | # while trying to push we already computed the following: |
|
523 | 523 | # common = (::commonheads) |
|
524 | 524 | # missing = ((commonheads::missingheads) - commonheads) |
|
525 | 525 | # |
|
526 | 526 | # We can pick: |
|
527 | 527 | # * missingheads part of common (::commonheads) |
|
528 | 528 | common = self.outgoing.common |
|
529 | 529 | rev = self.repo.changelog.index.rev |
|
530 | 530 | cheads = [node for node in self.revs if rev(node) in common] |
|
531 | 531 | # and |
|
532 | 532 | # * commonheads parents on missing |
|
533 | 533 | revset = unfi.set( |
|
534 | 534 | b'%ln and parents(roots(%ln))', |
|
535 | 535 | self.outgoing.commonheads, |
|
536 | 536 | self.outgoing.missing, |
|
537 | 537 | ) |
|
538 | 538 | cheads.extend(c.node() for c in revset) |
|
539 | 539 | return cheads |
|
540 | 540 | |
|
541 | 541 | @property |
|
542 | 542 | def commonheads(self): |
|
543 | 543 | """set of all common heads after changeset bundle push""" |
|
544 | 544 | if self.cgresult: |
|
545 | 545 | return self.futureheads |
|
546 | 546 | else: |
|
547 | 547 | return self.fallbackheads |
|
548 | 548 | |
|
549 | 549 | |
|
550 | 550 | # mapping of message used when pushing bookmark |
|
551 | 551 | bookmsgmap = { |
|
552 | 552 | b'update': ( |
|
553 | 553 | _(b"updating bookmark %s\n"), |
|
554 | 554 | _(b'updating bookmark %s failed!\n'), |
|
555 | 555 | ), |
|
556 | 556 | b'export': ( |
|
557 | 557 | _(b"exporting bookmark %s\n"), |
|
558 | 558 | _(b'exporting bookmark %s failed!\n'), |
|
559 | 559 | ), |
|
560 | 560 | b'delete': ( |
|
561 | 561 | _(b"deleting remote bookmark %s\n"), |
|
562 | 562 | _(b'deleting remote bookmark %s failed!\n'), |
|
563 | 563 | ), |
|
564 | 564 | } |
|
565 | 565 | |
|
566 | 566 | |
|
567 | 567 | def push( |
|
568 | 568 | repo, |
|
569 | 569 | remote, |
|
570 | 570 | force=False, |
|
571 | 571 | revs=None, |
|
572 | 572 | newbranch=False, |
|
573 | 573 | bookmarks=(), |
|
574 | 574 | publish=False, |
|
575 | 575 | opargs=None, |
|
576 | 576 | ): |
|
577 | 577 | '''Push outgoing changesets (limited by revs) from a local |
|
578 | 578 | repository to remote. Return an integer: |
|
579 | 579 | - None means nothing to push |
|
580 | 580 | - 0 means HTTP error |
|
581 | 581 | - 1 means we pushed and remote head count is unchanged *or* |
|
582 | 582 | we have outgoing changesets but refused to push |
|
583 | 583 | - other values as described by addchangegroup() |
|
584 | 584 | ''' |
|
585 | 585 | if opargs is None: |
|
586 | 586 | opargs = {} |
|
587 | 587 | pushop = pushoperation( |
|
588 | 588 | repo, |
|
589 | 589 | remote, |
|
590 | 590 | force, |
|
591 | 591 | revs, |
|
592 | 592 | newbranch, |
|
593 | 593 | bookmarks, |
|
594 | 594 | publish, |
|
595 | 595 | **pycompat.strkwargs(opargs) |
|
596 | 596 | ) |
|
597 | 597 | if pushop.remote.local(): |
|
598 | 598 | missing = ( |
|
599 | 599 | set(pushop.repo.requirements) - pushop.remote.local().supported |
|
600 | 600 | ) |
|
601 | 601 | if missing: |
|
602 | 602 | msg = _( |
|
603 | 603 | b"required features are not" |
|
604 | 604 | b" supported in the destination:" |
|
605 | 605 | b" %s" |
|
606 | 606 | ) % (b', '.join(sorted(missing))) |
|
607 | 607 | raise error.Abort(msg) |
|
608 | 608 | |
|
609 | 609 | if not pushop.remote.canpush(): |
|
610 | 610 | raise error.Abort(_(b"destination does not support push")) |
|
611 | 611 | |
|
612 | 612 | if not pushop.remote.capable(b'unbundle'): |
|
613 | 613 | raise error.Abort( |
|
614 | 614 | _( |
|
615 | 615 | b'cannot push: destination does not support the ' |
|
616 | 616 | b'unbundle wire protocol command' |
|
617 | 617 | ) |
|
618 | 618 | ) |
|
619 | 619 | |
|
620 | 620 | # get lock as we might write phase data |
|
621 | 621 | wlock = lock = None |
|
622 | 622 | try: |
|
623 | 623 | # bundle2 push may receive a reply bundle touching bookmarks |
|
624 | 624 | # requiring the wlock. Take it now to ensure proper ordering. |
|
625 | 625 | maypushback = pushop.ui.configbool(b'experimental', b'bundle2.pushback') |
|
626 | 626 | if ( |
|
627 | 627 | (not _forcebundle1(pushop)) |
|
628 | 628 | and maypushback |
|
629 | 629 | and not bookmod.bookmarksinstore(repo) |
|
630 | 630 | ): |
|
631 | 631 | wlock = pushop.repo.wlock() |
|
632 | 632 | lock = pushop.repo.lock() |
|
633 | 633 | pushop.trmanager = transactionmanager( |
|
634 | 634 | pushop.repo, b'push-response', pushop.remote.url() |
|
635 | 635 | ) |
|
636 | 636 | except error.LockUnavailable as err: |
|
637 | 637 | # source repo cannot be locked. |
|
638 | 638 | # We do not abort the push, but just disable the local phase |
|
639 | 639 | # synchronisation. |
|
640 | 640 | msg = b'cannot lock source repository: %s\n' % stringutil.forcebytestr( |
|
641 | 641 | err |
|
642 | 642 | ) |
|
643 | 643 | pushop.ui.debug(msg) |
|
644 | 644 | |
|
645 | 645 | with wlock or util.nullcontextmanager(): |
|
646 | 646 | with lock or util.nullcontextmanager(): |
|
647 | 647 | with pushop.trmanager or util.nullcontextmanager(): |
|
648 | 648 | pushop.repo.checkpush(pushop) |
|
649 | 649 | _checkpublish(pushop) |
|
650 | 650 | _pushdiscovery(pushop) |
|
651 | 651 | if not pushop.force: |
|
652 | 652 | _checksubrepostate(pushop) |
|
653 | 653 | if not _forcebundle1(pushop): |
|
654 | 654 | _pushbundle2(pushop) |
|
655 | 655 | _pushchangeset(pushop) |
|
656 | 656 | _pushsyncphase(pushop) |
|
657 | 657 | _pushobsolete(pushop) |
|
658 | 658 | _pushbookmark(pushop) |
|
659 | 659 | |
|
660 | 660 | if repo.ui.configbool(b'experimental', b'remotenames'): |
|
661 | 661 | logexchange.pullremotenames(repo, remote) |
|
662 | 662 | |
|
663 | 663 | return pushop |
|
664 | 664 | |
|
665 | 665 | |
|
666 | 666 | # list of steps to perform discovery before push |
|
667 | 667 | pushdiscoveryorder = [] |
|
668 | 668 | |
|
669 | 669 | # Mapping between step name and function |
|
670 | 670 | # |
|
671 | 671 | # This exists to help extensions wrap steps if necessary |
|
672 | 672 | pushdiscoverymapping = {} |
|
673 | 673 | |
|
674 | 674 | |
|
675 | 675 | def pushdiscovery(stepname): |
|
676 | 676 | """decorator for function performing discovery before push |
|
677 | 677 | |
|
678 | 678 | The function is added to the step -> function mapping and appended to the |
|
679 | 679 | list of steps. Beware that decorated function will be added in order (this |
|
680 | 680 | may matter). |
|
681 | 681 | |
|
682 | 682 | You can only use this decorator for a new step, if you want to wrap a step |
|
683 | 683 | from an extension, change the pushdiscovery dictionary directly.""" |
|
684 | 684 | |
|
685 | 685 | def dec(func): |
|
686 | 686 | assert stepname not in pushdiscoverymapping |
|
687 | 687 | pushdiscoverymapping[stepname] = func |
|
688 | 688 | pushdiscoveryorder.append(stepname) |
|
689 | 689 | return func |
|
690 | 690 | |
|
691 | 691 | return dec |
|
692 | 692 | |
|
693 | 693 | |
|
694 | 694 | def _pushdiscovery(pushop): |
|
695 | 695 | """Run all discovery steps""" |
|
696 | 696 | for stepname in pushdiscoveryorder: |
|
697 | 697 | step = pushdiscoverymapping[stepname] |
|
698 | 698 | step(pushop) |
|
699 | 699 | |
|
700 | 700 | |
|
701 | 701 | def _checksubrepostate(pushop): |
|
702 | 702 | """Ensure all outgoing referenced subrepo revisions are present locally""" |
|
703 | 703 | for n in pushop.outgoing.missing: |
|
704 | 704 | ctx = pushop.repo[n] |
|
705 | 705 | |
|
706 | 706 | if b'.hgsub' in ctx.manifest() and b'.hgsubstate' in ctx.files(): |
|
707 | 707 | for subpath in sorted(ctx.substate): |
|
708 | 708 | sub = ctx.sub(subpath) |
|
709 | 709 | sub.verify(onpush=True) |
|
710 | 710 | |
|
711 | 711 | |
|
712 | 712 | @pushdiscovery(b'changeset') |
|
713 | 713 | def _pushdiscoverychangeset(pushop): |
|
714 | 714 | """discover the changeset that need to be pushed""" |
|
715 | 715 | fci = discovery.findcommonincoming |
|
716 | 716 | if pushop.revs: |
|
717 | 717 | commoninc = fci( |
|
718 | 718 | pushop.repo, |
|
719 | 719 | pushop.remote, |
|
720 | 720 | force=pushop.force, |
|
721 | 721 | ancestorsof=pushop.revs, |
|
722 | 722 | ) |
|
723 | 723 | else: |
|
724 | 724 | commoninc = fci(pushop.repo, pushop.remote, force=pushop.force) |
|
725 | 725 | common, inc, remoteheads = commoninc |
|
726 | 726 | fco = discovery.findcommonoutgoing |
|
727 | 727 | outgoing = fco( |
|
728 | 728 | pushop.repo, |
|
729 | 729 | pushop.remote, |
|
730 | 730 | onlyheads=pushop.revs, |
|
731 | 731 | commoninc=commoninc, |
|
732 | 732 | force=pushop.force, |
|
733 | 733 | ) |
|
734 | 734 | pushop.outgoing = outgoing |
|
735 | 735 | pushop.remoteheads = remoteheads |
|
736 | 736 | pushop.incoming = inc |
|
737 | 737 | |
|
738 | 738 | |
|
739 | 739 | @pushdiscovery(b'phase') |
|
740 | 740 | def _pushdiscoveryphase(pushop): |
|
741 | 741 | """discover the phase that needs to be pushed |
|
742 | 742 | |
|
743 | 743 | (computed for both success and failure case for changesets push)""" |
|
744 | 744 | outgoing = pushop.outgoing |
|
745 | 745 | unfi = pushop.repo.unfiltered() |
|
746 | 746 | remotephases = listkeys(pushop.remote, b'phases') |
|
747 | 747 | |
|
748 | 748 | if ( |
|
749 | 749 | pushop.ui.configbool(b'ui', b'_usedassubrepo') |
|
750 | 750 | and remotephases # server supports phases |
|
751 | 751 | and not pushop.outgoing.missing # no changesets to be pushed |
|
752 | 752 | and remotephases.get(b'publishing', False) |
|
753 | 753 | ): |
|
754 | 754 | # When: |
|
755 | 755 | # - this is a subrepo push |
|
756 | 756 | # - and remote support phase |
|
757 | 757 | # - and no changeset are to be pushed |
|
758 | 758 | # - and remote is publishing |
|
759 | 759 | # We may be in issue 3781 case! |
|
760 | 760 | # We drop the possible phase synchronisation done by |
|
761 | 761 | # courtesy to publish changesets possibly locally draft |
|
762 | 762 | # on the remote. |
|
763 | 763 | pushop.outdatedphases = [] |
|
764 | 764 | pushop.fallbackoutdatedphases = [] |
|
765 | 765 | return |
|
766 | 766 | |
|
767 | 767 | pushop.remotephases = phases.remotephasessummary( |
|
768 | 768 | pushop.repo, pushop.fallbackheads, remotephases |
|
769 | 769 | ) |
|
770 | 770 | droots = pushop.remotephases.draftroots |
|
771 | 771 | |
|
772 | 772 | extracond = b'' |
|
773 | 773 | if not pushop.remotephases.publishing: |
|
774 | 774 | extracond = b' and public()' |
|
775 | 775 | revset = b'heads((%%ln::%%ln) %s)' % extracond |
|
776 | 776 | # Get the list of all revs draft on remote by public here. |
|
777 | 777 | # XXX Beware that revset break if droots is not strictly |
|
778 | 778 | # XXX root we may want to ensure it is but it is costly |
|
779 | 779 | fallback = list(unfi.set(revset, droots, pushop.fallbackheads)) |
|
780 | 780 | if not pushop.remotephases.publishing and pushop.publish: |
|
781 | 781 | future = list( |
|
782 | 782 | unfi.set( |
|
783 | 783 | b'%ln and (not public() or %ln::)', pushop.futureheads, droots |
|
784 | 784 | ) |
|
785 | 785 | ) |
|
786 | 786 | elif not outgoing.missing: |
|
787 | 787 | future = fallback |
|
788 | 788 | else: |
|
789 | 789 | # adds changeset we are going to push as draft |
|
790 | 790 | # |
|
791 | 791 | # should not be necessary for publishing server, but because of an |
|
792 | 792 | # issue fixed in xxxxx we have to do it anyway. |
|
793 | 793 | fdroots = list( |
|
794 | 794 | unfi.set(b'roots(%ln + %ln::)', outgoing.missing, droots) |
|
795 | 795 | ) |
|
796 | 796 | fdroots = [f.node() for f in fdroots] |
|
797 | 797 | future = list(unfi.set(revset, fdroots, pushop.futureheads)) |
|
798 | 798 | pushop.outdatedphases = future |
|
799 | 799 | pushop.fallbackoutdatedphases = fallback |
|
800 | 800 | |
|
801 | 801 | |
|
802 | 802 | @pushdiscovery(b'obsmarker') |
|
803 | 803 | def _pushdiscoveryobsmarkers(pushop): |
|
804 | 804 | if not obsolete.isenabled(pushop.repo, obsolete.exchangeopt): |
|
805 | 805 | return |
|
806 | 806 | |
|
807 | 807 | if not pushop.repo.obsstore: |
|
808 | 808 | return |
|
809 | 809 | |
|
810 | 810 | if b'obsolete' not in listkeys(pushop.remote, b'namespaces'): |
|
811 | 811 | return |
|
812 | 812 | |
|
813 | 813 | repo = pushop.repo |
|
814 | 814 | # very naive computation, that can be quite expensive on big repo. |
|
815 | 815 | # However: evolution is currently slow on them anyway. |
|
816 | 816 | nodes = (c.node() for c in repo.set(b'::%ln', pushop.futureheads)) |
|
817 | 817 | pushop.outobsmarkers = pushop.repo.obsstore.relevantmarkers(nodes) |
|
818 | 818 | |
|
819 | 819 | |
|
820 | 820 | @pushdiscovery(b'bookmarks') |
|
821 | 821 | def _pushdiscoverybookmarks(pushop): |
|
822 | 822 | ui = pushop.ui |
|
823 | 823 | repo = pushop.repo.unfiltered() |
|
824 | 824 | remote = pushop.remote |
|
825 | 825 | ui.debug(b"checking for updated bookmarks\n") |
|
826 | 826 | ancestors = () |
|
827 | 827 | if pushop.revs: |
|
828 | 828 | revnums = pycompat.maplist(repo.changelog.rev, pushop.revs) |
|
829 | 829 | ancestors = repo.changelog.ancestors(revnums, inclusive=True) |
|
830 | 830 | |
|
831 | 831 | remotebookmark = bookmod.unhexlifybookmarks(listkeys(remote, b'bookmarks')) |
|
832 | 832 | |
|
833 | 833 | explicit = { |
|
834 | 834 | repo._bookmarks.expandname(bookmark) for bookmark in pushop.bookmarks |
|
835 | 835 | } |
|
836 | 836 | |
|
837 | 837 | comp = bookmod.comparebookmarks(repo, repo._bookmarks, remotebookmark) |
|
838 | 838 | return _processcompared(pushop, ancestors, explicit, remotebookmark, comp) |
|
839 | 839 | |
|
840 | 840 | |
|
841 | 841 | def _processcompared(pushop, pushed, explicit, remotebms, comp): |
|
842 | 842 | """take decision on bookmarks to push to the remote repo |
|
843 | 843 | |
|
844 | 844 | Exists to help extensions alter this behavior. |
|
845 | 845 | """ |
|
846 | 846 | addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = comp |
|
847 | 847 | |
|
848 | 848 | repo = pushop.repo |
|
849 | 849 | |
|
850 | 850 | for b, scid, dcid in advsrc: |
|
851 | 851 | if b in explicit: |
|
852 | 852 | explicit.remove(b) |
|
853 | 853 | if not pushed or repo[scid].rev() in pushed: |
|
854 | 854 | pushop.outbookmarks.append((b, dcid, scid)) |
|
855 | 855 | # search added bookmark |
|
856 | 856 | for b, scid, dcid in addsrc: |
|
857 | 857 | if b in explicit: |
|
858 | 858 | explicit.remove(b) |
|
859 | pushop.outbookmarks.append((b, b'', scid)) | |
|
859 | if bookmod.isdivergent(b): | |
|
860 | pushop.ui.warn(_(b'cannot push divergent bookmark %s!\n') % b) | |
|
861 | pushop.bkresult = 2 | |
|
862 | else: | |
|
863 | pushop.outbookmarks.append((b, b'', scid)) | |
|
860 | 864 | # search for overwritten bookmark |
|
861 | 865 | for b, scid, dcid in list(advdst) + list(diverge) + list(differ): |
|
862 | 866 | if b in explicit: |
|
863 | 867 | explicit.remove(b) |
|
864 | 868 | pushop.outbookmarks.append((b, dcid, scid)) |
|
865 | 869 | # search for bookmark to delete |
|
866 | 870 | for b, scid, dcid in adddst: |
|
867 | 871 | if b in explicit: |
|
868 | 872 | explicit.remove(b) |
|
869 | 873 | # treat as "deleted locally" |
|
870 | 874 | pushop.outbookmarks.append((b, dcid, b'')) |
|
871 | 875 | # identical bookmarks shouldn't get reported |
|
872 | 876 | for b, scid, dcid in same: |
|
873 | 877 | if b in explicit: |
|
874 | 878 | explicit.remove(b) |
|
875 | 879 | |
|
876 | 880 | if explicit: |
|
877 | 881 | explicit = sorted(explicit) |
|
878 | 882 | # we should probably list all of them |
|
879 | 883 | pushop.ui.warn( |
|
880 | 884 | _( |
|
881 | 885 | b'bookmark %s does not exist on the local ' |
|
882 | 886 | b'or remote repository!\n' |
|
883 | 887 | ) |
|
884 | 888 | % explicit[0] |
|
885 | 889 | ) |
|
886 | 890 | pushop.bkresult = 2 |
|
887 | 891 | |
|
888 | 892 | pushop.outbookmarks.sort() |
|
889 | 893 | |
|
890 | 894 | |
|
891 | 895 | def _pushcheckoutgoing(pushop): |
|
892 | 896 | outgoing = pushop.outgoing |
|
893 | 897 | unfi = pushop.repo.unfiltered() |
|
894 | 898 | if not outgoing.missing: |
|
895 | 899 | # nothing to push |
|
896 | 900 | scmutil.nochangesfound(unfi.ui, unfi, outgoing.excluded) |
|
897 | 901 | return False |
|
898 | 902 | # something to push |
|
899 | 903 | if not pushop.force: |
|
900 | 904 | # if repo.obsstore == False --> no obsolete |
|
901 | 905 | # then, save the iteration |
|
902 | 906 | if unfi.obsstore: |
|
903 | 907 | # this message are here for 80 char limit reason |
|
904 | 908 | mso = _(b"push includes obsolete changeset: %s!") |
|
905 | 909 | mspd = _(b"push includes phase-divergent changeset: %s!") |
|
906 | 910 | mscd = _(b"push includes content-divergent changeset: %s!") |
|
907 | 911 | mst = { |
|
908 | 912 | b"orphan": _(b"push includes orphan changeset: %s!"), |
|
909 | 913 | b"phase-divergent": mspd, |
|
910 | 914 | b"content-divergent": mscd, |
|
911 | 915 | } |
|
912 | 916 | # If we are to push if there is at least one |
|
913 | 917 | # obsolete or unstable changeset in missing, at |
|
914 | 918 | # least one of the missinghead will be obsolete or |
|
915 | 919 | # unstable. So checking heads only is ok |
|
916 | 920 | for node in outgoing.missingheads: |
|
917 | 921 | ctx = unfi[node] |
|
918 | 922 | if ctx.obsolete(): |
|
919 | 923 | raise error.Abort(mso % ctx) |
|
920 | 924 | elif ctx.isunstable(): |
|
921 | 925 | # TODO print more than one instability in the abort |
|
922 | 926 | # message |
|
923 | 927 | raise error.Abort(mst[ctx.instabilities()[0]] % ctx) |
|
924 | 928 | |
|
925 | 929 | discovery.checkheads(pushop) |
|
926 | 930 | return True |
|
927 | 931 | |
|
928 | 932 | |
|
929 | 933 | # List of names of steps to perform for an outgoing bundle2, order matters. |
|
930 | 934 | b2partsgenorder = [] |
|
931 | 935 | |
|
932 | 936 | # Mapping between step name and function |
|
933 | 937 | # |
|
934 | 938 | # This exists to help extensions wrap steps if necessary |
|
935 | 939 | b2partsgenmapping = {} |
|
936 | 940 | |
|
937 | 941 | |
|
938 | 942 | def b2partsgenerator(stepname, idx=None): |
|
939 | 943 | """decorator for function generating bundle2 part |
|
940 | 944 | |
|
941 | 945 | The function is added to the step -> function mapping and appended to the |
|
942 | 946 | list of steps. Beware that decorated functions will be added in order |
|
943 | 947 | (this may matter). |
|
944 | 948 | |
|
945 | 949 | You can only use this decorator for new steps, if you want to wrap a step |
|
946 | 950 | from an extension, attack the b2partsgenmapping dictionary directly.""" |
|
947 | 951 | |
|
948 | 952 | def dec(func): |
|
949 | 953 | assert stepname not in b2partsgenmapping |
|
950 | 954 | b2partsgenmapping[stepname] = func |
|
951 | 955 | if idx is None: |
|
952 | 956 | b2partsgenorder.append(stepname) |
|
953 | 957 | else: |
|
954 | 958 | b2partsgenorder.insert(idx, stepname) |
|
955 | 959 | return func |
|
956 | 960 | |
|
957 | 961 | return dec |
|
958 | 962 | |
|
959 | 963 | |
|
960 | 964 | def _pushb2ctxcheckheads(pushop, bundler): |
|
961 | 965 | """Generate race condition checking parts |
|
962 | 966 | |
|
963 | 967 | Exists as an independent function to aid extensions |
|
964 | 968 | """ |
|
965 | 969 | # * 'force' do not check for push race, |
|
966 | 970 | # * if we don't push anything, there are nothing to check. |
|
967 | 971 | if not pushop.force and pushop.outgoing.missingheads: |
|
968 | 972 | allowunrelated = b'related' in bundler.capabilities.get( |
|
969 | 973 | b'checkheads', () |
|
970 | 974 | ) |
|
971 | 975 | emptyremote = pushop.pushbranchmap is None |
|
972 | 976 | if not allowunrelated or emptyremote: |
|
973 | 977 | bundler.newpart(b'check:heads', data=iter(pushop.remoteheads)) |
|
974 | 978 | else: |
|
975 | 979 | affected = set() |
|
976 | 980 | for branch, heads in pycompat.iteritems(pushop.pushbranchmap): |
|
977 | 981 | remoteheads, newheads, unsyncedheads, discardedheads = heads |
|
978 | 982 | if remoteheads is not None: |
|
979 | 983 | remote = set(remoteheads) |
|
980 | 984 | affected |= set(discardedheads) & remote |
|
981 | 985 | affected |= remote - set(newheads) |
|
982 | 986 | if affected: |
|
983 | 987 | data = iter(sorted(affected)) |
|
984 | 988 | bundler.newpart(b'check:updated-heads', data=data) |
|
985 | 989 | |
|
986 | 990 | |
|
987 | 991 | def _pushing(pushop): |
|
988 | 992 | """return True if we are pushing anything""" |
|
989 | 993 | return bool( |
|
990 | 994 | pushop.outgoing.missing |
|
991 | 995 | or pushop.outdatedphases |
|
992 | 996 | or pushop.outobsmarkers |
|
993 | 997 | or pushop.outbookmarks |
|
994 | 998 | ) |
|
995 | 999 | |
|
996 | 1000 | |
|
997 | 1001 | @b2partsgenerator(b'check-bookmarks') |
|
998 | 1002 | def _pushb2checkbookmarks(pushop, bundler): |
|
999 | 1003 | """insert bookmark move checking""" |
|
1000 | 1004 | if not _pushing(pushop) or pushop.force: |
|
1001 | 1005 | return |
|
1002 | 1006 | b2caps = bundle2.bundle2caps(pushop.remote) |
|
1003 | 1007 | hasbookmarkcheck = b'bookmarks' in b2caps |
|
1004 | 1008 | if not (pushop.outbookmarks and hasbookmarkcheck): |
|
1005 | 1009 | return |
|
1006 | 1010 | data = [] |
|
1007 | 1011 | for book, old, new in pushop.outbookmarks: |
|
1008 | 1012 | data.append((book, old)) |
|
1009 | 1013 | checkdata = bookmod.binaryencode(data) |
|
1010 | 1014 | bundler.newpart(b'check:bookmarks', data=checkdata) |
|
1011 | 1015 | |
|
1012 | 1016 | |
|
1013 | 1017 | @b2partsgenerator(b'check-phases') |
|
1014 | 1018 | def _pushb2checkphases(pushop, bundler): |
|
1015 | 1019 | """insert phase move checking""" |
|
1016 | 1020 | if not _pushing(pushop) or pushop.force: |
|
1017 | 1021 | return |
|
1018 | 1022 | b2caps = bundle2.bundle2caps(pushop.remote) |
|
1019 | 1023 | hasphaseheads = b'heads' in b2caps.get(b'phases', ()) |
|
1020 | 1024 | if pushop.remotephases is not None and hasphaseheads: |
|
1021 | 1025 | # check that the remote phase has not changed |
|
1022 | 1026 | checks = [[] for p in phases.allphases] |
|
1023 | 1027 | checks[phases.public].extend(pushop.remotephases.publicheads) |
|
1024 | 1028 | checks[phases.draft].extend(pushop.remotephases.draftroots) |
|
1025 | 1029 | if any(checks): |
|
1026 | 1030 | for nodes in checks: |
|
1027 | 1031 | nodes.sort() |
|
1028 | 1032 | checkdata = phases.binaryencode(checks) |
|
1029 | 1033 | bundler.newpart(b'check:phases', data=checkdata) |
|
1030 | 1034 | |
|
1031 | 1035 | |
|
1032 | 1036 | @b2partsgenerator(b'changeset') |
|
1033 | 1037 | def _pushb2ctx(pushop, bundler): |
|
1034 | 1038 | """handle changegroup push through bundle2 |
|
1035 | 1039 | |
|
1036 | 1040 | addchangegroup result is stored in the ``pushop.cgresult`` attribute. |
|
1037 | 1041 | """ |
|
1038 | 1042 | if b'changesets' in pushop.stepsdone: |
|
1039 | 1043 | return |
|
1040 | 1044 | pushop.stepsdone.add(b'changesets') |
|
1041 | 1045 | # Send known heads to the server for race detection. |
|
1042 | 1046 | if not _pushcheckoutgoing(pushop): |
|
1043 | 1047 | return |
|
1044 | 1048 | pushop.repo.prepushoutgoinghooks(pushop) |
|
1045 | 1049 | |
|
1046 | 1050 | _pushb2ctxcheckheads(pushop, bundler) |
|
1047 | 1051 | |
|
1048 | 1052 | b2caps = bundle2.bundle2caps(pushop.remote) |
|
1049 | 1053 | version = b'01' |
|
1050 | 1054 | cgversions = b2caps.get(b'changegroup') |
|
1051 | 1055 | if cgversions: # 3.1 and 3.2 ship with an empty value |
|
1052 | 1056 | cgversions = [ |
|
1053 | 1057 | v |
|
1054 | 1058 | for v in cgversions |
|
1055 | 1059 | if v in changegroup.supportedoutgoingversions(pushop.repo) |
|
1056 | 1060 | ] |
|
1057 | 1061 | if not cgversions: |
|
1058 | 1062 | raise error.Abort(_(b'no common changegroup version')) |
|
1059 | 1063 | version = max(cgversions) |
|
1060 | 1064 | cgstream = changegroup.makestream( |
|
1061 | 1065 | pushop.repo, pushop.outgoing, version, b'push' |
|
1062 | 1066 | ) |
|
1063 | 1067 | cgpart = bundler.newpart(b'changegroup', data=cgstream) |
|
1064 | 1068 | if cgversions: |
|
1065 | 1069 | cgpart.addparam(b'version', version) |
|
1066 | 1070 | if b'treemanifest' in pushop.repo.requirements: |
|
1067 | 1071 | cgpart.addparam(b'treemanifest', b'1') |
|
1068 | 1072 | if b'exp-sidedata-flag' in pushop.repo.requirements: |
|
1069 | 1073 | cgpart.addparam(b'exp-sidedata', b'1') |
|
1070 | 1074 | |
|
1071 | 1075 | def handlereply(op): |
|
1072 | 1076 | """extract addchangegroup returns from server reply""" |
|
1073 | 1077 | cgreplies = op.records.getreplies(cgpart.id) |
|
1074 | 1078 | assert len(cgreplies[b'changegroup']) == 1 |
|
1075 | 1079 | pushop.cgresult = cgreplies[b'changegroup'][0][b'return'] |
|
1076 | 1080 | |
|
1077 | 1081 | return handlereply |
|
1078 | 1082 | |
|
1079 | 1083 | |
|
1080 | 1084 | @b2partsgenerator(b'phase') |
|
1081 | 1085 | def _pushb2phases(pushop, bundler): |
|
1082 | 1086 | """handle phase push through bundle2""" |
|
1083 | 1087 | if b'phases' in pushop.stepsdone: |
|
1084 | 1088 | return |
|
1085 | 1089 | b2caps = bundle2.bundle2caps(pushop.remote) |
|
1086 | 1090 | ui = pushop.repo.ui |
|
1087 | 1091 | |
|
1088 | 1092 | legacyphase = b'phases' in ui.configlist(b'devel', b'legacy.exchange') |
|
1089 | 1093 | haspushkey = b'pushkey' in b2caps |
|
1090 | 1094 | hasphaseheads = b'heads' in b2caps.get(b'phases', ()) |
|
1091 | 1095 | |
|
1092 | 1096 | if hasphaseheads and not legacyphase: |
|
1093 | 1097 | return _pushb2phaseheads(pushop, bundler) |
|
1094 | 1098 | elif haspushkey: |
|
1095 | 1099 | return _pushb2phasespushkey(pushop, bundler) |
|
1096 | 1100 | |
|
1097 | 1101 | |
|
1098 | 1102 | def _pushb2phaseheads(pushop, bundler): |
|
1099 | 1103 | """push phase information through a bundle2 - binary part""" |
|
1100 | 1104 | pushop.stepsdone.add(b'phases') |
|
1101 | 1105 | if pushop.outdatedphases: |
|
1102 | 1106 | updates = [[] for p in phases.allphases] |
|
1103 | 1107 | updates[0].extend(h.node() for h in pushop.outdatedphases) |
|
1104 | 1108 | phasedata = phases.binaryencode(updates) |
|
1105 | 1109 | bundler.newpart(b'phase-heads', data=phasedata) |
|
1106 | 1110 | |
|
1107 | 1111 | |
|
1108 | 1112 | def _pushb2phasespushkey(pushop, bundler): |
|
1109 | 1113 | """push phase information through a bundle2 - pushkey part""" |
|
1110 | 1114 | pushop.stepsdone.add(b'phases') |
|
1111 | 1115 | part2node = [] |
|
1112 | 1116 | |
|
1113 | 1117 | def handlefailure(pushop, exc): |
|
1114 | 1118 | targetid = int(exc.partid) |
|
1115 | 1119 | for partid, node in part2node: |
|
1116 | 1120 | if partid == targetid: |
|
1117 | 1121 | raise error.Abort(_(b'updating %s to public failed') % node) |
|
1118 | 1122 | |
|
1119 | 1123 | enc = pushkey.encode |
|
1120 | 1124 | for newremotehead in pushop.outdatedphases: |
|
1121 | 1125 | part = bundler.newpart(b'pushkey') |
|
1122 | 1126 | part.addparam(b'namespace', enc(b'phases')) |
|
1123 | 1127 | part.addparam(b'key', enc(newremotehead.hex())) |
|
1124 | 1128 | part.addparam(b'old', enc(b'%d' % phases.draft)) |
|
1125 | 1129 | part.addparam(b'new', enc(b'%d' % phases.public)) |
|
1126 | 1130 | part2node.append((part.id, newremotehead)) |
|
1127 | 1131 | pushop.pkfailcb[part.id] = handlefailure |
|
1128 | 1132 | |
|
1129 | 1133 | def handlereply(op): |
|
1130 | 1134 | for partid, node in part2node: |
|
1131 | 1135 | partrep = op.records.getreplies(partid) |
|
1132 | 1136 | results = partrep[b'pushkey'] |
|
1133 | 1137 | assert len(results) <= 1 |
|
1134 | 1138 | msg = None |
|
1135 | 1139 | if not results: |
|
1136 | 1140 | msg = _(b'server ignored update of %s to public!\n') % node |
|
1137 | 1141 | elif not int(results[0][b'return']): |
|
1138 | 1142 | msg = _(b'updating %s to public failed!\n') % node |
|
1139 | 1143 | if msg is not None: |
|
1140 | 1144 | pushop.ui.warn(msg) |
|
1141 | 1145 | |
|
1142 | 1146 | return handlereply |
|
1143 | 1147 | |
|
1144 | 1148 | |
|
1145 | 1149 | @b2partsgenerator(b'obsmarkers') |
|
1146 | 1150 | def _pushb2obsmarkers(pushop, bundler): |
|
1147 | 1151 | if b'obsmarkers' in pushop.stepsdone: |
|
1148 | 1152 | return |
|
1149 | 1153 | remoteversions = bundle2.obsmarkersversion(bundler.capabilities) |
|
1150 | 1154 | if obsolete.commonversion(remoteversions) is None: |
|
1151 | 1155 | return |
|
1152 | 1156 | pushop.stepsdone.add(b'obsmarkers') |
|
1153 | 1157 | if pushop.outobsmarkers: |
|
1154 | 1158 | markers = obsutil.sortedmarkers(pushop.outobsmarkers) |
|
1155 | 1159 | bundle2.buildobsmarkerspart(bundler, markers) |
|
1156 | 1160 | |
|
1157 | 1161 | |
|
1158 | 1162 | @b2partsgenerator(b'bookmarks') |
|
1159 | 1163 | def _pushb2bookmarks(pushop, bundler): |
|
1160 | 1164 | """handle bookmark push through bundle2""" |
|
1161 | 1165 | if b'bookmarks' in pushop.stepsdone: |
|
1162 | 1166 | return |
|
1163 | 1167 | b2caps = bundle2.bundle2caps(pushop.remote) |
|
1164 | 1168 | |
|
1165 | 1169 | legacy = pushop.repo.ui.configlist(b'devel', b'legacy.exchange') |
|
1166 | 1170 | legacybooks = b'bookmarks' in legacy |
|
1167 | 1171 | |
|
1168 | 1172 | if not legacybooks and b'bookmarks' in b2caps: |
|
1169 | 1173 | return _pushb2bookmarkspart(pushop, bundler) |
|
1170 | 1174 | elif b'pushkey' in b2caps: |
|
1171 | 1175 | return _pushb2bookmarkspushkey(pushop, bundler) |
|
1172 | 1176 | |
|
1173 | 1177 | |
|
1174 | 1178 | def _bmaction(old, new): |
|
1175 | 1179 | """small utility for bookmark pushing""" |
|
1176 | 1180 | if not old: |
|
1177 | 1181 | return b'export' |
|
1178 | 1182 | elif not new: |
|
1179 | 1183 | return b'delete' |
|
1180 | 1184 | return b'update' |
|
1181 | 1185 | |
|
1182 | 1186 | |
|
1183 | 1187 | def _abortonsecretctx(pushop, node, b): |
|
1184 | 1188 | """abort if a given bookmark points to a secret changeset""" |
|
1185 | 1189 | if node and pushop.repo[node].phase() == phases.secret: |
|
1186 | 1190 | raise error.Abort( |
|
1187 | 1191 | _(b'cannot push bookmark %s as it points to a secret changeset') % b |
|
1188 | 1192 | ) |
|
1189 | 1193 | |
|
1190 | 1194 | |
|
1191 | 1195 | def _pushb2bookmarkspart(pushop, bundler): |
|
1192 | 1196 | pushop.stepsdone.add(b'bookmarks') |
|
1193 | 1197 | if not pushop.outbookmarks: |
|
1194 | 1198 | return |
|
1195 | 1199 | |
|
1196 | 1200 | allactions = [] |
|
1197 | 1201 | data = [] |
|
1198 | 1202 | for book, old, new in pushop.outbookmarks: |
|
1199 | 1203 | _abortonsecretctx(pushop, new, book) |
|
1200 | 1204 | data.append((book, new)) |
|
1201 | 1205 | allactions.append((book, _bmaction(old, new))) |
|
1202 | 1206 | checkdata = bookmod.binaryencode(data) |
|
1203 | 1207 | bundler.newpart(b'bookmarks', data=checkdata) |
|
1204 | 1208 | |
|
1205 | 1209 | def handlereply(op): |
|
1206 | 1210 | ui = pushop.ui |
|
1207 | 1211 | # if success |
|
1208 | 1212 | for book, action in allactions: |
|
1209 | 1213 | ui.status(bookmsgmap[action][0] % book) |
|
1210 | 1214 | |
|
1211 | 1215 | return handlereply |
|
1212 | 1216 | |
|
1213 | 1217 | |
|
1214 | 1218 | def _pushb2bookmarkspushkey(pushop, bundler): |
|
1215 | 1219 | pushop.stepsdone.add(b'bookmarks') |
|
1216 | 1220 | part2book = [] |
|
1217 | 1221 | enc = pushkey.encode |
|
1218 | 1222 | |
|
1219 | 1223 | def handlefailure(pushop, exc): |
|
1220 | 1224 | targetid = int(exc.partid) |
|
1221 | 1225 | for partid, book, action in part2book: |
|
1222 | 1226 | if partid == targetid: |
|
1223 | 1227 | raise error.Abort(bookmsgmap[action][1].rstrip() % book) |
|
1224 | 1228 | # we should not be called for part we did not generated |
|
1225 | 1229 | assert False |
|
1226 | 1230 | |
|
1227 | 1231 | for book, old, new in pushop.outbookmarks: |
|
1228 | 1232 | _abortonsecretctx(pushop, new, book) |
|
1229 | 1233 | part = bundler.newpart(b'pushkey') |
|
1230 | 1234 | part.addparam(b'namespace', enc(b'bookmarks')) |
|
1231 | 1235 | part.addparam(b'key', enc(book)) |
|
1232 | 1236 | part.addparam(b'old', enc(hex(old))) |
|
1233 | 1237 | part.addparam(b'new', enc(hex(new))) |
|
1234 | 1238 | action = b'update' |
|
1235 | 1239 | if not old: |
|
1236 | 1240 | action = b'export' |
|
1237 | 1241 | elif not new: |
|
1238 | 1242 | action = b'delete' |
|
1239 | 1243 | part2book.append((part.id, book, action)) |
|
1240 | 1244 | pushop.pkfailcb[part.id] = handlefailure |
|
1241 | 1245 | |
|
1242 | 1246 | def handlereply(op): |
|
1243 | 1247 | ui = pushop.ui |
|
1244 | 1248 | for partid, book, action in part2book: |
|
1245 | 1249 | partrep = op.records.getreplies(partid) |
|
1246 | 1250 | results = partrep[b'pushkey'] |
|
1247 | 1251 | assert len(results) <= 1 |
|
1248 | 1252 | if not results: |
|
1249 | 1253 | pushop.ui.warn(_(b'server ignored bookmark %s update\n') % book) |
|
1250 | 1254 | else: |
|
1251 | 1255 | ret = int(results[0][b'return']) |
|
1252 | 1256 | if ret: |
|
1253 | 1257 | ui.status(bookmsgmap[action][0] % book) |
|
1254 | 1258 | else: |
|
1255 | 1259 | ui.warn(bookmsgmap[action][1] % book) |
|
1256 | 1260 | if pushop.bkresult is not None: |
|
1257 | 1261 | pushop.bkresult = 1 |
|
1258 | 1262 | |
|
1259 | 1263 | return handlereply |
|
1260 | 1264 | |
|
1261 | 1265 | |
|
1262 | 1266 | @b2partsgenerator(b'pushvars', idx=0) |
|
1263 | 1267 | def _getbundlesendvars(pushop, bundler): |
|
1264 | 1268 | '''send shellvars via bundle2''' |
|
1265 | 1269 | pushvars = pushop.pushvars |
|
1266 | 1270 | if pushvars: |
|
1267 | 1271 | shellvars = {} |
|
1268 | 1272 | for raw in pushvars: |
|
1269 | 1273 | if b'=' not in raw: |
|
1270 | 1274 | msg = ( |
|
1271 | 1275 | b"unable to parse variable '%s', should follow " |
|
1272 | 1276 | b"'KEY=VALUE' or 'KEY=' format" |
|
1273 | 1277 | ) |
|
1274 | 1278 | raise error.Abort(msg % raw) |
|
1275 | 1279 | k, v = raw.split(b'=', 1) |
|
1276 | 1280 | shellvars[k] = v |
|
1277 | 1281 | |
|
1278 | 1282 | part = bundler.newpart(b'pushvars') |
|
1279 | 1283 | |
|
1280 | 1284 | for key, value in pycompat.iteritems(shellvars): |
|
1281 | 1285 | part.addparam(key, value, mandatory=False) |
|
1282 | 1286 | |
|
1283 | 1287 | |
|
1284 | 1288 | def _pushbundle2(pushop): |
|
1285 | 1289 | """push data to the remote using bundle2 |
|
1286 | 1290 | |
|
1287 | 1291 | The only currently supported type of data is changegroup but this will |
|
1288 | 1292 | evolve in the future.""" |
|
1289 | 1293 | bundler = bundle2.bundle20(pushop.ui, bundle2.bundle2caps(pushop.remote)) |
|
1290 | 1294 | pushback = pushop.trmanager and pushop.ui.configbool( |
|
1291 | 1295 | b'experimental', b'bundle2.pushback' |
|
1292 | 1296 | ) |
|
1293 | 1297 | |
|
1294 | 1298 | # create reply capability |
|
1295 | 1299 | capsblob = bundle2.encodecaps( |
|
1296 | 1300 | bundle2.getrepocaps(pushop.repo, allowpushback=pushback, role=b'client') |
|
1297 | 1301 | ) |
|
1298 | 1302 | bundler.newpart(b'replycaps', data=capsblob) |
|
1299 | 1303 | replyhandlers = [] |
|
1300 | 1304 | for partgenname in b2partsgenorder: |
|
1301 | 1305 | partgen = b2partsgenmapping[partgenname] |
|
1302 | 1306 | ret = partgen(pushop, bundler) |
|
1303 | 1307 | if callable(ret): |
|
1304 | 1308 | replyhandlers.append(ret) |
|
1305 | 1309 | # do not push if nothing to push |
|
1306 | 1310 | if bundler.nbparts <= 1: |
|
1307 | 1311 | return |
|
1308 | 1312 | stream = util.chunkbuffer(bundler.getchunks()) |
|
1309 | 1313 | try: |
|
1310 | 1314 | try: |
|
1311 | 1315 | with pushop.remote.commandexecutor() as e: |
|
1312 | 1316 | reply = e.callcommand( |
|
1313 | 1317 | b'unbundle', |
|
1314 | 1318 | { |
|
1315 | 1319 | b'bundle': stream, |
|
1316 | 1320 | b'heads': [b'force'], |
|
1317 | 1321 | b'url': pushop.remote.url(), |
|
1318 | 1322 | }, |
|
1319 | 1323 | ).result() |
|
1320 | 1324 | except error.BundleValueError as exc: |
|
1321 | 1325 | raise error.Abort(_(b'missing support for %s') % exc) |
|
1322 | 1326 | try: |
|
1323 | 1327 | trgetter = None |
|
1324 | 1328 | if pushback: |
|
1325 | 1329 | trgetter = pushop.trmanager.transaction |
|
1326 | 1330 | op = bundle2.processbundle(pushop.repo, reply, trgetter) |
|
1327 | 1331 | except error.BundleValueError as exc: |
|
1328 | 1332 | raise error.Abort(_(b'missing support for %s') % exc) |
|
1329 | 1333 | except bundle2.AbortFromPart as exc: |
|
1330 | 1334 | pushop.ui.status(_(b'remote: %s\n') % exc) |
|
1331 | 1335 | if exc.hint is not None: |
|
1332 | 1336 | pushop.ui.status(_(b'remote: %s\n') % (b'(%s)' % exc.hint)) |
|
1333 | 1337 | raise error.Abort(_(b'push failed on remote')) |
|
1334 | 1338 | except error.PushkeyFailed as exc: |
|
1335 | 1339 | partid = int(exc.partid) |
|
1336 | 1340 | if partid not in pushop.pkfailcb: |
|
1337 | 1341 | raise |
|
1338 | 1342 | pushop.pkfailcb[partid](pushop, exc) |
|
1339 | 1343 | for rephand in replyhandlers: |
|
1340 | 1344 | rephand(op) |
|
1341 | 1345 | |
|
1342 | 1346 | |
|
1343 | 1347 | def _pushchangeset(pushop): |
|
1344 | 1348 | """Make the actual push of changeset bundle to remote repo""" |
|
1345 | 1349 | if b'changesets' in pushop.stepsdone: |
|
1346 | 1350 | return |
|
1347 | 1351 | pushop.stepsdone.add(b'changesets') |
|
1348 | 1352 | if not _pushcheckoutgoing(pushop): |
|
1349 | 1353 | return |
|
1350 | 1354 | |
|
1351 | 1355 | # Should have verified this in push(). |
|
1352 | 1356 | assert pushop.remote.capable(b'unbundle') |
|
1353 | 1357 | |
|
1354 | 1358 | pushop.repo.prepushoutgoinghooks(pushop) |
|
1355 | 1359 | outgoing = pushop.outgoing |
|
1356 | 1360 | # TODO: get bundlecaps from remote |
|
1357 | 1361 | bundlecaps = None |
|
1358 | 1362 | # create a changegroup from local |
|
1359 | 1363 | if pushop.revs is None and not ( |
|
1360 | 1364 | outgoing.excluded or pushop.repo.changelog.filteredrevs |
|
1361 | 1365 | ): |
|
1362 | 1366 | # push everything, |
|
1363 | 1367 | # use the fast path, no race possible on push |
|
1364 | 1368 | cg = changegroup.makechangegroup( |
|
1365 | 1369 | pushop.repo, |
|
1366 | 1370 | outgoing, |
|
1367 | 1371 | b'01', |
|
1368 | 1372 | b'push', |
|
1369 | 1373 | fastpath=True, |
|
1370 | 1374 | bundlecaps=bundlecaps, |
|
1371 | 1375 | ) |
|
1372 | 1376 | else: |
|
1373 | 1377 | cg = changegroup.makechangegroup( |
|
1374 | 1378 | pushop.repo, outgoing, b'01', b'push', bundlecaps=bundlecaps |
|
1375 | 1379 | ) |
|
1376 | 1380 | |
|
1377 | 1381 | # apply changegroup to remote |
|
1378 | 1382 | # local repo finds heads on server, finds out what |
|
1379 | 1383 | # revs it must push. once revs transferred, if server |
|
1380 | 1384 | # finds it has different heads (someone else won |
|
1381 | 1385 | # commit/push race), server aborts. |
|
1382 | 1386 | if pushop.force: |
|
1383 | 1387 | remoteheads = [b'force'] |
|
1384 | 1388 | else: |
|
1385 | 1389 | remoteheads = pushop.remoteheads |
|
1386 | 1390 | # ssh: return remote's addchangegroup() |
|
1387 | 1391 | # http: return remote's addchangegroup() or 0 for error |
|
1388 | 1392 | pushop.cgresult = pushop.remote.unbundle(cg, remoteheads, pushop.repo.url()) |
|
1389 | 1393 | |
|
1390 | 1394 | |
|
1391 | 1395 | def _pushsyncphase(pushop): |
|
1392 | 1396 | """synchronise phase information locally and remotely""" |
|
1393 | 1397 | cheads = pushop.commonheads |
|
1394 | 1398 | # even when we don't push, exchanging phase data is useful |
|
1395 | 1399 | remotephases = listkeys(pushop.remote, b'phases') |
|
1396 | 1400 | if ( |
|
1397 | 1401 | pushop.ui.configbool(b'ui', b'_usedassubrepo') |
|
1398 | 1402 | and remotephases # server supports phases |
|
1399 | 1403 | and pushop.cgresult is None # nothing was pushed |
|
1400 | 1404 | and remotephases.get(b'publishing', False) |
|
1401 | 1405 | ): |
|
1402 | 1406 | # When: |
|
1403 | 1407 | # - this is a subrepo push |
|
1404 | 1408 | # - and remote support phase |
|
1405 | 1409 | # - and no changeset was pushed |
|
1406 | 1410 | # - and remote is publishing |
|
1407 | 1411 | # We may be in issue 3871 case! |
|
1408 | 1412 | # We drop the possible phase synchronisation done by |
|
1409 | 1413 | # courtesy to publish changesets possibly locally draft |
|
1410 | 1414 | # on the remote. |
|
1411 | 1415 | remotephases = {b'publishing': b'True'} |
|
1412 | 1416 | if not remotephases: # old server or public only reply from non-publishing |
|
1413 | 1417 | _localphasemove(pushop, cheads) |
|
1414 | 1418 | # don't push any phase data as there is nothing to push |
|
1415 | 1419 | else: |
|
1416 | 1420 | ana = phases.analyzeremotephases(pushop.repo, cheads, remotephases) |
|
1417 | 1421 | pheads, droots = ana |
|
1418 | 1422 | ### Apply remote phase on local |
|
1419 | 1423 | if remotephases.get(b'publishing', False): |
|
1420 | 1424 | _localphasemove(pushop, cheads) |
|
1421 | 1425 | else: # publish = False |
|
1422 | 1426 | _localphasemove(pushop, pheads) |
|
1423 | 1427 | _localphasemove(pushop, cheads, phases.draft) |
|
1424 | 1428 | ### Apply local phase on remote |
|
1425 | 1429 | |
|
1426 | 1430 | if pushop.cgresult: |
|
1427 | 1431 | if b'phases' in pushop.stepsdone: |
|
1428 | 1432 | # phases already pushed though bundle2 |
|
1429 | 1433 | return |
|
1430 | 1434 | outdated = pushop.outdatedphases |
|
1431 | 1435 | else: |
|
1432 | 1436 | outdated = pushop.fallbackoutdatedphases |
|
1433 | 1437 | |
|
1434 | 1438 | pushop.stepsdone.add(b'phases') |
|
1435 | 1439 | |
|
1436 | 1440 | # filter heads already turned public by the push |
|
1437 | 1441 | outdated = [c for c in outdated if c.node() not in pheads] |
|
1438 | 1442 | # fallback to independent pushkey command |
|
1439 | 1443 | for newremotehead in outdated: |
|
1440 | 1444 | with pushop.remote.commandexecutor() as e: |
|
1441 | 1445 | r = e.callcommand( |
|
1442 | 1446 | b'pushkey', |
|
1443 | 1447 | { |
|
1444 | 1448 | b'namespace': b'phases', |
|
1445 | 1449 | b'key': newremotehead.hex(), |
|
1446 | 1450 | b'old': b'%d' % phases.draft, |
|
1447 | 1451 | b'new': b'%d' % phases.public, |
|
1448 | 1452 | }, |
|
1449 | 1453 | ).result() |
|
1450 | 1454 | |
|
1451 | 1455 | if not r: |
|
1452 | 1456 | pushop.ui.warn( |
|
1453 | 1457 | _(b'updating %s to public failed!\n') % newremotehead |
|
1454 | 1458 | ) |
|
1455 | 1459 | |
|
1456 | 1460 | |
|
1457 | 1461 | def _localphasemove(pushop, nodes, phase=phases.public): |
|
1458 | 1462 | """move <nodes> to <phase> in the local source repo""" |
|
1459 | 1463 | if pushop.trmanager: |
|
1460 | 1464 | phases.advanceboundary( |
|
1461 | 1465 | pushop.repo, pushop.trmanager.transaction(), phase, nodes |
|
1462 | 1466 | ) |
|
1463 | 1467 | else: |
|
1464 | 1468 | # repo is not locked, do not change any phases! |
|
1465 | 1469 | # Informs the user that phases should have been moved when |
|
1466 | 1470 | # applicable. |
|
1467 | 1471 | actualmoves = [n for n in nodes if phase < pushop.repo[n].phase()] |
|
1468 | 1472 | phasestr = phases.phasenames[phase] |
|
1469 | 1473 | if actualmoves: |
|
1470 | 1474 | pushop.ui.status( |
|
1471 | 1475 | _( |
|
1472 | 1476 | b'cannot lock source repo, skipping ' |
|
1473 | 1477 | b'local %s phase update\n' |
|
1474 | 1478 | ) |
|
1475 | 1479 | % phasestr |
|
1476 | 1480 | ) |
|
1477 | 1481 | |
|
1478 | 1482 | |
|
1479 | 1483 | def _pushobsolete(pushop): |
|
1480 | 1484 | """utility function to push obsolete markers to a remote""" |
|
1481 | 1485 | if b'obsmarkers' in pushop.stepsdone: |
|
1482 | 1486 | return |
|
1483 | 1487 | repo = pushop.repo |
|
1484 | 1488 | remote = pushop.remote |
|
1485 | 1489 | pushop.stepsdone.add(b'obsmarkers') |
|
1486 | 1490 | if pushop.outobsmarkers: |
|
1487 | 1491 | pushop.ui.debug(b'try to push obsolete markers to remote\n') |
|
1488 | 1492 | rslts = [] |
|
1489 | 1493 | markers = obsutil.sortedmarkers(pushop.outobsmarkers) |
|
1490 | 1494 | remotedata = obsolete._pushkeyescape(markers) |
|
1491 | 1495 | for key in sorted(remotedata, reverse=True): |
|
1492 | 1496 | # reverse sort to ensure we end with dump0 |
|
1493 | 1497 | data = remotedata[key] |
|
1494 | 1498 | rslts.append(remote.pushkey(b'obsolete', key, b'', data)) |
|
1495 | 1499 | if [r for r in rslts if not r]: |
|
1496 | 1500 | msg = _(b'failed to push some obsolete markers!\n') |
|
1497 | 1501 | repo.ui.warn(msg) |
|
1498 | 1502 | |
|
1499 | 1503 | |
|
1500 | 1504 | def _pushbookmark(pushop): |
|
1501 | 1505 | """Update bookmark position on remote""" |
|
1502 | 1506 | if pushop.cgresult == 0 or b'bookmarks' in pushop.stepsdone: |
|
1503 | 1507 | return |
|
1504 | 1508 | pushop.stepsdone.add(b'bookmarks') |
|
1505 | 1509 | ui = pushop.ui |
|
1506 | 1510 | remote = pushop.remote |
|
1507 | 1511 | |
|
1508 | 1512 | for b, old, new in pushop.outbookmarks: |
|
1509 | 1513 | action = b'update' |
|
1510 | 1514 | if not old: |
|
1511 | 1515 | action = b'export' |
|
1512 | 1516 | elif not new: |
|
1513 | 1517 | action = b'delete' |
|
1514 | 1518 | |
|
1515 | 1519 | with remote.commandexecutor() as e: |
|
1516 | 1520 | r = e.callcommand( |
|
1517 | 1521 | b'pushkey', |
|
1518 | 1522 | { |
|
1519 | 1523 | b'namespace': b'bookmarks', |
|
1520 | 1524 | b'key': b, |
|
1521 | 1525 | b'old': hex(old), |
|
1522 | 1526 | b'new': hex(new), |
|
1523 | 1527 | }, |
|
1524 | 1528 | ).result() |
|
1525 | 1529 | |
|
1526 | 1530 | if r: |
|
1527 | 1531 | ui.status(bookmsgmap[action][0] % b) |
|
1528 | 1532 | else: |
|
1529 | 1533 | ui.warn(bookmsgmap[action][1] % b) |
|
1530 | 1534 | # discovery can have set the value form invalid entry |
|
1531 | 1535 | if pushop.bkresult is not None: |
|
1532 | 1536 | pushop.bkresult = 1 |
|
1533 | 1537 | |
|
1534 | 1538 | |
|
1535 | 1539 | class pulloperation(object): |
|
1536 | 1540 | """A object that represent a single pull operation |
|
1537 | 1541 | |
|
1538 | 1542 | It purpose is to carry pull related state and very common operation. |
|
1539 | 1543 | |
|
1540 | 1544 | A new should be created at the beginning of each pull and discarded |
|
1541 | 1545 | afterward. |
|
1542 | 1546 | """ |
|
1543 | 1547 | |
|
1544 | 1548 | def __init__( |
|
1545 | 1549 | self, |
|
1546 | 1550 | repo, |
|
1547 | 1551 | remote, |
|
1548 | 1552 | heads=None, |
|
1549 | 1553 | force=False, |
|
1550 | 1554 | bookmarks=(), |
|
1551 | 1555 | remotebookmarks=None, |
|
1552 | 1556 | streamclonerequested=None, |
|
1553 | 1557 | includepats=None, |
|
1554 | 1558 | excludepats=None, |
|
1555 | 1559 | depth=None, |
|
1556 | 1560 | ): |
|
1557 | 1561 | # repo we pull into |
|
1558 | 1562 | self.repo = repo |
|
1559 | 1563 | # repo we pull from |
|
1560 | 1564 | self.remote = remote |
|
1561 | 1565 | # revision we try to pull (None is "all") |
|
1562 | 1566 | self.heads = heads |
|
1563 | 1567 | # bookmark pulled explicitly |
|
1564 | 1568 | self.explicitbookmarks = [ |
|
1565 | 1569 | repo._bookmarks.expandname(bookmark) for bookmark in bookmarks |
|
1566 | 1570 | ] |
|
1567 | 1571 | # do we force pull? |
|
1568 | 1572 | self.force = force |
|
1569 | 1573 | # whether a streaming clone was requested |
|
1570 | 1574 | self.streamclonerequested = streamclonerequested |
|
1571 | 1575 | # transaction manager |
|
1572 | 1576 | self.trmanager = None |
|
1573 | 1577 | # set of common changeset between local and remote before pull |
|
1574 | 1578 | self.common = None |
|
1575 | 1579 | # set of pulled head |
|
1576 | 1580 | self.rheads = None |
|
1577 | 1581 | # list of missing changeset to fetch remotely |
|
1578 | 1582 | self.fetch = None |
|
1579 | 1583 | # remote bookmarks data |
|
1580 | 1584 | self.remotebookmarks = remotebookmarks |
|
1581 | 1585 | # result of changegroup pulling (used as return code by pull) |
|
1582 | 1586 | self.cgresult = None |
|
1583 | 1587 | # list of step already done |
|
1584 | 1588 | self.stepsdone = set() |
|
1585 | 1589 | # Whether we attempted a clone from pre-generated bundles. |
|
1586 | 1590 | self.clonebundleattempted = False |
|
1587 | 1591 | # Set of file patterns to include. |
|
1588 | 1592 | self.includepats = includepats |
|
1589 | 1593 | # Set of file patterns to exclude. |
|
1590 | 1594 | self.excludepats = excludepats |
|
1591 | 1595 | # Number of ancestor changesets to pull from each pulled head. |
|
1592 | 1596 | self.depth = depth |
|
1593 | 1597 | |
|
1594 | 1598 | @util.propertycache |
|
1595 | 1599 | def pulledsubset(self): |
|
1596 | 1600 | """heads of the set of changeset target by the pull""" |
|
1597 | 1601 | # compute target subset |
|
1598 | 1602 | if self.heads is None: |
|
1599 | 1603 | # We pulled every thing possible |
|
1600 | 1604 | # sync on everything common |
|
1601 | 1605 | c = set(self.common) |
|
1602 | 1606 | ret = list(self.common) |
|
1603 | 1607 | for n in self.rheads: |
|
1604 | 1608 | if n not in c: |
|
1605 | 1609 | ret.append(n) |
|
1606 | 1610 | return ret |
|
1607 | 1611 | else: |
|
1608 | 1612 | # We pulled a specific subset |
|
1609 | 1613 | # sync on this subset |
|
1610 | 1614 | return self.heads |
|
1611 | 1615 | |
|
1612 | 1616 | @util.propertycache |
|
1613 | 1617 | def canusebundle2(self): |
|
1614 | 1618 | return not _forcebundle1(self) |
|
1615 | 1619 | |
|
1616 | 1620 | @util.propertycache |
|
1617 | 1621 | def remotebundle2caps(self): |
|
1618 | 1622 | return bundle2.bundle2caps(self.remote) |
|
1619 | 1623 | |
|
1620 | 1624 | def gettransaction(self): |
|
1621 | 1625 | # deprecated; talk to trmanager directly |
|
1622 | 1626 | return self.trmanager.transaction() |
|
1623 | 1627 | |
|
1624 | 1628 | |
|
1625 | 1629 | class transactionmanager(util.transactional): |
|
1626 | 1630 | """An object to manage the life cycle of a transaction |
|
1627 | 1631 | |
|
1628 | 1632 | It creates the transaction on demand and calls the appropriate hooks when |
|
1629 | 1633 | closing the transaction.""" |
|
1630 | 1634 | |
|
1631 | 1635 | def __init__(self, repo, source, url): |
|
1632 | 1636 | self.repo = repo |
|
1633 | 1637 | self.source = source |
|
1634 | 1638 | self.url = url |
|
1635 | 1639 | self._tr = None |
|
1636 | 1640 | |
|
1637 | 1641 | def transaction(self): |
|
1638 | 1642 | """Return an open transaction object, constructing if necessary""" |
|
1639 | 1643 | if not self._tr: |
|
1640 | 1644 | trname = b'%s\n%s' % (self.source, util.hidepassword(self.url)) |
|
1641 | 1645 | self._tr = self.repo.transaction(trname) |
|
1642 | 1646 | self._tr.hookargs[b'source'] = self.source |
|
1643 | 1647 | self._tr.hookargs[b'url'] = self.url |
|
1644 | 1648 | return self._tr |
|
1645 | 1649 | |
|
1646 | 1650 | def close(self): |
|
1647 | 1651 | """close transaction if created""" |
|
1648 | 1652 | if self._tr is not None: |
|
1649 | 1653 | self._tr.close() |
|
1650 | 1654 | |
|
1651 | 1655 | def release(self): |
|
1652 | 1656 | """release transaction if created""" |
|
1653 | 1657 | if self._tr is not None: |
|
1654 | 1658 | self._tr.release() |
|
1655 | 1659 | |
|
1656 | 1660 | |
|
1657 | 1661 | def listkeys(remote, namespace): |
|
1658 | 1662 | with remote.commandexecutor() as e: |
|
1659 | 1663 | return e.callcommand(b'listkeys', {b'namespace': namespace}).result() |
|
1660 | 1664 | |
|
1661 | 1665 | |
|
1662 | 1666 | def _fullpullbundle2(repo, pullop): |
|
1663 | 1667 | # The server may send a partial reply, i.e. when inlining |
|
1664 | 1668 | # pre-computed bundles. In that case, update the common |
|
1665 | 1669 | # set based on the results and pull another bundle. |
|
1666 | 1670 | # |
|
1667 | 1671 | # There are two indicators that the process is finished: |
|
1668 | 1672 | # - no changeset has been added, or |
|
1669 | 1673 | # - all remote heads are known locally. |
|
1670 | 1674 | # The head check must use the unfiltered view as obsoletion |
|
1671 | 1675 | # markers can hide heads. |
|
1672 | 1676 | unfi = repo.unfiltered() |
|
1673 | 1677 | unficl = unfi.changelog |
|
1674 | 1678 | |
|
1675 | 1679 | def headsofdiff(h1, h2): |
|
1676 | 1680 | """Returns heads(h1 % h2)""" |
|
1677 | 1681 | res = unfi.set(b'heads(%ln %% %ln)', h1, h2) |
|
1678 | 1682 | return set(ctx.node() for ctx in res) |
|
1679 | 1683 | |
|
1680 | 1684 | def headsofunion(h1, h2): |
|
1681 | 1685 | """Returns heads((h1 + h2) - null)""" |
|
1682 | 1686 | res = unfi.set(b'heads((%ln + %ln - null))', h1, h2) |
|
1683 | 1687 | return set(ctx.node() for ctx in res) |
|
1684 | 1688 | |
|
1685 | 1689 | while True: |
|
1686 | 1690 | old_heads = unficl.heads() |
|
1687 | 1691 | clstart = len(unficl) |
|
1688 | 1692 | _pullbundle2(pullop) |
|
1689 | 1693 | if repository.NARROW_REQUIREMENT in repo.requirements: |
|
1690 | 1694 | # XXX narrow clones filter the heads on the server side during |
|
1691 | 1695 | # XXX getbundle and result in partial replies as well. |
|
1692 | 1696 | # XXX Disable pull bundles in this case as band aid to avoid |
|
1693 | 1697 | # XXX extra round trips. |
|
1694 | 1698 | break |
|
1695 | 1699 | if clstart == len(unficl): |
|
1696 | 1700 | break |
|
1697 | 1701 | if all(unficl.hasnode(n) for n in pullop.rheads): |
|
1698 | 1702 | break |
|
1699 | 1703 | new_heads = headsofdiff(unficl.heads(), old_heads) |
|
1700 | 1704 | pullop.common = headsofunion(new_heads, pullop.common) |
|
1701 | 1705 | pullop.rheads = set(pullop.rheads) - pullop.common |
|
1702 | 1706 | |
|
1703 | 1707 | |
|
1704 | 1708 | def pull( |
|
1705 | 1709 | repo, |
|
1706 | 1710 | remote, |
|
1707 | 1711 | heads=None, |
|
1708 | 1712 | force=False, |
|
1709 | 1713 | bookmarks=(), |
|
1710 | 1714 | opargs=None, |
|
1711 | 1715 | streamclonerequested=None, |
|
1712 | 1716 | includepats=None, |
|
1713 | 1717 | excludepats=None, |
|
1714 | 1718 | depth=None, |
|
1715 | 1719 | ): |
|
1716 | 1720 | """Fetch repository data from a remote. |
|
1717 | 1721 | |
|
1718 | 1722 | This is the main function used to retrieve data from a remote repository. |
|
1719 | 1723 | |
|
1720 | 1724 | ``repo`` is the local repository to clone into. |
|
1721 | 1725 | ``remote`` is a peer instance. |
|
1722 | 1726 | ``heads`` is an iterable of revisions we want to pull. ``None`` (the |
|
1723 | 1727 | default) means to pull everything from the remote. |
|
1724 | 1728 | ``bookmarks`` is an iterable of bookmarks requesting to be pulled. By |
|
1725 | 1729 | default, all remote bookmarks are pulled. |
|
1726 | 1730 | ``opargs`` are additional keyword arguments to pass to ``pulloperation`` |
|
1727 | 1731 | initialization. |
|
1728 | 1732 | ``streamclonerequested`` is a boolean indicating whether a "streaming |
|
1729 | 1733 | clone" is requested. A "streaming clone" is essentially a raw file copy |
|
1730 | 1734 | of revlogs from the server. This only works when the local repository is |
|
1731 | 1735 | empty. The default value of ``None`` means to respect the server |
|
1732 | 1736 | configuration for preferring stream clones. |
|
1733 | 1737 | ``includepats`` and ``excludepats`` define explicit file patterns to |
|
1734 | 1738 | include and exclude in storage, respectively. If not defined, narrow |
|
1735 | 1739 | patterns from the repo instance are used, if available. |
|
1736 | 1740 | ``depth`` is an integer indicating the DAG depth of history we're |
|
1737 | 1741 | interested in. If defined, for each revision specified in ``heads``, we |
|
1738 | 1742 | will fetch up to this many of its ancestors and data associated with them. |
|
1739 | 1743 | |
|
1740 | 1744 | Returns the ``pulloperation`` created for this pull. |
|
1741 | 1745 | """ |
|
1742 | 1746 | if opargs is None: |
|
1743 | 1747 | opargs = {} |
|
1744 | 1748 | |
|
1745 | 1749 | # We allow the narrow patterns to be passed in explicitly to provide more |
|
1746 | 1750 | # flexibility for API consumers. |
|
1747 | 1751 | if includepats or excludepats: |
|
1748 | 1752 | includepats = includepats or set() |
|
1749 | 1753 | excludepats = excludepats or set() |
|
1750 | 1754 | else: |
|
1751 | 1755 | includepats, excludepats = repo.narrowpats |
|
1752 | 1756 | |
|
1753 | 1757 | narrowspec.validatepatterns(includepats) |
|
1754 | 1758 | narrowspec.validatepatterns(excludepats) |
|
1755 | 1759 | |
|
1756 | 1760 | pullop = pulloperation( |
|
1757 | 1761 | repo, |
|
1758 | 1762 | remote, |
|
1759 | 1763 | heads, |
|
1760 | 1764 | force, |
|
1761 | 1765 | bookmarks=bookmarks, |
|
1762 | 1766 | streamclonerequested=streamclonerequested, |
|
1763 | 1767 | includepats=includepats, |
|
1764 | 1768 | excludepats=excludepats, |
|
1765 | 1769 | depth=depth, |
|
1766 | 1770 | **pycompat.strkwargs(opargs) |
|
1767 | 1771 | ) |
|
1768 | 1772 | |
|
1769 | 1773 | peerlocal = pullop.remote.local() |
|
1770 | 1774 | if peerlocal: |
|
1771 | 1775 | missing = set(peerlocal.requirements) - pullop.repo.supported |
|
1772 | 1776 | if missing: |
|
1773 | 1777 | msg = _( |
|
1774 | 1778 | b"required features are not" |
|
1775 | 1779 | b" supported in the destination:" |
|
1776 | 1780 | b" %s" |
|
1777 | 1781 | ) % (b', '.join(sorted(missing))) |
|
1778 | 1782 | raise error.Abort(msg) |
|
1779 | 1783 | |
|
1780 | 1784 | pullop.trmanager = transactionmanager(repo, b'pull', remote.url()) |
|
1781 | 1785 | wlock = util.nullcontextmanager() |
|
1782 | 1786 | if not bookmod.bookmarksinstore(repo): |
|
1783 | 1787 | wlock = repo.wlock() |
|
1784 | 1788 | with wlock, repo.lock(), pullop.trmanager: |
|
1785 | 1789 | # Use the modern wire protocol, if available. |
|
1786 | 1790 | if remote.capable(b'command-changesetdata'): |
|
1787 | 1791 | exchangev2.pull(pullop) |
|
1788 | 1792 | else: |
|
1789 | 1793 | # This should ideally be in _pullbundle2(). However, it needs to run |
|
1790 | 1794 | # before discovery to avoid extra work. |
|
1791 | 1795 | _maybeapplyclonebundle(pullop) |
|
1792 | 1796 | streamclone.maybeperformlegacystreamclone(pullop) |
|
1793 | 1797 | _pulldiscovery(pullop) |
|
1794 | 1798 | if pullop.canusebundle2: |
|
1795 | 1799 | _fullpullbundle2(repo, pullop) |
|
1796 | 1800 | _pullchangeset(pullop) |
|
1797 | 1801 | _pullphase(pullop) |
|
1798 | 1802 | _pullbookmarks(pullop) |
|
1799 | 1803 | _pullobsolete(pullop) |
|
1800 | 1804 | |
|
1801 | 1805 | # storing remotenames |
|
1802 | 1806 | if repo.ui.configbool(b'experimental', b'remotenames'): |
|
1803 | 1807 | logexchange.pullremotenames(repo, remote) |
|
1804 | 1808 | |
|
1805 | 1809 | return pullop |
|
1806 | 1810 | |
|
1807 | 1811 | |
|
1808 | 1812 | # list of steps to perform discovery before pull |
|
1809 | 1813 | pulldiscoveryorder = [] |
|
1810 | 1814 | |
|
1811 | 1815 | # Mapping between step name and function |
|
1812 | 1816 | # |
|
1813 | 1817 | # This exists to help extensions wrap steps if necessary |
|
1814 | 1818 | pulldiscoverymapping = {} |
|
1815 | 1819 | |
|
1816 | 1820 | |
|
1817 | 1821 | def pulldiscovery(stepname): |
|
1818 | 1822 | """decorator for function performing discovery before pull |
|
1819 | 1823 | |
|
1820 | 1824 | The function is added to the step -> function mapping and appended to the |
|
1821 | 1825 | list of steps. Beware that decorated function will be added in order (this |
|
1822 | 1826 | may matter). |
|
1823 | 1827 | |
|
1824 | 1828 | You can only use this decorator for a new step, if you want to wrap a step |
|
1825 | 1829 | from an extension, change the pulldiscovery dictionary directly.""" |
|
1826 | 1830 | |
|
1827 | 1831 | def dec(func): |
|
1828 | 1832 | assert stepname not in pulldiscoverymapping |
|
1829 | 1833 | pulldiscoverymapping[stepname] = func |
|
1830 | 1834 | pulldiscoveryorder.append(stepname) |
|
1831 | 1835 | return func |
|
1832 | 1836 | |
|
1833 | 1837 | return dec |
|
1834 | 1838 | |
|
1835 | 1839 | |
|
1836 | 1840 | def _pulldiscovery(pullop): |
|
1837 | 1841 | """Run all discovery steps""" |
|
1838 | 1842 | for stepname in pulldiscoveryorder: |
|
1839 | 1843 | step = pulldiscoverymapping[stepname] |
|
1840 | 1844 | step(pullop) |
|
1841 | 1845 | |
|
1842 | 1846 | |
|
1843 | 1847 | @pulldiscovery(b'b1:bookmarks') |
|
1844 | 1848 | def _pullbookmarkbundle1(pullop): |
|
1845 | 1849 | """fetch bookmark data in bundle1 case |
|
1846 | 1850 | |
|
1847 | 1851 | If not using bundle2, we have to fetch bookmarks before changeset |
|
1848 | 1852 | discovery to reduce the chance and impact of race conditions.""" |
|
1849 | 1853 | if pullop.remotebookmarks is not None: |
|
1850 | 1854 | return |
|
1851 | 1855 | if pullop.canusebundle2 and b'listkeys' in pullop.remotebundle2caps: |
|
1852 | 1856 | # all known bundle2 servers now support listkeys, but lets be nice with |
|
1853 | 1857 | # new implementation. |
|
1854 | 1858 | return |
|
1855 | 1859 | books = listkeys(pullop.remote, b'bookmarks') |
|
1856 | 1860 | pullop.remotebookmarks = bookmod.unhexlifybookmarks(books) |
|
1857 | 1861 | |
|
1858 | 1862 | |
|
1859 | 1863 | @pulldiscovery(b'changegroup') |
|
1860 | 1864 | def _pulldiscoverychangegroup(pullop): |
|
1861 | 1865 | """discovery phase for the pull |
|
1862 | 1866 | |
|
1863 | 1867 | Current handle changeset discovery only, will change handle all discovery |
|
1864 | 1868 | at some point.""" |
|
1865 | 1869 | tmp = discovery.findcommonincoming( |
|
1866 | 1870 | pullop.repo, pullop.remote, heads=pullop.heads, force=pullop.force |
|
1867 | 1871 | ) |
|
1868 | 1872 | common, fetch, rheads = tmp |
|
1869 | 1873 | has_node = pullop.repo.unfiltered().changelog.index.has_node |
|
1870 | 1874 | if fetch and rheads: |
|
1871 | 1875 | # If a remote heads is filtered locally, put in back in common. |
|
1872 | 1876 | # |
|
1873 | 1877 | # This is a hackish solution to catch most of "common but locally |
|
1874 | 1878 | # hidden situation". We do not performs discovery on unfiltered |
|
1875 | 1879 | # repository because it end up doing a pathological amount of round |
|
1876 | 1880 | # trip for w huge amount of changeset we do not care about. |
|
1877 | 1881 | # |
|
1878 | 1882 | # If a set of such "common but filtered" changeset exist on the server |
|
1879 | 1883 | # but are not including a remote heads, we'll not be able to detect it, |
|
1880 | 1884 | scommon = set(common) |
|
1881 | 1885 | for n in rheads: |
|
1882 | 1886 | if has_node(n): |
|
1883 | 1887 | if n not in scommon: |
|
1884 | 1888 | common.append(n) |
|
1885 | 1889 | if set(rheads).issubset(set(common)): |
|
1886 | 1890 | fetch = [] |
|
1887 | 1891 | pullop.common = common |
|
1888 | 1892 | pullop.fetch = fetch |
|
1889 | 1893 | pullop.rheads = rheads |
|
1890 | 1894 | |
|
1891 | 1895 | |
|
1892 | 1896 | def _pullbundle2(pullop): |
|
1893 | 1897 | """pull data using bundle2 |
|
1894 | 1898 | |
|
1895 | 1899 | For now, the only supported data are changegroup.""" |
|
1896 | 1900 | kwargs = {b'bundlecaps': caps20to10(pullop.repo, role=b'client')} |
|
1897 | 1901 | |
|
1898 | 1902 | # make ui easier to access |
|
1899 | 1903 | ui = pullop.repo.ui |
|
1900 | 1904 | |
|
1901 | 1905 | # At the moment we don't do stream clones over bundle2. If that is |
|
1902 | 1906 | # implemented then here's where the check for that will go. |
|
1903 | 1907 | streaming = streamclone.canperformstreamclone(pullop, bundle2=True)[0] |
|
1904 | 1908 | |
|
1905 | 1909 | # declare pull perimeters |
|
1906 | 1910 | kwargs[b'common'] = pullop.common |
|
1907 | 1911 | kwargs[b'heads'] = pullop.heads or pullop.rheads |
|
1908 | 1912 | |
|
1909 | 1913 | # check server supports narrow and then adding includepats and excludepats |
|
1910 | 1914 | servernarrow = pullop.remote.capable(wireprototypes.NARROWCAP) |
|
1911 | 1915 | if servernarrow and pullop.includepats: |
|
1912 | 1916 | kwargs[b'includepats'] = pullop.includepats |
|
1913 | 1917 | if servernarrow and pullop.excludepats: |
|
1914 | 1918 | kwargs[b'excludepats'] = pullop.excludepats |
|
1915 | 1919 | |
|
1916 | 1920 | if streaming: |
|
1917 | 1921 | kwargs[b'cg'] = False |
|
1918 | 1922 | kwargs[b'stream'] = True |
|
1919 | 1923 | pullop.stepsdone.add(b'changegroup') |
|
1920 | 1924 | pullop.stepsdone.add(b'phases') |
|
1921 | 1925 | |
|
1922 | 1926 | else: |
|
1923 | 1927 | # pulling changegroup |
|
1924 | 1928 | pullop.stepsdone.add(b'changegroup') |
|
1925 | 1929 | |
|
1926 | 1930 | kwargs[b'cg'] = pullop.fetch |
|
1927 | 1931 | |
|
1928 | 1932 | legacyphase = b'phases' in ui.configlist(b'devel', b'legacy.exchange') |
|
1929 | 1933 | hasbinaryphase = b'heads' in pullop.remotebundle2caps.get(b'phases', ()) |
|
1930 | 1934 | if not legacyphase and hasbinaryphase: |
|
1931 | 1935 | kwargs[b'phases'] = True |
|
1932 | 1936 | pullop.stepsdone.add(b'phases') |
|
1933 | 1937 | |
|
1934 | 1938 | if b'listkeys' in pullop.remotebundle2caps: |
|
1935 | 1939 | if b'phases' not in pullop.stepsdone: |
|
1936 | 1940 | kwargs[b'listkeys'] = [b'phases'] |
|
1937 | 1941 | |
|
1938 | 1942 | bookmarksrequested = False |
|
1939 | 1943 | legacybookmark = b'bookmarks' in ui.configlist(b'devel', b'legacy.exchange') |
|
1940 | 1944 | hasbinarybook = b'bookmarks' in pullop.remotebundle2caps |
|
1941 | 1945 | |
|
1942 | 1946 | if pullop.remotebookmarks is not None: |
|
1943 | 1947 | pullop.stepsdone.add(b'request-bookmarks') |
|
1944 | 1948 | |
|
1945 | 1949 | if ( |
|
1946 | 1950 | b'request-bookmarks' not in pullop.stepsdone |
|
1947 | 1951 | and pullop.remotebookmarks is None |
|
1948 | 1952 | and not legacybookmark |
|
1949 | 1953 | and hasbinarybook |
|
1950 | 1954 | ): |
|
1951 | 1955 | kwargs[b'bookmarks'] = True |
|
1952 | 1956 | bookmarksrequested = True |
|
1953 | 1957 | |
|
1954 | 1958 | if b'listkeys' in pullop.remotebundle2caps: |
|
1955 | 1959 | if b'request-bookmarks' not in pullop.stepsdone: |
|
1956 | 1960 | # make sure to always includes bookmark data when migrating |
|
1957 | 1961 | # `hg incoming --bundle` to using this function. |
|
1958 | 1962 | pullop.stepsdone.add(b'request-bookmarks') |
|
1959 | 1963 | kwargs.setdefault(b'listkeys', []).append(b'bookmarks') |
|
1960 | 1964 | |
|
1961 | 1965 | # If this is a full pull / clone and the server supports the clone bundles |
|
1962 | 1966 | # feature, tell the server whether we attempted a clone bundle. The |
|
1963 | 1967 | # presence of this flag indicates the client supports clone bundles. This |
|
1964 | 1968 | # will enable the server to treat clients that support clone bundles |
|
1965 | 1969 | # differently from those that don't. |
|
1966 | 1970 | if ( |
|
1967 | 1971 | pullop.remote.capable(b'clonebundles') |
|
1968 | 1972 | and pullop.heads is None |
|
1969 | 1973 | and list(pullop.common) == [nullid] |
|
1970 | 1974 | ): |
|
1971 | 1975 | kwargs[b'cbattempted'] = pullop.clonebundleattempted |
|
1972 | 1976 | |
|
1973 | 1977 | if streaming: |
|
1974 | 1978 | pullop.repo.ui.status(_(b'streaming all changes\n')) |
|
1975 | 1979 | elif not pullop.fetch: |
|
1976 | 1980 | pullop.repo.ui.status(_(b"no changes found\n")) |
|
1977 | 1981 | pullop.cgresult = 0 |
|
1978 | 1982 | else: |
|
1979 | 1983 | if pullop.heads is None and list(pullop.common) == [nullid]: |
|
1980 | 1984 | pullop.repo.ui.status(_(b"requesting all changes\n")) |
|
1981 | 1985 | if obsolete.isenabled(pullop.repo, obsolete.exchangeopt): |
|
1982 | 1986 | remoteversions = bundle2.obsmarkersversion(pullop.remotebundle2caps) |
|
1983 | 1987 | if obsolete.commonversion(remoteversions) is not None: |
|
1984 | 1988 | kwargs[b'obsmarkers'] = True |
|
1985 | 1989 | pullop.stepsdone.add(b'obsmarkers') |
|
1986 | 1990 | _pullbundle2extraprepare(pullop, kwargs) |
|
1987 | 1991 | |
|
1988 | 1992 | with pullop.remote.commandexecutor() as e: |
|
1989 | 1993 | args = dict(kwargs) |
|
1990 | 1994 | args[b'source'] = b'pull' |
|
1991 | 1995 | bundle = e.callcommand(b'getbundle', args).result() |
|
1992 | 1996 | |
|
1993 | 1997 | try: |
|
1994 | 1998 | op = bundle2.bundleoperation( |
|
1995 | 1999 | pullop.repo, pullop.gettransaction, source=b'pull' |
|
1996 | 2000 | ) |
|
1997 | 2001 | op.modes[b'bookmarks'] = b'records' |
|
1998 | 2002 | bundle2.processbundle(pullop.repo, bundle, op=op) |
|
1999 | 2003 | except bundle2.AbortFromPart as exc: |
|
2000 | 2004 | pullop.repo.ui.status(_(b'remote: abort: %s\n') % exc) |
|
2001 | 2005 | raise error.Abort(_(b'pull failed on remote'), hint=exc.hint) |
|
2002 | 2006 | except error.BundleValueError as exc: |
|
2003 | 2007 | raise error.Abort(_(b'missing support for %s') % exc) |
|
2004 | 2008 | |
|
2005 | 2009 | if pullop.fetch: |
|
2006 | 2010 | pullop.cgresult = bundle2.combinechangegroupresults(op) |
|
2007 | 2011 | |
|
2008 | 2012 | # processing phases change |
|
2009 | 2013 | for namespace, value in op.records[b'listkeys']: |
|
2010 | 2014 | if namespace == b'phases': |
|
2011 | 2015 | _pullapplyphases(pullop, value) |
|
2012 | 2016 | |
|
2013 | 2017 | # processing bookmark update |
|
2014 | 2018 | if bookmarksrequested: |
|
2015 | 2019 | books = {} |
|
2016 | 2020 | for record in op.records[b'bookmarks']: |
|
2017 | 2021 | books[record[b'bookmark']] = record[b"node"] |
|
2018 | 2022 | pullop.remotebookmarks = books |
|
2019 | 2023 | else: |
|
2020 | 2024 | for namespace, value in op.records[b'listkeys']: |
|
2021 | 2025 | if namespace == b'bookmarks': |
|
2022 | 2026 | pullop.remotebookmarks = bookmod.unhexlifybookmarks(value) |
|
2023 | 2027 | |
|
2024 | 2028 | # bookmark data were either already there or pulled in the bundle |
|
2025 | 2029 | if pullop.remotebookmarks is not None: |
|
2026 | 2030 | _pullbookmarks(pullop) |
|
2027 | 2031 | |
|
2028 | 2032 | |
|
2029 | 2033 | def _pullbundle2extraprepare(pullop, kwargs): |
|
2030 | 2034 | """hook function so that extensions can extend the getbundle call""" |
|
2031 | 2035 | |
|
2032 | 2036 | |
|
2033 | 2037 | def _pullchangeset(pullop): |
|
2034 | 2038 | """pull changeset from unbundle into the local repo""" |
|
2035 | 2039 | # We delay the open of the transaction as late as possible so we |
|
2036 | 2040 | # don't open transaction for nothing or you break future useful |
|
2037 | 2041 | # rollback call |
|
2038 | 2042 | if b'changegroup' in pullop.stepsdone: |
|
2039 | 2043 | return |
|
2040 | 2044 | pullop.stepsdone.add(b'changegroup') |
|
2041 | 2045 | if not pullop.fetch: |
|
2042 | 2046 | pullop.repo.ui.status(_(b"no changes found\n")) |
|
2043 | 2047 | pullop.cgresult = 0 |
|
2044 | 2048 | return |
|
2045 | 2049 | tr = pullop.gettransaction() |
|
2046 | 2050 | if pullop.heads is None and list(pullop.common) == [nullid]: |
|
2047 | 2051 | pullop.repo.ui.status(_(b"requesting all changes\n")) |
|
2048 | 2052 | elif pullop.heads is None and pullop.remote.capable(b'changegroupsubset'): |
|
2049 | 2053 | # issue1320, avoid a race if remote changed after discovery |
|
2050 | 2054 | pullop.heads = pullop.rheads |
|
2051 | 2055 | |
|
2052 | 2056 | if pullop.remote.capable(b'getbundle'): |
|
2053 | 2057 | # TODO: get bundlecaps from remote |
|
2054 | 2058 | cg = pullop.remote.getbundle( |
|
2055 | 2059 | b'pull', common=pullop.common, heads=pullop.heads or pullop.rheads |
|
2056 | 2060 | ) |
|
2057 | 2061 | elif pullop.heads is None: |
|
2058 | 2062 | with pullop.remote.commandexecutor() as e: |
|
2059 | 2063 | cg = e.callcommand( |
|
2060 | 2064 | b'changegroup', {b'nodes': pullop.fetch, b'source': b'pull',} |
|
2061 | 2065 | ).result() |
|
2062 | 2066 | |
|
2063 | 2067 | elif not pullop.remote.capable(b'changegroupsubset'): |
|
2064 | 2068 | raise error.Abort( |
|
2065 | 2069 | _( |
|
2066 | 2070 | b"partial pull cannot be done because " |
|
2067 | 2071 | b"other repository doesn't support " |
|
2068 | 2072 | b"changegroupsubset." |
|
2069 | 2073 | ) |
|
2070 | 2074 | ) |
|
2071 | 2075 | else: |
|
2072 | 2076 | with pullop.remote.commandexecutor() as e: |
|
2073 | 2077 | cg = e.callcommand( |
|
2074 | 2078 | b'changegroupsubset', |
|
2075 | 2079 | { |
|
2076 | 2080 | b'bases': pullop.fetch, |
|
2077 | 2081 | b'heads': pullop.heads, |
|
2078 | 2082 | b'source': b'pull', |
|
2079 | 2083 | }, |
|
2080 | 2084 | ).result() |
|
2081 | 2085 | |
|
2082 | 2086 | bundleop = bundle2.applybundle( |
|
2083 | 2087 | pullop.repo, cg, tr, b'pull', pullop.remote.url() |
|
2084 | 2088 | ) |
|
2085 | 2089 | pullop.cgresult = bundle2.combinechangegroupresults(bundleop) |
|
2086 | 2090 | |
|
2087 | 2091 | |
|
2088 | 2092 | def _pullphase(pullop): |
|
2089 | 2093 | # Get remote phases data from remote |
|
2090 | 2094 | if b'phases' in pullop.stepsdone: |
|
2091 | 2095 | return |
|
2092 | 2096 | remotephases = listkeys(pullop.remote, b'phases') |
|
2093 | 2097 | _pullapplyphases(pullop, remotephases) |
|
2094 | 2098 | |
|
2095 | 2099 | |
|
2096 | 2100 | def _pullapplyphases(pullop, remotephases): |
|
2097 | 2101 | """apply phase movement from observed remote state""" |
|
2098 | 2102 | if b'phases' in pullop.stepsdone: |
|
2099 | 2103 | return |
|
2100 | 2104 | pullop.stepsdone.add(b'phases') |
|
2101 | 2105 | publishing = bool(remotephases.get(b'publishing', False)) |
|
2102 | 2106 | if remotephases and not publishing: |
|
2103 | 2107 | # remote is new and non-publishing |
|
2104 | 2108 | pheads, _dr = phases.analyzeremotephases( |
|
2105 | 2109 | pullop.repo, pullop.pulledsubset, remotephases |
|
2106 | 2110 | ) |
|
2107 | 2111 | dheads = pullop.pulledsubset |
|
2108 | 2112 | else: |
|
2109 | 2113 | # Remote is old or publishing all common changesets |
|
2110 | 2114 | # should be seen as public |
|
2111 | 2115 | pheads = pullop.pulledsubset |
|
2112 | 2116 | dheads = [] |
|
2113 | 2117 | unfi = pullop.repo.unfiltered() |
|
2114 | 2118 | phase = unfi._phasecache.phase |
|
2115 | 2119 | rev = unfi.changelog.index.get_rev |
|
2116 | 2120 | public = phases.public |
|
2117 | 2121 | draft = phases.draft |
|
2118 | 2122 | |
|
2119 | 2123 | # exclude changesets already public locally and update the others |
|
2120 | 2124 | pheads = [pn for pn in pheads if phase(unfi, rev(pn)) > public] |
|
2121 | 2125 | if pheads: |
|
2122 | 2126 | tr = pullop.gettransaction() |
|
2123 | 2127 | phases.advanceboundary(pullop.repo, tr, public, pheads) |
|
2124 | 2128 | |
|
2125 | 2129 | # exclude changesets already draft locally and update the others |
|
2126 | 2130 | dheads = [pn for pn in dheads if phase(unfi, rev(pn)) > draft] |
|
2127 | 2131 | if dheads: |
|
2128 | 2132 | tr = pullop.gettransaction() |
|
2129 | 2133 | phases.advanceboundary(pullop.repo, tr, draft, dheads) |
|
2130 | 2134 | |
|
2131 | 2135 | |
|
2132 | 2136 | def _pullbookmarks(pullop): |
|
2133 | 2137 | """process the remote bookmark information to update the local one""" |
|
2134 | 2138 | if b'bookmarks' in pullop.stepsdone: |
|
2135 | 2139 | return |
|
2136 | 2140 | pullop.stepsdone.add(b'bookmarks') |
|
2137 | 2141 | repo = pullop.repo |
|
2138 | 2142 | remotebookmarks = pullop.remotebookmarks |
|
2139 | 2143 | bookmod.updatefromremote( |
|
2140 | 2144 | repo.ui, |
|
2141 | 2145 | repo, |
|
2142 | 2146 | remotebookmarks, |
|
2143 | 2147 | pullop.remote.url(), |
|
2144 | 2148 | pullop.gettransaction, |
|
2145 | 2149 | explicit=pullop.explicitbookmarks, |
|
2146 | 2150 | ) |
|
2147 | 2151 | |
|
2148 | 2152 | |
|
2149 | 2153 | def _pullobsolete(pullop): |
|
2150 | 2154 | """utility function to pull obsolete markers from a remote |
|
2151 | 2155 | |
|
2152 | 2156 | The `gettransaction` is function that return the pull transaction, creating |
|
2153 | 2157 | one if necessary. We return the transaction to inform the calling code that |
|
2154 | 2158 | a new transaction have been created (when applicable). |
|
2155 | 2159 | |
|
2156 | 2160 | Exists mostly to allow overriding for experimentation purpose""" |
|
2157 | 2161 | if b'obsmarkers' in pullop.stepsdone: |
|
2158 | 2162 | return |
|
2159 | 2163 | pullop.stepsdone.add(b'obsmarkers') |
|
2160 | 2164 | tr = None |
|
2161 | 2165 | if obsolete.isenabled(pullop.repo, obsolete.exchangeopt): |
|
2162 | 2166 | pullop.repo.ui.debug(b'fetching remote obsolete markers\n') |
|
2163 | 2167 | remoteobs = listkeys(pullop.remote, b'obsolete') |
|
2164 | 2168 | if b'dump0' in remoteobs: |
|
2165 | 2169 | tr = pullop.gettransaction() |
|
2166 | 2170 | markers = [] |
|
2167 | 2171 | for key in sorted(remoteobs, reverse=True): |
|
2168 | 2172 | if key.startswith(b'dump'): |
|
2169 | 2173 | data = util.b85decode(remoteobs[key]) |
|
2170 | 2174 | version, newmarks = obsolete._readmarkers(data) |
|
2171 | 2175 | markers += newmarks |
|
2172 | 2176 | if markers: |
|
2173 | 2177 | pullop.repo.obsstore.add(tr, markers) |
|
2174 | 2178 | pullop.repo.invalidatevolatilesets() |
|
2175 | 2179 | return tr |
|
2176 | 2180 | |
|
2177 | 2181 | |
|
2178 | 2182 | def applynarrowacl(repo, kwargs): |
|
2179 | 2183 | """Apply narrow fetch access control. |
|
2180 | 2184 | |
|
2181 | 2185 | This massages the named arguments for getbundle wire protocol commands |
|
2182 | 2186 | so requested data is filtered through access control rules. |
|
2183 | 2187 | """ |
|
2184 | 2188 | ui = repo.ui |
|
2185 | 2189 | # TODO this assumes existence of HTTP and is a layering violation. |
|
2186 | 2190 | username = ui.shortuser(ui.environ.get(b'REMOTE_USER') or ui.username()) |
|
2187 | 2191 | user_includes = ui.configlist( |
|
2188 | 2192 | _NARROWACL_SECTION, |
|
2189 | 2193 | username + b'.includes', |
|
2190 | 2194 | ui.configlist(_NARROWACL_SECTION, b'default.includes'), |
|
2191 | 2195 | ) |
|
2192 | 2196 | user_excludes = ui.configlist( |
|
2193 | 2197 | _NARROWACL_SECTION, |
|
2194 | 2198 | username + b'.excludes', |
|
2195 | 2199 | ui.configlist(_NARROWACL_SECTION, b'default.excludes'), |
|
2196 | 2200 | ) |
|
2197 | 2201 | if not user_includes: |
|
2198 | 2202 | raise error.Abort( |
|
2199 | 2203 | _(b"%s configuration for user %s is empty") |
|
2200 | 2204 | % (_NARROWACL_SECTION, username) |
|
2201 | 2205 | ) |
|
2202 | 2206 | |
|
2203 | 2207 | user_includes = [ |
|
2204 | 2208 | b'path:.' if p == b'*' else b'path:' + p for p in user_includes |
|
2205 | 2209 | ] |
|
2206 | 2210 | user_excludes = [ |
|
2207 | 2211 | b'path:.' if p == b'*' else b'path:' + p for p in user_excludes |
|
2208 | 2212 | ] |
|
2209 | 2213 | |
|
2210 | 2214 | req_includes = set(kwargs.get('includepats', [])) |
|
2211 | 2215 | req_excludes = set(kwargs.get('excludepats', [])) |
|
2212 | 2216 | |
|
2213 | 2217 | req_includes, req_excludes, invalid_includes = narrowspec.restrictpatterns( |
|
2214 | 2218 | req_includes, req_excludes, user_includes, user_excludes |
|
2215 | 2219 | ) |
|
2216 | 2220 | |
|
2217 | 2221 | if invalid_includes: |
|
2218 | 2222 | raise error.Abort( |
|
2219 | 2223 | _(b"The following includes are not accessible for %s: %s") |
|
2220 | 2224 | % (username, stringutil.pprint(invalid_includes)) |
|
2221 | 2225 | ) |
|
2222 | 2226 | |
|
2223 | 2227 | new_args = {} |
|
2224 | 2228 | new_args.update(kwargs) |
|
2225 | 2229 | new_args['narrow'] = True |
|
2226 | 2230 | new_args['narrow_acl'] = True |
|
2227 | 2231 | new_args['includepats'] = req_includes |
|
2228 | 2232 | if req_excludes: |
|
2229 | 2233 | new_args['excludepats'] = req_excludes |
|
2230 | 2234 | |
|
2231 | 2235 | return new_args |
|
2232 | 2236 | |
|
2233 | 2237 | |
|
2234 | 2238 | def _computeellipsis(repo, common, heads, known, match, depth=None): |
|
2235 | 2239 | """Compute the shape of a narrowed DAG. |
|
2236 | 2240 | |
|
2237 | 2241 | Args: |
|
2238 | 2242 | repo: The repository we're transferring. |
|
2239 | 2243 | common: The roots of the DAG range we're transferring. |
|
2240 | 2244 | May be just [nullid], which means all ancestors of heads. |
|
2241 | 2245 | heads: The heads of the DAG range we're transferring. |
|
2242 | 2246 | match: The narrowmatcher that allows us to identify relevant changes. |
|
2243 | 2247 | depth: If not None, only consider nodes to be full nodes if they are at |
|
2244 | 2248 | most depth changesets away from one of heads. |
|
2245 | 2249 | |
|
2246 | 2250 | Returns: |
|
2247 | 2251 | A tuple of (visitnodes, relevant_nodes, ellipsisroots) where: |
|
2248 | 2252 | |
|
2249 | 2253 | visitnodes: The list of nodes (either full or ellipsis) which |
|
2250 | 2254 | need to be sent to the client. |
|
2251 | 2255 | relevant_nodes: The set of changelog nodes which change a file inside |
|
2252 | 2256 | the narrowspec. The client needs these as non-ellipsis nodes. |
|
2253 | 2257 | ellipsisroots: A dict of {rev: parents} that is used in |
|
2254 | 2258 | narrowchangegroup to produce ellipsis nodes with the |
|
2255 | 2259 | correct parents. |
|
2256 | 2260 | """ |
|
2257 | 2261 | cl = repo.changelog |
|
2258 | 2262 | mfl = repo.manifestlog |
|
2259 | 2263 | |
|
2260 | 2264 | clrev = cl.rev |
|
2261 | 2265 | |
|
2262 | 2266 | commonrevs = {clrev(n) for n in common} | {nullrev} |
|
2263 | 2267 | headsrevs = {clrev(n) for n in heads} |
|
2264 | 2268 | |
|
2265 | 2269 | if depth: |
|
2266 | 2270 | revdepth = {h: 0 for h in headsrevs} |
|
2267 | 2271 | |
|
2268 | 2272 | ellipsisheads = collections.defaultdict(set) |
|
2269 | 2273 | ellipsisroots = collections.defaultdict(set) |
|
2270 | 2274 | |
|
2271 | 2275 | def addroot(head, curchange): |
|
2272 | 2276 | """Add a root to an ellipsis head, splitting heads with 3 roots.""" |
|
2273 | 2277 | ellipsisroots[head].add(curchange) |
|
2274 | 2278 | # Recursively split ellipsis heads with 3 roots by finding the |
|
2275 | 2279 | # roots' youngest common descendant which is an elided merge commit. |
|
2276 | 2280 | # That descendant takes 2 of the 3 roots as its own, and becomes a |
|
2277 | 2281 | # root of the head. |
|
2278 | 2282 | while len(ellipsisroots[head]) > 2: |
|
2279 | 2283 | child, roots = splithead(head) |
|
2280 | 2284 | splitroots(head, child, roots) |
|
2281 | 2285 | head = child # Recurse in case we just added a 3rd root |
|
2282 | 2286 | |
|
2283 | 2287 | def splitroots(head, child, roots): |
|
2284 | 2288 | ellipsisroots[head].difference_update(roots) |
|
2285 | 2289 | ellipsisroots[head].add(child) |
|
2286 | 2290 | ellipsisroots[child].update(roots) |
|
2287 | 2291 | ellipsisroots[child].discard(child) |
|
2288 | 2292 | |
|
2289 | 2293 | def splithead(head): |
|
2290 | 2294 | r1, r2, r3 = sorted(ellipsisroots[head]) |
|
2291 | 2295 | for nr1, nr2 in ((r2, r3), (r1, r3), (r1, r2)): |
|
2292 | 2296 | mid = repo.revs( |
|
2293 | 2297 | b'sort(merge() & %d::%d & %d::%d, -rev)', nr1, head, nr2, head |
|
2294 | 2298 | ) |
|
2295 | 2299 | for j in mid: |
|
2296 | 2300 | if j == nr2: |
|
2297 | 2301 | return nr2, (nr1, nr2) |
|
2298 | 2302 | if j not in ellipsisroots or len(ellipsisroots[j]) < 2: |
|
2299 | 2303 | return j, (nr1, nr2) |
|
2300 | 2304 | raise error.Abort( |
|
2301 | 2305 | _( |
|
2302 | 2306 | b'Failed to split up ellipsis node! head: %d, ' |
|
2303 | 2307 | b'roots: %d %d %d' |
|
2304 | 2308 | ) |
|
2305 | 2309 | % (head, r1, r2, r3) |
|
2306 | 2310 | ) |
|
2307 | 2311 | |
|
2308 | 2312 | missing = list(cl.findmissingrevs(common=commonrevs, heads=headsrevs)) |
|
2309 | 2313 | visit = reversed(missing) |
|
2310 | 2314 | relevant_nodes = set() |
|
2311 | 2315 | visitnodes = [cl.node(m) for m in missing] |
|
2312 | 2316 | required = set(headsrevs) | known |
|
2313 | 2317 | for rev in visit: |
|
2314 | 2318 | clrev = cl.changelogrevision(rev) |
|
2315 | 2319 | ps = [prev for prev in cl.parentrevs(rev) if prev != nullrev] |
|
2316 | 2320 | if depth is not None: |
|
2317 | 2321 | curdepth = revdepth[rev] |
|
2318 | 2322 | for p in ps: |
|
2319 | 2323 | revdepth[p] = min(curdepth + 1, revdepth.get(p, depth + 1)) |
|
2320 | 2324 | needed = False |
|
2321 | 2325 | shallow_enough = depth is None or revdepth[rev] <= depth |
|
2322 | 2326 | if shallow_enough: |
|
2323 | 2327 | curmf = mfl[clrev.manifest].read() |
|
2324 | 2328 | if ps: |
|
2325 | 2329 | # We choose to not trust the changed files list in |
|
2326 | 2330 | # changesets because it's not always correct. TODO: could |
|
2327 | 2331 | # we trust it for the non-merge case? |
|
2328 | 2332 | p1mf = mfl[cl.changelogrevision(ps[0]).manifest].read() |
|
2329 | 2333 | needed = bool(curmf.diff(p1mf, match)) |
|
2330 | 2334 | if not needed and len(ps) > 1: |
|
2331 | 2335 | # For merge changes, the list of changed files is not |
|
2332 | 2336 | # helpful, since we need to emit the merge if a file |
|
2333 | 2337 | # in the narrow spec has changed on either side of the |
|
2334 | 2338 | # merge. As a result, we do a manifest diff to check. |
|
2335 | 2339 | p2mf = mfl[cl.changelogrevision(ps[1]).manifest].read() |
|
2336 | 2340 | needed = bool(curmf.diff(p2mf, match)) |
|
2337 | 2341 | else: |
|
2338 | 2342 | # For a root node, we need to include the node if any |
|
2339 | 2343 | # files in the node match the narrowspec. |
|
2340 | 2344 | needed = any(curmf.walk(match)) |
|
2341 | 2345 | |
|
2342 | 2346 | if needed: |
|
2343 | 2347 | for head in ellipsisheads[rev]: |
|
2344 | 2348 | addroot(head, rev) |
|
2345 | 2349 | for p in ps: |
|
2346 | 2350 | required.add(p) |
|
2347 | 2351 | relevant_nodes.add(cl.node(rev)) |
|
2348 | 2352 | else: |
|
2349 | 2353 | if not ps: |
|
2350 | 2354 | ps = [nullrev] |
|
2351 | 2355 | if rev in required: |
|
2352 | 2356 | for head in ellipsisheads[rev]: |
|
2353 | 2357 | addroot(head, rev) |
|
2354 | 2358 | for p in ps: |
|
2355 | 2359 | ellipsisheads[p].add(rev) |
|
2356 | 2360 | else: |
|
2357 | 2361 | for p in ps: |
|
2358 | 2362 | ellipsisheads[p] |= ellipsisheads[rev] |
|
2359 | 2363 | |
|
2360 | 2364 | # add common changesets as roots of their reachable ellipsis heads |
|
2361 | 2365 | for c in commonrevs: |
|
2362 | 2366 | for head in ellipsisheads[c]: |
|
2363 | 2367 | addroot(head, c) |
|
2364 | 2368 | return visitnodes, relevant_nodes, ellipsisroots |
|
2365 | 2369 | |
|
2366 | 2370 | |
|
2367 | 2371 | def caps20to10(repo, role): |
|
2368 | 2372 | """return a set with appropriate options to use bundle20 during getbundle""" |
|
2369 | 2373 | caps = {b'HG20'} |
|
2370 | 2374 | capsblob = bundle2.encodecaps(bundle2.getrepocaps(repo, role=role)) |
|
2371 | 2375 | caps.add(b'bundle2=' + urlreq.quote(capsblob)) |
|
2372 | 2376 | return caps |
|
2373 | 2377 | |
|
2374 | 2378 | |
|
2375 | 2379 | # List of names of steps to perform for a bundle2 for getbundle, order matters. |
|
2376 | 2380 | getbundle2partsorder = [] |
|
2377 | 2381 | |
|
2378 | 2382 | # Mapping between step name and function |
|
2379 | 2383 | # |
|
2380 | 2384 | # This exists to help extensions wrap steps if necessary |
|
2381 | 2385 | getbundle2partsmapping = {} |
|
2382 | 2386 | |
|
2383 | 2387 | |
|
2384 | 2388 | def getbundle2partsgenerator(stepname, idx=None): |
|
2385 | 2389 | """decorator for function generating bundle2 part for getbundle |
|
2386 | 2390 | |
|
2387 | 2391 | The function is added to the step -> function mapping and appended to the |
|
2388 | 2392 | list of steps. Beware that decorated functions will be added in order |
|
2389 | 2393 | (this may matter). |
|
2390 | 2394 | |
|
2391 | 2395 | You can only use this decorator for new steps, if you want to wrap a step |
|
2392 | 2396 | from an extension, attack the getbundle2partsmapping dictionary directly.""" |
|
2393 | 2397 | |
|
2394 | 2398 | def dec(func): |
|
2395 | 2399 | assert stepname not in getbundle2partsmapping |
|
2396 | 2400 | getbundle2partsmapping[stepname] = func |
|
2397 | 2401 | if idx is None: |
|
2398 | 2402 | getbundle2partsorder.append(stepname) |
|
2399 | 2403 | else: |
|
2400 | 2404 | getbundle2partsorder.insert(idx, stepname) |
|
2401 | 2405 | return func |
|
2402 | 2406 | |
|
2403 | 2407 | return dec |
|
2404 | 2408 | |
|
2405 | 2409 | |
|
2406 | 2410 | def bundle2requested(bundlecaps): |
|
2407 | 2411 | if bundlecaps is not None: |
|
2408 | 2412 | return any(cap.startswith(b'HG2') for cap in bundlecaps) |
|
2409 | 2413 | return False |
|
2410 | 2414 | |
|
2411 | 2415 | |
|
2412 | 2416 | def getbundlechunks( |
|
2413 | 2417 | repo, source, heads=None, common=None, bundlecaps=None, **kwargs |
|
2414 | 2418 | ): |
|
2415 | 2419 | """Return chunks constituting a bundle's raw data. |
|
2416 | 2420 | |
|
2417 | 2421 | Could be a bundle HG10 or a bundle HG20 depending on bundlecaps |
|
2418 | 2422 | passed. |
|
2419 | 2423 | |
|
2420 | 2424 | Returns a 2-tuple of a dict with metadata about the generated bundle |
|
2421 | 2425 | and an iterator over raw chunks (of varying sizes). |
|
2422 | 2426 | """ |
|
2423 | 2427 | kwargs = pycompat.byteskwargs(kwargs) |
|
2424 | 2428 | info = {} |
|
2425 | 2429 | usebundle2 = bundle2requested(bundlecaps) |
|
2426 | 2430 | # bundle10 case |
|
2427 | 2431 | if not usebundle2: |
|
2428 | 2432 | if bundlecaps and not kwargs.get(b'cg', True): |
|
2429 | 2433 | raise ValueError( |
|
2430 | 2434 | _(b'request for bundle10 must include changegroup') |
|
2431 | 2435 | ) |
|
2432 | 2436 | |
|
2433 | 2437 | if kwargs: |
|
2434 | 2438 | raise ValueError( |
|
2435 | 2439 | _(b'unsupported getbundle arguments: %s') |
|
2436 | 2440 | % b', '.join(sorted(kwargs.keys())) |
|
2437 | 2441 | ) |
|
2438 | 2442 | outgoing = _computeoutgoing(repo, heads, common) |
|
2439 | 2443 | info[b'bundleversion'] = 1 |
|
2440 | 2444 | return ( |
|
2441 | 2445 | info, |
|
2442 | 2446 | changegroup.makestream( |
|
2443 | 2447 | repo, outgoing, b'01', source, bundlecaps=bundlecaps |
|
2444 | 2448 | ), |
|
2445 | 2449 | ) |
|
2446 | 2450 | |
|
2447 | 2451 | # bundle20 case |
|
2448 | 2452 | info[b'bundleversion'] = 2 |
|
2449 | 2453 | b2caps = {} |
|
2450 | 2454 | for bcaps in bundlecaps: |
|
2451 | 2455 | if bcaps.startswith(b'bundle2='): |
|
2452 | 2456 | blob = urlreq.unquote(bcaps[len(b'bundle2=') :]) |
|
2453 | 2457 | b2caps.update(bundle2.decodecaps(blob)) |
|
2454 | 2458 | bundler = bundle2.bundle20(repo.ui, b2caps) |
|
2455 | 2459 | |
|
2456 | 2460 | kwargs[b'heads'] = heads |
|
2457 | 2461 | kwargs[b'common'] = common |
|
2458 | 2462 | |
|
2459 | 2463 | for name in getbundle2partsorder: |
|
2460 | 2464 | func = getbundle2partsmapping[name] |
|
2461 | 2465 | func( |
|
2462 | 2466 | bundler, |
|
2463 | 2467 | repo, |
|
2464 | 2468 | source, |
|
2465 | 2469 | bundlecaps=bundlecaps, |
|
2466 | 2470 | b2caps=b2caps, |
|
2467 | 2471 | **pycompat.strkwargs(kwargs) |
|
2468 | 2472 | ) |
|
2469 | 2473 | |
|
2470 | 2474 | info[b'prefercompressed'] = bundler.prefercompressed |
|
2471 | 2475 | |
|
2472 | 2476 | return info, bundler.getchunks() |
|
2473 | 2477 | |
|
2474 | 2478 | |
|
2475 | 2479 | @getbundle2partsgenerator(b'stream2') |
|
2476 | 2480 | def _getbundlestream2(bundler, repo, *args, **kwargs): |
|
2477 | 2481 | return bundle2.addpartbundlestream2(bundler, repo, **kwargs) |
|
2478 | 2482 | |
|
2479 | 2483 | |
|
2480 | 2484 | @getbundle2partsgenerator(b'changegroup') |
|
2481 | 2485 | def _getbundlechangegrouppart( |
|
2482 | 2486 | bundler, |
|
2483 | 2487 | repo, |
|
2484 | 2488 | source, |
|
2485 | 2489 | bundlecaps=None, |
|
2486 | 2490 | b2caps=None, |
|
2487 | 2491 | heads=None, |
|
2488 | 2492 | common=None, |
|
2489 | 2493 | **kwargs |
|
2490 | 2494 | ): |
|
2491 | 2495 | """add a changegroup part to the requested bundle""" |
|
2492 | 2496 | if not kwargs.get('cg', True) or not b2caps: |
|
2493 | 2497 | return |
|
2494 | 2498 | |
|
2495 | 2499 | version = b'01' |
|
2496 | 2500 | cgversions = b2caps.get(b'changegroup') |
|
2497 | 2501 | if cgversions: # 3.1 and 3.2 ship with an empty value |
|
2498 | 2502 | cgversions = [ |
|
2499 | 2503 | v |
|
2500 | 2504 | for v in cgversions |
|
2501 | 2505 | if v in changegroup.supportedoutgoingversions(repo) |
|
2502 | 2506 | ] |
|
2503 | 2507 | if not cgversions: |
|
2504 | 2508 | raise error.Abort(_(b'no common changegroup version')) |
|
2505 | 2509 | version = max(cgversions) |
|
2506 | 2510 | |
|
2507 | 2511 | outgoing = _computeoutgoing(repo, heads, common) |
|
2508 | 2512 | if not outgoing.missing: |
|
2509 | 2513 | return |
|
2510 | 2514 | |
|
2511 | 2515 | if kwargs.get('narrow', False): |
|
2512 | 2516 | include = sorted(filter(bool, kwargs.get('includepats', []))) |
|
2513 | 2517 | exclude = sorted(filter(bool, kwargs.get('excludepats', []))) |
|
2514 | 2518 | matcher = narrowspec.match(repo.root, include=include, exclude=exclude) |
|
2515 | 2519 | else: |
|
2516 | 2520 | matcher = None |
|
2517 | 2521 | |
|
2518 | 2522 | cgstream = changegroup.makestream( |
|
2519 | 2523 | repo, outgoing, version, source, bundlecaps=bundlecaps, matcher=matcher |
|
2520 | 2524 | ) |
|
2521 | 2525 | |
|
2522 | 2526 | part = bundler.newpart(b'changegroup', data=cgstream) |
|
2523 | 2527 | if cgversions: |
|
2524 | 2528 | part.addparam(b'version', version) |
|
2525 | 2529 | |
|
2526 | 2530 | part.addparam(b'nbchanges', b'%d' % len(outgoing.missing), mandatory=False) |
|
2527 | 2531 | |
|
2528 | 2532 | if b'treemanifest' in repo.requirements: |
|
2529 | 2533 | part.addparam(b'treemanifest', b'1') |
|
2530 | 2534 | |
|
2531 | 2535 | if b'exp-sidedata-flag' in repo.requirements: |
|
2532 | 2536 | part.addparam(b'exp-sidedata', b'1') |
|
2533 | 2537 | |
|
2534 | 2538 | if ( |
|
2535 | 2539 | kwargs.get('narrow', False) |
|
2536 | 2540 | and kwargs.get('narrow_acl', False) |
|
2537 | 2541 | and (include or exclude) |
|
2538 | 2542 | ): |
|
2539 | 2543 | # this is mandatory because otherwise ACL clients won't work |
|
2540 | 2544 | narrowspecpart = bundler.newpart(b'Narrow:responsespec') |
|
2541 | 2545 | narrowspecpart.data = b'%s\0%s' % ( |
|
2542 | 2546 | b'\n'.join(include), |
|
2543 | 2547 | b'\n'.join(exclude), |
|
2544 | 2548 | ) |
|
2545 | 2549 | |
|
2546 | 2550 | |
|
2547 | 2551 | @getbundle2partsgenerator(b'bookmarks') |
|
2548 | 2552 | def _getbundlebookmarkpart( |
|
2549 | 2553 | bundler, repo, source, bundlecaps=None, b2caps=None, **kwargs |
|
2550 | 2554 | ): |
|
2551 | 2555 | """add a bookmark part to the requested bundle""" |
|
2552 | 2556 | if not kwargs.get('bookmarks', False): |
|
2553 | 2557 | return |
|
2554 | 2558 | if not b2caps or b'bookmarks' not in b2caps: |
|
2555 | 2559 | raise error.Abort(_(b'no common bookmarks exchange method')) |
|
2556 | 2560 | books = bookmod.listbinbookmarks(repo) |
|
2557 | 2561 | data = bookmod.binaryencode(books) |
|
2558 | 2562 | if data: |
|
2559 | 2563 | bundler.newpart(b'bookmarks', data=data) |
|
2560 | 2564 | |
|
2561 | 2565 | |
|
2562 | 2566 | @getbundle2partsgenerator(b'listkeys') |
|
2563 | 2567 | def _getbundlelistkeysparts( |
|
2564 | 2568 | bundler, repo, source, bundlecaps=None, b2caps=None, **kwargs |
|
2565 | 2569 | ): |
|
2566 | 2570 | """add parts containing listkeys namespaces to the requested bundle""" |
|
2567 | 2571 | listkeys = kwargs.get('listkeys', ()) |
|
2568 | 2572 | for namespace in listkeys: |
|
2569 | 2573 | part = bundler.newpart(b'listkeys') |
|
2570 | 2574 | part.addparam(b'namespace', namespace) |
|
2571 | 2575 | keys = repo.listkeys(namespace).items() |
|
2572 | 2576 | part.data = pushkey.encodekeys(keys) |
|
2573 | 2577 | |
|
2574 | 2578 | |
|
2575 | 2579 | @getbundle2partsgenerator(b'obsmarkers') |
|
2576 | 2580 | def _getbundleobsmarkerpart( |
|
2577 | 2581 | bundler, repo, source, bundlecaps=None, b2caps=None, heads=None, **kwargs |
|
2578 | 2582 | ): |
|
2579 | 2583 | """add an obsolescence markers part to the requested bundle""" |
|
2580 | 2584 | if kwargs.get('obsmarkers', False): |
|
2581 | 2585 | if heads is None: |
|
2582 | 2586 | heads = repo.heads() |
|
2583 | 2587 | subset = [c.node() for c in repo.set(b'::%ln', heads)] |
|
2584 | 2588 | markers = repo.obsstore.relevantmarkers(subset) |
|
2585 | 2589 | markers = obsutil.sortedmarkers(markers) |
|
2586 | 2590 | bundle2.buildobsmarkerspart(bundler, markers) |
|
2587 | 2591 | |
|
2588 | 2592 | |
|
2589 | 2593 | @getbundle2partsgenerator(b'phases') |
|
2590 | 2594 | def _getbundlephasespart( |
|
2591 | 2595 | bundler, repo, source, bundlecaps=None, b2caps=None, heads=None, **kwargs |
|
2592 | 2596 | ): |
|
2593 | 2597 | """add phase heads part to the requested bundle""" |
|
2594 | 2598 | if kwargs.get('phases', False): |
|
2595 | 2599 | if not b2caps or b'heads' not in b2caps.get(b'phases'): |
|
2596 | 2600 | raise error.Abort(_(b'no common phases exchange method')) |
|
2597 | 2601 | if heads is None: |
|
2598 | 2602 | heads = repo.heads() |
|
2599 | 2603 | |
|
2600 | 2604 | headsbyphase = collections.defaultdict(set) |
|
2601 | 2605 | if repo.publishing(): |
|
2602 | 2606 | headsbyphase[phases.public] = heads |
|
2603 | 2607 | else: |
|
2604 | 2608 | # find the appropriate heads to move |
|
2605 | 2609 | |
|
2606 | 2610 | phase = repo._phasecache.phase |
|
2607 | 2611 | node = repo.changelog.node |
|
2608 | 2612 | rev = repo.changelog.rev |
|
2609 | 2613 | for h in heads: |
|
2610 | 2614 | headsbyphase[phase(repo, rev(h))].add(h) |
|
2611 | 2615 | seenphases = list(headsbyphase.keys()) |
|
2612 | 2616 | |
|
2613 | 2617 | # We do not handle anything but public and draft phase for now) |
|
2614 | 2618 | if seenphases: |
|
2615 | 2619 | assert max(seenphases) <= phases.draft |
|
2616 | 2620 | |
|
2617 | 2621 | # if client is pulling non-public changesets, we need to find |
|
2618 | 2622 | # intermediate public heads. |
|
2619 | 2623 | draftheads = headsbyphase.get(phases.draft, set()) |
|
2620 | 2624 | if draftheads: |
|
2621 | 2625 | publicheads = headsbyphase.get(phases.public, set()) |
|
2622 | 2626 | |
|
2623 | 2627 | revset = b'heads(only(%ln, %ln) and public())' |
|
2624 | 2628 | extraheads = repo.revs(revset, draftheads, publicheads) |
|
2625 | 2629 | for r in extraheads: |
|
2626 | 2630 | headsbyphase[phases.public].add(node(r)) |
|
2627 | 2631 | |
|
2628 | 2632 | # transform data in a format used by the encoding function |
|
2629 | 2633 | phasemapping = [] |
|
2630 | 2634 | for phase in phases.allphases: |
|
2631 | 2635 | phasemapping.append(sorted(headsbyphase[phase])) |
|
2632 | 2636 | |
|
2633 | 2637 | # generate the actual part |
|
2634 | 2638 | phasedata = phases.binaryencode(phasemapping) |
|
2635 | 2639 | bundler.newpart(b'phase-heads', data=phasedata) |
|
2636 | 2640 | |
|
2637 | 2641 | |
|
2638 | 2642 | @getbundle2partsgenerator(b'hgtagsfnodes') |
|
2639 | 2643 | def _getbundletagsfnodes( |
|
2640 | 2644 | bundler, |
|
2641 | 2645 | repo, |
|
2642 | 2646 | source, |
|
2643 | 2647 | bundlecaps=None, |
|
2644 | 2648 | b2caps=None, |
|
2645 | 2649 | heads=None, |
|
2646 | 2650 | common=None, |
|
2647 | 2651 | **kwargs |
|
2648 | 2652 | ): |
|
2649 | 2653 | """Transfer the .hgtags filenodes mapping. |
|
2650 | 2654 | |
|
2651 | 2655 | Only values for heads in this bundle will be transferred. |
|
2652 | 2656 | |
|
2653 | 2657 | The part data consists of pairs of 20 byte changeset node and .hgtags |
|
2654 | 2658 | filenodes raw values. |
|
2655 | 2659 | """ |
|
2656 | 2660 | # Don't send unless: |
|
2657 | 2661 | # - changeset are being exchanged, |
|
2658 | 2662 | # - the client supports it. |
|
2659 | 2663 | if not b2caps or not (kwargs.get('cg', True) and b'hgtagsfnodes' in b2caps): |
|
2660 | 2664 | return |
|
2661 | 2665 | |
|
2662 | 2666 | outgoing = _computeoutgoing(repo, heads, common) |
|
2663 | 2667 | bundle2.addparttagsfnodescache(repo, bundler, outgoing) |
|
2664 | 2668 | |
|
2665 | 2669 | |
|
2666 | 2670 | @getbundle2partsgenerator(b'cache:rev-branch-cache') |
|
2667 | 2671 | def _getbundlerevbranchcache( |
|
2668 | 2672 | bundler, |
|
2669 | 2673 | repo, |
|
2670 | 2674 | source, |
|
2671 | 2675 | bundlecaps=None, |
|
2672 | 2676 | b2caps=None, |
|
2673 | 2677 | heads=None, |
|
2674 | 2678 | common=None, |
|
2675 | 2679 | **kwargs |
|
2676 | 2680 | ): |
|
2677 | 2681 | """Transfer the rev-branch-cache mapping |
|
2678 | 2682 | |
|
2679 | 2683 | The payload is a series of data related to each branch |
|
2680 | 2684 | |
|
2681 | 2685 | 1) branch name length |
|
2682 | 2686 | 2) number of open heads |
|
2683 | 2687 | 3) number of closed heads |
|
2684 | 2688 | 4) open heads nodes |
|
2685 | 2689 | 5) closed heads nodes |
|
2686 | 2690 | """ |
|
2687 | 2691 | # Don't send unless: |
|
2688 | 2692 | # - changeset are being exchanged, |
|
2689 | 2693 | # - the client supports it. |
|
2690 | 2694 | # - narrow bundle isn't in play (not currently compatible). |
|
2691 | 2695 | if ( |
|
2692 | 2696 | not kwargs.get('cg', True) |
|
2693 | 2697 | or not b2caps |
|
2694 | 2698 | or b'rev-branch-cache' not in b2caps |
|
2695 | 2699 | or kwargs.get('narrow', False) |
|
2696 | 2700 | or repo.ui.has_section(_NARROWACL_SECTION) |
|
2697 | 2701 | ): |
|
2698 | 2702 | return |
|
2699 | 2703 | |
|
2700 | 2704 | outgoing = _computeoutgoing(repo, heads, common) |
|
2701 | 2705 | bundle2.addpartrevbranchcache(repo, bundler, outgoing) |
|
2702 | 2706 | |
|
2703 | 2707 | |
|
2704 | 2708 | def check_heads(repo, their_heads, context): |
|
2705 | 2709 | """check if the heads of a repo have been modified |
|
2706 | 2710 | |
|
2707 | 2711 | Used by peer for unbundling. |
|
2708 | 2712 | """ |
|
2709 | 2713 | heads = repo.heads() |
|
2710 | 2714 | heads_hash = hashutil.sha1(b''.join(sorted(heads))).digest() |
|
2711 | 2715 | if not ( |
|
2712 | 2716 | their_heads == [b'force'] |
|
2713 | 2717 | or their_heads == heads |
|
2714 | 2718 | or their_heads == [b'hashed', heads_hash] |
|
2715 | 2719 | ): |
|
2716 | 2720 | # someone else committed/pushed/unbundled while we |
|
2717 | 2721 | # were transferring data |
|
2718 | 2722 | raise error.PushRaced( |
|
2719 | 2723 | b'repository changed while %s - please try again' % context |
|
2720 | 2724 | ) |
|
2721 | 2725 | |
|
2722 | 2726 | |
|
2723 | 2727 | def unbundle(repo, cg, heads, source, url): |
|
2724 | 2728 | """Apply a bundle to a repo. |
|
2725 | 2729 | |
|
2726 | 2730 | this function makes sure the repo is locked during the application and have |
|
2727 | 2731 | mechanism to check that no push race occurred between the creation of the |
|
2728 | 2732 | bundle and its application. |
|
2729 | 2733 | |
|
2730 | 2734 | If the push was raced as PushRaced exception is raised.""" |
|
2731 | 2735 | r = 0 |
|
2732 | 2736 | # need a transaction when processing a bundle2 stream |
|
2733 | 2737 | # [wlock, lock, tr] - needs to be an array so nested functions can modify it |
|
2734 | 2738 | lockandtr = [None, None, None] |
|
2735 | 2739 | recordout = None |
|
2736 | 2740 | # quick fix for output mismatch with bundle2 in 3.4 |
|
2737 | 2741 | captureoutput = repo.ui.configbool( |
|
2738 | 2742 | b'experimental', b'bundle2-output-capture' |
|
2739 | 2743 | ) |
|
2740 | 2744 | if url.startswith(b'remote:http:') or url.startswith(b'remote:https:'): |
|
2741 | 2745 | captureoutput = True |
|
2742 | 2746 | try: |
|
2743 | 2747 | # note: outside bundle1, 'heads' is expected to be empty and this |
|
2744 | 2748 | # 'check_heads' call wil be a no-op |
|
2745 | 2749 | check_heads(repo, heads, b'uploading changes') |
|
2746 | 2750 | # push can proceed |
|
2747 | 2751 | if not isinstance(cg, bundle2.unbundle20): |
|
2748 | 2752 | # legacy case: bundle1 (changegroup 01) |
|
2749 | 2753 | txnname = b"\n".join([source, util.hidepassword(url)]) |
|
2750 | 2754 | with repo.lock(), repo.transaction(txnname) as tr: |
|
2751 | 2755 | op = bundle2.applybundle(repo, cg, tr, source, url) |
|
2752 | 2756 | r = bundle2.combinechangegroupresults(op) |
|
2753 | 2757 | else: |
|
2754 | 2758 | r = None |
|
2755 | 2759 | try: |
|
2756 | 2760 | |
|
2757 | 2761 | def gettransaction(): |
|
2758 | 2762 | if not lockandtr[2]: |
|
2759 | 2763 | if not bookmod.bookmarksinstore(repo): |
|
2760 | 2764 | lockandtr[0] = repo.wlock() |
|
2761 | 2765 | lockandtr[1] = repo.lock() |
|
2762 | 2766 | lockandtr[2] = repo.transaction(source) |
|
2763 | 2767 | lockandtr[2].hookargs[b'source'] = source |
|
2764 | 2768 | lockandtr[2].hookargs[b'url'] = url |
|
2765 | 2769 | lockandtr[2].hookargs[b'bundle2'] = b'1' |
|
2766 | 2770 | return lockandtr[2] |
|
2767 | 2771 | |
|
2768 | 2772 | # Do greedy locking by default until we're satisfied with lazy |
|
2769 | 2773 | # locking. |
|
2770 | 2774 | if not repo.ui.configbool( |
|
2771 | 2775 | b'experimental', b'bundle2lazylocking' |
|
2772 | 2776 | ): |
|
2773 | 2777 | gettransaction() |
|
2774 | 2778 | |
|
2775 | 2779 | op = bundle2.bundleoperation( |
|
2776 | 2780 | repo, |
|
2777 | 2781 | gettransaction, |
|
2778 | 2782 | captureoutput=captureoutput, |
|
2779 | 2783 | source=b'push', |
|
2780 | 2784 | ) |
|
2781 | 2785 | try: |
|
2782 | 2786 | op = bundle2.processbundle(repo, cg, op=op) |
|
2783 | 2787 | finally: |
|
2784 | 2788 | r = op.reply |
|
2785 | 2789 | if captureoutput and r is not None: |
|
2786 | 2790 | repo.ui.pushbuffer(error=True, subproc=True) |
|
2787 | 2791 | |
|
2788 | 2792 | def recordout(output): |
|
2789 | 2793 | r.newpart(b'output', data=output, mandatory=False) |
|
2790 | 2794 | |
|
2791 | 2795 | if lockandtr[2] is not None: |
|
2792 | 2796 | lockandtr[2].close() |
|
2793 | 2797 | except BaseException as exc: |
|
2794 | 2798 | exc.duringunbundle2 = True |
|
2795 | 2799 | if captureoutput and r is not None: |
|
2796 | 2800 | parts = exc._bundle2salvagedoutput = r.salvageoutput() |
|
2797 | 2801 | |
|
2798 | 2802 | def recordout(output): |
|
2799 | 2803 | part = bundle2.bundlepart( |
|
2800 | 2804 | b'output', data=output, mandatory=False |
|
2801 | 2805 | ) |
|
2802 | 2806 | parts.append(part) |
|
2803 | 2807 | |
|
2804 | 2808 | raise |
|
2805 | 2809 | finally: |
|
2806 | 2810 | lockmod.release(lockandtr[2], lockandtr[1], lockandtr[0]) |
|
2807 | 2811 | if recordout is not None: |
|
2808 | 2812 | recordout(repo.ui.popbuffer()) |
|
2809 | 2813 | return r |
|
2810 | 2814 | |
|
2811 | 2815 | |
|
2812 | 2816 | def _maybeapplyclonebundle(pullop): |
|
2813 | 2817 | """Apply a clone bundle from a remote, if possible.""" |
|
2814 | 2818 | |
|
2815 | 2819 | repo = pullop.repo |
|
2816 | 2820 | remote = pullop.remote |
|
2817 | 2821 | |
|
2818 | 2822 | if not repo.ui.configbool(b'ui', b'clonebundles'): |
|
2819 | 2823 | return |
|
2820 | 2824 | |
|
2821 | 2825 | # Only run if local repo is empty. |
|
2822 | 2826 | if len(repo): |
|
2823 | 2827 | return |
|
2824 | 2828 | |
|
2825 | 2829 | if pullop.heads: |
|
2826 | 2830 | return |
|
2827 | 2831 | |
|
2828 | 2832 | if not remote.capable(b'clonebundles'): |
|
2829 | 2833 | return |
|
2830 | 2834 | |
|
2831 | 2835 | with remote.commandexecutor() as e: |
|
2832 | 2836 | res = e.callcommand(b'clonebundles', {}).result() |
|
2833 | 2837 | |
|
2834 | 2838 | # If we call the wire protocol command, that's good enough to record the |
|
2835 | 2839 | # attempt. |
|
2836 | 2840 | pullop.clonebundleattempted = True |
|
2837 | 2841 | |
|
2838 | 2842 | entries = parseclonebundlesmanifest(repo, res) |
|
2839 | 2843 | if not entries: |
|
2840 | 2844 | repo.ui.note( |
|
2841 | 2845 | _( |
|
2842 | 2846 | b'no clone bundles available on remote; ' |
|
2843 | 2847 | b'falling back to regular clone\n' |
|
2844 | 2848 | ) |
|
2845 | 2849 | ) |
|
2846 | 2850 | return |
|
2847 | 2851 | |
|
2848 | 2852 | entries = filterclonebundleentries( |
|
2849 | 2853 | repo, entries, streamclonerequested=pullop.streamclonerequested |
|
2850 | 2854 | ) |
|
2851 | 2855 | |
|
2852 | 2856 | if not entries: |
|
2853 | 2857 | # There is a thundering herd concern here. However, if a server |
|
2854 | 2858 | # operator doesn't advertise bundles appropriate for its clients, |
|
2855 | 2859 | # they deserve what's coming. Furthermore, from a client's |
|
2856 | 2860 | # perspective, no automatic fallback would mean not being able to |
|
2857 | 2861 | # clone! |
|
2858 | 2862 | repo.ui.warn( |
|
2859 | 2863 | _( |
|
2860 | 2864 | b'no compatible clone bundles available on server; ' |
|
2861 | 2865 | b'falling back to regular clone\n' |
|
2862 | 2866 | ) |
|
2863 | 2867 | ) |
|
2864 | 2868 | repo.ui.warn( |
|
2865 | 2869 | _(b'(you may want to report this to the server operator)\n') |
|
2866 | 2870 | ) |
|
2867 | 2871 | return |
|
2868 | 2872 | |
|
2869 | 2873 | entries = sortclonebundleentries(repo.ui, entries) |
|
2870 | 2874 | |
|
2871 | 2875 | url = entries[0][b'URL'] |
|
2872 | 2876 | repo.ui.status(_(b'applying clone bundle from %s\n') % url) |
|
2873 | 2877 | if trypullbundlefromurl(repo.ui, repo, url): |
|
2874 | 2878 | repo.ui.status(_(b'finished applying clone bundle\n')) |
|
2875 | 2879 | # Bundle failed. |
|
2876 | 2880 | # |
|
2877 | 2881 | # We abort by default to avoid the thundering herd of |
|
2878 | 2882 | # clients flooding a server that was expecting expensive |
|
2879 | 2883 | # clone load to be offloaded. |
|
2880 | 2884 | elif repo.ui.configbool(b'ui', b'clonebundlefallback'): |
|
2881 | 2885 | repo.ui.warn(_(b'falling back to normal clone\n')) |
|
2882 | 2886 | else: |
|
2883 | 2887 | raise error.Abort( |
|
2884 | 2888 | _(b'error applying bundle'), |
|
2885 | 2889 | hint=_( |
|
2886 | 2890 | b'if this error persists, consider contacting ' |
|
2887 | 2891 | b'the server operator or disable clone ' |
|
2888 | 2892 | b'bundles via ' |
|
2889 | 2893 | b'"--config ui.clonebundles=false"' |
|
2890 | 2894 | ), |
|
2891 | 2895 | ) |
|
2892 | 2896 | |
|
2893 | 2897 | |
|
2894 | 2898 | def parseclonebundlesmanifest(repo, s): |
|
2895 | 2899 | """Parses the raw text of a clone bundles manifest. |
|
2896 | 2900 | |
|
2897 | 2901 | Returns a list of dicts. The dicts have a ``URL`` key corresponding |
|
2898 | 2902 | to the URL and other keys are the attributes for the entry. |
|
2899 | 2903 | """ |
|
2900 | 2904 | m = [] |
|
2901 | 2905 | for line in s.splitlines(): |
|
2902 | 2906 | fields = line.split() |
|
2903 | 2907 | if not fields: |
|
2904 | 2908 | continue |
|
2905 | 2909 | attrs = {b'URL': fields[0]} |
|
2906 | 2910 | for rawattr in fields[1:]: |
|
2907 | 2911 | key, value = rawattr.split(b'=', 1) |
|
2908 | 2912 | key = urlreq.unquote(key) |
|
2909 | 2913 | value = urlreq.unquote(value) |
|
2910 | 2914 | attrs[key] = value |
|
2911 | 2915 | |
|
2912 | 2916 | # Parse BUNDLESPEC into components. This makes client-side |
|
2913 | 2917 | # preferences easier to specify since you can prefer a single |
|
2914 | 2918 | # component of the BUNDLESPEC. |
|
2915 | 2919 | if key == b'BUNDLESPEC': |
|
2916 | 2920 | try: |
|
2917 | 2921 | bundlespec = parsebundlespec(repo, value) |
|
2918 | 2922 | attrs[b'COMPRESSION'] = bundlespec.compression |
|
2919 | 2923 | attrs[b'VERSION'] = bundlespec.version |
|
2920 | 2924 | except error.InvalidBundleSpecification: |
|
2921 | 2925 | pass |
|
2922 | 2926 | except error.UnsupportedBundleSpecification: |
|
2923 | 2927 | pass |
|
2924 | 2928 | |
|
2925 | 2929 | m.append(attrs) |
|
2926 | 2930 | |
|
2927 | 2931 | return m |
|
2928 | 2932 | |
|
2929 | 2933 | |
|
2930 | 2934 | def isstreamclonespec(bundlespec): |
|
2931 | 2935 | # Stream clone v1 |
|
2932 | 2936 | if bundlespec.wirecompression == b'UN' and bundlespec.wireversion == b's1': |
|
2933 | 2937 | return True |
|
2934 | 2938 | |
|
2935 | 2939 | # Stream clone v2 |
|
2936 | 2940 | if ( |
|
2937 | 2941 | bundlespec.wirecompression == b'UN' |
|
2938 | 2942 | and bundlespec.wireversion == b'02' |
|
2939 | 2943 | and bundlespec.contentopts.get(b'streamv2') |
|
2940 | 2944 | ): |
|
2941 | 2945 | return True |
|
2942 | 2946 | |
|
2943 | 2947 | return False |
|
2944 | 2948 | |
|
2945 | 2949 | |
|
2946 | 2950 | def filterclonebundleentries(repo, entries, streamclonerequested=False): |
|
2947 | 2951 | """Remove incompatible clone bundle manifest entries. |
|
2948 | 2952 | |
|
2949 | 2953 | Accepts a list of entries parsed with ``parseclonebundlesmanifest`` |
|
2950 | 2954 | and returns a new list consisting of only the entries that this client |
|
2951 | 2955 | should be able to apply. |
|
2952 | 2956 | |
|
2953 | 2957 | There is no guarantee we'll be able to apply all returned entries because |
|
2954 | 2958 | the metadata we use to filter on may be missing or wrong. |
|
2955 | 2959 | """ |
|
2956 | 2960 | newentries = [] |
|
2957 | 2961 | for entry in entries: |
|
2958 | 2962 | spec = entry.get(b'BUNDLESPEC') |
|
2959 | 2963 | if spec: |
|
2960 | 2964 | try: |
|
2961 | 2965 | bundlespec = parsebundlespec(repo, spec, strict=True) |
|
2962 | 2966 | |
|
2963 | 2967 | # If a stream clone was requested, filter out non-streamclone |
|
2964 | 2968 | # entries. |
|
2965 | 2969 | if streamclonerequested and not isstreamclonespec(bundlespec): |
|
2966 | 2970 | repo.ui.debug( |
|
2967 | 2971 | b'filtering %s because not a stream clone\n' |
|
2968 | 2972 | % entry[b'URL'] |
|
2969 | 2973 | ) |
|
2970 | 2974 | continue |
|
2971 | 2975 | |
|
2972 | 2976 | except error.InvalidBundleSpecification as e: |
|
2973 | 2977 | repo.ui.debug(stringutil.forcebytestr(e) + b'\n') |
|
2974 | 2978 | continue |
|
2975 | 2979 | except error.UnsupportedBundleSpecification as e: |
|
2976 | 2980 | repo.ui.debug( |
|
2977 | 2981 | b'filtering %s because unsupported bundle ' |
|
2978 | 2982 | b'spec: %s\n' % (entry[b'URL'], stringutil.forcebytestr(e)) |
|
2979 | 2983 | ) |
|
2980 | 2984 | continue |
|
2981 | 2985 | # If we don't have a spec and requested a stream clone, we don't know |
|
2982 | 2986 | # what the entry is so don't attempt to apply it. |
|
2983 | 2987 | elif streamclonerequested: |
|
2984 | 2988 | repo.ui.debug( |
|
2985 | 2989 | b'filtering %s because cannot determine if a stream ' |
|
2986 | 2990 | b'clone bundle\n' % entry[b'URL'] |
|
2987 | 2991 | ) |
|
2988 | 2992 | continue |
|
2989 | 2993 | |
|
2990 | 2994 | if b'REQUIRESNI' in entry and not sslutil.hassni: |
|
2991 | 2995 | repo.ui.debug( |
|
2992 | 2996 | b'filtering %s because SNI not supported\n' % entry[b'URL'] |
|
2993 | 2997 | ) |
|
2994 | 2998 | continue |
|
2995 | 2999 | |
|
2996 | 3000 | newentries.append(entry) |
|
2997 | 3001 | |
|
2998 | 3002 | return newentries |
|
2999 | 3003 | |
|
3000 | 3004 | |
|
3001 | 3005 | class clonebundleentry(object): |
|
3002 | 3006 | """Represents an item in a clone bundles manifest. |
|
3003 | 3007 | |
|
3004 | 3008 | This rich class is needed to support sorting since sorted() in Python 3 |
|
3005 | 3009 | doesn't support ``cmp`` and our comparison is complex enough that ``key=`` |
|
3006 | 3010 | won't work. |
|
3007 | 3011 | """ |
|
3008 | 3012 | |
|
3009 | 3013 | def __init__(self, value, prefers): |
|
3010 | 3014 | self.value = value |
|
3011 | 3015 | self.prefers = prefers |
|
3012 | 3016 | |
|
3013 | 3017 | def _cmp(self, other): |
|
3014 | 3018 | for prefkey, prefvalue in self.prefers: |
|
3015 | 3019 | avalue = self.value.get(prefkey) |
|
3016 | 3020 | bvalue = other.value.get(prefkey) |
|
3017 | 3021 | |
|
3018 | 3022 | # Special case for b missing attribute and a matches exactly. |
|
3019 | 3023 | if avalue is not None and bvalue is None and avalue == prefvalue: |
|
3020 | 3024 | return -1 |
|
3021 | 3025 | |
|
3022 | 3026 | # Special case for a missing attribute and b matches exactly. |
|
3023 | 3027 | if bvalue is not None and avalue is None and bvalue == prefvalue: |
|
3024 | 3028 | return 1 |
|
3025 | 3029 | |
|
3026 | 3030 | # We can't compare unless attribute present on both. |
|
3027 | 3031 | if avalue is None or bvalue is None: |
|
3028 | 3032 | continue |
|
3029 | 3033 | |
|
3030 | 3034 | # Same values should fall back to next attribute. |
|
3031 | 3035 | if avalue == bvalue: |
|
3032 | 3036 | continue |
|
3033 | 3037 | |
|
3034 | 3038 | # Exact matches come first. |
|
3035 | 3039 | if avalue == prefvalue: |
|
3036 | 3040 | return -1 |
|
3037 | 3041 | if bvalue == prefvalue: |
|
3038 | 3042 | return 1 |
|
3039 | 3043 | |
|
3040 | 3044 | # Fall back to next attribute. |
|
3041 | 3045 | continue |
|
3042 | 3046 | |
|
3043 | 3047 | # If we got here we couldn't sort by attributes and prefers. Fall |
|
3044 | 3048 | # back to index order. |
|
3045 | 3049 | return 0 |
|
3046 | 3050 | |
|
3047 | 3051 | def __lt__(self, other): |
|
3048 | 3052 | return self._cmp(other) < 0 |
|
3049 | 3053 | |
|
3050 | 3054 | def __gt__(self, other): |
|
3051 | 3055 | return self._cmp(other) > 0 |
|
3052 | 3056 | |
|
3053 | 3057 | def __eq__(self, other): |
|
3054 | 3058 | return self._cmp(other) == 0 |
|
3055 | 3059 | |
|
3056 | 3060 | def __le__(self, other): |
|
3057 | 3061 | return self._cmp(other) <= 0 |
|
3058 | 3062 | |
|
3059 | 3063 | def __ge__(self, other): |
|
3060 | 3064 | return self._cmp(other) >= 0 |
|
3061 | 3065 | |
|
3062 | 3066 | def __ne__(self, other): |
|
3063 | 3067 | return self._cmp(other) != 0 |
|
3064 | 3068 | |
|
3065 | 3069 | |
|
3066 | 3070 | def sortclonebundleentries(ui, entries): |
|
3067 | 3071 | prefers = ui.configlist(b'ui', b'clonebundleprefers') |
|
3068 | 3072 | if not prefers: |
|
3069 | 3073 | return list(entries) |
|
3070 | 3074 | |
|
3071 | 3075 | def _split(p): |
|
3072 | 3076 | if b'=' not in p: |
|
3073 | 3077 | hint = _(b"each comma separated item should be key=value pairs") |
|
3074 | 3078 | raise error.Abort( |
|
3075 | 3079 | _(b"invalid ui.clonebundleprefers item: %s") % p, hint=hint |
|
3076 | 3080 | ) |
|
3077 | 3081 | return p.split(b'=', 1) |
|
3078 | 3082 | |
|
3079 | 3083 | prefers = [_split(p) for p in prefers] |
|
3080 | 3084 | |
|
3081 | 3085 | items = sorted(clonebundleentry(v, prefers) for v in entries) |
|
3082 | 3086 | return [i.value for i in items] |
|
3083 | 3087 | |
|
3084 | 3088 | |
|
3085 | 3089 | def trypullbundlefromurl(ui, repo, url): |
|
3086 | 3090 | """Attempt to apply a bundle from a URL.""" |
|
3087 | 3091 | with repo.lock(), repo.transaction(b'bundleurl') as tr: |
|
3088 | 3092 | try: |
|
3089 | 3093 | fh = urlmod.open(ui, url) |
|
3090 | 3094 | cg = readbundle(ui, fh, b'stream') |
|
3091 | 3095 | |
|
3092 | 3096 | if isinstance(cg, streamclone.streamcloneapplier): |
|
3093 | 3097 | cg.apply(repo) |
|
3094 | 3098 | else: |
|
3095 | 3099 | bundle2.applybundle(repo, cg, tr, b'clonebundles', url) |
|
3096 | 3100 | return True |
|
3097 | 3101 | except urlerr.httperror as e: |
|
3098 | 3102 | ui.warn( |
|
3099 | 3103 | _(b'HTTP error fetching bundle: %s\n') |
|
3100 | 3104 | % stringutil.forcebytestr(e) |
|
3101 | 3105 | ) |
|
3102 | 3106 | except urlerr.urlerror as e: |
|
3103 | 3107 | ui.warn( |
|
3104 | 3108 | _(b'error fetching bundle: %s\n') |
|
3105 | 3109 | % stringutil.forcebytestr(e.reason) |
|
3106 | 3110 | ) |
|
3107 | 3111 | |
|
3108 | 3112 | return False |
@@ -1,51 +1,52 b'' | |||
|
1 | 1 | == New Features == |
|
2 | 2 | |
|
3 | 3 | * `hg purge`/`hg clean` can now delete ignored files instead of |
|
4 | 4 | untracked files, with the new -i flag. |
|
5 | 5 | |
|
6 | 6 | * `hg log` now defaults to using an '%' symbol for commits involved |
|
7 | 7 | in unresolved merge conflicts. That includes unresolved conflicts |
|
8 | 8 | caused by e.g. `hg update --merge` and `hg graft`. '@' still takes |
|
9 | 9 | precedence, so what used to be marked '@' still is. |
|
10 | 10 | |
|
11 | 11 | * New `conflictlocal()` and `conflictother()` revsets return the |
|
12 | 12 | commits that are being merged, when there are conflicts. Also works |
|
13 | 13 | for conflicts caused by e.g. `hg graft`. |
|
14 | 14 | |
|
15 | 15 | * `hg copy --forget` can be used to unmark a file as copied. |
|
16 | 16 | |
|
17 | 17 | == New Experimental Features == |
|
18 | 18 | |
|
19 | 19 | * `hg copy` now supports a `--at-rev` argument to mark files as |
|
20 | 20 | copied in the specified commit. It only works with `--after` for |
|
21 | 21 | now (i.e., it's only useful for marking files copied using non-hg |
|
22 | 22 | `cp` as copied). |
|
23 | 23 | |
|
24 | 24 | * Use `hg copy --forget --at-rev REV` to unmark already committed |
|
25 | 25 | copies. |
|
26 | 26 | |
|
27 | * prevent pushes of divergent bookmarks (foo@remote) | |
|
27 | 28 | |
|
28 | 29 | == Bug Fixes == |
|
29 | 30 | |
|
30 | 31 | * Fix server exception when concurrent pushes delete the same bookmark |
|
31 | 32 | |
|
32 | 33 | == Backwards Compatibility Changes == |
|
33 | 34 | |
|
34 | 35 | * When `hg rebase` pauses for merge conflict resolution, the working |
|
35 | 36 | copy will no longer have the rebased node as a second parent. You |
|
36 | 37 | can use the new `conflictparents()` revset for finding the other |
|
37 | 38 | parent during a conflict. |
|
38 | 39 | |
|
39 | 40 | * `hg recover` does not verify the validity of the whole repository |
|
40 | 41 | anymore. You can pass `--verify` or call `hg verify` if necessary. |
|
41 | 42 | |
|
42 | 43 | == Internal API Changes == |
|
43 | 44 | |
|
44 | 45 | * The deprecated `ui.progress()` has now been deleted. Please use |
|
45 | 46 | `ui.makeprogress()` instead. |
|
46 | 47 | |
|
47 | 48 | * `hg.merge()` has lost its `abort` argument. Please call |
|
48 | 49 | `hg.abortmerge()` directly instead. |
|
49 | 50 | |
|
50 | 51 | * The `*others` argument of `cmdutil.check_incompatible_arguments()` |
|
51 | 52 | changed from being varargs argument to being a single collection. |
@@ -1,1355 +1,1366 b'' | |||
|
1 | 1 | #testcases b2-pushkey b2-binary |
|
2 | 2 | |
|
3 | 3 | #if b2-pushkey |
|
4 | 4 | $ cat << EOF >> $HGRCPATH |
|
5 | 5 | > [devel] |
|
6 | 6 | > legacy.exchange=bookmarks |
|
7 | 7 | > EOF |
|
8 | 8 | #endif |
|
9 | 9 | |
|
10 | 10 | #require serve |
|
11 | 11 | |
|
12 | 12 | $ cat << EOF >> $HGRCPATH |
|
13 | 13 | > [ui] |
|
14 | 14 | > logtemplate={rev}:{node|short} {desc|firstline} |
|
15 | 15 | > [phases] |
|
16 | 16 | > publish=False |
|
17 | 17 | > [experimental] |
|
18 | 18 | > evolution.createmarkers=True |
|
19 | 19 | > evolution.exchange=True |
|
20 | 20 | > EOF |
|
21 | 21 | |
|
22 | 22 | $ cat > $TESTTMP/hook.sh <<'EOF' |
|
23 | 23 | > echo "test-hook-bookmark: $HG_BOOKMARK: $HG_OLDNODE -> $HG_NODE" |
|
24 | 24 | > EOF |
|
25 | 25 | $ TESTHOOK="hooks.txnclose-bookmark.test=sh $TESTTMP/hook.sh" |
|
26 | 26 | |
|
27 | 27 | initialize |
|
28 | 28 | |
|
29 | 29 | $ hg init a |
|
30 | 30 | $ cd a |
|
31 | 31 | $ echo 'test' > test |
|
32 | 32 | $ hg commit -Am'test' |
|
33 | 33 | adding test |
|
34 | 34 | |
|
35 | 35 | set bookmarks |
|
36 | 36 | |
|
37 | 37 | $ hg bookmark X |
|
38 | 38 | $ hg bookmark Y |
|
39 | 39 | $ hg bookmark Z |
|
40 | 40 | |
|
41 | 41 | import bookmark by name |
|
42 | 42 | |
|
43 | 43 | $ hg init ../b |
|
44 | 44 | $ cd ../b |
|
45 | 45 | $ hg book Y |
|
46 | 46 | $ hg book |
|
47 | 47 | * Y -1:000000000000 |
|
48 | 48 | $ hg pull ../a --config "$TESTHOOK" |
|
49 | 49 | pulling from ../a |
|
50 | 50 | requesting all changes |
|
51 | 51 | adding changesets |
|
52 | 52 | adding manifests |
|
53 | 53 | adding file changes |
|
54 | 54 | adding remote bookmark X |
|
55 | 55 | updating bookmark Y |
|
56 | 56 | adding remote bookmark Z |
|
57 | 57 | added 1 changesets with 1 changes to 1 files |
|
58 | 58 | new changesets 4e3505fd9583 (1 drafts) |
|
59 | 59 | test-hook-bookmark: X: -> 4e3505fd95835d721066b76e75dbb8cc554d7f77 |
|
60 | 60 | test-hook-bookmark: Y: 0000000000000000000000000000000000000000 -> 4e3505fd95835d721066b76e75dbb8cc554d7f77 |
|
61 | 61 | test-hook-bookmark: Z: -> 4e3505fd95835d721066b76e75dbb8cc554d7f77 |
|
62 | 62 | (run 'hg update' to get a working copy) |
|
63 | 63 | $ hg bookmarks |
|
64 | 64 | X 0:4e3505fd9583 |
|
65 | 65 | * Y 0:4e3505fd9583 |
|
66 | 66 | Z 0:4e3505fd9583 |
|
67 | 67 | $ hg debugpushkey ../a namespaces |
|
68 | 68 | bookmarks |
|
69 | 69 | namespaces |
|
70 | 70 | obsolete |
|
71 | 71 | phases |
|
72 | 72 | $ hg debugpushkey ../a bookmarks |
|
73 | 73 | X 4e3505fd95835d721066b76e75dbb8cc554d7f77 |
|
74 | 74 | Y 4e3505fd95835d721066b76e75dbb8cc554d7f77 |
|
75 | 75 | Z 4e3505fd95835d721066b76e75dbb8cc554d7f77 |
|
76 | 76 | |
|
77 | 77 | delete the bookmark to re-pull it |
|
78 | 78 | |
|
79 | 79 | $ hg book -d X |
|
80 | 80 | $ hg pull -B X ../a |
|
81 | 81 | pulling from ../a |
|
82 | 82 | no changes found |
|
83 | 83 | adding remote bookmark X |
|
84 | 84 | |
|
85 | 85 | finally no-op pull |
|
86 | 86 | |
|
87 | 87 | $ hg pull -B X ../a |
|
88 | 88 | pulling from ../a |
|
89 | 89 | no changes found |
|
90 | 90 | $ hg bookmark |
|
91 | 91 | X 0:4e3505fd9583 |
|
92 | 92 | * Y 0:4e3505fd9583 |
|
93 | 93 | Z 0:4e3505fd9583 |
|
94 | 94 | |
|
95 | 95 | export bookmark by name |
|
96 | 96 | |
|
97 | 97 | $ hg bookmark W |
|
98 | 98 | $ hg bookmark foo |
|
99 | 99 | $ hg bookmark foobar |
|
100 | 100 | $ hg push -B W ../a |
|
101 | 101 | pushing to ../a |
|
102 | 102 | searching for changes |
|
103 | 103 | no changes found |
|
104 | 104 | exporting bookmark W |
|
105 | 105 | [1] |
|
106 | 106 | $ hg -R ../a bookmarks |
|
107 | 107 | W -1:000000000000 |
|
108 | 108 | X 0:4e3505fd9583 |
|
109 | 109 | Y 0:4e3505fd9583 |
|
110 | 110 | * Z 0:4e3505fd9583 |
|
111 | 111 | |
|
112 | 112 | delete a remote bookmark |
|
113 | 113 | |
|
114 | 114 | $ hg book -d W |
|
115 | 115 | |
|
116 | 116 | #if b2-pushkey |
|
117 | 117 | |
|
118 | 118 | $ hg push -B W ../a --config "$TESTHOOK" --debug --config devel.bundle2.debug=yes |
|
119 | 119 | pushing to ../a |
|
120 | 120 | query 1; heads |
|
121 | 121 | searching for changes |
|
122 | 122 | all remote heads known locally |
|
123 | 123 | listing keys for "phases" |
|
124 | 124 | checking for updated bookmarks |
|
125 | 125 | listing keys for "bookmarks" |
|
126 | 126 | no changes found |
|
127 | 127 | bundle2-output-bundle: "HG20", 4 parts total |
|
128 | 128 | bundle2-output: start emission of HG20 stream |
|
129 | 129 | bundle2-output: bundle parameter: |
|
130 | 130 | bundle2-output: start of parts |
|
131 | 131 | bundle2-output: bundle part: "replycaps" |
|
132 | 132 | bundle2-output-part: "replycaps" 222 bytes payload |
|
133 | 133 | bundle2-output: part 0: "REPLYCAPS" |
|
134 | 134 | bundle2-output: header chunk size: 16 |
|
135 | 135 | bundle2-output: payload chunk size: 222 |
|
136 | 136 | bundle2-output: closing payload chunk |
|
137 | 137 | bundle2-output: bundle part: "check:bookmarks" |
|
138 | 138 | bundle2-output-part: "check:bookmarks" 23 bytes payload |
|
139 | 139 | bundle2-output: part 1: "CHECK:BOOKMARKS" |
|
140 | 140 | bundle2-output: header chunk size: 22 |
|
141 | 141 | bundle2-output: payload chunk size: 23 |
|
142 | 142 | bundle2-output: closing payload chunk |
|
143 | 143 | bundle2-output: bundle part: "check:phases" |
|
144 | 144 | bundle2-output-part: "check:phases" 24 bytes payload |
|
145 | 145 | bundle2-output: part 2: "CHECK:PHASES" |
|
146 | 146 | bundle2-output: header chunk size: 19 |
|
147 | 147 | bundle2-output: payload chunk size: 24 |
|
148 | 148 | bundle2-output: closing payload chunk |
|
149 | 149 | bundle2-output: bundle part: "pushkey" |
|
150 | 150 | bundle2-output-part: "pushkey" (params: 4 mandatory) empty payload |
|
151 | 151 | bundle2-output: part 3: "PUSHKEY" |
|
152 | 152 | bundle2-output: header chunk size: 90 |
|
153 | 153 | bundle2-output: closing payload chunk |
|
154 | 154 | bundle2-output: end of bundle |
|
155 | 155 | bundle2-input: start processing of HG20 stream |
|
156 | 156 | bundle2-input: reading bundle2 stream parameters |
|
157 | 157 | bundle2-input-bundle: with-transaction |
|
158 | 158 | bundle2-input: start extraction of bundle2 parts |
|
159 | 159 | bundle2-input: part header size: 16 |
|
160 | 160 | bundle2-input: part type: "REPLYCAPS" |
|
161 | 161 | bundle2-input: part id: "0" |
|
162 | 162 | bundle2-input: part parameters: 0 |
|
163 | 163 | bundle2-input: found a handler for part replycaps |
|
164 | 164 | bundle2-input-part: "replycaps" supported |
|
165 | 165 | bundle2-input: payload chunk size: 222 |
|
166 | 166 | bundle2-input: payload chunk size: 0 |
|
167 | 167 | bundle2-input-part: total payload size 222 |
|
168 | 168 | bundle2-input: part header size: 22 |
|
169 | 169 | bundle2-input: part type: "CHECK:BOOKMARKS" |
|
170 | 170 | bundle2-input: part id: "1" |
|
171 | 171 | bundle2-input: part parameters: 0 |
|
172 | 172 | bundle2-input: found a handler for part check:bookmarks |
|
173 | 173 | bundle2-input-part: "check:bookmarks" supported |
|
174 | 174 | bundle2-input: payload chunk size: 23 |
|
175 | 175 | bundle2-input: payload chunk size: 0 |
|
176 | 176 | bundle2-input-part: total payload size 23 |
|
177 | 177 | bundle2-input: part header size: 19 |
|
178 | 178 | bundle2-input: part type: "CHECK:PHASES" |
|
179 | 179 | bundle2-input: part id: "2" |
|
180 | 180 | bundle2-input: part parameters: 0 |
|
181 | 181 | bundle2-input: found a handler for part check:phases |
|
182 | 182 | bundle2-input-part: "check:phases" supported |
|
183 | 183 | bundle2-input: payload chunk size: 24 |
|
184 | 184 | bundle2-input: payload chunk size: 0 |
|
185 | 185 | bundle2-input-part: total payload size 24 |
|
186 | 186 | bundle2-input: part header size: 90 |
|
187 | 187 | bundle2-input: part type: "PUSHKEY" |
|
188 | 188 | bundle2-input: part id: "3" |
|
189 | 189 | bundle2-input: part parameters: 4 |
|
190 | 190 | bundle2-input: found a handler for part pushkey |
|
191 | 191 | bundle2-input-part: "pushkey" (params: 4 mandatory) supported |
|
192 | 192 | pushing key for "bookmarks:W" |
|
193 | 193 | bundle2-input: payload chunk size: 0 |
|
194 | 194 | bundle2-input: part header size: 0 |
|
195 | 195 | bundle2-input: end of bundle2 stream |
|
196 | 196 | bundle2-input-bundle: 4 parts total |
|
197 | 197 | running hook txnclose-bookmark.test: sh $TESTTMP/hook.sh |
|
198 | 198 | test-hook-bookmark: W: 0000000000000000000000000000000000000000 -> |
|
199 | 199 | bundle2-output-bundle: "HG20", 1 parts total |
|
200 | 200 | bundle2-output: start emission of HG20 stream |
|
201 | 201 | bundle2-output: bundle parameter: |
|
202 | 202 | bundle2-output: start of parts |
|
203 | 203 | bundle2-output: bundle part: "reply:pushkey" |
|
204 | 204 | bundle2-output-part: "reply:pushkey" (params: 0 advisory) empty payload |
|
205 | 205 | bundle2-output: part 0: "REPLY:PUSHKEY" |
|
206 | 206 | bundle2-output: header chunk size: 43 |
|
207 | 207 | bundle2-output: closing payload chunk |
|
208 | 208 | bundle2-output: end of bundle |
|
209 | 209 | bundle2-input: start processing of HG20 stream |
|
210 | 210 | bundle2-input: reading bundle2 stream parameters |
|
211 | 211 | bundle2-input-bundle: no-transaction |
|
212 | 212 | bundle2-input: start extraction of bundle2 parts |
|
213 | 213 | bundle2-input: part header size: 43 |
|
214 | 214 | bundle2-input: part type: "REPLY:PUSHKEY" |
|
215 | 215 | bundle2-input: part id: "0" |
|
216 | 216 | bundle2-input: part parameters: 2 |
|
217 | 217 | bundle2-input: found a handler for part reply:pushkey |
|
218 | 218 | bundle2-input-part: "reply:pushkey" (params: 0 advisory) supported |
|
219 | 219 | bundle2-input: payload chunk size: 0 |
|
220 | 220 | bundle2-input: part header size: 0 |
|
221 | 221 | bundle2-input: end of bundle2 stream |
|
222 | 222 | bundle2-input-bundle: 1 parts total |
|
223 | 223 | deleting remote bookmark W |
|
224 | 224 | listing keys for "phases" |
|
225 | 225 | [1] |
|
226 | 226 | |
|
227 | 227 | #endif |
|
228 | 228 | #if b2-binary |
|
229 | 229 | |
|
230 | 230 | $ hg push -B W ../a --config "$TESTHOOK" --debug --config devel.bundle2.debug=yes |
|
231 | 231 | pushing to ../a |
|
232 | 232 | query 1; heads |
|
233 | 233 | searching for changes |
|
234 | 234 | all remote heads known locally |
|
235 | 235 | listing keys for "phases" |
|
236 | 236 | checking for updated bookmarks |
|
237 | 237 | listing keys for "bookmarks" |
|
238 | 238 | no changes found |
|
239 | 239 | bundle2-output-bundle: "HG20", 4 parts total |
|
240 | 240 | bundle2-output: start emission of HG20 stream |
|
241 | 241 | bundle2-output: bundle parameter: |
|
242 | 242 | bundle2-output: start of parts |
|
243 | 243 | bundle2-output: bundle part: "replycaps" |
|
244 | 244 | bundle2-output-part: "replycaps" 222 bytes payload |
|
245 | 245 | bundle2-output: part 0: "REPLYCAPS" |
|
246 | 246 | bundle2-output: header chunk size: 16 |
|
247 | 247 | bundle2-output: payload chunk size: 222 |
|
248 | 248 | bundle2-output: closing payload chunk |
|
249 | 249 | bundle2-output: bundle part: "check:bookmarks" |
|
250 | 250 | bundle2-output-part: "check:bookmarks" 23 bytes payload |
|
251 | 251 | bundle2-output: part 1: "CHECK:BOOKMARKS" |
|
252 | 252 | bundle2-output: header chunk size: 22 |
|
253 | 253 | bundle2-output: payload chunk size: 23 |
|
254 | 254 | bundle2-output: closing payload chunk |
|
255 | 255 | bundle2-output: bundle part: "check:phases" |
|
256 | 256 | bundle2-output-part: "check:phases" 24 bytes payload |
|
257 | 257 | bundle2-output: part 2: "CHECK:PHASES" |
|
258 | 258 | bundle2-output: header chunk size: 19 |
|
259 | 259 | bundle2-output: payload chunk size: 24 |
|
260 | 260 | bundle2-output: closing payload chunk |
|
261 | 261 | bundle2-output: bundle part: "bookmarks" |
|
262 | 262 | bundle2-output-part: "bookmarks" 23 bytes payload |
|
263 | 263 | bundle2-output: part 3: "BOOKMARKS" |
|
264 | 264 | bundle2-output: header chunk size: 16 |
|
265 | 265 | bundle2-output: payload chunk size: 23 |
|
266 | 266 | bundle2-output: closing payload chunk |
|
267 | 267 | bundle2-output: end of bundle |
|
268 | 268 | bundle2-input: start processing of HG20 stream |
|
269 | 269 | bundle2-input: reading bundle2 stream parameters |
|
270 | 270 | bundle2-input-bundle: with-transaction |
|
271 | 271 | bundle2-input: start extraction of bundle2 parts |
|
272 | 272 | bundle2-input: part header size: 16 |
|
273 | 273 | bundle2-input: part type: "REPLYCAPS" |
|
274 | 274 | bundle2-input: part id: "0" |
|
275 | 275 | bundle2-input: part parameters: 0 |
|
276 | 276 | bundle2-input: found a handler for part replycaps |
|
277 | 277 | bundle2-input-part: "replycaps" supported |
|
278 | 278 | bundle2-input: payload chunk size: 222 |
|
279 | 279 | bundle2-input: payload chunk size: 0 |
|
280 | 280 | bundle2-input-part: total payload size 222 |
|
281 | 281 | bundle2-input: part header size: 22 |
|
282 | 282 | bundle2-input: part type: "CHECK:BOOKMARKS" |
|
283 | 283 | bundle2-input: part id: "1" |
|
284 | 284 | bundle2-input: part parameters: 0 |
|
285 | 285 | bundle2-input: found a handler for part check:bookmarks |
|
286 | 286 | bundle2-input-part: "check:bookmarks" supported |
|
287 | 287 | bundle2-input: payload chunk size: 23 |
|
288 | 288 | bundle2-input: payload chunk size: 0 |
|
289 | 289 | bundle2-input-part: total payload size 23 |
|
290 | 290 | bundle2-input: part header size: 19 |
|
291 | 291 | bundle2-input: part type: "CHECK:PHASES" |
|
292 | 292 | bundle2-input: part id: "2" |
|
293 | 293 | bundle2-input: part parameters: 0 |
|
294 | 294 | bundle2-input: found a handler for part check:phases |
|
295 | 295 | bundle2-input-part: "check:phases" supported |
|
296 | 296 | bundle2-input: payload chunk size: 24 |
|
297 | 297 | bundle2-input: payload chunk size: 0 |
|
298 | 298 | bundle2-input-part: total payload size 24 |
|
299 | 299 | bundle2-input: part header size: 16 |
|
300 | 300 | bundle2-input: part type: "BOOKMARKS" |
|
301 | 301 | bundle2-input: part id: "3" |
|
302 | 302 | bundle2-input: part parameters: 0 |
|
303 | 303 | bundle2-input: found a handler for part bookmarks |
|
304 | 304 | bundle2-input-part: "bookmarks" supported |
|
305 | 305 | bundle2-input: payload chunk size: 23 |
|
306 | 306 | bundle2-input: payload chunk size: 0 |
|
307 | 307 | bundle2-input-part: total payload size 23 |
|
308 | 308 | bundle2-input: part header size: 0 |
|
309 | 309 | bundle2-input: end of bundle2 stream |
|
310 | 310 | bundle2-input-bundle: 4 parts total |
|
311 | 311 | running hook txnclose-bookmark.test: sh $TESTTMP/hook.sh |
|
312 | 312 | test-hook-bookmark: W: 0000000000000000000000000000000000000000 -> |
|
313 | 313 | bundle2-output-bundle: "HG20", 0 parts total |
|
314 | 314 | bundle2-output: start emission of HG20 stream |
|
315 | 315 | bundle2-output: bundle parameter: |
|
316 | 316 | bundle2-output: start of parts |
|
317 | 317 | bundle2-output: end of bundle |
|
318 | 318 | bundle2-input: start processing of HG20 stream |
|
319 | 319 | bundle2-input: reading bundle2 stream parameters |
|
320 | 320 | bundle2-input-bundle: no-transaction |
|
321 | 321 | bundle2-input: start extraction of bundle2 parts |
|
322 | 322 | bundle2-input: part header size: 0 |
|
323 | 323 | bundle2-input: end of bundle2 stream |
|
324 | 324 | bundle2-input-bundle: 0 parts total |
|
325 | 325 | deleting remote bookmark W |
|
326 | 326 | listing keys for "phases" |
|
327 | 327 | [1] |
|
328 | 328 | |
|
329 | 329 | #endif |
|
330 | 330 | |
|
331 | Divergent bookmark cannot be exported | |
|
332 | ||
|
333 | $ hg book W@default | |
|
334 | $ hg push -B W@default ../a | |
|
335 | pushing to ../a | |
|
336 | searching for changes | |
|
337 | cannot push divergent bookmark W@default! | |
|
338 | no changes found | |
|
339 | [2] | |
|
340 | $ hg book -d W@default | |
|
341 | ||
|
331 | 342 | export the active bookmark |
|
332 | 343 | |
|
333 | 344 | $ hg bookmark V |
|
334 | 345 | $ hg push -B . ../a |
|
335 | 346 | pushing to ../a |
|
336 | 347 | searching for changes |
|
337 | 348 | no changes found |
|
338 | 349 | exporting bookmark V |
|
339 | 350 | [1] |
|
340 | 351 | |
|
341 | 352 | exporting the active bookmark with 'push -B .' |
|
342 | 353 | demand that one of the bookmarks is activated |
|
343 | 354 | |
|
344 | 355 | $ hg update -r default |
|
345 | 356 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
346 | 357 | (leaving bookmark V) |
|
347 | 358 | $ hg push -B . ../a |
|
348 | 359 | abort: no active bookmark! |
|
349 | 360 | [255] |
|
350 | 361 | $ hg update -r V |
|
351 | 362 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
352 | 363 | (activating bookmark V) |
|
353 | 364 | |
|
354 | 365 | delete the bookmark |
|
355 | 366 | |
|
356 | 367 | $ hg book -d V |
|
357 | 368 | $ hg push -B V ../a |
|
358 | 369 | pushing to ../a |
|
359 | 370 | searching for changes |
|
360 | 371 | no changes found |
|
361 | 372 | deleting remote bookmark V |
|
362 | 373 | [1] |
|
363 | 374 | $ hg up foobar |
|
364 | 375 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
365 | 376 | (activating bookmark foobar) |
|
366 | 377 | |
|
367 | 378 | push/pull name that doesn't exist |
|
368 | 379 | |
|
369 | 380 | $ hg push -B badname ../a |
|
370 | 381 | pushing to ../a |
|
371 | 382 | searching for changes |
|
372 | 383 | bookmark badname does not exist on the local or remote repository! |
|
373 | 384 | no changes found |
|
374 | 385 | [2] |
|
375 | 386 | $ hg pull -B anotherbadname ../a |
|
376 | 387 | pulling from ../a |
|
377 | 388 | abort: remote bookmark anotherbadname not found! |
|
378 | 389 | [255] |
|
379 | 390 | |
|
380 | 391 | divergent bookmarks |
|
381 | 392 | |
|
382 | 393 | $ cd ../a |
|
383 | 394 | $ echo c1 > f1 |
|
384 | 395 | $ hg ci -Am1 |
|
385 | 396 | adding f1 |
|
386 | 397 | $ hg book -f @ |
|
387 | 398 | $ hg book -f X |
|
388 | 399 | $ hg book |
|
389 | 400 | @ 1:0d2164f0ce0d |
|
390 | 401 | * X 1:0d2164f0ce0d |
|
391 | 402 | Y 0:4e3505fd9583 |
|
392 | 403 | Z 1:0d2164f0ce0d |
|
393 | 404 | |
|
394 | 405 | $ cd ../b |
|
395 | 406 | $ hg up |
|
396 | 407 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
397 | 408 | updating bookmark foobar |
|
398 | 409 | $ echo c2 > f2 |
|
399 | 410 | $ hg ci -Am2 |
|
400 | 411 | adding f2 |
|
401 | 412 | $ hg book -if @ |
|
402 | 413 | $ hg book -if X |
|
403 | 414 | $ hg book |
|
404 | 415 | @ 1:9b140be10808 |
|
405 | 416 | X 1:9b140be10808 |
|
406 | 417 | Y 0:4e3505fd9583 |
|
407 | 418 | Z 0:4e3505fd9583 |
|
408 | 419 | foo -1:000000000000 |
|
409 | 420 | * foobar 1:9b140be10808 |
|
410 | 421 | |
|
411 | 422 | $ hg pull --config paths.foo=../a foo --config "$TESTHOOK" |
|
412 | 423 | pulling from $TESTTMP/a |
|
413 | 424 | searching for changes |
|
414 | 425 | adding changesets |
|
415 | 426 | adding manifests |
|
416 | 427 | adding file changes |
|
417 | 428 | divergent bookmark @ stored as @foo |
|
418 | 429 | divergent bookmark X stored as X@foo |
|
419 | 430 | updating bookmark Z |
|
420 | 431 | added 1 changesets with 1 changes to 1 files (+1 heads) |
|
421 | 432 | new changesets 0d2164f0ce0d (1 drafts) |
|
422 | 433 | test-hook-bookmark: @foo: -> 0d2164f0ce0d8f1d6f94351eba04b794909be66c |
|
423 | 434 | test-hook-bookmark: X@foo: -> 0d2164f0ce0d8f1d6f94351eba04b794909be66c |
|
424 | 435 | test-hook-bookmark: Z: 4e3505fd95835d721066b76e75dbb8cc554d7f77 -> 0d2164f0ce0d8f1d6f94351eba04b794909be66c |
|
425 | 436 | (run 'hg heads' to see heads, 'hg merge' to merge) |
|
426 | 437 | $ hg book |
|
427 | 438 | @ 1:9b140be10808 |
|
428 | 439 | @foo 2:0d2164f0ce0d |
|
429 | 440 | X 1:9b140be10808 |
|
430 | 441 | X@foo 2:0d2164f0ce0d |
|
431 | 442 | Y 0:4e3505fd9583 |
|
432 | 443 | Z 2:0d2164f0ce0d |
|
433 | 444 | foo -1:000000000000 |
|
434 | 445 | * foobar 1:9b140be10808 |
|
435 | 446 | |
|
436 | 447 | (test that too many divergence of bookmark) |
|
437 | 448 | |
|
438 | 449 | $ "$PYTHON" $TESTDIR/seq.py 1 100 | while read i; do hg bookmarks -r 000000000000 "X@${i}"; done |
|
439 | 450 | $ hg pull ../a |
|
440 | 451 | pulling from ../a |
|
441 | 452 | searching for changes |
|
442 | 453 | no changes found |
|
443 | 454 | warning: failed to assign numbered name to divergent bookmark X |
|
444 | 455 | divergent bookmark @ stored as @1 |
|
445 | 456 | $ hg bookmarks | grep '^ X' | grep -v ':000000000000' |
|
446 | 457 | X 1:9b140be10808 |
|
447 | 458 | X@foo 2:0d2164f0ce0d |
|
448 | 459 | |
|
449 | 460 | (test that remotely diverged bookmarks are reused if they aren't changed) |
|
450 | 461 | |
|
451 | 462 | $ hg bookmarks | grep '^ @' |
|
452 | 463 | @ 1:9b140be10808 |
|
453 | 464 | @1 2:0d2164f0ce0d |
|
454 | 465 | @foo 2:0d2164f0ce0d |
|
455 | 466 | $ hg pull ../a |
|
456 | 467 | pulling from ../a |
|
457 | 468 | searching for changes |
|
458 | 469 | no changes found |
|
459 | 470 | warning: failed to assign numbered name to divergent bookmark X |
|
460 | 471 | divergent bookmark @ stored as @1 |
|
461 | 472 | $ hg bookmarks | grep '^ @' |
|
462 | 473 | @ 1:9b140be10808 |
|
463 | 474 | @1 2:0d2164f0ce0d |
|
464 | 475 | @foo 2:0d2164f0ce0d |
|
465 | 476 | |
|
466 | 477 | $ "$PYTHON" $TESTDIR/seq.py 1 100 | while read i; do hg bookmarks -d "X@${i}"; done |
|
467 | 478 | $ hg bookmarks -d "@1" |
|
468 | 479 | |
|
469 | 480 | $ hg push -f ../a |
|
470 | 481 | pushing to ../a |
|
471 | 482 | searching for changes |
|
472 | 483 | adding changesets |
|
473 | 484 | adding manifests |
|
474 | 485 | adding file changes |
|
475 | 486 | added 1 changesets with 1 changes to 1 files (+1 heads) |
|
476 | 487 | $ hg -R ../a book |
|
477 | 488 | @ 1:0d2164f0ce0d |
|
478 | 489 | * X 1:0d2164f0ce0d |
|
479 | 490 | Y 0:4e3505fd9583 |
|
480 | 491 | Z 1:0d2164f0ce0d |
|
481 | 492 | |
|
482 | 493 | explicit pull should overwrite the local version (issue4439) |
|
483 | 494 | |
|
484 | 495 | $ hg update -r X |
|
485 | 496 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
486 | 497 | (activating bookmark X) |
|
487 | 498 | $ hg pull --config paths.foo=../a foo -B . --config "$TESTHOOK" |
|
488 | 499 | pulling from $TESTTMP/a |
|
489 | 500 | no changes found |
|
490 | 501 | divergent bookmark @ stored as @foo |
|
491 | 502 | importing bookmark X |
|
492 | 503 | test-hook-bookmark: @foo: 0d2164f0ce0d8f1d6f94351eba04b794909be66c -> 0d2164f0ce0d8f1d6f94351eba04b794909be66c |
|
493 | 504 | test-hook-bookmark: X: 9b140be1080824d768c5a4691a564088eede71f9 -> 0d2164f0ce0d8f1d6f94351eba04b794909be66c |
|
494 | 505 | |
|
495 | 506 | reinstall state for further testing: |
|
496 | 507 | |
|
497 | 508 | $ hg book -fr 9b140be10808 X |
|
498 | 509 | |
|
499 | 510 | revsets should not ignore divergent bookmarks |
|
500 | 511 | |
|
501 | 512 | $ hg bookmark -fr 1 Z |
|
502 | 513 | $ hg log -r 'bookmark()' --template '{rev}:{node|short} {bookmarks}\n' |
|
503 | 514 | 0:4e3505fd9583 Y |
|
504 | 515 | 1:9b140be10808 @ X Z foobar |
|
505 | 516 | 2:0d2164f0ce0d @foo X@foo |
|
506 | 517 | $ hg log -r 'bookmark("X@foo")' --template '{rev}:{node|short} {bookmarks}\n' |
|
507 | 518 | 2:0d2164f0ce0d @foo X@foo |
|
508 | 519 | $ hg log -r 'bookmark("re:X@foo")' --template '{rev}:{node|short} {bookmarks}\n' |
|
509 | 520 | 2:0d2164f0ce0d @foo X@foo |
|
510 | 521 | |
|
511 | 522 | update a remote bookmark from a non-head to a head |
|
512 | 523 | |
|
513 | 524 | $ hg up -q Y |
|
514 | 525 | $ echo c3 > f2 |
|
515 | 526 | $ hg ci -Am3 |
|
516 | 527 | adding f2 |
|
517 | 528 | created new head |
|
518 | 529 | $ hg push ../a --config "$TESTHOOK" |
|
519 | 530 | pushing to ../a |
|
520 | 531 | searching for changes |
|
521 | 532 | adding changesets |
|
522 | 533 | adding manifests |
|
523 | 534 | adding file changes |
|
524 | 535 | added 1 changesets with 1 changes to 1 files (+1 heads) |
|
525 | 536 | test-hook-bookmark: Y: 4e3505fd95835d721066b76e75dbb8cc554d7f77 -> f6fc62dde3c0771e29704af56ba4d8af77abcc2f |
|
526 | 537 | updating bookmark Y |
|
527 | 538 | $ hg -R ../a book |
|
528 | 539 | @ 1:0d2164f0ce0d |
|
529 | 540 | * X 1:0d2164f0ce0d |
|
530 | 541 | Y 3:f6fc62dde3c0 |
|
531 | 542 | Z 1:0d2164f0ce0d |
|
532 | 543 | |
|
533 | 544 | update a bookmark in the middle of a client pulling changes |
|
534 | 545 | |
|
535 | 546 | $ cd .. |
|
536 | 547 | $ hg clone -q a pull-race |
|
537 | 548 | |
|
538 | 549 | We want to use http because it is stateless and therefore more susceptible to |
|
539 | 550 | race conditions |
|
540 | 551 | |
|
541 | 552 | $ hg serve -R pull-race -p $HGPORT -d --pid-file=pull-race.pid -E main-error.log |
|
542 | 553 | $ cat pull-race.pid >> $DAEMON_PIDS |
|
543 | 554 | |
|
544 | 555 | $ cat <<EOF > $TESTTMP/out_makecommit.sh |
|
545 | 556 | > #!/bin/sh |
|
546 | 557 | > hg ci -Am5 |
|
547 | 558 | > echo committed in pull-race |
|
548 | 559 | > EOF |
|
549 | 560 | |
|
550 | 561 | $ hg clone -q http://localhost:$HGPORT/ pull-race2 --config "$TESTHOOK" |
|
551 | 562 | test-hook-bookmark: @: -> 0d2164f0ce0d8f1d6f94351eba04b794909be66c |
|
552 | 563 | test-hook-bookmark: X: -> 0d2164f0ce0d8f1d6f94351eba04b794909be66c |
|
553 | 564 | test-hook-bookmark: Y: -> f6fc62dde3c0771e29704af56ba4d8af77abcc2f |
|
554 | 565 | test-hook-bookmark: Z: -> 0d2164f0ce0d8f1d6f94351eba04b794909be66c |
|
555 | 566 | $ cd pull-race |
|
556 | 567 | $ hg up -q Y |
|
557 | 568 | $ echo c4 > f2 |
|
558 | 569 | $ hg ci -Am4 |
|
559 | 570 | $ echo c5 > f3 |
|
560 | 571 | $ cat <<EOF > .hg/hgrc |
|
561 | 572 | > [hooks] |
|
562 | 573 | > outgoing.makecommit = sh $TESTTMP/out_makecommit.sh |
|
563 | 574 | > EOF |
|
564 | 575 | |
|
565 | 576 | (new config needs a server restart) |
|
566 | 577 | |
|
567 | 578 | $ cd .. |
|
568 | 579 | $ killdaemons.py |
|
569 | 580 | $ hg serve -R pull-race -p $HGPORT -d --pid-file=pull-race.pid -E main-error.log |
|
570 | 581 | $ cat pull-race.pid >> $DAEMON_PIDS |
|
571 | 582 | $ cd pull-race2 |
|
572 | 583 | $ hg -R $TESTTMP/pull-race book |
|
573 | 584 | @ 1:0d2164f0ce0d |
|
574 | 585 | X 1:0d2164f0ce0d |
|
575 | 586 | * Y 4:b0a5eff05604 |
|
576 | 587 | Z 1:0d2164f0ce0d |
|
577 | 588 | $ hg pull |
|
578 | 589 | pulling from http://localhost:$HGPORT/ |
|
579 | 590 | searching for changes |
|
580 | 591 | adding changesets |
|
581 | 592 | adding manifests |
|
582 | 593 | adding file changes |
|
583 | 594 | updating bookmark Y |
|
584 | 595 | added 1 changesets with 1 changes to 1 files |
|
585 | 596 | new changesets b0a5eff05604 (1 drafts) |
|
586 | 597 | (run 'hg update' to get a working copy) |
|
587 | 598 | $ hg book |
|
588 | 599 | * @ 1:0d2164f0ce0d |
|
589 | 600 | X 1:0d2164f0ce0d |
|
590 | 601 | Y 4:b0a5eff05604 |
|
591 | 602 | Z 1:0d2164f0ce0d |
|
592 | 603 | |
|
593 | 604 | Update a bookmark right after the initial lookup -B (issue4689) |
|
594 | 605 | |
|
595 | 606 | $ echo c6 > ../pull-race/f3 # to be committed during the race |
|
596 | 607 | $ cat <<EOF > $TESTTMP/listkeys_makecommit.sh |
|
597 | 608 | > #!/bin/sh |
|
598 | 609 | > if hg st | grep -q M; then |
|
599 | 610 | > hg commit -m race |
|
600 | 611 | > echo committed in pull-race |
|
601 | 612 | > else |
|
602 | 613 | > exit 0 |
|
603 | 614 | > fi |
|
604 | 615 | > EOF |
|
605 | 616 | $ cat <<EOF > ../pull-race/.hg/hgrc |
|
606 | 617 | > [hooks] |
|
607 | 618 | > # If anything to commit, commit it right after the first key listing used |
|
608 | 619 | > # during lookup. This makes the commit appear before the actual getbundle |
|
609 | 620 | > # call. |
|
610 | 621 | > listkeys.makecommit= sh $TESTTMP/listkeys_makecommit.sh |
|
611 | 622 | > EOF |
|
612 | 623 | $ restart_server() { |
|
613 | 624 | > "$TESTDIR/killdaemons.py" $DAEMON_PIDS |
|
614 | 625 | > hg serve -R ../pull-race -p $HGPORT -d --pid-file=../pull-race.pid -E main-error.log |
|
615 | 626 | > cat ../pull-race.pid >> $DAEMON_PIDS |
|
616 | 627 | > } |
|
617 | 628 | $ restart_server # new config need server restart |
|
618 | 629 | $ hg -R $TESTTMP/pull-race book |
|
619 | 630 | @ 1:0d2164f0ce0d |
|
620 | 631 | X 1:0d2164f0ce0d |
|
621 | 632 | * Y 5:35d1ef0a8d1b |
|
622 | 633 | Z 1:0d2164f0ce0d |
|
623 | 634 | $ hg update -r Y |
|
624 | 635 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
625 | 636 | (activating bookmark Y) |
|
626 | 637 | $ hg pull -B . |
|
627 | 638 | pulling from http://localhost:$HGPORT/ |
|
628 | 639 | searching for changes |
|
629 | 640 | adding changesets |
|
630 | 641 | adding manifests |
|
631 | 642 | adding file changes |
|
632 | 643 | updating bookmark Y |
|
633 | 644 | added 1 changesets with 1 changes to 1 files |
|
634 | 645 | new changesets 35d1ef0a8d1b (1 drafts) |
|
635 | 646 | (run 'hg update' to get a working copy) |
|
636 | 647 | $ hg book |
|
637 | 648 | @ 1:0d2164f0ce0d |
|
638 | 649 | X 1:0d2164f0ce0d |
|
639 | 650 | * Y 5:35d1ef0a8d1b |
|
640 | 651 | Z 1:0d2164f0ce0d |
|
641 | 652 | |
|
642 | 653 | Update a bookmark right after the initial lookup -r (issue4700) |
|
643 | 654 | |
|
644 | 655 | $ echo c7 > ../pull-race/f3 # to be committed during the race |
|
645 | 656 | $ cat <<EOF > ../lookuphook.py |
|
646 | 657 | > """small extensions adding a hook after wireprotocol lookup to test race""" |
|
647 | 658 | > import functools |
|
648 | 659 | > from mercurial import wireprotov1server, wireprotov2server |
|
649 | 660 | > |
|
650 | 661 | > def wrappedlookup(orig, repo, *args, **kwargs): |
|
651 | 662 | > ret = orig(repo, *args, **kwargs) |
|
652 | 663 | > repo.hook(b'lookup') |
|
653 | 664 | > return ret |
|
654 | 665 | > for table in [wireprotov1server.commands, wireprotov2server.COMMANDS]: |
|
655 | 666 | > table[b'lookup'].func = functools.partial(wrappedlookup, table[b'lookup'].func) |
|
656 | 667 | > EOF |
|
657 | 668 | $ cat <<EOF > ../pull-race/.hg/hgrc |
|
658 | 669 | > [extensions] |
|
659 | 670 | > lookuphook=$TESTTMP/lookuphook.py |
|
660 | 671 | > [hooks] |
|
661 | 672 | > lookup.makecommit= sh $TESTTMP/listkeys_makecommit.sh |
|
662 | 673 | > EOF |
|
663 | 674 | $ restart_server # new config need server restart |
|
664 | 675 | $ hg -R $TESTTMP/pull-race book |
|
665 | 676 | @ 1:0d2164f0ce0d |
|
666 | 677 | X 1:0d2164f0ce0d |
|
667 | 678 | * Y 6:0d60821d2197 |
|
668 | 679 | Z 1:0d2164f0ce0d |
|
669 | 680 | $ hg pull -r Y |
|
670 | 681 | pulling from http://localhost:$HGPORT/ |
|
671 | 682 | searching for changes |
|
672 | 683 | adding changesets |
|
673 | 684 | adding manifests |
|
674 | 685 | adding file changes |
|
675 | 686 | updating bookmark Y |
|
676 | 687 | added 1 changesets with 1 changes to 1 files |
|
677 | 688 | new changesets 0d60821d2197 (1 drafts) |
|
678 | 689 | (run 'hg update' to get a working copy) |
|
679 | 690 | $ hg book |
|
680 | 691 | @ 1:0d2164f0ce0d |
|
681 | 692 | X 1:0d2164f0ce0d |
|
682 | 693 | * Y 6:0d60821d2197 |
|
683 | 694 | Z 1:0d2164f0ce0d |
|
684 | 695 | $ hg -R $TESTTMP/pull-race book |
|
685 | 696 | @ 1:0d2164f0ce0d |
|
686 | 697 | X 1:0d2164f0ce0d |
|
687 | 698 | * Y 7:714424d9e8b8 |
|
688 | 699 | Z 1:0d2164f0ce0d |
|
689 | 700 | |
|
690 | 701 | (done with this section of the test) |
|
691 | 702 | |
|
692 | 703 | $ killdaemons.py |
|
693 | 704 | $ cd ../b |
|
694 | 705 | |
|
695 | 706 | diverging a remote bookmark fails |
|
696 | 707 | |
|
697 | 708 | $ hg up -q 4e3505fd9583 |
|
698 | 709 | $ echo c4 > f2 |
|
699 | 710 | $ hg ci -Am4 |
|
700 | 711 | adding f2 |
|
701 | 712 | created new head |
|
702 | 713 | $ echo c5 > f2 |
|
703 | 714 | $ hg ci -Am5 |
|
704 | 715 | $ hg log -G |
|
705 | 716 | @ 5:c922c0139ca0 5 |
|
706 | 717 | | |
|
707 | 718 | o 4:4efff6d98829 4 |
|
708 | 719 | | |
|
709 | 720 | | o 3:f6fc62dde3c0 3 |
|
710 | 721 | |/ |
|
711 | 722 | | o 2:0d2164f0ce0d 1 |
|
712 | 723 | |/ |
|
713 | 724 | | o 1:9b140be10808 2 |
|
714 | 725 | |/ |
|
715 | 726 | o 0:4e3505fd9583 test |
|
716 | 727 | |
|
717 | 728 | |
|
718 | 729 | $ hg book -f Y |
|
719 | 730 | |
|
720 | 731 | $ cat <<EOF > ../a/.hg/hgrc |
|
721 | 732 | > [web] |
|
722 | 733 | > push_ssl = false |
|
723 | 734 | > allow_push = * |
|
724 | 735 | > EOF |
|
725 | 736 | |
|
726 | 737 | $ hg serve -R ../a -p $HGPORT2 -d --pid-file=../hg2.pid |
|
727 | 738 | $ cat ../hg2.pid >> $DAEMON_PIDS |
|
728 | 739 | |
|
729 | 740 | $ hg push http://localhost:$HGPORT2/ |
|
730 | 741 | pushing to http://localhost:$HGPORT2/ |
|
731 | 742 | searching for changes |
|
732 | 743 | abort: push creates new remote head c922c0139ca0 with bookmark 'Y'! |
|
733 | 744 | (merge or see 'hg help push' for details about pushing new heads) |
|
734 | 745 | [255] |
|
735 | 746 | $ hg -R ../a book |
|
736 | 747 | @ 1:0d2164f0ce0d |
|
737 | 748 | * X 1:0d2164f0ce0d |
|
738 | 749 | Y 3:f6fc62dde3c0 |
|
739 | 750 | Z 1:0d2164f0ce0d |
|
740 | 751 | |
|
741 | 752 | |
|
742 | 753 | Unrelated marker does not alter the decision |
|
743 | 754 | |
|
744 | 755 | $ hg debugobsolete aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |
|
745 | 756 | 1 new obsolescence markers |
|
746 | 757 | $ hg push http://localhost:$HGPORT2/ |
|
747 | 758 | pushing to http://localhost:$HGPORT2/ |
|
748 | 759 | searching for changes |
|
749 | 760 | abort: push creates new remote head c922c0139ca0 with bookmark 'Y'! |
|
750 | 761 | (merge or see 'hg help push' for details about pushing new heads) |
|
751 | 762 | [255] |
|
752 | 763 | $ hg -R ../a book |
|
753 | 764 | @ 1:0d2164f0ce0d |
|
754 | 765 | * X 1:0d2164f0ce0d |
|
755 | 766 | Y 3:f6fc62dde3c0 |
|
756 | 767 | Z 1:0d2164f0ce0d |
|
757 | 768 | |
|
758 | 769 | Update to a successor works |
|
759 | 770 | |
|
760 | 771 | $ hg id --debug -r 3 |
|
761 | 772 | f6fc62dde3c0771e29704af56ba4d8af77abcc2f |
|
762 | 773 | $ hg id --debug -r 4 |
|
763 | 774 | 4efff6d98829d9c824c621afd6e3f01865f5439f |
|
764 | 775 | $ hg id --debug -r 5 |
|
765 | 776 | c922c0139ca03858f655e4a2af4dd02796a63969 tip Y |
|
766 | 777 | $ hg debugobsolete f6fc62dde3c0771e29704af56ba4d8af77abcc2f cccccccccccccccccccccccccccccccccccccccc |
|
767 | 778 | 1 new obsolescence markers |
|
768 | 779 | obsoleted 1 changesets |
|
769 | 780 | $ hg debugobsolete cccccccccccccccccccccccccccccccccccccccc 4efff6d98829d9c824c621afd6e3f01865f5439f |
|
770 | 781 | 1 new obsolescence markers |
|
771 | 782 | $ hg push http://localhost:$HGPORT2/ |
|
772 | 783 | pushing to http://localhost:$HGPORT2/ |
|
773 | 784 | searching for changes |
|
774 | 785 | remote: adding changesets |
|
775 | 786 | remote: adding manifests |
|
776 | 787 | remote: adding file changes |
|
777 | 788 | remote: added 2 changesets with 2 changes to 1 files (+1 heads) |
|
778 | 789 | remote: 2 new obsolescence markers |
|
779 | 790 | remote: obsoleted 1 changesets |
|
780 | 791 | updating bookmark Y |
|
781 | 792 | $ hg -R ../a book |
|
782 | 793 | @ 1:0d2164f0ce0d |
|
783 | 794 | * X 1:0d2164f0ce0d |
|
784 | 795 | Y 5:c922c0139ca0 |
|
785 | 796 | Z 1:0d2164f0ce0d |
|
786 | 797 | |
|
787 | 798 | hgweb |
|
788 | 799 | |
|
789 | 800 | $ cat <<EOF > .hg/hgrc |
|
790 | 801 | > [web] |
|
791 | 802 | > push_ssl = false |
|
792 | 803 | > allow_push = * |
|
793 | 804 | > EOF |
|
794 | 805 | |
|
795 | 806 | $ hg serve -p $HGPORT -d --pid-file=../hg.pid -E errors.log |
|
796 | 807 | $ cat ../hg.pid >> $DAEMON_PIDS |
|
797 | 808 | $ cd ../a |
|
798 | 809 | |
|
799 | 810 | $ hg debugpushkey http://localhost:$HGPORT/ namespaces |
|
800 | 811 | bookmarks |
|
801 | 812 | namespaces |
|
802 | 813 | obsolete |
|
803 | 814 | phases |
|
804 | 815 | $ hg debugpushkey http://localhost:$HGPORT/ bookmarks |
|
805 | 816 | @ 9b140be1080824d768c5a4691a564088eede71f9 |
|
806 | 817 | X 9b140be1080824d768c5a4691a564088eede71f9 |
|
807 | 818 | Y c922c0139ca03858f655e4a2af4dd02796a63969 |
|
808 | 819 | Z 9b140be1080824d768c5a4691a564088eede71f9 |
|
809 | 820 | foo 0000000000000000000000000000000000000000 |
|
810 | 821 | foobar 9b140be1080824d768c5a4691a564088eede71f9 |
|
811 | 822 | $ hg out -B http://localhost:$HGPORT/ |
|
812 | 823 | comparing with http://localhost:$HGPORT/ |
|
813 | 824 | searching for changed bookmarks |
|
814 | 825 | @ 0d2164f0ce0d |
|
815 | 826 | X 0d2164f0ce0d |
|
816 | 827 | Z 0d2164f0ce0d |
|
817 | 828 | foo |
|
818 | 829 | foobar |
|
819 | 830 | $ hg push -B Z http://localhost:$HGPORT/ |
|
820 | 831 | pushing to http://localhost:$HGPORT/ |
|
821 | 832 | searching for changes |
|
822 | 833 | no changes found |
|
823 | 834 | updating bookmark Z |
|
824 | 835 | [1] |
|
825 | 836 | $ hg book -d Z |
|
826 | 837 | $ hg in -B http://localhost:$HGPORT/ |
|
827 | 838 | comparing with http://localhost:$HGPORT/ |
|
828 | 839 | searching for changed bookmarks |
|
829 | 840 | @ 9b140be10808 |
|
830 | 841 | X 9b140be10808 |
|
831 | 842 | Z 0d2164f0ce0d |
|
832 | 843 | foo 000000000000 |
|
833 | 844 | foobar 9b140be10808 |
|
834 | 845 | $ hg pull -B Z http://localhost:$HGPORT/ |
|
835 | 846 | pulling from http://localhost:$HGPORT/ |
|
836 | 847 | no changes found |
|
837 | 848 | divergent bookmark @ stored as @1 |
|
838 | 849 | divergent bookmark X stored as X@1 |
|
839 | 850 | adding remote bookmark Z |
|
840 | 851 | adding remote bookmark foo |
|
841 | 852 | adding remote bookmark foobar |
|
842 | 853 | $ hg clone http://localhost:$HGPORT/ cloned-bookmarks |
|
843 | 854 | requesting all changes |
|
844 | 855 | adding changesets |
|
845 | 856 | adding manifests |
|
846 | 857 | adding file changes |
|
847 | 858 | added 5 changesets with 5 changes to 3 files (+2 heads) |
|
848 | 859 | 2 new obsolescence markers |
|
849 | 860 | new changesets 4e3505fd9583:c922c0139ca0 (5 drafts) |
|
850 | 861 | updating to bookmark @ |
|
851 | 862 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
852 | 863 | $ hg -R cloned-bookmarks bookmarks |
|
853 | 864 | * @ 1:9b140be10808 |
|
854 | 865 | X 1:9b140be10808 |
|
855 | 866 | Y 4:c922c0139ca0 |
|
856 | 867 | Z 2:0d2164f0ce0d |
|
857 | 868 | foo -1:000000000000 |
|
858 | 869 | foobar 1:9b140be10808 |
|
859 | 870 | |
|
860 | 871 | $ cd .. |
|
861 | 872 | |
|
862 | 873 | Test to show result of bookmarks comparison |
|
863 | 874 | |
|
864 | 875 | $ mkdir bmcomparison |
|
865 | 876 | $ cd bmcomparison |
|
866 | 877 | |
|
867 | 878 | $ hg init source |
|
868 | 879 | $ hg -R source debugbuilddag '+2*2*3*4' |
|
869 | 880 | $ hg -R source log -G --template '{rev}:{node|short}' |
|
870 | 881 | o 4:e7bd5218ca15 |
|
871 | 882 | | |
|
872 | 883 | | o 3:6100d3090acf |
|
873 | 884 | |/ |
|
874 | 885 | | o 2:fa942426a6fd |
|
875 | 886 | |/ |
|
876 | 887 | | o 1:66f7d451a68b |
|
877 | 888 | |/ |
|
878 | 889 | o 0:1ea73414a91b |
|
879 | 890 | |
|
880 | 891 | $ hg -R source bookmarks -r 0 SAME |
|
881 | 892 | $ hg -R source bookmarks -r 0 ADV_ON_REPO1 |
|
882 | 893 | $ hg -R source bookmarks -r 0 ADV_ON_REPO2 |
|
883 | 894 | $ hg -R source bookmarks -r 0 DIFF_ADV_ON_REPO1 |
|
884 | 895 | $ hg -R source bookmarks -r 0 DIFF_ADV_ON_REPO2 |
|
885 | 896 | $ hg -R source bookmarks -r 1 DIVERGED |
|
886 | 897 | |
|
887 | 898 | $ hg clone -U source repo1 |
|
888 | 899 | |
|
889 | 900 | (test that incoming/outgoing exit with 1, if there is no bookmark to |
|
890 | 901 | be exchanged) |
|
891 | 902 | |
|
892 | 903 | $ hg -R repo1 incoming -B |
|
893 | 904 | comparing with $TESTTMP/bmcomparison/source |
|
894 | 905 | searching for changed bookmarks |
|
895 | 906 | no changed bookmarks found |
|
896 | 907 | [1] |
|
897 | 908 | $ hg -R repo1 outgoing -B |
|
898 | 909 | comparing with $TESTTMP/bmcomparison/source |
|
899 | 910 | searching for changed bookmarks |
|
900 | 911 | no changed bookmarks found |
|
901 | 912 | [1] |
|
902 | 913 | |
|
903 | 914 | $ hg -R repo1 bookmarks -f -r 1 ADD_ON_REPO1 |
|
904 | 915 | $ hg -R repo1 bookmarks -f -r 2 ADV_ON_REPO1 |
|
905 | 916 | $ hg -R repo1 bookmarks -f -r 3 DIFF_ADV_ON_REPO1 |
|
906 | 917 | $ hg -R repo1 bookmarks -f -r 3 DIFF_DIVERGED |
|
907 | 918 | $ hg -R repo1 -q --config extensions.mq= strip 4 |
|
908 | 919 | $ hg -R repo1 log -G --template '{node|short} ({bookmarks})' |
|
909 | 920 | o 6100d3090acf (DIFF_ADV_ON_REPO1 DIFF_DIVERGED) |
|
910 | 921 | | |
|
911 | 922 | | o fa942426a6fd (ADV_ON_REPO1) |
|
912 | 923 | |/ |
|
913 | 924 | | o 66f7d451a68b (ADD_ON_REPO1 DIVERGED) |
|
914 | 925 | |/ |
|
915 | 926 | o 1ea73414a91b (ADV_ON_REPO2 DIFF_ADV_ON_REPO2 SAME) |
|
916 | 927 | |
|
917 | 928 | |
|
918 | 929 | $ hg clone -U source repo2 |
|
919 | 930 | $ hg -R repo2 bookmarks -f -r 1 ADD_ON_REPO2 |
|
920 | 931 | $ hg -R repo2 bookmarks -f -r 1 ADV_ON_REPO2 |
|
921 | 932 | $ hg -R repo2 bookmarks -f -r 2 DIVERGED |
|
922 | 933 | $ hg -R repo2 bookmarks -f -r 4 DIFF_ADV_ON_REPO2 |
|
923 | 934 | $ hg -R repo2 bookmarks -f -r 4 DIFF_DIVERGED |
|
924 | 935 | $ hg -R repo2 -q --config extensions.mq= strip 3 |
|
925 | 936 | $ hg -R repo2 log -G --template '{node|short} ({bookmarks})' |
|
926 | 937 | o e7bd5218ca15 (DIFF_ADV_ON_REPO2 DIFF_DIVERGED) |
|
927 | 938 | | |
|
928 | 939 | | o fa942426a6fd (DIVERGED) |
|
929 | 940 | |/ |
|
930 | 941 | | o 66f7d451a68b (ADD_ON_REPO2 ADV_ON_REPO2) |
|
931 | 942 | |/ |
|
932 | 943 | o 1ea73414a91b (ADV_ON_REPO1 DIFF_ADV_ON_REPO1 SAME) |
|
933 | 944 | |
|
934 | 945 | |
|
935 | 946 | (test that difference of bookmarks between repositories are fully shown) |
|
936 | 947 | |
|
937 | 948 | $ hg -R repo1 incoming -B repo2 -v |
|
938 | 949 | comparing with repo2 |
|
939 | 950 | searching for changed bookmarks |
|
940 | 951 | ADD_ON_REPO2 66f7d451a68b added |
|
941 | 952 | ADV_ON_REPO2 66f7d451a68b advanced |
|
942 | 953 | DIFF_ADV_ON_REPO2 e7bd5218ca15 changed |
|
943 | 954 | DIFF_DIVERGED e7bd5218ca15 changed |
|
944 | 955 | DIVERGED fa942426a6fd diverged |
|
945 | 956 | $ hg -R repo1 outgoing -B repo2 -v |
|
946 | 957 | comparing with repo2 |
|
947 | 958 | searching for changed bookmarks |
|
948 | 959 | ADD_ON_REPO1 66f7d451a68b added |
|
949 | 960 | ADD_ON_REPO2 deleted |
|
950 | 961 | ADV_ON_REPO1 fa942426a6fd advanced |
|
951 | 962 | DIFF_ADV_ON_REPO1 6100d3090acf advanced |
|
952 | 963 | DIFF_ADV_ON_REPO2 1ea73414a91b changed |
|
953 | 964 | DIFF_DIVERGED 6100d3090acf changed |
|
954 | 965 | DIVERGED 66f7d451a68b diverged |
|
955 | 966 | |
|
956 | 967 | $ hg -R repo2 incoming -B repo1 -v |
|
957 | 968 | comparing with repo1 |
|
958 | 969 | searching for changed bookmarks |
|
959 | 970 | ADD_ON_REPO1 66f7d451a68b added |
|
960 | 971 | ADV_ON_REPO1 fa942426a6fd advanced |
|
961 | 972 | DIFF_ADV_ON_REPO1 6100d3090acf changed |
|
962 | 973 | DIFF_DIVERGED 6100d3090acf changed |
|
963 | 974 | DIVERGED 66f7d451a68b diverged |
|
964 | 975 | $ hg -R repo2 outgoing -B repo1 -v |
|
965 | 976 | comparing with repo1 |
|
966 | 977 | searching for changed bookmarks |
|
967 | 978 | ADD_ON_REPO1 deleted |
|
968 | 979 | ADD_ON_REPO2 66f7d451a68b added |
|
969 | 980 | ADV_ON_REPO2 66f7d451a68b advanced |
|
970 | 981 | DIFF_ADV_ON_REPO1 1ea73414a91b changed |
|
971 | 982 | DIFF_ADV_ON_REPO2 e7bd5218ca15 advanced |
|
972 | 983 | DIFF_DIVERGED e7bd5218ca15 changed |
|
973 | 984 | DIVERGED fa942426a6fd diverged |
|
974 | 985 | |
|
975 | 986 | $ cd .. |
|
976 | 987 | |
|
977 | 988 | Pushing a bookmark should only push the changes required by that |
|
978 | 989 | bookmark, not all outgoing changes: |
|
979 | 990 | $ hg clone http://localhost:$HGPORT/ addmarks |
|
980 | 991 | requesting all changes |
|
981 | 992 | adding changesets |
|
982 | 993 | adding manifests |
|
983 | 994 | adding file changes |
|
984 | 995 | added 5 changesets with 5 changes to 3 files (+2 heads) |
|
985 | 996 | 2 new obsolescence markers |
|
986 | 997 | new changesets 4e3505fd9583:c922c0139ca0 (5 drafts) |
|
987 | 998 | updating to bookmark @ |
|
988 | 999 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
989 | 1000 | $ cd addmarks |
|
990 | 1001 | $ echo foo > foo |
|
991 | 1002 | $ hg add foo |
|
992 | 1003 | $ hg commit -m 'add foo' |
|
993 | 1004 | $ echo bar > bar |
|
994 | 1005 | $ hg add bar |
|
995 | 1006 | $ hg commit -m 'add bar' |
|
996 | 1007 | $ hg co "tip^" |
|
997 | 1008 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
998 | 1009 | (leaving bookmark @) |
|
999 | 1010 | $ hg book add-foo |
|
1000 | 1011 | $ hg book -r tip add-bar |
|
1001 | 1012 | Note: this push *must* push only a single changeset, as that's the point |
|
1002 | 1013 | of this test. |
|
1003 | 1014 | $ hg push -B add-foo --traceback |
|
1004 | 1015 | pushing to http://localhost:$HGPORT/ |
|
1005 | 1016 | searching for changes |
|
1006 | 1017 | remote: adding changesets |
|
1007 | 1018 | remote: adding manifests |
|
1008 | 1019 | remote: adding file changes |
|
1009 | 1020 | remote: added 1 changesets with 1 changes to 1 files |
|
1010 | 1021 | exporting bookmark add-foo |
|
1011 | 1022 | |
|
1012 | 1023 | pushing a new bookmark on a new head does not require -f if -B is specified |
|
1013 | 1024 | |
|
1014 | 1025 | $ hg up -q X |
|
1015 | 1026 | $ hg book W |
|
1016 | 1027 | $ echo c5 > f2 |
|
1017 | 1028 | $ hg ci -Am5 |
|
1018 | 1029 | created new head |
|
1019 | 1030 | $ hg push -B . |
|
1020 | 1031 | pushing to http://localhost:$HGPORT/ |
|
1021 | 1032 | searching for changes |
|
1022 | 1033 | remote: adding changesets |
|
1023 | 1034 | remote: adding manifests |
|
1024 | 1035 | remote: adding file changes |
|
1025 | 1036 | remote: added 1 changesets with 1 changes to 1 files (+1 heads) |
|
1026 | 1037 | exporting bookmark W |
|
1027 | 1038 | $ hg -R ../b id -r W |
|
1028 | 1039 | cc978a373a53 tip W |
|
1029 | 1040 | |
|
1030 | 1041 | pushing an existing but divergent bookmark with -B still requires -f |
|
1031 | 1042 | |
|
1032 | 1043 | $ hg clone -q . ../r |
|
1033 | 1044 | $ hg up -q X |
|
1034 | 1045 | $ echo 1 > f2 |
|
1035 | 1046 | $ hg ci -qAml |
|
1036 | 1047 | |
|
1037 | 1048 | $ cd ../r |
|
1038 | 1049 | $ hg up -q X |
|
1039 | 1050 | $ echo 2 > f2 |
|
1040 | 1051 | $ hg ci -qAmr |
|
1041 | 1052 | $ hg push -B X |
|
1042 | 1053 | pushing to $TESTTMP/addmarks |
|
1043 | 1054 | searching for changes |
|
1044 | 1055 | remote has heads on branch 'default' that are not known locally: a2a606d9ff1b |
|
1045 | 1056 | abort: push creates new remote head 54694f811df9 with bookmark 'X'! |
|
1046 | 1057 | (pull and merge or see 'hg help push' for details about pushing new heads) |
|
1047 | 1058 | [255] |
|
1048 | 1059 | $ cd ../addmarks |
|
1049 | 1060 | |
|
1050 | 1061 | Check summary output for incoming/outgoing bookmarks |
|
1051 | 1062 | |
|
1052 | 1063 | $ hg bookmarks -d X |
|
1053 | 1064 | $ hg bookmarks -d Y |
|
1054 | 1065 | $ hg summary --remote | grep '^remote:' |
|
1055 | 1066 | remote: *, 2 incoming bookmarks, 1 outgoing bookmarks (glob) |
|
1056 | 1067 | |
|
1057 | 1068 | $ cd .. |
|
1058 | 1069 | |
|
1059 | 1070 | pushing an unchanged bookmark should result in no changes |
|
1060 | 1071 | |
|
1061 | 1072 | $ hg init unchanged-a |
|
1062 | 1073 | $ hg init unchanged-b |
|
1063 | 1074 | $ cd unchanged-a |
|
1064 | 1075 | $ echo initial > foo |
|
1065 | 1076 | $ hg commit -A -m initial |
|
1066 | 1077 | adding foo |
|
1067 | 1078 | $ hg bookmark @ |
|
1068 | 1079 | $ hg push -B @ ../unchanged-b |
|
1069 | 1080 | pushing to ../unchanged-b |
|
1070 | 1081 | searching for changes |
|
1071 | 1082 | adding changesets |
|
1072 | 1083 | adding manifests |
|
1073 | 1084 | adding file changes |
|
1074 | 1085 | added 1 changesets with 1 changes to 1 files |
|
1075 | 1086 | exporting bookmark @ |
|
1076 | 1087 | |
|
1077 | 1088 | $ hg push -B @ ../unchanged-b |
|
1078 | 1089 | pushing to ../unchanged-b |
|
1079 | 1090 | searching for changes |
|
1080 | 1091 | no changes found |
|
1081 | 1092 | [1] |
|
1082 | 1093 | |
|
1083 | 1094 | Pushing a really long bookmark should work fine (issue5165) |
|
1084 | 1095 | =============================================== |
|
1085 | 1096 | |
|
1086 | 1097 | #if b2-binary |
|
1087 | 1098 | >>> with open('longname', 'w') as f: |
|
1088 | 1099 | ... f.write('wat' * 100) and None |
|
1089 | 1100 | $ hg book `cat longname` |
|
1090 | 1101 | $ hg push -B `cat longname` ../unchanged-b |
|
1091 | 1102 | pushing to ../unchanged-b |
|
1092 | 1103 | searching for changes |
|
1093 | 1104 | no changes found |
|
1094 | 1105 | exporting bookmark (wat){100} (re) |
|
1095 | 1106 | [1] |
|
1096 | 1107 | $ hg -R ../unchanged-b book --delete `cat longname` |
|
1097 | 1108 | |
|
1098 | 1109 | Test again but forcing bundle2 exchange to make sure that doesn't regress. |
|
1099 | 1110 | |
|
1100 | 1111 | $ hg push -B `cat longname` ../unchanged-b --config devel.legacy.exchange=bundle1 |
|
1101 | 1112 | pushing to ../unchanged-b |
|
1102 | 1113 | searching for changes |
|
1103 | 1114 | no changes found |
|
1104 | 1115 | exporting bookmark (wat){100} (re) |
|
1105 | 1116 | [1] |
|
1106 | 1117 | $ hg -R ../unchanged-b book --delete `cat longname` |
|
1107 | 1118 | $ hg book --delete `cat longname` |
|
1108 | 1119 | $ hg co @ |
|
1109 | 1120 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
1110 | 1121 | (activating bookmark @) |
|
1111 | 1122 | #endif |
|
1112 | 1123 | |
|
1113 | 1124 | Check hook preventing push (issue4455) |
|
1114 | 1125 | ====================================== |
|
1115 | 1126 | |
|
1116 | 1127 | $ hg bookmarks |
|
1117 | 1128 | * @ 0:55482a6fb4b1 |
|
1118 | 1129 | $ hg log -G |
|
1119 | 1130 | @ 0:55482a6fb4b1 initial |
|
1120 | 1131 | |
|
1121 | 1132 | $ hg init ../issue4455-dest |
|
1122 | 1133 | $ hg push ../issue4455-dest # changesets only |
|
1123 | 1134 | pushing to ../issue4455-dest |
|
1124 | 1135 | searching for changes |
|
1125 | 1136 | adding changesets |
|
1126 | 1137 | adding manifests |
|
1127 | 1138 | adding file changes |
|
1128 | 1139 | added 1 changesets with 1 changes to 1 files |
|
1129 | 1140 | $ cat >> .hg/hgrc << EOF |
|
1130 | 1141 | > [paths] |
|
1131 | 1142 | > local=../issue4455-dest/ |
|
1132 | 1143 | > ssh=ssh://user@dummy/issue4455-dest |
|
1133 | 1144 | > http=http://localhost:$HGPORT/ |
|
1134 | 1145 | > [ui] |
|
1135 | 1146 | > ssh="$PYTHON" "$TESTDIR/dummyssh" |
|
1136 | 1147 | > EOF |
|
1137 | 1148 | $ cat >> ../issue4455-dest/.hg/hgrc << EOF |
|
1138 | 1149 | > [hooks] |
|
1139 | 1150 | > prepushkey=false |
|
1140 | 1151 | > [web] |
|
1141 | 1152 | > push_ssl = false |
|
1142 | 1153 | > allow_push = * |
|
1143 | 1154 | > EOF |
|
1144 | 1155 | $ killdaemons.py |
|
1145 | 1156 | $ hg serve -R ../issue4455-dest -p $HGPORT -d --pid-file=../issue4455.pid -E ../issue4455-error.log |
|
1146 | 1157 | $ cat ../issue4455.pid >> $DAEMON_PIDS |
|
1147 | 1158 | |
|
1148 | 1159 | Local push |
|
1149 | 1160 | ---------- |
|
1150 | 1161 | |
|
1151 | 1162 | #if b2-pushkey |
|
1152 | 1163 | |
|
1153 | 1164 | $ hg push -B @ local |
|
1154 | 1165 | pushing to $TESTTMP/issue4455-dest |
|
1155 | 1166 | searching for changes |
|
1156 | 1167 | no changes found |
|
1157 | 1168 | pushkey-abort: prepushkey hook exited with status 1 |
|
1158 | 1169 | abort: exporting bookmark @ failed! |
|
1159 | 1170 | [255] |
|
1160 | 1171 | |
|
1161 | 1172 | #endif |
|
1162 | 1173 | #if b2-binary |
|
1163 | 1174 | |
|
1164 | 1175 | $ hg push -B @ local |
|
1165 | 1176 | pushing to $TESTTMP/issue4455-dest |
|
1166 | 1177 | searching for changes |
|
1167 | 1178 | no changes found |
|
1168 | 1179 | abort: prepushkey hook exited with status 1 |
|
1169 | 1180 | [255] |
|
1170 | 1181 | |
|
1171 | 1182 | #endif |
|
1172 | 1183 | |
|
1173 | 1184 | $ hg -R ../issue4455-dest/ bookmarks |
|
1174 | 1185 | no bookmarks set |
|
1175 | 1186 | |
|
1176 | 1187 | Using ssh |
|
1177 | 1188 | --------- |
|
1178 | 1189 | |
|
1179 | 1190 | #if b2-pushkey |
|
1180 | 1191 | |
|
1181 | 1192 | $ hg push -B @ ssh # bundle2+ |
|
1182 | 1193 | pushing to ssh://user@dummy/issue4455-dest |
|
1183 | 1194 | searching for changes |
|
1184 | 1195 | no changes found |
|
1185 | 1196 | remote: pushkey-abort: prepushkey hook exited with status 1 |
|
1186 | 1197 | abort: exporting bookmark @ failed! |
|
1187 | 1198 | [255] |
|
1188 | 1199 | |
|
1189 | 1200 | $ hg -R ../issue4455-dest/ bookmarks |
|
1190 | 1201 | no bookmarks set |
|
1191 | 1202 | |
|
1192 | 1203 | $ hg push -B @ ssh --config devel.legacy.exchange=bundle1 |
|
1193 | 1204 | pushing to ssh://user@dummy/issue4455-dest |
|
1194 | 1205 | searching for changes |
|
1195 | 1206 | no changes found |
|
1196 | 1207 | remote: pushkey-abort: prepushkey hook exited with status 1 |
|
1197 | 1208 | exporting bookmark @ failed! |
|
1198 | 1209 | [1] |
|
1199 | 1210 | |
|
1200 | 1211 | #endif |
|
1201 | 1212 | #if b2-binary |
|
1202 | 1213 | |
|
1203 | 1214 | $ hg push -B @ ssh # bundle2+ |
|
1204 | 1215 | pushing to ssh://user@dummy/issue4455-dest |
|
1205 | 1216 | searching for changes |
|
1206 | 1217 | no changes found |
|
1207 | 1218 | remote: prepushkey hook exited with status 1 |
|
1208 | 1219 | abort: push failed on remote |
|
1209 | 1220 | [255] |
|
1210 | 1221 | |
|
1211 | 1222 | #endif |
|
1212 | 1223 | |
|
1213 | 1224 | $ hg -R ../issue4455-dest/ bookmarks |
|
1214 | 1225 | no bookmarks set |
|
1215 | 1226 | |
|
1216 | 1227 | Using http |
|
1217 | 1228 | ---------- |
|
1218 | 1229 | |
|
1219 | 1230 | #if b2-pushkey |
|
1220 | 1231 | $ hg push -B @ http # bundle2+ |
|
1221 | 1232 | pushing to http://localhost:$HGPORT/ |
|
1222 | 1233 | searching for changes |
|
1223 | 1234 | no changes found |
|
1224 | 1235 | remote: pushkey-abort: prepushkey hook exited with status 1 |
|
1225 | 1236 | abort: exporting bookmark @ failed! |
|
1226 | 1237 | [255] |
|
1227 | 1238 | |
|
1228 | 1239 | $ hg -R ../issue4455-dest/ bookmarks |
|
1229 | 1240 | no bookmarks set |
|
1230 | 1241 | |
|
1231 | 1242 | $ hg push -B @ http --config devel.legacy.exchange=bundle1 |
|
1232 | 1243 | pushing to http://localhost:$HGPORT/ |
|
1233 | 1244 | searching for changes |
|
1234 | 1245 | no changes found |
|
1235 | 1246 | remote: pushkey-abort: prepushkey hook exited with status 1 |
|
1236 | 1247 | exporting bookmark @ failed! |
|
1237 | 1248 | [1] |
|
1238 | 1249 | |
|
1239 | 1250 | #endif |
|
1240 | 1251 | |
|
1241 | 1252 | #if b2-binary |
|
1242 | 1253 | |
|
1243 | 1254 | $ hg push -B @ ssh # bundle2+ |
|
1244 | 1255 | pushing to ssh://user@dummy/issue4455-dest |
|
1245 | 1256 | searching for changes |
|
1246 | 1257 | no changes found |
|
1247 | 1258 | remote: prepushkey hook exited with status 1 |
|
1248 | 1259 | abort: push failed on remote |
|
1249 | 1260 | [255] |
|
1250 | 1261 | |
|
1251 | 1262 | #endif |
|
1252 | 1263 | |
|
1253 | 1264 | $ hg -R ../issue4455-dest/ bookmarks |
|
1254 | 1265 | no bookmarks set |
|
1255 | 1266 | |
|
1256 | 1267 | $ cd .. |
|
1257 | 1268 | |
|
1258 | 1269 | Test that pre-pushkey compat for bookmark works as expected (issue5777) |
|
1259 | 1270 | |
|
1260 | 1271 | $ cat << EOF >> $HGRCPATH |
|
1261 | 1272 | > [ui] |
|
1262 | 1273 | > ssh="$PYTHON" "$TESTDIR/dummyssh" |
|
1263 | 1274 | > [server] |
|
1264 | 1275 | > bookmarks-pushkey-compat = yes |
|
1265 | 1276 | > EOF |
|
1266 | 1277 | |
|
1267 | 1278 | $ hg init server |
|
1268 | 1279 | $ echo foo > server/a |
|
1269 | 1280 | $ hg -R server book foo |
|
1270 | 1281 | $ hg -R server commit -Am a |
|
1271 | 1282 | adding a |
|
1272 | 1283 | $ hg clone ssh://user@dummy/server client |
|
1273 | 1284 | requesting all changes |
|
1274 | 1285 | adding changesets |
|
1275 | 1286 | adding manifests |
|
1276 | 1287 | adding file changes |
|
1277 | 1288 | added 1 changesets with 1 changes to 1 files |
|
1278 | 1289 | new changesets 79513d0d7716 (1 drafts) |
|
1279 | 1290 | updating to branch default |
|
1280 | 1291 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
1281 | 1292 | |
|
1282 | 1293 | Forbid bookmark move on the server |
|
1283 | 1294 | |
|
1284 | 1295 | $ cat << EOF >> $TESTTMP/no-bm-move.sh |
|
1285 | 1296 | > #!/bin/sh |
|
1286 | 1297 | > echo \$HG_NAMESPACE | grep -v bookmarks |
|
1287 | 1298 | > EOF |
|
1288 | 1299 | $ cat << EOF >> server/.hg/hgrc |
|
1289 | 1300 | > [hooks] |
|
1290 | 1301 | > prepushkey.no-bm-move= sh $TESTTMP/no-bm-move.sh |
|
1291 | 1302 | > EOF |
|
1292 | 1303 | |
|
1293 | 1304 | pushing changeset is okay |
|
1294 | 1305 | |
|
1295 | 1306 | $ echo bar >> client/a |
|
1296 | 1307 | $ hg -R client commit -m b |
|
1297 | 1308 | $ hg -R client push |
|
1298 | 1309 | pushing to ssh://user@dummy/server |
|
1299 | 1310 | searching for changes |
|
1300 | 1311 | remote: adding changesets |
|
1301 | 1312 | remote: adding manifests |
|
1302 | 1313 | remote: adding file changes |
|
1303 | 1314 | remote: added 1 changesets with 1 changes to 1 files |
|
1304 | 1315 | |
|
1305 | 1316 | attempt to move the bookmark is rejected |
|
1306 | 1317 | |
|
1307 | 1318 | $ hg -R client book foo -r . |
|
1308 | 1319 | moving bookmark 'foo' forward from 79513d0d7716 |
|
1309 | 1320 | |
|
1310 | 1321 | #if b2-pushkey |
|
1311 | 1322 | $ hg -R client push |
|
1312 | 1323 | pushing to ssh://user@dummy/server |
|
1313 | 1324 | searching for changes |
|
1314 | 1325 | no changes found |
|
1315 | 1326 | remote: pushkey-abort: prepushkey.no-bm-move hook exited with status 1 |
|
1316 | 1327 | abort: updating bookmark foo failed! |
|
1317 | 1328 | [255] |
|
1318 | 1329 | #endif |
|
1319 | 1330 | #if b2-binary |
|
1320 | 1331 | $ hg -R client push |
|
1321 | 1332 | pushing to ssh://user@dummy/server |
|
1322 | 1333 | searching for changes |
|
1323 | 1334 | no changes found |
|
1324 | 1335 | remote: prepushkey.no-bm-move hook exited with status 1 |
|
1325 | 1336 | abort: push failed on remote |
|
1326 | 1337 | [255] |
|
1327 | 1338 | #endif |
|
1328 | 1339 | |
|
1329 | 1340 | -- test for pushing bookmarks pointing to secret changesets |
|
1330 | 1341 | |
|
1331 | 1342 | Set up a "remote" repo |
|
1332 | 1343 | $ hg init issue6159remote |
|
1333 | 1344 | $ cd issue6159remote |
|
1334 | 1345 | $ echo a > a |
|
1335 | 1346 | $ hg add a |
|
1336 | 1347 | $ hg commit -m_ |
|
1337 | 1348 | $ hg bookmark foo |
|
1338 | 1349 | $ cd .. |
|
1339 | 1350 | |
|
1340 | 1351 | Clone a local repo |
|
1341 | 1352 | $ hg clone -q issue6159remote issue6159local |
|
1342 | 1353 | $ cd issue6159local |
|
1343 | 1354 | $ hg up -qr foo |
|
1344 | 1355 | $ echo b > b |
|
1345 | 1356 | |
|
1346 | 1357 | Move the bookmark "foo" to point at a secret changeset |
|
1347 | 1358 | $ hg commit -qAm_ --config phases.new-commit=secret |
|
1348 | 1359 | |
|
1349 | 1360 | Pushing the bookmark "foo" now fails as it contains a secret changeset |
|
1350 | 1361 | $ hg push -r foo |
|
1351 | 1362 | pushing to $TESTTMP/issue6159remote |
|
1352 | 1363 | searching for changes |
|
1353 | 1364 | no changes found (ignored 1 secret changesets) |
|
1354 | 1365 | abort: cannot push bookmark foo as it points to a secret changeset |
|
1355 | 1366 | [255] |
General Comments 0
You need to be logged in to leave comments.
Login now