comparison mercurial/revlog.py @ 46858:85e3a630cad9

revlog: move the details of revlog "v2" index inside revlog.utils.constants the revlog module is quite large and this kind of format information would handy for other module. So let us start to gather this information about the format in a more appropriate place. We update various reference to this information to use the new "source of truth" in the process. Differential Revision: https://phab.mercurial-scm.org/D10305
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 05 Apr 2021 12:21:12 +0200
parents cc65cea90edb
children c6e23fb4bfb4
comparison
equal deleted inserted replaced
46857:cc65cea90edb 46858:85e3a630cad9
41 from .revlogutils.constants import ( 41 from .revlogutils.constants import (
42 FLAG_GENERALDELTA, 42 FLAG_GENERALDELTA,
43 FLAG_INLINE_DATA, 43 FLAG_INLINE_DATA,
44 INDEX_ENTRY_V0, 44 INDEX_ENTRY_V0,
45 INDEX_ENTRY_V1, 45 INDEX_ENTRY_V1,
46 INDEX_ENTRY_V2,
46 REVLOGV0, 47 REVLOGV0,
47 REVLOGV1, 48 REVLOGV1,
48 REVLOGV1_FLAGS, 49 REVLOGV1_FLAGS,
49 REVLOGV2, 50 REVLOGV2,
50 REVLOGV2_FLAGS, 51 REVLOGV2_FLAGS,
85 ) 86 )
86 from .utils import ( 87 from .utils import (
87 storageutil, 88 storageutil,
88 stringutil, 89 stringutil,
89 ) 90 )
90 from .pure import parsers as pureparsers
91 91
92 # blanked usage of all the name to prevent pyflakes constraints 92 # blanked usage of all the name to prevent pyflakes constraints
93 # We need these name available in the module for extensions. 93 # We need these name available in the module for extensions.
94 REVLOGV0 94 REVLOGV0
95 REVLOGV1 95 REVLOGV1
350 if rev == 0: 350 if rev == 0:
351 p = versionformat_pack(version) + p[4:] 351 p = versionformat_pack(version) + p[4:]
352 return p 352 return p
353 353
354 354
355 indexformatv2 = struct.Struct(pureparsers.Index2Mixin.index_format)
356 indexformatv2_pack = indexformatv2.pack
357
358
359 class revlogv2io(object): 355 class revlogv2io(object):
360 def __init__(self): 356 def __init__(self):
361 self.size = indexformatv2.size 357 self.size = INDEX_ENTRY_V2.size
362 358
363 def parseindex(self, data, inline): 359 def parseindex(self, data, inline):
364 index, cache = parsers.parse_index2(data, inline, revlogv2=True) 360 index, cache = parsers.parse_index2(data, inline, revlogv2=True)
365 return index, cache 361 return index, cache
366 362
367 def packentry(self, entry, node, version, rev): 363 def packentry(self, entry, node, version, rev):
368 p = indexformatv2_pack(*entry) 364 p = INDEX_ENTRY_V2.pack(*entry)
369 if rev == 0: 365 if rev == 0:
370 p = versionformat_pack(version) + p[4:] 366 p = versionformat_pack(version) + p[4:]
371 return p 367 return p
372 368
373 369