mercurial/changegroup.py
changeset 20927 24a443948627
parent 20926 7c1ed40e3325
child 20928 91b47139d0cb
equal deleted inserted replaced
20926:7c1ed40e3325 20927:24a443948627
     4 #
     4 #
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 from i18n import _
     8 from i18n import _
     9 from node import nullrev, hex
     9 from node import nullrev, nullid, hex
    10 import mdiff, util, dagutil
    10 import mdiff, util, dagutil
    11 import struct, os, bz2, zlib, tempfile
    11 import struct, os, bz2, zlib, tempfile
       
    12 import discovery
    12 
    13 
    13 _BUNDLE10_DELTA_HEADER = "20s20s20s20s"
    14 _BUNDLE10_DELTA_HEADER = "20s20s20s20s"
    14 
    15 
    15 def readexactly(stream, n):
    16 def readexactly(stream, n):
    16     '''read n bytes from stream.read and abort if less was available'''
    17     '''read n bytes from stream.read and abort if less was available'''
   451 
   452 
   452     repo.hook('preoutgoing', throw=True, source=source)
   453     repo.hook('preoutgoing', throw=True, source=source)
   453     _changegroupinfo(repo, csets, source)
   454     _changegroupinfo(repo, csets, source)
   454     gengroup = bundler.generate(commonrevs, csets, fastpathlinkrev, source)
   455     gengroup = bundler.generate(commonrevs, csets, fastpathlinkrev, source)
   455     return unbundle10(util.chunkbuffer(gengroup), 'UN')
   456     return unbundle10(util.chunkbuffer(gengroup), 'UN')
       
   457 
       
   458 def changegroupsubset(repo, roots, heads, source):
       
   459     """Compute a changegroup consisting of all the nodes that are
       
   460     descendants of any of the roots and ancestors of any of the heads.
       
   461     Return a chunkbuffer object whose read() method will return
       
   462     successive changegroup chunks.
       
   463 
       
   464     It is fairly complex as determining which filenodes and which
       
   465     manifest nodes need to be included for the changeset to be complete
       
   466     is non-trivial.
       
   467 
       
   468     Another wrinkle is doing the reverse, figuring out which changeset in
       
   469     the changegroup a particular filenode or manifestnode belongs to.
       
   470     """
       
   471     cl = repo.changelog
       
   472     if not roots:
       
   473         roots = [nullid]
       
   474     # TODO: remove call to nodesbetween.
       
   475     csets, roots, heads = cl.nodesbetween(roots, heads)
       
   476     discbases = []
       
   477     for n in roots:
       
   478         discbases.extend([p for p in cl.parents(n) if p != nullid])
       
   479     outgoing = discovery.outgoing(cl, discbases, heads)
       
   480     bundler = bundle10(repo)
       
   481     return getsubset(repo, outgoing, bundler, source)
       
   482