comparison mercurial/bundle2.py @ 36963:9988fc10f49e

revbranchcache: add a bundle2 handler for a rbc part We add the necessary bit to process a part containing rev-branch-cache information. The local rev branch cache is then updated with the received information. Computing branch cache can become a significant part of the time spent pulling.
author Boris Feld <boris.feld@octobus.net>
date Wed, 21 Feb 2018 17:35:04 +0100
parents 0b697c650b04
children 79b73be4dda5
comparison
equal deleted inserted replaced
36962:95f4f1bfb650 36963:9988fc10f49e
156 156
157 from .i18n import _ 157 from .i18n import _
158 from . import ( 158 from . import (
159 bookmarks, 159 bookmarks,
160 changegroup, 160 changegroup,
161 encoding,
161 error, 162 error,
162 node as nodemod, 163 node as nodemod,
163 obsolete, 164 obsolete,
164 phases, 165 phases,
165 pushkey, 166 pushkey,
2127 count += 1 2128 count += 1
2128 2129
2129 cache.write() 2130 cache.write()
2130 op.ui.debug('applied %i hgtags fnodes cache entries\n' % count) 2131 op.ui.debug('applied %i hgtags fnodes cache entries\n' % count)
2131 2132
2133 rbcstruct = struct.Struct('>III')
2134
2135 @parthandler('cache:rev-branch-cache')
2136 def handlerbc(op, inpart):
2137 """receive a rev-branch-cache payload and update the local cache
2138
2139 The payload is a series of data related to each branch
2140
2141 1) branch name length
2142 2) number of open heads
2143 3) number of closed heads
2144 4) open heads nodes
2145 5) closed heads nodes
2146 """
2147 total = 0
2148 rawheader = inpart.read(rbcstruct.size)
2149 cache = op.repo.revbranchcache()
2150 cl = op.repo.unfiltered().changelog
2151 while rawheader:
2152 header = rbcstruct.unpack(rawheader)
2153 total += header[1] + header[2]
2154 utf8branch = inpart.read(header[0])
2155 branch = encoding.tolocal(utf8branch)
2156 for x in xrange(header[1]):
2157 node = inpart.read(20)
2158 rev = cl.rev(node)
2159 cache.setdata(branch, rev, node, False)
2160 for x in xrange(header[2]):
2161 node = inpart.read(20)
2162 rev = cl.rev(node)
2163 cache.setdata(branch, rev, node, True)
2164 rawheader = inpart.read(rbcstruct.size)
2165 cache.write()
2166
2132 @parthandler('pushvars') 2167 @parthandler('pushvars')
2133 def bundle2getvars(op, part): 2168 def bundle2getvars(op, part):
2134 '''unbundle a bundle2 containing shellvars on the server''' 2169 '''unbundle a bundle2 containing shellvars on the server'''
2135 # An option to disable unbundling on server-side for security reasons 2170 # An option to disable unbundling on server-side for security reasons
2136 if op.ui.configbool('push', 'pushvars.server'): 2171 if op.ui.configbool('push', 'pushvars.server'):