mercurial/bundle2.py
changeset 33031 e8c8d81eb864
parent 33030 3e102a8dd52c
child 33035 6e3a6774d998
equal deleted inserted replaced
33030:3e102a8dd52c 33031:e8c8d81eb864
   156 from .i18n import _
   156 from .i18n import _
   157 from . import (
   157 from . import (
   158     changegroup,
   158     changegroup,
   159     error,
   159     error,
   160     obsolete,
   160     obsolete,
       
   161     phases,
   161     pushkey,
   162     pushkey,
   162     pycompat,
   163     pycompat,
   163     tags,
   164     tags,
   164     url,
   165     url,
   165     util,
   166     util,
   175 _fpartheadersize = '>i'
   176 _fpartheadersize = '>i'
   176 _fparttypesize = '>B'
   177 _fparttypesize = '>B'
   177 _fpartid = '>I'
   178 _fpartid = '>I'
   178 _fpayloadsize = '>i'
   179 _fpayloadsize = '>i'
   179 _fpartparamcount = '>BB'
   180 _fpartparamcount = '>BB'
       
   181 
       
   182 _fphasesentry = '>i20s'
   180 
   183 
   181 preferedchunksize = 4096
   184 preferedchunksize = 4096
   182 
   185 
   183 _parttypeforbidden = re.compile('[^a-zA-Z0-9_:-]')
   186 _parttypeforbidden = re.compile('[^a-zA-Z0-9_:-]')
   184 
   187 
  1385 
  1388 
  1386     if opts.get('obsolescence', False):
  1389     if opts.get('obsolescence', False):
  1387         obsmarkers = repo.obsstore.relevantmarkers(outgoing.missing)
  1390         obsmarkers = repo.obsstore.relevantmarkers(outgoing.missing)
  1388         buildobsmarkerspart(bundler, obsmarkers)
  1391         buildobsmarkerspart(bundler, obsmarkers)
  1389 
  1392 
       
  1393     if opts.get('phases', False):
       
  1394         headsbyphase = phases.subsetphaseheads(repo, outgoing.missing)
       
  1395         phasedata = []
       
  1396         for phase in phases.allphases:
       
  1397             for head in headsbyphase[phase]:
       
  1398                 phasedata.append(_pack(_fphasesentry, phase, head))
       
  1399         bundler.newpart('phase-heads', data=''.join(phasedata))
       
  1400 
  1390 def addparttagsfnodescache(repo, bundler, outgoing):
  1401 def addparttagsfnodescache(repo, bundler, outgoing):
  1391     # we include the tags fnode cache for the bundle changeset
  1402     # we include the tags fnode cache for the bundle changeset
  1392     # (as an optional parts)
  1403     # (as an optional parts)
  1393     cache = tags.hgtagsfnodescache(repo.unfiltered())
  1404     cache = tags.hgtagsfnodescache(repo.unfiltered())
  1394     chunks = []
  1405     chunks = []
  1719         for key in ('namespace', 'key', 'new', 'old', 'ret'):
  1730         for key in ('namespace', 'key', 'new', 'old', 'ret'):
  1720             if key in inpart.params:
  1731             if key in inpart.params:
  1721                 kwargs[key] = inpart.params[key]
  1732                 kwargs[key] = inpart.params[key]
  1722         raise error.PushkeyFailed(partid=str(inpart.id), **kwargs)
  1733         raise error.PushkeyFailed(partid=str(inpart.id), **kwargs)
  1723 
  1734 
       
  1735 def _readphaseheads(inpart):
       
  1736     headsbyphase = [[] for i in phases.allphases]
       
  1737     entrysize = struct.calcsize(_fphasesentry)
       
  1738     while True:
       
  1739         entry = inpart.read(entrysize)
       
  1740         if len(entry) < entrysize:
       
  1741             if entry:
       
  1742                 raise error.Abort(_('bad phase-heads bundle part'))
       
  1743             break
       
  1744         phase, node = struct.unpack(_fphasesentry, entry)
       
  1745         headsbyphase[phase].append(node)
       
  1746     return headsbyphase
       
  1747 
       
  1748 @parthandler('phase-heads')
       
  1749 def handlephases(op, inpart):
       
  1750     """apply phases from bundle part to repo"""
       
  1751     headsbyphase = _readphaseheads(inpart)
       
  1752     addednodes = []
       
  1753     for entry in op.records['changegroup']:
       
  1754         addednodes.extend(entry['addednodes'])
       
  1755     phases.updatephases(op.repo.unfiltered(), op.gettransaction(), headsbyphase,
       
  1756                         addednodes)
       
  1757 
  1724 @parthandler('reply:pushkey', ('return', 'in-reply-to'))
  1758 @parthandler('reply:pushkey', ('return', 'in-reply-to'))
  1725 def handlepushkeyreply(op, inpart):
  1759 def handlepushkeyreply(op, inpart):
  1726     """retrieve the result of a pushkey request"""
  1760     """retrieve the result of a pushkey request"""
  1727     ret = int(inpart.params['return'])
  1761     ret = int(inpart.params['return'])
  1728     partid = int(inpart.params['in-reply-to'])
  1762     partid = int(inpart.params['in-reply-to'])