##// END OF EJS Templates
hook: schedule run "b2x-transactionclose" for after lock release...
Pierre-Yves David -
r23047:f10019d2 default
parent child Browse files
Show More
@@ -1,1260 +1,1266 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 i18n import _
9 9 from node import hex, nullid
10 10 import errno, urllib
11 11 import util, scmutil, changegroup, base85, error
12 12 import discovery, phases, obsolete, bookmarks as bookmod, bundle2, pushkey
13 13
14 14 def readbundle(ui, fh, fname, vfs=None):
15 15 header = changegroup.readexactly(fh, 4)
16 16
17 17 alg = None
18 18 if not fname:
19 19 fname = "stream"
20 20 if not header.startswith('HG') and header.startswith('\0'):
21 21 fh = changegroup.headerlessfixup(fh, header)
22 22 header = "HG10"
23 23 alg = 'UN'
24 24 elif vfs:
25 25 fname = vfs.join(fname)
26 26
27 27 magic, version = header[0:2], header[2:4]
28 28
29 29 if magic != 'HG':
30 30 raise util.Abort(_('%s: not a Mercurial bundle') % fname)
31 31 if version == '10':
32 32 if alg is None:
33 33 alg = changegroup.readexactly(fh, 2)
34 34 return changegroup.cg1unpacker(fh, alg)
35 35 elif version == '2Y':
36 36 return bundle2.unbundle20(ui, fh, header=magic + version)
37 37 else:
38 38 raise util.Abort(_('%s: unknown bundle version %s') % (fname, version))
39 39
40 40 def buildobsmarkerspart(bundler, markers):
41 41 """add an obsmarker part to the bundler with <markers>
42 42
43 43 No part is created if markers is empty.
44 44 Raises ValueError if the bundler doesn't support any known obsmarker format.
45 45 """
46 46 if markers:
47 47 remoteversions = bundle2.obsmarkersversion(bundler.capabilities)
48 48 version = obsolete.commonversion(remoteversions)
49 49 if version is None:
50 50 raise ValueError('bundler do not support common obsmarker format')
51 51 stream = obsolete.encodemarkers(markers, True, version=version)
52 52 return bundler.newpart('B2X:OBSMARKERS', data=stream)
53 53 return None
54 54
55 55 class pushoperation(object):
56 56 """A object that represent a single push operation
57 57
58 58 It purpose is to carry push related state and very common operation.
59 59
60 60 A new should be created at the beginning of each push and discarded
61 61 afterward.
62 62 """
63 63
64 64 def __init__(self, repo, remote, force=False, revs=None, newbranch=False,
65 65 bookmarks=()):
66 66 # repo we push from
67 67 self.repo = repo
68 68 self.ui = repo.ui
69 69 # repo we push to
70 70 self.remote = remote
71 71 # force option provided
72 72 self.force = force
73 73 # revs to be pushed (None is "all")
74 74 self.revs = revs
75 75 # bookmark explicitly pushed
76 76 self.bookmarks = bookmarks
77 77 # allow push of new branch
78 78 self.newbranch = newbranch
79 79 # did a local lock get acquired?
80 80 self.locallocked = None
81 81 # step already performed
82 82 # (used to check what steps have been already performed through bundle2)
83 83 self.stepsdone = set()
84 84 # Integer version of the changegroup push result
85 85 # - None means nothing to push
86 86 # - 0 means HTTP error
87 87 # - 1 means we pushed and remote head count is unchanged *or*
88 88 # we have outgoing changesets but refused to push
89 89 # - other values as described by addchangegroup()
90 90 self.cgresult = None
91 91 # Boolean value for the bookmark push
92 92 self.bkresult = None
93 93 # discover.outgoing object (contains common and outgoing data)
94 94 self.outgoing = None
95 95 # all remote heads before the push
96 96 self.remoteheads = None
97 97 # testable as a boolean indicating if any nodes are missing locally.
98 98 self.incoming = None
99 99 # phases changes that must be pushed along side the changesets
100 100 self.outdatedphases = None
101 101 # phases changes that must be pushed if changeset push fails
102 102 self.fallbackoutdatedphases = None
103 103 # outgoing obsmarkers
104 104 self.outobsmarkers = set()
105 105 # outgoing bookmarks
106 106 self.outbookmarks = []
107 107
108 108 @util.propertycache
109 109 def futureheads(self):
110 110 """future remote heads if the changeset push succeeds"""
111 111 return self.outgoing.missingheads
112 112
113 113 @util.propertycache
114 114 def fallbackheads(self):
115 115 """future remote heads if the changeset push fails"""
116 116 if self.revs is None:
117 117 # not target to push, all common are relevant
118 118 return self.outgoing.commonheads
119 119 unfi = self.repo.unfiltered()
120 120 # I want cheads = heads(::missingheads and ::commonheads)
121 121 # (missingheads is revs with secret changeset filtered out)
122 122 #
123 123 # This can be expressed as:
124 124 # cheads = ( (missingheads and ::commonheads)
125 125 # + (commonheads and ::missingheads))"
126 126 # )
127 127 #
128 128 # while trying to push we already computed the following:
129 129 # common = (::commonheads)
130 130 # missing = ((commonheads::missingheads) - commonheads)
131 131 #
132 132 # We can pick:
133 133 # * missingheads part of common (::commonheads)
134 134 common = set(self.outgoing.common)
135 135 nm = self.repo.changelog.nodemap
136 136 cheads = [node for node in self.revs if nm[node] in common]
137 137 # and
138 138 # * commonheads parents on missing
139 139 revset = unfi.set('%ln and parents(roots(%ln))',
140 140 self.outgoing.commonheads,
141 141 self.outgoing.missing)
142 142 cheads.extend(c.node() for c in revset)
143 143 return cheads
144 144
145 145 @property
146 146 def commonheads(self):
147 147 """set of all common heads after changeset bundle push"""
148 148 if self.cgresult:
149 149 return self.futureheads
150 150 else:
151 151 return self.fallbackheads
152 152
153 153 # mapping of message used when pushing bookmark
154 154 bookmsgmap = {'update': (_("updating bookmark %s\n"),
155 155 _('updating bookmark %s failed!\n')),
156 156 'export': (_("exporting bookmark %s\n"),
157 157 _('exporting bookmark %s failed!\n')),
158 158 'delete': (_("deleting remote bookmark %s\n"),
159 159 _('deleting remote bookmark %s failed!\n')),
160 160 }
161 161
162 162
163 163 def push(repo, remote, force=False, revs=None, newbranch=False, bookmarks=()):
164 164 '''Push outgoing changesets (limited by revs) from a local
165 165 repository to remote. Return an integer:
166 166 - None means nothing to push
167 167 - 0 means HTTP error
168 168 - 1 means we pushed and remote head count is unchanged *or*
169 169 we have outgoing changesets but refused to push
170 170 - other values as described by addchangegroup()
171 171 '''
172 172 pushop = pushoperation(repo, remote, force, revs, newbranch, bookmarks)
173 173 if pushop.remote.local():
174 174 missing = (set(pushop.repo.requirements)
175 175 - pushop.remote.local().supported)
176 176 if missing:
177 177 msg = _("required features are not"
178 178 " supported in the destination:"
179 179 " %s") % (', '.join(sorted(missing)))
180 180 raise util.Abort(msg)
181 181
182 182 # there are two ways to push to remote repo:
183 183 #
184 184 # addchangegroup assumes local user can lock remote
185 185 # repo (local filesystem, old ssh servers).
186 186 #
187 187 # unbundle assumes local user cannot lock remote repo (new ssh
188 188 # servers, http servers).
189 189
190 190 if not pushop.remote.canpush():
191 191 raise util.Abort(_("destination does not support push"))
192 192 # get local lock as we might write phase data
193 193 locallock = None
194 194 try:
195 195 locallock = pushop.repo.lock()
196 196 pushop.locallocked = True
197 197 except IOError, err:
198 198 pushop.locallocked = False
199 199 if err.errno != errno.EACCES:
200 200 raise
201 201 # source repo cannot be locked.
202 202 # We do not abort the push, but just disable the local phase
203 203 # synchronisation.
204 204 msg = 'cannot lock source repository: %s\n' % err
205 205 pushop.ui.debug(msg)
206 206 try:
207 207 pushop.repo.checkpush(pushop)
208 208 lock = None
209 209 unbundle = pushop.remote.capable('unbundle')
210 210 if not unbundle:
211 211 lock = pushop.remote.lock()
212 212 try:
213 213 _pushdiscovery(pushop)
214 214 if (pushop.repo.ui.configbool('experimental', 'bundle2-exp',
215 215 False)
216 216 and pushop.remote.capable('bundle2-exp')):
217 217 _pushbundle2(pushop)
218 218 _pushchangeset(pushop)
219 219 _pushsyncphase(pushop)
220 220 _pushobsolete(pushop)
221 221 _pushbookmark(pushop)
222 222 finally:
223 223 if lock is not None:
224 224 lock.release()
225 225 finally:
226 226 if locallock is not None:
227 227 locallock.release()
228 228
229 229 return pushop
230 230
231 231 # list of steps to perform discovery before push
232 232 pushdiscoveryorder = []
233 233
234 234 # Mapping between step name and function
235 235 #
236 236 # This exists to help extensions wrap steps if necessary
237 237 pushdiscoverymapping = {}
238 238
239 239 def pushdiscovery(stepname):
240 240 """decorator for function performing discovery before push
241 241
242 242 The function is added to the step -> function mapping and appended to the
243 243 list of steps. Beware that decorated function will be added in order (this
244 244 may matter).
245 245
246 246 You can only use this decorator for a new step, if you want to wrap a step
247 247 from an extension, change the pushdiscovery dictionary directly."""
248 248 def dec(func):
249 249 assert stepname not in pushdiscoverymapping
250 250 pushdiscoverymapping[stepname] = func
251 251 pushdiscoveryorder.append(stepname)
252 252 return func
253 253 return dec
254 254
255 255 def _pushdiscovery(pushop):
256 256 """Run all discovery steps"""
257 257 for stepname in pushdiscoveryorder:
258 258 step = pushdiscoverymapping[stepname]
259 259 step(pushop)
260 260
261 261 @pushdiscovery('changeset')
262 262 def _pushdiscoverychangeset(pushop):
263 263 """discover the changeset that need to be pushed"""
264 264 unfi = pushop.repo.unfiltered()
265 265 fci = discovery.findcommonincoming
266 266 commoninc = fci(unfi, pushop.remote, force=pushop.force)
267 267 common, inc, remoteheads = commoninc
268 268 fco = discovery.findcommonoutgoing
269 269 outgoing = fco(unfi, pushop.remote, onlyheads=pushop.revs,
270 270 commoninc=commoninc, force=pushop.force)
271 271 pushop.outgoing = outgoing
272 272 pushop.remoteheads = remoteheads
273 273 pushop.incoming = inc
274 274
275 275 @pushdiscovery('phase')
276 276 def _pushdiscoveryphase(pushop):
277 277 """discover the phase that needs to be pushed
278 278
279 279 (computed for both success and failure case for changesets push)"""
280 280 outgoing = pushop.outgoing
281 281 unfi = pushop.repo.unfiltered()
282 282 remotephases = pushop.remote.listkeys('phases')
283 283 publishing = remotephases.get('publishing', False)
284 284 ana = phases.analyzeremotephases(pushop.repo,
285 285 pushop.fallbackheads,
286 286 remotephases)
287 287 pheads, droots = ana
288 288 extracond = ''
289 289 if not publishing:
290 290 extracond = ' and public()'
291 291 revset = 'heads((%%ln::%%ln) %s)' % extracond
292 292 # Get the list of all revs draft on remote by public here.
293 293 # XXX Beware that revset break if droots is not strictly
294 294 # XXX root we may want to ensure it is but it is costly
295 295 fallback = list(unfi.set(revset, droots, pushop.fallbackheads))
296 296 if not outgoing.missing:
297 297 future = fallback
298 298 else:
299 299 # adds changeset we are going to push as draft
300 300 #
301 301 # should not be necessary for pushblishing server, but because of an
302 302 # issue fixed in xxxxx we have to do it anyway.
303 303 fdroots = list(unfi.set('roots(%ln + %ln::)',
304 304 outgoing.missing, droots))
305 305 fdroots = [f.node() for f in fdroots]
306 306 future = list(unfi.set(revset, fdroots, pushop.futureheads))
307 307 pushop.outdatedphases = future
308 308 pushop.fallbackoutdatedphases = fallback
309 309
310 310 @pushdiscovery('obsmarker')
311 311 def _pushdiscoveryobsmarkers(pushop):
312 312 if (obsolete.isenabled(pushop.repo, obsolete.exchangeopt)
313 313 and pushop.repo.obsstore
314 314 and 'obsolete' in pushop.remote.listkeys('namespaces')):
315 315 repo = pushop.repo
316 316 # very naive computation, that can be quite expensive on big repo.
317 317 # However: evolution is currently slow on them anyway.
318 318 nodes = (c.node() for c in repo.set('::%ln', pushop.futureheads))
319 319 pushop.outobsmarkers = pushop.repo.obsstore.relevantmarkers(nodes)
320 320
321 321 @pushdiscovery('bookmarks')
322 322 def _pushdiscoverybookmarks(pushop):
323 323 ui = pushop.ui
324 324 repo = pushop.repo.unfiltered()
325 325 remote = pushop.remote
326 326 ui.debug("checking for updated bookmarks\n")
327 327 ancestors = ()
328 328 if pushop.revs:
329 329 revnums = map(repo.changelog.rev, pushop.revs)
330 330 ancestors = repo.changelog.ancestors(revnums, inclusive=True)
331 331 remotebookmark = remote.listkeys('bookmarks')
332 332
333 333 explicit = set(pushop.bookmarks)
334 334
335 335 comp = bookmod.compare(repo, repo._bookmarks, remotebookmark, srchex=hex)
336 336 addsrc, adddst, advsrc, advdst, diverge, differ, invalid = comp
337 337 for b, scid, dcid in advsrc:
338 338 if b in explicit:
339 339 explicit.remove(b)
340 340 if not ancestors or repo[scid].rev() in ancestors:
341 341 pushop.outbookmarks.append((b, dcid, scid))
342 342 # search added bookmark
343 343 for b, scid, dcid in addsrc:
344 344 if b in explicit:
345 345 explicit.remove(b)
346 346 pushop.outbookmarks.append((b, '', scid))
347 347 # search for overwritten bookmark
348 348 for b, scid, dcid in advdst + diverge + differ:
349 349 if b in explicit:
350 350 explicit.remove(b)
351 351 pushop.outbookmarks.append((b, dcid, scid))
352 352 # search for bookmark to delete
353 353 for b, scid, dcid in adddst:
354 354 if b in explicit:
355 355 explicit.remove(b)
356 356 # treat as "deleted locally"
357 357 pushop.outbookmarks.append((b, dcid, ''))
358 358
359 359 if explicit:
360 360 explicit = sorted(explicit)
361 361 # we should probably list all of them
362 362 ui.warn(_('bookmark %s does not exist on the local '
363 363 'or remote repository!\n') % explicit[0])
364 364 pushop.bkresult = 2
365 365
366 366 pushop.outbookmarks.sort()
367 367
368 368 def _pushcheckoutgoing(pushop):
369 369 outgoing = pushop.outgoing
370 370 unfi = pushop.repo.unfiltered()
371 371 if not outgoing.missing:
372 372 # nothing to push
373 373 scmutil.nochangesfound(unfi.ui, unfi, outgoing.excluded)
374 374 return False
375 375 # something to push
376 376 if not pushop.force:
377 377 # if repo.obsstore == False --> no obsolete
378 378 # then, save the iteration
379 379 if unfi.obsstore:
380 380 # this message are here for 80 char limit reason
381 381 mso = _("push includes obsolete changeset: %s!")
382 382 mst = {"unstable": _("push includes unstable changeset: %s!"),
383 383 "bumped": _("push includes bumped changeset: %s!"),
384 384 "divergent": _("push includes divergent changeset: %s!")}
385 385 # If we are to push if there is at least one
386 386 # obsolete or unstable changeset in missing, at
387 387 # least one of the missinghead will be obsolete or
388 388 # unstable. So checking heads only is ok
389 389 for node in outgoing.missingheads:
390 390 ctx = unfi[node]
391 391 if ctx.obsolete():
392 392 raise util.Abort(mso % ctx)
393 393 elif ctx.troubled():
394 394 raise util.Abort(mst[ctx.troubles()[0]] % ctx)
395 395 newbm = pushop.ui.configlist('bookmarks', 'pushing')
396 396 discovery.checkheads(unfi, pushop.remote, outgoing,
397 397 pushop.remoteheads,
398 398 pushop.newbranch,
399 399 bool(pushop.incoming),
400 400 newbm)
401 401 return True
402 402
403 403 # List of names of steps to perform for an outgoing bundle2, order matters.
404 404 b2partsgenorder = []
405 405
406 406 # Mapping between step name and function
407 407 #
408 408 # This exists to help extensions wrap steps if necessary
409 409 b2partsgenmapping = {}
410 410
411 411 def b2partsgenerator(stepname):
412 412 """decorator for function generating bundle2 part
413 413
414 414 The function is added to the step -> function mapping and appended to the
415 415 list of steps. Beware that decorated functions will be added in order
416 416 (this may matter).
417 417
418 418 You can only use this decorator for new steps, if you want to wrap a step
419 419 from an extension, attack the b2partsgenmapping dictionary directly."""
420 420 def dec(func):
421 421 assert stepname not in b2partsgenmapping
422 422 b2partsgenmapping[stepname] = func
423 423 b2partsgenorder.append(stepname)
424 424 return func
425 425 return dec
426 426
427 427 @b2partsgenerator('changeset')
428 428 def _pushb2ctx(pushop, bundler):
429 429 """handle changegroup push through bundle2
430 430
431 431 addchangegroup result is stored in the ``pushop.cgresult`` attribute.
432 432 """
433 433 if 'changesets' in pushop.stepsdone:
434 434 return
435 435 pushop.stepsdone.add('changesets')
436 436 # Send known heads to the server for race detection.
437 437 if not _pushcheckoutgoing(pushop):
438 438 return
439 439 pushop.repo.prepushoutgoinghooks(pushop.repo,
440 440 pushop.remote,
441 441 pushop.outgoing)
442 442 if not pushop.force:
443 443 bundler.newpart('B2X:CHECK:HEADS', data=iter(pushop.remoteheads))
444 444 cg = changegroup.getlocalchangegroup(pushop.repo, 'push', pushop.outgoing)
445 445 cgpart = bundler.newpart('B2X:CHANGEGROUP', data=cg.getchunks())
446 446 def handlereply(op):
447 447 """extract addchangroup returns from server reply"""
448 448 cgreplies = op.records.getreplies(cgpart.id)
449 449 assert len(cgreplies['changegroup']) == 1
450 450 pushop.cgresult = cgreplies['changegroup'][0]['return']
451 451 return handlereply
452 452
453 453 @b2partsgenerator('phase')
454 454 def _pushb2phases(pushop, bundler):
455 455 """handle phase push through bundle2"""
456 456 if 'phases' in pushop.stepsdone:
457 457 return
458 458 b2caps = bundle2.bundle2caps(pushop.remote)
459 459 if not 'b2x:pushkey' in b2caps:
460 460 return
461 461 pushop.stepsdone.add('phases')
462 462 part2node = []
463 463 enc = pushkey.encode
464 464 for newremotehead in pushop.outdatedphases:
465 465 part = bundler.newpart('b2x:pushkey')
466 466 part.addparam('namespace', enc('phases'))
467 467 part.addparam('key', enc(newremotehead.hex()))
468 468 part.addparam('old', enc(str(phases.draft)))
469 469 part.addparam('new', enc(str(phases.public)))
470 470 part2node.append((part.id, newremotehead))
471 471 def handlereply(op):
472 472 for partid, node in part2node:
473 473 partrep = op.records.getreplies(partid)
474 474 results = partrep['pushkey']
475 475 assert len(results) <= 1
476 476 msg = None
477 477 if not results:
478 478 msg = _('server ignored update of %s to public!\n') % node
479 479 elif not int(results[0]['return']):
480 480 msg = _('updating %s to public failed!\n') % node
481 481 if msg is not None:
482 482 pushop.ui.warn(msg)
483 483 return handlereply
484 484
485 485 @b2partsgenerator('obsmarkers')
486 486 def _pushb2obsmarkers(pushop, bundler):
487 487 if 'obsmarkers' in pushop.stepsdone:
488 488 return
489 489 remoteversions = bundle2.obsmarkersversion(bundler.capabilities)
490 490 if obsolete.commonversion(remoteversions) is None:
491 491 return
492 492 pushop.stepsdone.add('obsmarkers')
493 493 if pushop.outobsmarkers:
494 494 buildobsmarkerspart(bundler, pushop.outobsmarkers)
495 495
496 496 @b2partsgenerator('bookmarks')
497 497 def _pushb2bookmarks(pushop, bundler):
498 498 """handle phase push through bundle2"""
499 499 if 'bookmarks' in pushop.stepsdone:
500 500 return
501 501 b2caps = bundle2.bundle2caps(pushop.remote)
502 502 if 'b2x:pushkey' not in b2caps:
503 503 return
504 504 pushop.stepsdone.add('bookmarks')
505 505 part2book = []
506 506 enc = pushkey.encode
507 507 for book, old, new in pushop.outbookmarks:
508 508 part = bundler.newpart('b2x:pushkey')
509 509 part.addparam('namespace', enc('bookmarks'))
510 510 part.addparam('key', enc(book))
511 511 part.addparam('old', enc(old))
512 512 part.addparam('new', enc(new))
513 513 action = 'update'
514 514 if not old:
515 515 action = 'export'
516 516 elif not new:
517 517 action = 'delete'
518 518 part2book.append((part.id, book, action))
519 519
520 520
521 521 def handlereply(op):
522 522 ui = pushop.ui
523 523 for partid, book, action in part2book:
524 524 partrep = op.records.getreplies(partid)
525 525 results = partrep['pushkey']
526 526 assert len(results) <= 1
527 527 if not results:
528 528 pushop.ui.warn(_('server ignored bookmark %s update\n') % book)
529 529 else:
530 530 ret = int(results[0]['return'])
531 531 if ret:
532 532 ui.status(bookmsgmap[action][0] % book)
533 533 else:
534 534 ui.warn(bookmsgmap[action][1] % book)
535 535 if pushop.bkresult is not None:
536 536 pushop.bkresult = 1
537 537 return handlereply
538 538
539 539
540 540 def _pushbundle2(pushop):
541 541 """push data to the remote using bundle2
542 542
543 543 The only currently supported type of data is changegroup but this will
544 544 evolve in the future."""
545 545 bundler = bundle2.bundle20(pushop.ui, bundle2.bundle2caps(pushop.remote))
546 546 # create reply capability
547 547 capsblob = bundle2.encodecaps(bundle2.getrepocaps(pushop.repo))
548 548 bundler.newpart('b2x:replycaps', data=capsblob)
549 549 replyhandlers = []
550 550 for partgenname in b2partsgenorder:
551 551 partgen = b2partsgenmapping[partgenname]
552 552 ret = partgen(pushop, bundler)
553 553 if callable(ret):
554 554 replyhandlers.append(ret)
555 555 # do not push if nothing to push
556 556 if bundler.nbparts <= 1:
557 557 return
558 558 stream = util.chunkbuffer(bundler.getchunks())
559 559 try:
560 560 reply = pushop.remote.unbundle(stream, ['force'], 'push')
561 561 except error.BundleValueError, exc:
562 562 raise util.Abort('missing support for %s' % exc)
563 563 try:
564 564 op = bundle2.processbundle(pushop.repo, reply)
565 565 except error.BundleValueError, exc:
566 566 raise util.Abort('missing support for %s' % exc)
567 567 for rephand in replyhandlers:
568 568 rephand(op)
569 569
570 570 def _pushchangeset(pushop):
571 571 """Make the actual push of changeset bundle to remote repo"""
572 572 if 'changesets' in pushop.stepsdone:
573 573 return
574 574 pushop.stepsdone.add('changesets')
575 575 if not _pushcheckoutgoing(pushop):
576 576 return
577 577 pushop.repo.prepushoutgoinghooks(pushop.repo,
578 578 pushop.remote,
579 579 pushop.outgoing)
580 580 outgoing = pushop.outgoing
581 581 unbundle = pushop.remote.capable('unbundle')
582 582 # TODO: get bundlecaps from remote
583 583 bundlecaps = None
584 584 # create a changegroup from local
585 585 if pushop.revs is None and not (outgoing.excluded
586 586 or pushop.repo.changelog.filteredrevs):
587 587 # push everything,
588 588 # use the fast path, no race possible on push
589 589 bundler = changegroup.cg1packer(pushop.repo, bundlecaps)
590 590 cg = changegroup.getsubset(pushop.repo,
591 591 outgoing,
592 592 bundler,
593 593 'push',
594 594 fastpath=True)
595 595 else:
596 596 cg = changegroup.getlocalchangegroup(pushop.repo, 'push', outgoing,
597 597 bundlecaps)
598 598
599 599 # apply changegroup to remote
600 600 if unbundle:
601 601 # local repo finds heads on server, finds out what
602 602 # revs it must push. once revs transferred, if server
603 603 # finds it has different heads (someone else won
604 604 # commit/push race), server aborts.
605 605 if pushop.force:
606 606 remoteheads = ['force']
607 607 else:
608 608 remoteheads = pushop.remoteheads
609 609 # ssh: return remote's addchangegroup()
610 610 # http: return remote's addchangegroup() or 0 for error
611 611 pushop.cgresult = pushop.remote.unbundle(cg, remoteheads,
612 612 pushop.repo.url())
613 613 else:
614 614 # we return an integer indicating remote head count
615 615 # change
616 616 pushop.cgresult = pushop.remote.addchangegroup(cg, 'push',
617 617 pushop.repo.url())
618 618
619 619 def _pushsyncphase(pushop):
620 620 """synchronise phase information locally and remotely"""
621 621 cheads = pushop.commonheads
622 622 # even when we don't push, exchanging phase data is useful
623 623 remotephases = pushop.remote.listkeys('phases')
624 624 if (pushop.ui.configbool('ui', '_usedassubrepo', False)
625 625 and remotephases # server supports phases
626 626 and pushop.cgresult is None # nothing was pushed
627 627 and remotephases.get('publishing', False)):
628 628 # When:
629 629 # - this is a subrepo push
630 630 # - and remote support phase
631 631 # - and no changeset was pushed
632 632 # - and remote is publishing
633 633 # We may be in issue 3871 case!
634 634 # We drop the possible phase synchronisation done by
635 635 # courtesy to publish changesets possibly locally draft
636 636 # on the remote.
637 637 remotephases = {'publishing': 'True'}
638 638 if not remotephases: # old server or public only reply from non-publishing
639 639 _localphasemove(pushop, cheads)
640 640 # don't push any phase data as there is nothing to push
641 641 else:
642 642 ana = phases.analyzeremotephases(pushop.repo, cheads,
643 643 remotephases)
644 644 pheads, droots = ana
645 645 ### Apply remote phase on local
646 646 if remotephases.get('publishing', False):
647 647 _localphasemove(pushop, cheads)
648 648 else: # publish = False
649 649 _localphasemove(pushop, pheads)
650 650 _localphasemove(pushop, cheads, phases.draft)
651 651 ### Apply local phase on remote
652 652
653 653 if pushop.cgresult:
654 654 if 'phases' in pushop.stepsdone:
655 655 # phases already pushed though bundle2
656 656 return
657 657 outdated = pushop.outdatedphases
658 658 else:
659 659 outdated = pushop.fallbackoutdatedphases
660 660
661 661 pushop.stepsdone.add('phases')
662 662
663 663 # filter heads already turned public by the push
664 664 outdated = [c for c in outdated if c.node() not in pheads]
665 665 b2caps = bundle2.bundle2caps(pushop.remote)
666 666 if 'b2x:pushkey' in b2caps:
667 667 # server supports bundle2, let's do a batched push through it
668 668 #
669 669 # This will eventually be unified with the changesets bundle2 push
670 670 bundler = bundle2.bundle20(pushop.ui, b2caps)
671 671 capsblob = bundle2.encodecaps(bundle2.getrepocaps(pushop.repo))
672 672 bundler.newpart('b2x:replycaps', data=capsblob)
673 673 part2node = []
674 674 enc = pushkey.encode
675 675 for newremotehead in outdated:
676 676 part = bundler.newpart('b2x:pushkey')
677 677 part.addparam('namespace', enc('phases'))
678 678 part.addparam('key', enc(newremotehead.hex()))
679 679 part.addparam('old', enc(str(phases.draft)))
680 680 part.addparam('new', enc(str(phases.public)))
681 681 part2node.append((part.id, newremotehead))
682 682 stream = util.chunkbuffer(bundler.getchunks())
683 683 try:
684 684 reply = pushop.remote.unbundle(stream, ['force'], 'push')
685 685 op = bundle2.processbundle(pushop.repo, reply)
686 686 except error.BundleValueError, exc:
687 687 raise util.Abort('missing support for %s' % exc)
688 688 for partid, node in part2node:
689 689 partrep = op.records.getreplies(partid)
690 690 results = partrep['pushkey']
691 691 assert len(results) <= 1
692 692 msg = None
693 693 if not results:
694 694 msg = _('server ignored update of %s to public!\n') % node
695 695 elif not int(results[0]['return']):
696 696 msg = _('updating %s to public failed!\n') % node
697 697 if msg is not None:
698 698 pushop.ui.warn(msg)
699 699
700 700 else:
701 701 # fallback to independant pushkey command
702 702 for newremotehead in outdated:
703 703 r = pushop.remote.pushkey('phases',
704 704 newremotehead.hex(),
705 705 str(phases.draft),
706 706 str(phases.public))
707 707 if not r:
708 708 pushop.ui.warn(_('updating %s to public failed!\n')
709 709 % newremotehead)
710 710
711 711 def _localphasemove(pushop, nodes, phase=phases.public):
712 712 """move <nodes> to <phase> in the local source repo"""
713 713 if pushop.locallocked:
714 714 tr = pushop.repo.transaction('push-phase-sync')
715 715 try:
716 716 phases.advanceboundary(pushop.repo, tr, phase, nodes)
717 717 tr.close()
718 718 finally:
719 719 tr.release()
720 720 else:
721 721 # repo is not locked, do not change any phases!
722 722 # Informs the user that phases should have been moved when
723 723 # applicable.
724 724 actualmoves = [n for n in nodes if phase < pushop.repo[n].phase()]
725 725 phasestr = phases.phasenames[phase]
726 726 if actualmoves:
727 727 pushop.ui.status(_('cannot lock source repo, skipping '
728 728 'local %s phase update\n') % phasestr)
729 729
730 730 def _pushobsolete(pushop):
731 731 """utility function to push obsolete markers to a remote"""
732 732 if 'obsmarkers' in pushop.stepsdone:
733 733 return
734 734 pushop.ui.debug('try to push obsolete markers to remote\n')
735 735 repo = pushop.repo
736 736 remote = pushop.remote
737 737 pushop.stepsdone.add('obsmarkers')
738 738 if pushop.outobsmarkers:
739 739 rslts = []
740 740 remotedata = obsolete._pushkeyescape(pushop.outobsmarkers)
741 741 for key in sorted(remotedata, reverse=True):
742 742 # reverse sort to ensure we end with dump0
743 743 data = remotedata[key]
744 744 rslts.append(remote.pushkey('obsolete', key, '', data))
745 745 if [r for r in rslts if not r]:
746 746 msg = _('failed to push some obsolete markers!\n')
747 747 repo.ui.warn(msg)
748 748
749 749 def _pushbookmark(pushop):
750 750 """Update bookmark position on remote"""
751 751 if pushop.cgresult == 0 or 'bookmarks' in pushop.stepsdone:
752 752 return
753 753 pushop.stepsdone.add('bookmarks')
754 754 ui = pushop.ui
755 755 remote = pushop.remote
756 756
757 757 for b, old, new in pushop.outbookmarks:
758 758 action = 'update'
759 759 if not old:
760 760 action = 'export'
761 761 elif not new:
762 762 action = 'delete'
763 763 if remote.pushkey('bookmarks', b, old, new):
764 764 ui.status(bookmsgmap[action][0] % b)
765 765 else:
766 766 ui.warn(bookmsgmap[action][1] % b)
767 767 # discovery can have set the value form invalid entry
768 768 if pushop.bkresult is not None:
769 769 pushop.bkresult = 1
770 770
771 771 class pulloperation(object):
772 772 """A object that represent a single pull operation
773 773
774 774 It purpose is to carry push related state and very common operation.
775 775
776 776 A new should be created at the beginning of each pull and discarded
777 777 afterward.
778 778 """
779 779
780 780 def __init__(self, repo, remote, heads=None, force=False, bookmarks=()):
781 781 # repo we pull into
782 782 self.repo = repo
783 783 # repo we pull from
784 784 self.remote = remote
785 785 # revision we try to pull (None is "all")
786 786 self.heads = heads
787 787 # bookmark pulled explicitly
788 788 self.explicitbookmarks = bookmarks
789 789 # do we force pull?
790 790 self.force = force
791 791 # the name the pull transaction
792 792 self._trname = 'pull\n' + util.hidepassword(remote.url())
793 793 # hold the transaction once created
794 794 self._tr = None
795 795 # set of common changeset between local and remote before pull
796 796 self.common = None
797 797 # set of pulled head
798 798 self.rheads = None
799 799 # list of missing changeset to fetch remotely
800 800 self.fetch = None
801 801 # remote bookmarks data
802 802 self.remotebookmarks = None
803 803 # result of changegroup pulling (used as return code by pull)
804 804 self.cgresult = None
805 805 # list of step already done
806 806 self.stepsdone = set()
807 807
808 808 @util.propertycache
809 809 def pulledsubset(self):
810 810 """heads of the set of changeset target by the pull"""
811 811 # compute target subset
812 812 if self.heads is None:
813 813 # We pulled every thing possible
814 814 # sync on everything common
815 815 c = set(self.common)
816 816 ret = list(self.common)
817 817 for n in self.rheads:
818 818 if n not in c:
819 819 ret.append(n)
820 820 return ret
821 821 else:
822 822 # We pulled a specific subset
823 823 # sync on this subset
824 824 return self.heads
825 825
826 826 def gettransaction(self):
827 827 """get appropriate pull transaction, creating it if needed"""
828 828 if self._tr is None:
829 829 self._tr = self.repo.transaction(self._trname)
830 830 self._tr.hookargs['source'] = 'pull'
831 831 self._tr.hookargs['url'] = self.remote.url()
832 832 return self._tr
833 833
834 834 def closetransaction(self):
835 835 """close transaction if created"""
836 836 if self._tr is not None:
837 837 repo = self.repo
838 838 cl = repo.unfiltered().changelog
839 839 p = cl.writepending() and repo.root or ""
840 840 p = cl.writepending() and repo.root or ""
841 841 repo.hook('b2x-pretransactionclose', throw=True, pending=p,
842 842 **self._tr.hookargs)
843 843 self._tr.close()
844 repo.hook('b2x-transactionclose', **self._tr.hookargs)
844 hookargs = dict(self._tr.hookargs)
845 def runhooks():
846 repo.hook('b2x-transactionclose', **hookargs)
847 repo._afterlock(runhooks)
845 848
846 849 def releasetransaction(self):
847 850 """release transaction if created"""
848 851 if self._tr is not None:
849 852 self._tr.release()
850 853
851 854 def pull(repo, remote, heads=None, force=False, bookmarks=()):
852 855 pullop = pulloperation(repo, remote, heads, force, bookmarks=bookmarks)
853 856 if pullop.remote.local():
854 857 missing = set(pullop.remote.requirements) - pullop.repo.supported
855 858 if missing:
856 859 msg = _("required features are not"
857 860 " supported in the destination:"
858 861 " %s") % (', '.join(sorted(missing)))
859 862 raise util.Abort(msg)
860 863
861 864 pullop.remotebookmarks = remote.listkeys('bookmarks')
862 865 lock = pullop.repo.lock()
863 866 try:
864 867 _pulldiscovery(pullop)
865 868 if (pullop.repo.ui.configbool('experimental', 'bundle2-exp', False)
866 869 and pullop.remote.capable('bundle2-exp')):
867 870 _pullbundle2(pullop)
868 871 _pullchangeset(pullop)
869 872 _pullphase(pullop)
870 873 _pullbookmarks(pullop)
871 874 _pullobsolete(pullop)
872 875 pullop.closetransaction()
873 876 finally:
874 877 pullop.releasetransaction()
875 878 lock.release()
876 879
877 880 return pullop
878 881
879 882 # list of steps to perform discovery before pull
880 883 pulldiscoveryorder = []
881 884
882 885 # Mapping between step name and function
883 886 #
884 887 # This exists to help extensions wrap steps if necessary
885 888 pulldiscoverymapping = {}
886 889
887 890 def pulldiscovery(stepname):
888 891 """decorator for function performing discovery before pull
889 892
890 893 The function is added to the step -> function mapping and appended to the
891 894 list of steps. Beware that decorated function will be added in order (this
892 895 may matter).
893 896
894 897 You can only use this decorator for a new step, if you want to wrap a step
895 898 from an extension, change the pulldiscovery dictionary directly."""
896 899 def dec(func):
897 900 assert stepname not in pulldiscoverymapping
898 901 pulldiscoverymapping[stepname] = func
899 902 pulldiscoveryorder.append(stepname)
900 903 return func
901 904 return dec
902 905
903 906 def _pulldiscovery(pullop):
904 907 """Run all discovery steps"""
905 908 for stepname in pulldiscoveryorder:
906 909 step = pulldiscoverymapping[stepname]
907 910 step(pullop)
908 911
909 912 @pulldiscovery('changegroup')
910 913 def _pulldiscoverychangegroup(pullop):
911 914 """discovery phase for the pull
912 915
913 916 Current handle changeset discovery only, will change handle all discovery
914 917 at some point."""
915 918 tmp = discovery.findcommonincoming(pullop.repo.unfiltered(),
916 919 pullop.remote,
917 920 heads=pullop.heads,
918 921 force=pullop.force)
919 922 pullop.common, pullop.fetch, pullop.rheads = tmp
920 923
921 924 def _pullbundle2(pullop):
922 925 """pull data using bundle2
923 926
924 927 For now, the only supported data are changegroup."""
925 928 remotecaps = bundle2.bundle2caps(pullop.remote)
926 929 kwargs = {'bundlecaps': caps20to10(pullop.repo)}
927 930 # pulling changegroup
928 931 pullop.stepsdone.add('changegroup')
929 932
930 933 kwargs['common'] = pullop.common
931 934 kwargs['heads'] = pullop.heads or pullop.rheads
932 935 kwargs['cg'] = pullop.fetch
933 936 if 'b2x:listkeys' in remotecaps:
934 937 kwargs['listkeys'] = ['phase', 'bookmarks']
935 938 if not pullop.fetch:
936 939 pullop.repo.ui.status(_("no changes found\n"))
937 940 pullop.cgresult = 0
938 941 else:
939 942 if pullop.heads is None and list(pullop.common) == [nullid]:
940 943 pullop.repo.ui.status(_("requesting all changes\n"))
941 944 if obsolete.isenabled(pullop.repo, obsolete.exchangeopt):
942 945 remoteversions = bundle2.obsmarkersversion(remotecaps)
943 946 if obsolete.commonversion(remoteversions) is not None:
944 947 kwargs['obsmarkers'] = True
945 948 pullop.stepsdone.add('obsmarkers')
946 949 _pullbundle2extraprepare(pullop, kwargs)
947 950 if kwargs.keys() == ['format']:
948 951 return # nothing to pull
949 952 bundle = pullop.remote.getbundle('pull', **kwargs)
950 953 try:
951 954 op = bundle2.processbundle(pullop.repo, bundle, pullop.gettransaction)
952 955 except error.BundleValueError, exc:
953 956 raise util.Abort('missing support for %s' % exc)
954 957
955 958 if pullop.fetch:
956 959 changedheads = 0
957 960 pullop.cgresult = 1
958 961 for cg in op.records['changegroup']:
959 962 ret = cg['return']
960 963 # If any changegroup result is 0, return 0
961 964 if ret == 0:
962 965 pullop.cgresult = 0
963 966 break
964 967 if ret < -1:
965 968 changedheads += ret + 1
966 969 elif ret > 1:
967 970 changedheads += ret - 1
968 971 if changedheads > 0:
969 972 pullop.cgresult = 1 + changedheads
970 973 elif changedheads < 0:
971 974 pullop.cgresult = -1 + changedheads
972 975
973 976 # processing phases change
974 977 for namespace, value in op.records['listkeys']:
975 978 if namespace == 'phases':
976 979 _pullapplyphases(pullop, value)
977 980
978 981 # processing bookmark update
979 982 for namespace, value in op.records['listkeys']:
980 983 if namespace == 'bookmarks':
981 984 pullop.remotebookmarks = value
982 985 _pullbookmarks(pullop)
983 986
984 987 def _pullbundle2extraprepare(pullop, kwargs):
985 988 """hook function so that extensions can extend the getbundle call"""
986 989 pass
987 990
988 991 def _pullchangeset(pullop):
989 992 """pull changeset from unbundle into the local repo"""
990 993 # We delay the open of the transaction as late as possible so we
991 994 # don't open transaction for nothing or you break future useful
992 995 # rollback call
993 996 if 'changegroup' in pullop.stepsdone:
994 997 return
995 998 pullop.stepsdone.add('changegroup')
996 999 if not pullop.fetch:
997 1000 pullop.repo.ui.status(_("no changes found\n"))
998 1001 pullop.cgresult = 0
999 1002 return
1000 1003 pullop.gettransaction()
1001 1004 if pullop.heads is None and list(pullop.common) == [nullid]:
1002 1005 pullop.repo.ui.status(_("requesting all changes\n"))
1003 1006 elif pullop.heads is None and pullop.remote.capable('changegroupsubset'):
1004 1007 # issue1320, avoid a race if remote changed after discovery
1005 1008 pullop.heads = pullop.rheads
1006 1009
1007 1010 if pullop.remote.capable('getbundle'):
1008 1011 # TODO: get bundlecaps from remote
1009 1012 cg = pullop.remote.getbundle('pull', common=pullop.common,
1010 1013 heads=pullop.heads or pullop.rheads)
1011 1014 elif pullop.heads is None:
1012 1015 cg = pullop.remote.changegroup(pullop.fetch, 'pull')
1013 1016 elif not pullop.remote.capable('changegroupsubset'):
1014 1017 raise util.Abort(_("partial pull cannot be done because "
1015 1018 "other repository doesn't support "
1016 1019 "changegroupsubset."))
1017 1020 else:
1018 1021 cg = pullop.remote.changegroupsubset(pullop.fetch, pullop.heads, 'pull')
1019 1022 pullop.cgresult = changegroup.addchangegroup(pullop.repo, cg, 'pull',
1020 1023 pullop.remote.url())
1021 1024
1022 1025 def _pullphase(pullop):
1023 1026 # Get remote phases data from remote
1024 1027 if 'phases' in pullop.stepsdone:
1025 1028 return
1026 1029 remotephases = pullop.remote.listkeys('phases')
1027 1030 _pullapplyphases(pullop, remotephases)
1028 1031
1029 1032 def _pullapplyphases(pullop, remotephases):
1030 1033 """apply phase movement from observed remote state"""
1031 1034 if 'phases' in pullop.stepsdone:
1032 1035 return
1033 1036 pullop.stepsdone.add('phases')
1034 1037 publishing = bool(remotephases.get('publishing', False))
1035 1038 if remotephases and not publishing:
1036 1039 # remote is new and unpublishing
1037 1040 pheads, _dr = phases.analyzeremotephases(pullop.repo,
1038 1041 pullop.pulledsubset,
1039 1042 remotephases)
1040 1043 dheads = pullop.pulledsubset
1041 1044 else:
1042 1045 # Remote is old or publishing all common changesets
1043 1046 # should be seen as public
1044 1047 pheads = pullop.pulledsubset
1045 1048 dheads = []
1046 1049 unfi = pullop.repo.unfiltered()
1047 1050 phase = unfi._phasecache.phase
1048 1051 rev = unfi.changelog.nodemap.get
1049 1052 public = phases.public
1050 1053 draft = phases.draft
1051 1054
1052 1055 # exclude changesets already public locally and update the others
1053 1056 pheads = [pn for pn in pheads if phase(unfi, rev(pn)) > public]
1054 1057 if pheads:
1055 1058 tr = pullop.gettransaction()
1056 1059 phases.advanceboundary(pullop.repo, tr, public, pheads)
1057 1060
1058 1061 # exclude changesets already draft locally and update the others
1059 1062 dheads = [pn for pn in dheads if phase(unfi, rev(pn)) > draft]
1060 1063 if dheads:
1061 1064 tr = pullop.gettransaction()
1062 1065 phases.advanceboundary(pullop.repo, tr, draft, dheads)
1063 1066
1064 1067 def _pullbookmarks(pullop):
1065 1068 """process the remote bookmark information to update the local one"""
1066 1069 if 'bookmarks' in pullop.stepsdone:
1067 1070 return
1068 1071 pullop.stepsdone.add('bookmarks')
1069 1072 repo = pullop.repo
1070 1073 remotebookmarks = pullop.remotebookmarks
1071 1074 bookmod.updatefromremote(repo.ui, repo, remotebookmarks,
1072 1075 pullop.remote.url(),
1073 1076 pullop.gettransaction,
1074 1077 explicit=pullop.explicitbookmarks)
1075 1078
1076 1079 def _pullobsolete(pullop):
1077 1080 """utility function to pull obsolete markers from a remote
1078 1081
1079 1082 The `gettransaction` is function that return the pull transaction, creating
1080 1083 one if necessary. We return the transaction to inform the calling code that
1081 1084 a new transaction have been created (when applicable).
1082 1085
1083 1086 Exists mostly to allow overriding for experimentation purpose"""
1084 1087 if 'obsmarkers' in pullop.stepsdone:
1085 1088 return
1086 1089 pullop.stepsdone.add('obsmarkers')
1087 1090 tr = None
1088 1091 if obsolete.isenabled(pullop.repo, obsolete.exchangeopt):
1089 1092 pullop.repo.ui.debug('fetching remote obsolete markers\n')
1090 1093 remoteobs = pullop.remote.listkeys('obsolete')
1091 1094 if 'dump0' in remoteobs:
1092 1095 tr = pullop.gettransaction()
1093 1096 for key in sorted(remoteobs, reverse=True):
1094 1097 if key.startswith('dump'):
1095 1098 data = base85.b85decode(remoteobs[key])
1096 1099 pullop.repo.obsstore.mergemarkers(tr, data)
1097 1100 pullop.repo.invalidatevolatilesets()
1098 1101 return tr
1099 1102
1100 1103 def caps20to10(repo):
1101 1104 """return a set with appropriate options to use bundle20 during getbundle"""
1102 1105 caps = set(['HG2Y'])
1103 1106 capsblob = bundle2.encodecaps(bundle2.getrepocaps(repo))
1104 1107 caps.add('bundle2=' + urllib.quote(capsblob))
1105 1108 return caps
1106 1109
1107 1110 # List of names of steps to perform for a bundle2 for getbundle, order matters.
1108 1111 getbundle2partsorder = []
1109 1112
1110 1113 # Mapping between step name and function
1111 1114 #
1112 1115 # This exists to help extensions wrap steps if necessary
1113 1116 getbundle2partsmapping = {}
1114 1117
1115 1118 def getbundle2partsgenerator(stepname):
1116 1119 """decorator for function generating bundle2 part for getbundle
1117 1120
1118 1121 The function is added to the step -> function mapping and appended to the
1119 1122 list of steps. Beware that decorated functions will be added in order
1120 1123 (this may matter).
1121 1124
1122 1125 You can only use this decorator for new steps, if you want to wrap a step
1123 1126 from an extension, attack the getbundle2partsmapping dictionary directly."""
1124 1127 def dec(func):
1125 1128 assert stepname not in getbundle2partsmapping
1126 1129 getbundle2partsmapping[stepname] = func
1127 1130 getbundle2partsorder.append(stepname)
1128 1131 return func
1129 1132 return dec
1130 1133
1131 1134 def getbundle(repo, source, heads=None, common=None, bundlecaps=None,
1132 1135 **kwargs):
1133 1136 """return a full bundle (with potentially multiple kind of parts)
1134 1137
1135 1138 Could be a bundle HG10 or a bundle HG2Y depending on bundlecaps
1136 1139 passed. For now, the bundle can contain only changegroup, but this will
1137 1140 changes when more part type will be available for bundle2.
1138 1141
1139 1142 This is different from changegroup.getchangegroup that only returns an HG10
1140 1143 changegroup bundle. They may eventually get reunited in the future when we
1141 1144 have a clearer idea of the API we what to query different data.
1142 1145
1143 1146 The implementation is at a very early stage and will get massive rework
1144 1147 when the API of bundle is refined.
1145 1148 """
1146 1149 # bundle10 case
1147 1150 if bundlecaps is None or 'HG2Y' not in bundlecaps:
1148 1151 if bundlecaps and not kwargs.get('cg', True):
1149 1152 raise ValueError(_('request for bundle10 must include changegroup'))
1150 1153
1151 1154 if kwargs:
1152 1155 raise ValueError(_('unsupported getbundle arguments: %s')
1153 1156 % ', '.join(sorted(kwargs.keys())))
1154 1157 return changegroup.getchangegroup(repo, source, heads=heads,
1155 1158 common=common, bundlecaps=bundlecaps)
1156 1159
1157 1160 # bundle20 case
1158 1161 b2caps = {}
1159 1162 for bcaps in bundlecaps:
1160 1163 if bcaps.startswith('bundle2='):
1161 1164 blob = urllib.unquote(bcaps[len('bundle2='):])
1162 1165 b2caps.update(bundle2.decodecaps(blob))
1163 1166 bundler = bundle2.bundle20(repo.ui, b2caps)
1164 1167
1165 1168 for name in getbundle2partsorder:
1166 1169 func = getbundle2partsmapping[name]
1167 1170 kwargs['heads'] = heads
1168 1171 kwargs['common'] = common
1169 1172 func(bundler, repo, source, bundlecaps=bundlecaps, b2caps=b2caps,
1170 1173 **kwargs)
1171 1174
1172 1175 return util.chunkbuffer(bundler.getchunks())
1173 1176
1174 1177 @getbundle2partsgenerator('changegroup')
1175 1178 def _getbundlechangegrouppart(bundler, repo, source, bundlecaps=None,
1176 1179 b2caps=None, heads=None, common=None, **kwargs):
1177 1180 """add a changegroup part to the requested bundle"""
1178 1181 cg = None
1179 1182 if kwargs.get('cg', True):
1180 1183 # build changegroup bundle here.
1181 1184 cg = changegroup.getchangegroup(repo, source, heads=heads,
1182 1185 common=common, bundlecaps=bundlecaps)
1183 1186
1184 1187 if cg:
1185 1188 bundler.newpart('b2x:changegroup', data=cg.getchunks())
1186 1189
1187 1190 @getbundle2partsgenerator('listkeys')
1188 1191 def _getbundlelistkeysparts(bundler, repo, source, bundlecaps=None,
1189 1192 b2caps=None, **kwargs):
1190 1193 """add parts containing listkeys namespaces to the requested bundle"""
1191 1194 listkeys = kwargs.get('listkeys', ())
1192 1195 for namespace in listkeys:
1193 1196 part = bundler.newpart('b2x:listkeys')
1194 1197 part.addparam('namespace', namespace)
1195 1198 keys = repo.listkeys(namespace).items()
1196 1199 part.data = pushkey.encodekeys(keys)
1197 1200
1198 1201 @getbundle2partsgenerator('obsmarkers')
1199 1202 def _getbundleobsmarkerpart(bundler, repo, source, bundlecaps=None,
1200 1203 b2caps=None, heads=None, **kwargs):
1201 1204 """add an obsolescence markers part to the requested bundle"""
1202 1205 if kwargs.get('obsmarkers', False):
1203 1206 if heads is None:
1204 1207 heads = repo.heads()
1205 1208 subset = [c.node() for c in repo.set('::%ln', heads)]
1206 1209 markers = repo.obsstore.relevantmarkers(subset)
1207 1210 buildobsmarkerspart(bundler, markers)
1208 1211
1209 1212 def check_heads(repo, their_heads, context):
1210 1213 """check if the heads of a repo have been modified
1211 1214
1212 1215 Used by peer for unbundling.
1213 1216 """
1214 1217 heads = repo.heads()
1215 1218 heads_hash = util.sha1(''.join(sorted(heads))).digest()
1216 1219 if not (their_heads == ['force'] or their_heads == heads or
1217 1220 their_heads == ['hashed', heads_hash]):
1218 1221 # someone else committed/pushed/unbundled while we
1219 1222 # were transferring data
1220 1223 raise error.PushRaced('repository changed while %s - '
1221 1224 'please try again' % context)
1222 1225
1223 1226 def unbundle(repo, cg, heads, source, url):
1224 1227 """Apply a bundle to a repo.
1225 1228
1226 1229 this function makes sure the repo is locked during the application and have
1227 1230 mechanism to check that no push race occurred between the creation of the
1228 1231 bundle and its application.
1229 1232
1230 1233 If the push was raced as PushRaced exception is raised."""
1231 1234 r = 0
1232 1235 # need a transaction when processing a bundle2 stream
1233 1236 tr = None
1234 1237 lock = repo.lock()
1235 1238 try:
1236 1239 check_heads(repo, heads, 'uploading changes')
1237 1240 # push can proceed
1238 1241 if util.safehasattr(cg, 'params'):
1239 1242 try:
1240 1243 tr = repo.transaction('unbundle')
1241 1244 tr.hookargs['source'] = source
1242 1245 tr.hookargs['url'] = url
1243 1246 tr.hookargs['bundle2-exp'] = '1'
1244 1247 r = bundle2.processbundle(repo, cg, lambda: tr).reply
1245 1248 cl = repo.unfiltered().changelog
1246 1249 p = cl.writepending() and repo.root or ""
1247 1250 repo.hook('b2x-pretransactionclose', throw=True, pending=p,
1248 1251 **tr.hookargs)
1249 1252 tr.close()
1250 repo.hook('b2x-transactionclose', **tr.hookargs)
1253 hookargs = dict(tr.hookargs)
1254 def runhooks():
1255 repo.hook('b2x-transactionclose', **hookargs)
1256 repo._afterlock(runhooks)
1251 1257 except Exception, exc:
1252 1258 exc.duringunbundle2 = True
1253 1259 raise
1254 1260 else:
1255 1261 r = changegroup.addchangegroup(repo, cg, source, url)
1256 1262 finally:
1257 1263 if tr is not None:
1258 1264 tr.release()
1259 1265 lock.release()
1260 1266 return r
@@ -1,484 +1,484 b''
1 1 Test exchange of common information using bundle2
2 2
3 3
4 4 $ getmainid() {
5 5 > hg -R main log --template '{node}\n' --rev "$1"
6 6 > }
7 7
8 8 enable obsolescence
9 9
10 10 $ cat >> $HGRCPATH << EOF
11 11 > [experimental]
12 12 > evolution=createmarkers,exchange
13 13 > bundle2-exp=True
14 14 > [ui]
15 15 > ssh=python "$TESTDIR/dummyssh"
16 16 > logtemplate={rev}:{node|short} {phase} {author} {bookmarks} {desc|firstline}
17 17 > [web]
18 18 > push_ssl = false
19 19 > allow_push = *
20 20 > [phases]
21 21 > publish=False
22 22 > [hooks]
23 23 > changegroup = sh -c "HG_LOCAL= python \"$TESTDIR/printenv.py\" changegroup"
24 24 > b2x-transactionclose = sh -c "HG_LOCAL= python \"$TESTDIR/printenv.py\" b2x-transactionclose"
25 25 > EOF
26 26
27 27 The extension requires a repo (currently unused)
28 28
29 29 $ hg init main
30 30 $ cd main
31 31 $ touch a
32 32 $ hg add a
33 33 $ hg commit -m 'a'
34 34
35 35 $ hg unbundle $TESTDIR/bundles/rebase.hg
36 36 adding changesets
37 37 adding manifests
38 38 adding file changes
39 39 added 8 changesets with 7 changes to 7 files (+3 heads)
40 40 changegroup hook: HG_NODE=cd010b8cd998f3981a5a8115f94f8da4ab506089 HG_SOURCE=unbundle HG_URL=bundle:*/rebase.hg (glob)
41 41 (run 'hg heads' to see heads, 'hg merge' to merge)
42 42
43 43 $ cd ..
44 44
45 45 Real world exchange
46 46 =====================
47 47
48 48 Add more obsolescence information
49 49
50 50 $ hg -R main debugobsolete -d '0 0' 1111111111111111111111111111111111111111 `getmainid 9520eea781bc`
51 51 $ hg -R main debugobsolete -d '0 0' 2222222222222222222222222222222222222222 `getmainid 24b6387c8c8c`
52 52
53 53 clone --pull
54 54
55 55 $ hg -R main phase --public cd010b8cd998
56 56 $ hg clone main other --pull --rev 9520eea781bc
57 57 adding changesets
58 58 adding manifests
59 59 adding file changes
60 60 added 2 changesets with 2 changes to 2 files
61 61 1 new obsolescence markers
62 changegroup hook: HG_NODE=cd010b8cd998f3981a5a8115f94f8da4ab506089 HG_SOURCE=pull HG_URL=file:$TESTTMP/main
62 63 b2x-transactionclose hook: HG_NEW_OBSMARKERS=1 HG_NODE=cd010b8cd998f3981a5a8115f94f8da4ab506089 HG_PHASES_MOVED=1 HG_SOURCE=pull HG_URL=file:$TESTTMP/main
63 changegroup hook: HG_NODE=cd010b8cd998f3981a5a8115f94f8da4ab506089 HG_SOURCE=pull HG_URL=file:$TESTTMP/main
64 64 updating to branch default
65 65 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
66 66 $ hg -R other log -G
67 67 @ 1:9520eea781bc draft Nicolas Dumazet <nicdumz.commits@gmail.com> E
68 68 |
69 69 o 0:cd010b8cd998 public Nicolas Dumazet <nicdumz.commits@gmail.com> A
70 70
71 71 $ hg -R other debugobsolete
72 72 1111111111111111111111111111111111111111 9520eea781bcca16c1e15acc0ba14335a0e8e5ba 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
73 73
74 74 pull
75 75
76 76 $ hg -R main phase --public 9520eea781bc
77 77 $ hg -R other pull -r 24b6387c8c8c
78 78 pulling from $TESTTMP/main (glob)
79 79 searching for changes
80 80 adding changesets
81 81 adding manifests
82 82 adding file changes
83 83 added 1 changesets with 1 changes to 1 files (+1 heads)
84 84 1 new obsolescence markers
85 changegroup hook: HG_NODE=24b6387c8c8cae37178880f3fa95ded3cb1cf785 HG_SOURCE=pull HG_URL=file:$TESTTMP/main
85 86 b2x-transactionclose hook: HG_NEW_OBSMARKERS=1 HG_NODE=24b6387c8c8cae37178880f3fa95ded3cb1cf785 HG_PHASES_MOVED=1 HG_SOURCE=pull HG_URL=file:$TESTTMP/main
86 changegroup hook: HG_NODE=24b6387c8c8cae37178880f3fa95ded3cb1cf785 HG_SOURCE=pull HG_URL=file:$TESTTMP/main
87 87 (run 'hg heads' to see heads, 'hg merge' to merge)
88 88 $ hg -R other log -G
89 89 o 2:24b6387c8c8c draft Nicolas Dumazet <nicdumz.commits@gmail.com> F
90 90 |
91 91 | @ 1:9520eea781bc draft Nicolas Dumazet <nicdumz.commits@gmail.com> E
92 92 |/
93 93 o 0:cd010b8cd998 public Nicolas Dumazet <nicdumz.commits@gmail.com> A
94 94
95 95 $ hg -R other debugobsolete
96 96 1111111111111111111111111111111111111111 9520eea781bcca16c1e15acc0ba14335a0e8e5ba 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
97 97 2222222222222222222222222222222222222222 24b6387c8c8cae37178880f3fa95ded3cb1cf785 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
98 98
99 99 pull empty (with phase movement)
100 100
101 101 $ hg -R main phase --public 24b6387c8c8c
102 102 $ hg -R other pull -r 24b6387c8c8c
103 103 pulling from $TESTTMP/main (glob)
104 104 no changes found
105 105 b2x-transactionclose hook: HG_NEW_OBSMARKERS=0 HG_PHASES_MOVED=1 HG_SOURCE=pull HG_URL=file:$TESTTMP/main
106 106 $ hg -R other log -G
107 107 o 2:24b6387c8c8c public Nicolas Dumazet <nicdumz.commits@gmail.com> F
108 108 |
109 109 | @ 1:9520eea781bc draft Nicolas Dumazet <nicdumz.commits@gmail.com> E
110 110 |/
111 111 o 0:cd010b8cd998 public Nicolas Dumazet <nicdumz.commits@gmail.com> A
112 112
113 113 $ hg -R other debugobsolete
114 114 1111111111111111111111111111111111111111 9520eea781bcca16c1e15acc0ba14335a0e8e5ba 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
115 115 2222222222222222222222222222222222222222 24b6387c8c8cae37178880f3fa95ded3cb1cf785 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
116 116
117 117 pull empty
118 118
119 119 $ hg -R other pull -r 24b6387c8c8c
120 120 pulling from $TESTTMP/main (glob)
121 121 no changes found
122 122 b2x-transactionclose hook: HG_NEW_OBSMARKERS=0 HG_SOURCE=pull HG_URL=file:$TESTTMP/main
123 123 $ hg -R other log -G
124 124 o 2:24b6387c8c8c public Nicolas Dumazet <nicdumz.commits@gmail.com> F
125 125 |
126 126 | @ 1:9520eea781bc draft Nicolas Dumazet <nicdumz.commits@gmail.com> E
127 127 |/
128 128 o 0:cd010b8cd998 public Nicolas Dumazet <nicdumz.commits@gmail.com> A
129 129
130 130 $ hg -R other debugobsolete
131 131 1111111111111111111111111111111111111111 9520eea781bcca16c1e15acc0ba14335a0e8e5ba 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
132 132 2222222222222222222222222222222222222222 24b6387c8c8cae37178880f3fa95ded3cb1cf785 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
133 133
134 134 add extra data to test their exchange during push
135 135
136 136 $ hg -R main bookmark --rev eea13746799a book_eea1
137 137 $ hg -R main debugobsolete -d '0 0' 3333333333333333333333333333333333333333 `getmainid eea13746799a`
138 138 $ hg -R main bookmark --rev 02de42196ebe book_02de
139 139 $ hg -R main debugobsolete -d '0 0' 4444444444444444444444444444444444444444 `getmainid 02de42196ebe`
140 140 $ hg -R main bookmark --rev 42ccdea3bb16 book_42cc
141 141 $ hg -R main debugobsolete -d '0 0' 5555555555555555555555555555555555555555 `getmainid 42ccdea3bb16`
142 142 $ hg -R main bookmark --rev 5fddd98957c8 book_5fdd
143 143 $ hg -R main debugobsolete -d '0 0' 6666666666666666666666666666666666666666 `getmainid 5fddd98957c8`
144 144 $ hg -R main bookmark --rev 32af7686d403 book_32af
145 145 $ hg -R main debugobsolete -d '0 0' 7777777777777777777777777777777777777777 `getmainid 32af7686d403`
146 146
147 147 $ hg -R other bookmark --rev cd010b8cd998 book_eea1
148 148 $ hg -R other bookmark --rev cd010b8cd998 book_02de
149 149 $ hg -R other bookmark --rev cd010b8cd998 book_42cc
150 150 $ hg -R other bookmark --rev cd010b8cd998 book_5fdd
151 151 $ hg -R other bookmark --rev cd010b8cd998 book_32af
152 152
153 153 $ hg -R main phase --public eea13746799a
154 154
155 155 push
156 156 $ hg -R main push other --rev eea13746799a --bookmark book_eea1
157 157 pushing to other
158 158 searching for changes
159 changegroup hook: HG_BUNDLE2-EXP=1 HG_NODE=eea13746799a9e0bfd88f29d3c2e9dc9389f524f HG_SOURCE=push HG_URL=push
159 160 b2x-transactionclose hook: HG_BOOKMARK_MOVED=1 HG_BUNDLE2-EXP=1 HG_NEW_OBSMARKERS=1 HG_NODE=eea13746799a9e0bfd88f29d3c2e9dc9389f524f HG_PHASES_MOVED=1 HG_SOURCE=push HG_URL=push
160 changegroup hook: HG_BUNDLE2-EXP=1 HG_NODE=eea13746799a9e0bfd88f29d3c2e9dc9389f524f HG_SOURCE=push HG_URL=push
161 161 remote: adding changesets
162 162 remote: adding manifests
163 163 remote: adding file changes
164 164 remote: added 1 changesets with 0 changes to 0 files (-1 heads)
165 165 remote: 1 new obsolescence markers
166 166 updating bookmark book_eea1
167 167 $ hg -R other log -G
168 168 o 3:eea13746799a public Nicolas Dumazet <nicdumz.commits@gmail.com> book_eea1 G
169 169 |\
170 170 | o 2:24b6387c8c8c public Nicolas Dumazet <nicdumz.commits@gmail.com> F
171 171 | |
172 172 @ | 1:9520eea781bc public Nicolas Dumazet <nicdumz.commits@gmail.com> E
173 173 |/
174 174 o 0:cd010b8cd998 public Nicolas Dumazet <nicdumz.commits@gmail.com> book_02de book_32af book_42cc book_5fdd A
175 175
176 176 $ hg -R other debugobsolete
177 177 1111111111111111111111111111111111111111 9520eea781bcca16c1e15acc0ba14335a0e8e5ba 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
178 178 2222222222222222222222222222222222222222 24b6387c8c8cae37178880f3fa95ded3cb1cf785 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
179 179 3333333333333333333333333333333333333333 eea13746799a9e0bfd88f29d3c2e9dc9389f524f 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
180 180
181 181 pull over ssh
182 182
183 183 $ hg -R other pull ssh://user@dummy/main -r 02de42196ebe --bookmark book_02de
184 184 pulling from ssh://user@dummy/main
185 185 searching for changes
186 186 adding changesets
187 187 adding manifests
188 188 adding file changes
189 189 added 1 changesets with 1 changes to 1 files (+1 heads)
190 190 1 new obsolescence markers
191 191 updating bookmark book_02de
192 changegroup hook: HG_NODE=02de42196ebee42ef284b6780a87cdc96e8eaab6 HG_SOURCE=pull HG_URL=ssh://user@dummy/main
192 193 b2x-transactionclose hook: HG_BOOKMARK_MOVED=1 HG_NEW_OBSMARKERS=1 HG_NODE=02de42196ebee42ef284b6780a87cdc96e8eaab6 HG_PHASES_MOVED=1 HG_SOURCE=pull HG_URL=ssh://user@dummy/main
193 changegroup hook: HG_NODE=02de42196ebee42ef284b6780a87cdc96e8eaab6 HG_SOURCE=pull HG_URL=ssh://user@dummy/main
194 194 (run 'hg heads' to see heads, 'hg merge' to merge)
195 195 $ hg -R other debugobsolete
196 196 1111111111111111111111111111111111111111 9520eea781bcca16c1e15acc0ba14335a0e8e5ba 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
197 197 2222222222222222222222222222222222222222 24b6387c8c8cae37178880f3fa95ded3cb1cf785 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
198 198 3333333333333333333333333333333333333333 eea13746799a9e0bfd88f29d3c2e9dc9389f524f 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
199 199 4444444444444444444444444444444444444444 02de42196ebee42ef284b6780a87cdc96e8eaab6 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
200 200
201 201 pull over http
202 202
203 203 $ hg -R main serve -p $HGPORT -d --pid-file=main.pid -E main-error.log
204 204 $ cat main.pid >> $DAEMON_PIDS
205 205
206 206 $ hg -R other pull http://localhost:$HGPORT/ -r 42ccdea3bb16 --bookmark book_42cc
207 207 pulling from http://localhost:$HGPORT/
208 208 searching for changes
209 209 adding changesets
210 210 adding manifests
211 211 adding file changes
212 212 added 1 changesets with 1 changes to 1 files (+1 heads)
213 213 1 new obsolescence markers
214 214 updating bookmark book_42cc
215 changegroup hook: HG_NODE=42ccdea3bb16d28e1848c95fe2e44c000f3f21b1 HG_SOURCE=pull HG_URL=http://localhost:$HGPORT/
215 216 b2x-transactionclose hook: HG_BOOKMARK_MOVED=1 HG_NEW_OBSMARKERS=1 HG_NODE=42ccdea3bb16d28e1848c95fe2e44c000f3f21b1 HG_PHASES_MOVED=1 HG_SOURCE=pull HG_URL=http://localhost:$HGPORT/
216 changegroup hook: HG_NODE=42ccdea3bb16d28e1848c95fe2e44c000f3f21b1 HG_SOURCE=pull HG_URL=http://localhost:$HGPORT/
217 217 (run 'hg heads .' to see heads, 'hg merge' to merge)
218 218 $ cat main-error.log
219 219 $ hg -R other debugobsolete
220 220 1111111111111111111111111111111111111111 9520eea781bcca16c1e15acc0ba14335a0e8e5ba 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
221 221 2222222222222222222222222222222222222222 24b6387c8c8cae37178880f3fa95ded3cb1cf785 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
222 222 3333333333333333333333333333333333333333 eea13746799a9e0bfd88f29d3c2e9dc9389f524f 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
223 223 4444444444444444444444444444444444444444 02de42196ebee42ef284b6780a87cdc96e8eaab6 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
224 224 5555555555555555555555555555555555555555 42ccdea3bb16d28e1848c95fe2e44c000f3f21b1 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
225 225
226 226 push over ssh
227 227
228 228 $ hg -R main push ssh://user@dummy/other -r 5fddd98957c8 --bookmark book_5fdd
229 229 pushing to ssh://user@dummy/other
230 230 searching for changes
231 231 remote: adding changesets
232 232 remote: adding manifests
233 233 remote: adding file changes
234 234 remote: added 1 changesets with 1 changes to 1 files
235 235 remote: 1 new obsolescence markers
236 236 updating bookmark book_5fdd
237 remote: changegroup hook: HG_BUNDLE2-EXP=1 HG_NODE=5fddd98957c8a54a4d436dfe1da9d87f21a1b97b HG_SOURCE=serve HG_URL=remote:ssh:127.0.0.1
237 238 remote: b2x-transactionclose hook: HG_BOOKMARK_MOVED=1 HG_BUNDLE2-EXP=1 HG_NEW_OBSMARKERS=1 HG_NODE=5fddd98957c8a54a4d436dfe1da9d87f21a1b97b HG_SOURCE=serve HG_URL=remote:ssh:127.0.0.1
238 remote: changegroup hook: HG_BUNDLE2-EXP=1 HG_NODE=5fddd98957c8a54a4d436dfe1da9d87f21a1b97b HG_SOURCE=serve HG_URL=remote:ssh:127.0.0.1
239 239 $ hg -R other log -G
240 240 o 6:5fddd98957c8 draft Nicolas Dumazet <nicdumz.commits@gmail.com> book_5fdd C
241 241 |
242 242 o 5:42ccdea3bb16 draft Nicolas Dumazet <nicdumz.commits@gmail.com> book_42cc B
243 243 |
244 244 | o 4:02de42196ebe draft Nicolas Dumazet <nicdumz.commits@gmail.com> book_02de H
245 245 | |
246 246 | | o 3:eea13746799a public Nicolas Dumazet <nicdumz.commits@gmail.com> book_eea1 G
247 247 | |/|
248 248 | o | 2:24b6387c8c8c public Nicolas Dumazet <nicdumz.commits@gmail.com> F
249 249 |/ /
250 250 | @ 1:9520eea781bc public Nicolas Dumazet <nicdumz.commits@gmail.com> E
251 251 |/
252 252 o 0:cd010b8cd998 public Nicolas Dumazet <nicdumz.commits@gmail.com> book_32af A
253 253
254 254 $ hg -R other debugobsolete
255 255 1111111111111111111111111111111111111111 9520eea781bcca16c1e15acc0ba14335a0e8e5ba 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
256 256 2222222222222222222222222222222222222222 24b6387c8c8cae37178880f3fa95ded3cb1cf785 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
257 257 3333333333333333333333333333333333333333 eea13746799a9e0bfd88f29d3c2e9dc9389f524f 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
258 258 4444444444444444444444444444444444444444 02de42196ebee42ef284b6780a87cdc96e8eaab6 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
259 259 5555555555555555555555555555555555555555 42ccdea3bb16d28e1848c95fe2e44c000f3f21b1 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
260 260 6666666666666666666666666666666666666666 5fddd98957c8a54a4d436dfe1da9d87f21a1b97b 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
261 261
262 262 push over http
263 263
264 264 $ hg -R other serve -p $HGPORT2 -d --pid-file=other.pid -E other-error.log
265 265 $ cat other.pid >> $DAEMON_PIDS
266 266
267 267 $ hg -R main phase --public 32af7686d403
268 268 $ hg -R main push http://localhost:$HGPORT2/ -r 32af7686d403 --bookmark book_32af
269 269 pushing to http://localhost:$HGPORT2/
270 270 searching for changes
271 271 remote: adding changesets
272 272 remote: adding manifests
273 273 remote: adding file changes
274 274 remote: added 1 changesets with 1 changes to 1 files
275 275 remote: 1 new obsolescence markers
276 276 updating bookmark book_32af
277 277 $ cat other-error.log
278 278
279 279 Check final content.
280 280
281 281 $ hg -R other log -G
282 282 o 7:32af7686d403 public Nicolas Dumazet <nicdumz.commits@gmail.com> book_32af D
283 283 |
284 284 o 6:5fddd98957c8 public Nicolas Dumazet <nicdumz.commits@gmail.com> book_5fdd C
285 285 |
286 286 o 5:42ccdea3bb16 public Nicolas Dumazet <nicdumz.commits@gmail.com> book_42cc B
287 287 |
288 288 | o 4:02de42196ebe draft Nicolas Dumazet <nicdumz.commits@gmail.com> book_02de H
289 289 | |
290 290 | | o 3:eea13746799a public Nicolas Dumazet <nicdumz.commits@gmail.com> book_eea1 G
291 291 | |/|
292 292 | o | 2:24b6387c8c8c public Nicolas Dumazet <nicdumz.commits@gmail.com> F
293 293 |/ /
294 294 | @ 1:9520eea781bc public Nicolas Dumazet <nicdumz.commits@gmail.com> E
295 295 |/
296 296 o 0:cd010b8cd998 public Nicolas Dumazet <nicdumz.commits@gmail.com> A
297 297
298 298 $ hg -R other debugobsolete
299 299 1111111111111111111111111111111111111111 9520eea781bcca16c1e15acc0ba14335a0e8e5ba 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
300 300 2222222222222222222222222222222222222222 24b6387c8c8cae37178880f3fa95ded3cb1cf785 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
301 301 3333333333333333333333333333333333333333 eea13746799a9e0bfd88f29d3c2e9dc9389f524f 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
302 302 4444444444444444444444444444444444444444 02de42196ebee42ef284b6780a87cdc96e8eaab6 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
303 303 5555555555555555555555555555555555555555 42ccdea3bb16d28e1848c95fe2e44c000f3f21b1 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
304 304 6666666666666666666666666666666666666666 5fddd98957c8a54a4d436dfe1da9d87f21a1b97b 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
305 305 7777777777777777777777777777777777777777 32af7686d403cf45b5d95f2d70cebea587ac806a 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
306 306
307 307 Error Handling
308 308 ==============
309 309
310 310 Check that errors are properly returned to the client during push.
311 311
312 312 Setting up
313 313
314 314 $ cat > failpush.py << EOF
315 315 > """A small extension that makes push fails when using bundle2
316 316 >
317 317 > used to test error handling in bundle2
318 318 > """
319 319 >
320 320 > from mercurial import util
321 321 > from mercurial import bundle2
322 322 > from mercurial import exchange
323 323 > from mercurial import extensions
324 324 >
325 325 > def _pushbundle2failpart(pushop, bundler):
326 326 > reason = pushop.ui.config('failpush', 'reason', None)
327 327 > part = None
328 328 > if reason == 'abort':
329 329 > bundler.newpart('test:abort')
330 330 > if reason == 'unknown':
331 331 > bundler.newpart('TEST:UNKNOWN')
332 332 > if reason == 'race':
333 333 > # 20 Bytes of crap
334 334 > bundler.newpart('b2x:check:heads', data='01234567890123456789')
335 335 >
336 336 > @bundle2.parthandler("test:abort")
337 337 > def handleabort(op, part):
338 338 > raise util.Abort('Abandon ship!', hint="don't panic")
339 339 >
340 340 > def uisetup(ui):
341 341 > exchange.b2partsgenmapping['failpart'] = _pushbundle2failpart
342 342 > exchange.b2partsgenorder.insert(0, 'failpart')
343 343 >
344 344 > EOF
345 345
346 346 $ cd main
347 347 $ hg up tip
348 348 3 files updated, 0 files merged, 1 files removed, 0 files unresolved
349 349 $ echo 'I' > I
350 350 $ hg add I
351 351 $ hg ci -m 'I'
352 352 $ hg id
353 353 e7ec4e813ba6 tip
354 354 $ cd ..
355 355
356 356 $ cat << EOF >> $HGRCPATH
357 357 > [extensions]
358 358 > failpush=$TESTTMP/failpush.py
359 359 > EOF
360 360
361 361 $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS
362 362 $ hg -R other serve -p $HGPORT2 -d --pid-file=other.pid -E other-error.log
363 363 $ cat other.pid >> $DAEMON_PIDS
364 364
365 365 Doing the actual push: Abort error
366 366
367 367 $ cat << EOF >> $HGRCPATH
368 368 > [failpush]
369 369 > reason = abort
370 370 > EOF
371 371
372 372 $ hg -R main push other -r e7ec4e813ba6
373 373 pushing to other
374 374 searching for changes
375 375 abort: Abandon ship!
376 376 (don't panic)
377 377 [255]
378 378
379 379 $ hg -R main push ssh://user@dummy/other -r e7ec4e813ba6
380 380 pushing to ssh://user@dummy/other
381 381 searching for changes
382 382 abort: Abandon ship!
383 383 (don't panic)
384 384 [255]
385 385
386 386 $ hg -R main push http://localhost:$HGPORT2/ -r e7ec4e813ba6
387 387 pushing to http://localhost:$HGPORT2/
388 388 searching for changes
389 389 abort: Abandon ship!
390 390 (don't panic)
391 391 [255]
392 392
393 393
394 394 Doing the actual push: unknown mandatory parts
395 395
396 396 $ cat << EOF >> $HGRCPATH
397 397 > [failpush]
398 398 > reason = unknown
399 399 > EOF
400 400
401 401 $ hg -R main push other -r e7ec4e813ba6
402 402 pushing to other
403 403 searching for changes
404 404 abort: missing support for test:unknown
405 405 [255]
406 406
407 407 $ hg -R main push ssh://user@dummy/other -r e7ec4e813ba6
408 408 pushing to ssh://user@dummy/other
409 409 searching for changes
410 410 abort: missing support for test:unknown
411 411 [255]
412 412
413 413 $ hg -R main push http://localhost:$HGPORT2/ -r e7ec4e813ba6
414 414 pushing to http://localhost:$HGPORT2/
415 415 searching for changes
416 416 abort: missing support for test:unknown
417 417 [255]
418 418
419 419 Doing the actual push: race
420 420
421 421 $ cat << EOF >> $HGRCPATH
422 422 > [failpush]
423 423 > reason = race
424 424 > EOF
425 425
426 426 $ hg -R main push other -r e7ec4e813ba6
427 427 pushing to other
428 428 searching for changes
429 429 abort: push failed:
430 430 'repository changed while pushing - please try again'
431 431 [255]
432 432
433 433 $ hg -R main push ssh://user@dummy/other -r e7ec4e813ba6
434 434 pushing to ssh://user@dummy/other
435 435 searching for changes
436 436 abort: push failed:
437 437 'repository changed while pushing - please try again'
438 438 [255]
439 439
440 440 $ hg -R main push http://localhost:$HGPORT2/ -r e7ec4e813ba6
441 441 pushing to http://localhost:$HGPORT2/
442 442 searching for changes
443 443 abort: push failed:
444 444 'repository changed while pushing - please try again'
445 445 [255]
446 446
447 447 Doing the actual push: hook abort
448 448
449 449 $ cat << EOF >> $HGRCPATH
450 450 > [failpush]
451 451 > reason =
452 452 > [hooks]
453 453 > b2x-pretransactionclose.failpush = false
454 454 > EOF
455 455
456 456 $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS
457 457 $ hg -R other serve -p $HGPORT2 -d --pid-file=other.pid -E other-error.log
458 458 $ cat other.pid >> $DAEMON_PIDS
459 459
460 460 $ hg -R main push other -r e7ec4e813ba6
461 461 pushing to other
462 462 searching for changes
463 463 transaction abort!
464 464 rollback completed
465 465 changegroup hook: HG_BUNDLE2-EXP=1 HG_NODE=e7ec4e813ba6b07be2a0516ce1a74bb4e503f91a HG_SOURCE=push HG_URL=push
466 466 abort: b2x-pretransactionclose.failpush hook exited with status 1
467 467 [255]
468 468
469 469 $ hg -R main push ssh://user@dummy/other -r e7ec4e813ba6
470 470 pushing to ssh://user@dummy/other
471 471 searching for changes
472 472 abort: b2x-pretransactionclose.failpush hook exited with status 1
473 473 remote: transaction abort!
474 474 remote: rollback completed
475 475 remote: changegroup hook: HG_BUNDLE2-EXP=1 HG_NODE=e7ec4e813ba6b07be2a0516ce1a74bb4e503f91a HG_SOURCE=serve HG_URL=remote:ssh:127.0.0.1
476 476 [255]
477 477
478 478 $ hg -R main push http://localhost:$HGPORT2/ -r e7ec4e813ba6
479 479 pushing to http://localhost:$HGPORT2/
480 480 searching for changes
481 481 abort: b2x-pretransactionclose.failpush hook exited with status 1
482 482 [255]
483 483
484 484
General Comments 0
You need to be logged in to leave comments. Login now