hgext/evolve.py
changeset 820 a9a66143e2ec
parent 819 0b6af104fd78
child 821 202376586cf6
equal deleted inserted replaced
819:0b6af104fd78 820:a9a66143e2ec
    22 testedwith = '2.7 2.7.1 2.7.2 2.8 2.8.1'
    22 testedwith = '2.7 2.7.1 2.7.2 2.8 2.8.1'
    23 buglink = 'https://bitbucket.org/marmoute/mutable-history/issues'
    23 buglink = 'https://bitbucket.org/marmoute/mutable-history/issues'
    24 
    24 
    25 import sys
    25 import sys
    26 import random
    26 import random
       
    27 import struct
    27 
    28 
    28 import mercurial
    29 import mercurial
    29 from mercurial import util
    30 from mercurial import util
    30 
    31 
    31 try:
    32 try:
    38     raise util.Abort('Your Mercurial is too old for this version of Evolve',
    39     raise util.Abort('Your Mercurial is too old for this version of Evolve',
    39                      hint='requires version >> 2.4.x')
    40                      hint='requires version >> 2.4.x')
    40 
    41 
    41 
    42 
    42 
    43 
       
    44 from mercurial import base85
    43 from mercurial import bookmarks
    45 from mercurial import bookmarks
    44 from mercurial import cmdutil
    46 from mercurial import cmdutil
    45 from mercurial import commands
    47 from mercurial import commands
    46 from mercurial import context
    48 from mercurial import context
    47 from mercurial import copies
    49 from mercurial import copies
    57 from mercurial import scmutil
    59 from mercurial import scmutil
    58 from mercurial import templatekw
    60 from mercurial import templatekw
    59 from mercurial.i18n import _
    61 from mercurial.i18n import _
    60 from mercurial.commands import walkopts, commitopts, commitopts2
    62 from mercurial.commands import walkopts, commitopts, commitopts2
    61 from mercurial.node import nullid
    63 from mercurial.node import nullid
    62 
    64 from mercurial import wireproto
       
    65 
       
    66 _pack = struct.pack
    63 
    67 
    64 
    68 
    65 # This extension contains the following code
    69 # This extension contains the following code
    66 #
    70 #
    67 # - Extension Helper code
    71 # - Extension Helper code
  2075     return seenmarkers
  2079     return seenmarkers
  2076 
  2080 
  2077 
  2081 
  2078 _pushkeyescape = getattr(obsolete, '_pushkeyescape', None)
  2082 _pushkeyescape = getattr(obsolete, '_pushkeyescape', None)
  2079 if _pushkeyescape is None:
  2083 if _pushkeyescape is None:
       
  2084     _maxpayload = 5300
  2080     def _pushkeyescape(markers):
  2085     def _pushkeyescape(markers):
  2081         """encode markers into a dict suitable for pushkey exchange
  2086         """encode markers into a dict suitable for pushkey exchange
  2082 
  2087 
  2083         - binary data are base86 encoded
  2088         - binary data are base86 encoded
  2084         - splited in chunk less than 5300 bytes"""
  2089         - splited in chunk less than 5300 bytes"""
  2085         parts = []
  2090         parts = []
  2086         currentlen = _maxpayload * 2  # ensure we create a new part
  2091         currentlen = _maxpayload * 2  # ensure we create a new part
  2087         for marker in markers:
  2092         for marker in markers:
  2088             nextdata = _encodeonemarker(marker)
  2093             nextdata = obsolete._encodeonemarker(marker)
  2089             if (len(nextdata) + currentlen > _maxpayload):
  2094             if (len(nextdata) + currentlen > _maxpayload):
  2090                 currentpart = []
  2095                 currentpart = []
  2091                 currentlen = 0
  2096                 currentlen = 0
  2092                 parts.append(currentpart)
  2097                 parts.append(currentpart)
  2093             currentpart.append(nextdata)
  2098             currentpart.append(nextdata)
  2094             currentlen += len(nextdata)
  2099             currentlen += len(nextdata)
  2095         keys = {}
  2100         keys = {}
  2096         for idx, part in enumerate(reversed(parts)):
  2101         for idx, part in enumerate(reversed(parts)):
  2097             data = ''.join([_pack('>B', _fmversion)] + part)
  2102             data = ''.join([_pack('>B', 0)] + part)
  2098             keys['dump%i' % idx] = base85.b85encode(data)
  2103             keys['dump%i' % idx] = base85.b85encode(data)
  2099         return keys
  2104         return keys
  2100 
  2105 
  2101 
  2106 
  2102 
  2107 
  2114         repo.ui.status("OBSEXC: computing markers relevant to %i nodes\n"
  2119         repo.ui.status("OBSEXC: computing markers relevant to %i nodes\n"
  2115                        % len(nodes))
  2120                        % len(nodes))
  2116         markers = repo.obsstore.relevantmarkers(nodes)
  2121         markers = repo.obsstore.relevantmarkers(nodes)
  2117         rslts = []
  2122         rslts = []
  2118         repo.ui.status("OBSEXC: encoding %i markers\n" % len(markers))
  2123         repo.ui.status("OBSEXC: encoding %i markers\n" % len(markers))
  2119         remotedata = obsolete._pushkeyescape(markers).items()
  2124         remotedata = _pushkeyescape(markers).items()
  2120         totalbytes = sum(len(d) for k,d in remotedata)
  2125         totalbytes = sum(len(d) for k,d in remotedata)
  2121         sentbytes = 0
  2126         sentbytes = 0
  2122         repo.ui.status("OBSEXC: sending %i pushkey payload (%i bytes)\n"
  2127         repo.ui.status("OBSEXC: sending %i pushkey payload (%i bytes)\n"
  2123                         % (len(remotedata), totalbytes))
  2128                         % (len(remotedata), totalbytes))
  2124         for key, data in remotedata:
  2129         for key, data in remotedata: