comparison mercurial/revlog.py @ 47231:4d1c893b9095

revlog: unify flag processing when loading index The new code use a simple declaration to do centralised processing. This is clearer, shorter and less error prone. This will be especially useful as we plan to add a fourth format: changelog-v2. Differential Revision: https://phab.mercurial-scm.org/D10622
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 03 May 2021 12:30:46 +0200
parents 0e9105bf54cb
children 616b8f412676
comparison
equal deleted inserted replaced
47230:0e9105bf54cb 47231:4d1c893b9095
33 ) 33 )
34 from .i18n import _ 34 from .i18n import _
35 from .pycompat import getattr 35 from .pycompat import getattr
36 from .revlogutils.constants import ( 36 from .revlogutils.constants import (
37 ALL_KINDS, 37 ALL_KINDS,
38 FEATURES_BY_VERSION,
38 FLAG_GENERALDELTA, 39 FLAG_GENERALDELTA,
39 FLAG_INLINE_DATA, 40 FLAG_INLINE_DATA,
40 INDEX_HEADER, 41 INDEX_HEADER,
41 REVLOGV0, 42 REVLOGV0,
42 REVLOGV1, 43 REVLOGV1,
497 msg = _(b'unknown flags (%#04x) in version %d revlog %s') 498 msg = _(b'unknown flags (%#04x) in version %d revlog %s')
498 display_flag = self._format_flags >> 16 499 display_flag = self._format_flags >> 16
499 msg %= (display_flag, self._format_version, self.display_id) 500 msg %= (display_flag, self._format_version, self.display_id)
500 raise error.RevlogError(msg) 501 raise error.RevlogError(msg)
501 502
502 if self._format_version == REVLOGV0: 503 features = FEATURES_BY_VERSION[self._format_version]
503 self._inline = False 504 self._inline = features[b'inline'](self._format_flags)
504 self._generaldelta = False 505 self._generaldelta = features[b'generaldelta'](self._format_flags)
505 elif self._format_version == REVLOGV1: 506 self.hassidedata = features[b'sidedata']
506 self._inline = self._format_flags & FLAG_INLINE_DATA
507 self._generaldelta = self._format_flags & FLAG_GENERALDELTA
508 elif self._format_version == REVLOGV2:
509 # There is a bug in the transaction handling when going from an
510 # inline revlog to a separate index and data file. Turn it off until
511 # it's fixed, since v2 revlogs sometimes get rewritten on exchange.
512 # See issue6485
513 self._inline = False
514 # generaldelta implied by version 2 revlogs.
515 self._generaldelta = True
516 # revlog-v2 has built in sidedata support
517 self.hassidedata = True
518 else:
519 assert False, 'unreachable'
520 507
521 index_data = entry_data 508 index_data = entry_data
522 self._indexfile = entry_point 509 self._indexfile = entry_point
523 510
524 if self.postfix is None or self.postfix == b'a': 511 if self.postfix is None or self.postfix == b'a':