comparison mercurial/revlogutils/nodemap.py @ 44321:f0862ee1a31e

nodemap: keep track of the ondisk id of nodemap blocks If we are to incrementally update the files, we need to keep some details about the data we read. Differential Revision: https://phab.mercurial-scm.org/D7883
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 15 Jan 2020 15:49:26 +0100
parents d58206b70199
children 72c15641c8b4
comparison
equal deleted inserted replaced
44320:671f9479af0e 44321:f0862ee1a31e
218 218
219 class Block(dict): 219 class Block(dict):
220 """represent a block of the Trie 220 """represent a block of the Trie
221 221
222 contains up to 16 entry indexed from 0 to 15""" 222 contains up to 16 entry indexed from 0 to 15"""
223
224 def __init__(self):
225 super(Block, self).__init__()
226 # If this block exist on disk, here is its ID
227 self.ondisk_id = None
223 228
224 def __iter__(self): 229 def __iter__(self):
225 return iter(self.get(i) for i in range(16)) 230 return iter(self.get(i) for i in range(16))
226 231
227 232
321 return Block() 326 return Block()
322 block_map = {} 327 block_map = {}
323 new_blocks = [] 328 new_blocks = []
324 for i in range(0, len(data), S_BLOCK.size): 329 for i in range(0, len(data), S_BLOCK.size):
325 block = Block() 330 block = Block()
326 ondisk_id = len(block_map) 331 block.ondisk_id = len(block_map)
327 block_map[ondisk_id] = block 332 block_map[block.ondisk_id] = block
328 block_data = data[i : i + S_BLOCK.size] 333 block_data = data[i : i + S_BLOCK.size]
329 values = S_BLOCK.unpack(block_data) 334 values = S_BLOCK.unpack(block_data)
330 new_blocks.append((block, values)) 335 new_blocks.append((block, values))
331 for b, values in new_blocks: 336 for b, values in new_blocks:
332 for idx, v in enumerate(values): 337 for idx, v in enumerate(values):