Mercurial > hg
comparison mercurial/changegroup.py @ 21260:aa3e56607675
changegroup: refactor outgoing logic into a function
Extensions that add to bundle2 will want to know which commits are outgoing so
they can bundle data that is appropriate to those commits. This moves the logic
for figuring that out to a separate function so extensions can do the same
computation.
author | Durham Goode <durham@fb.com> |
---|---|
date | Wed, 07 May 2014 17:22:34 -0700 |
parents | 53ee02b54e53 |
children | 97f86ce79abe |
comparison
equal
deleted
inserted
replaced
21259:ab5040cd5749 | 21260:aa3e56607675 |
---|---|
491 if not outgoing.missing: | 491 if not outgoing.missing: |
492 return None | 492 return None |
493 bundler = bundle10(repo, bundlecaps) | 493 bundler = bundle10(repo, bundlecaps) |
494 return getsubset(repo, outgoing, bundler, source) | 494 return getsubset(repo, outgoing, bundler, source) |
495 | 495 |
496 def getbundle(repo, source, heads=None, common=None, bundlecaps=None): | 496 def _computeoutgoing(repo, heads, common): |
497 """Like changegroupsubset, but returns the set difference between the | 497 """Computes which revs are outgoing given a set of common |
498 ancestors of heads and the ancestors common. | 498 and a set of heads. |
499 | 499 |
500 If heads is None, use the local heads. If common is None, use [nullid]. | 500 This is a separate function so extensions can have access to |
501 | 501 the logic. |
502 The nodes in common might not all be known locally due to the way the | 502 |
503 current discovery protocol works. | 503 Returns a discovery.outgoing object. |
504 """ | 504 """ |
505 cl = repo.changelog | 505 cl = repo.changelog |
506 if common: | 506 if common: |
507 hasnode = cl.hasnode | 507 hasnode = cl.hasnode |
508 common = [n for n in common if hasnode(n)] | 508 common = [n for n in common if hasnode(n)] |
509 else: | 509 else: |
510 common = [nullid] | 510 common = [nullid] |
511 if not heads: | 511 if not heads: |
512 heads = cl.heads() | 512 heads = cl.heads() |
513 outgoing = discovery.outgoing(cl, common, heads) | 513 return discovery.outgoing(cl, common, heads) |
514 | |
515 def getbundle(repo, source, heads=None, common=None, bundlecaps=None): | |
516 """Like changegroupsubset, but returns the set difference between the | |
517 ancestors of heads and the ancestors common. | |
518 | |
519 If heads is None, use the local heads. If common is None, use [nullid]. | |
520 | |
521 The nodes in common might not all be known locally due to the way the | |
522 current discovery protocol works. | |
523 """ | |
524 outgoing = _computeoutgoing(repo, heads, common) | |
514 return getlocalbundle(repo, source, outgoing, bundlecaps=bundlecaps) | 525 return getlocalbundle(repo, source, outgoing, bundlecaps=bundlecaps) |
515 | 526 |
516 def changegroup(repo, basenodes, source): | 527 def changegroup(repo, basenodes, source): |
517 # to avoid a race we use changegroupsubset() (issue1320) | 528 # to avoid a race we use changegroupsubset() (issue1320) |
518 return changegroupsubset(repo, basenodes, repo.heads(), source) | 529 return changegroupsubset(repo, basenodes, repo.heads(), source) |