comparison mercurial/changegroup.py @ 23177:706547a14b8b

changegroup: introduce "raw" versions of some commands The commands getchangegroup, getlocalchangegroup and getsubset now each have a version ending in -raw. The raw versions return the chunk generator from the changegroup packer directly, without wrapping it in a chunkbuffer and unpacker. This avoids extra chunkbuffers in the bundle2 code path. Also, the raw versions can be extended to support alternative packers in the future, to be used from bundle2.
author Sune Foldager <cryo@cyanite.org>
date Fri, 17 Oct 2014 14:41:02 +0200
parents a92ba36a1a9d
children 5e895ed5e955
comparison
equal deleted inserted replaced
23176:329c6b4414ae 23177:706547a14b8b
441 if repo.ui.debugflag: 441 if repo.ui.debugflag:
442 repo.ui.debug("list of changesets:\n") 442 repo.ui.debug("list of changesets:\n")
443 for node in nodes: 443 for node in nodes:
444 repo.ui.debug("%s\n" % hex(node)) 444 repo.ui.debug("%s\n" % hex(node))
445 445
446 def getsubset(repo, outgoing, bundler, source, fastpath=False): 446 def getsubsetraw(repo, outgoing, bundler, source, fastpath=False):
447 repo = repo.unfiltered() 447 repo = repo.unfiltered()
448 commonrevs = outgoing.common 448 commonrevs = outgoing.common
449 csets = outgoing.missing 449 csets = outgoing.missing
450 heads = outgoing.missingheads 450 heads = outgoing.missingheads
451 # We go through the fast path if we get told to, or if all (unfiltered 451 # We go through the fast path if we get told to, or if all (unfiltered
455 fastpathlinkrev = fastpath or ( 455 fastpathlinkrev = fastpath or (
456 repo.filtername is None and heads == sorted(repo.heads())) 456 repo.filtername is None and heads == sorted(repo.heads()))
457 457
458 repo.hook('preoutgoing', throw=True, source=source) 458 repo.hook('preoutgoing', throw=True, source=source)
459 _changegroupinfo(repo, csets, source) 459 _changegroupinfo(repo, csets, source)
460 gengroup = bundler.generate(commonrevs, csets, fastpathlinkrev, source) 460 return bundler.generate(commonrevs, csets, fastpathlinkrev, source)
461
462 def getsubset(repo, outgoing, bundler, source, fastpath=False):
463 gengroup = getsubsetraw(repo, outgoing, bundler, source, fastpath)
461 return cg1unpacker(util.chunkbuffer(gengroup), 'UN') 464 return cg1unpacker(util.chunkbuffer(gengroup), 'UN')
462 465
463 def changegroupsubset(repo, roots, heads, source): 466 def changegroupsubset(repo, roots, heads, source):
464 """Compute a changegroup consisting of all the nodes that are 467 """Compute a changegroup consisting of all the nodes that are
465 descendants of any of the roots and ancestors of any of the heads. 468 descendants of any of the roots and ancestors of any of the heads.
483 discbases.extend([p for p in cl.parents(n) if p != nullid]) 486 discbases.extend([p for p in cl.parents(n) if p != nullid])
484 outgoing = discovery.outgoing(cl, discbases, heads) 487 outgoing = discovery.outgoing(cl, discbases, heads)
485 bundler = cg1packer(repo) 488 bundler = cg1packer(repo)
486 return getsubset(repo, outgoing, bundler, source) 489 return getsubset(repo, outgoing, bundler, source)
487 490
491 def getlocalchangegroupraw(repo, source, outgoing, bundlecaps=None):
492 """Like getbundle, but taking a discovery.outgoing as an argument.
493
494 This is only implemented for local repos and reuses potentially
495 precomputed sets in outgoing. Returns a raw changegroup generator."""
496 if not outgoing.missing:
497 return None
498 bundler = cg1packer(repo, bundlecaps)
499 return getsubsetraw(repo, outgoing, bundler, source)
500
488 def getlocalchangegroup(repo, source, outgoing, bundlecaps=None): 501 def getlocalchangegroup(repo, source, outgoing, bundlecaps=None):
489 """Like getbundle, but taking a discovery.outgoing as an argument. 502 """Like getbundle, but taking a discovery.outgoing as an argument.
490 503
491 This is only implemented for local repos and reuses potentially 504 This is only implemented for local repos and reuses potentially
492 precomputed sets in outgoing.""" 505 precomputed sets in outgoing."""
511 else: 524 else:
512 common = [nullid] 525 common = [nullid]
513 if not heads: 526 if not heads:
514 heads = cl.heads() 527 heads = cl.heads()
515 return discovery.outgoing(cl, common, heads) 528 return discovery.outgoing(cl, common, heads)
529
530 def getchangegroupraw(repo, source, heads=None, common=None, bundlecaps=None):
531 """Like changegroupsubset, but returns the set difference between the
532 ancestors of heads and the ancestors common.
533
534 If heads is None, use the local heads. If common is None, use [nullid].
535
536 The nodes in common might not all be known locally due to the way the
537 current discovery protocol works. Returns a raw changegroup generator.
538 """
539 outgoing = _computeoutgoing(repo, heads, common)
540 return getlocalchangegroupraw(repo, source, outgoing, bundlecaps=bundlecaps)
516 541
517 def getchangegroup(repo, source, heads=None, common=None, bundlecaps=None): 542 def getchangegroup(repo, source, heads=None, common=None, bundlecaps=None):
518 """Like changegroupsubset, but returns the set difference between the 543 """Like changegroupsubset, but returns the set difference between the
519 ancestors of heads and the ancestors common. 544 ancestors of heads and the ancestors common.
520 545