comparison mercurial/revlog.py @ 46859:c6e23fb4bfb4

revlog: move the "index header" struct inside revlog.utils.constants The struct was previous called "version", but this is actually "version" + "flags". So header seems like a better name. The move to the `constants` module has the same motivation as the INDEX_ENTRY_V# ones. Differential Revision: https://phab.mercurial-scm.org/D10306
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 05 Apr 2021 12:21:23 +0200
parents 85e3a630cad9
children 3c9208702db3
comparison
equal deleted inserted replaced
46858:85e3a630cad9 46859:c6e23fb4bfb4
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 INDEX_ENTRY_V2,
47 INDEX_HEADER,
47 REVLOGV0, 48 REVLOGV0,
48 REVLOGV1, 49 REVLOGV1,
49 REVLOGV1_FLAGS, 50 REVLOGV1_FLAGS,
50 REVLOGV2, 51 REVLOGV2,
51 REVLOGV2_FLAGS, 52 REVLOGV2_FLAGS,
325 entry[7], 326 entry[7],
326 ) 327 )
327 return INDEX_ENTRY_V0.pack(*e2) 328 return INDEX_ENTRY_V0.pack(*e2)
328 329
329 330
330 versionformat = struct.Struct(b">I")
331 versionformat_pack = versionformat.pack
332 versionformat_unpack = versionformat.unpack
333
334 # corresponds to uncompressed length of indexformatng (2 gigs, 4-byte 331 # corresponds to uncompressed length of indexformatng (2 gigs, 4-byte
335 # signed integer) 332 # signed integer)
336 _maxentrysize = 0x7FFFFFFF 333 _maxentrysize = 0x7FFFFFFF
337 334
338 335
346 return index, cache 343 return index, cache
347 344
348 def packentry(self, entry, node, version, rev): 345 def packentry(self, entry, node, version, rev):
349 p = INDEX_ENTRY_V1.pack(*entry) 346 p = INDEX_ENTRY_V1.pack(*entry)
350 if rev == 0: 347 if rev == 0:
351 p = versionformat_pack(version) + p[4:] 348 p = INDEX_HEADER.pack(version) + p[4:]
352 return p 349 return p
353 350
354 351
355 class revlogv2io(object): 352 class revlogv2io(object):
356 def __init__(self): 353 def __init__(self):
361 return index, cache 358 return index, cache
362 359
363 def packentry(self, entry, node, version, rev): 360 def packentry(self, entry, node, version, rev):
364 p = INDEX_ENTRY_V2.pack(*entry) 361 p = INDEX_ENTRY_V2.pack(*entry)
365 if rev == 0: 362 if rev == 0:
366 p = versionformat_pack(version) + p[4:] 363 p = INDEX_HEADER.pack(version) + p[4:]
367 return p 364 return p
368 365
369 366
370 NodemapRevlogIO = None 367 NodemapRevlogIO = None
371 368
577 # relying on Python GC 574 # relying on Python GC
578 indexdata = util.buffer(util.mmapread(f)) 575 indexdata = util.buffer(util.mmapread(f))
579 else: 576 else:
580 indexdata = f.read() 577 indexdata = f.read()
581 if len(indexdata) > 0: 578 if len(indexdata) > 0:
582 versionflags = versionformat_unpack(indexdata[:4])[0] 579 versionflags = INDEX_HEADER.unpack(indexdata[:4])[0]
583 self._initempty = False 580 self._initempty = False
584 else: 581 else:
585 versionflags = newversionflags 582 versionflags = newversionflags
586 except IOError as inst: 583 except IOError as inst:
587 if inst.errno != errno.ENOENT: 584 if inst.errno != errno.ENOENT: