comparison mercurial/revlog.py @ 47230:0e9105bf54cb

revlog: unify checks for supported flag The new code use a simple declaration to do centralised checking. 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/D10621
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 03 May 2021 12:30:35 +0200
parents e51392acd70c
children 4d1c893b9095
comparison
equal deleted inserted replaced
47229:21b3e6116bd1 47230:0e9105bf54cb
44 REVLOGV2, 44 REVLOGV2,
45 REVLOGV2_FLAGS, 45 REVLOGV2_FLAGS,
46 REVLOG_DEFAULT_FLAGS, 46 REVLOG_DEFAULT_FLAGS,
47 REVLOG_DEFAULT_FORMAT, 47 REVLOG_DEFAULT_FORMAT,
48 REVLOG_DEFAULT_VERSION, 48 REVLOG_DEFAULT_VERSION,
49 SUPPORTED_FLAGS,
49 ) 50 )
50 from .revlogutils.flagutil import ( 51 from .revlogutils.flagutil import (
51 REVIDX_DEFAULT_FLAGS, 52 REVIDX_DEFAULT_FLAGS,
52 REVIDX_ELLIPSIS, 53 REVIDX_ELLIPSIS,
53 REVIDX_EXTSTORED, 54 REVIDX_EXTSTORED,
485 header = new_header 486 header = new_header
486 487
487 self._format_flags = header & ~0xFFFF 488 self._format_flags = header & ~0xFFFF
488 self._format_version = header & 0xFFFF 489 self._format_version = header & 0xFFFF
489 490
491 supported_flags = SUPPORTED_FLAGS.get(self._format_version)
492 if supported_flags is None:
493 msg = _(b'unknown version (%d) in revlog %s')
494 msg %= (self._format_version, self.display_id)
495 raise error.RevlogError(msg)
496 elif self._format_flags & ~supported_flags:
497 msg = _(b'unknown flags (%#04x) in version %d revlog %s')
498 display_flag = self._format_flags >> 16
499 msg %= (display_flag, self._format_version, self.display_id)
500 raise error.RevlogError(msg)
501
490 if self._format_version == REVLOGV0: 502 if self._format_version == REVLOGV0:
491 if self._format_flags:
492 msg = _(b'unknown flags (%#04x) in version %d revlog %s')
493 display_flag = self._format_flags >> 16
494 msg %= (display_flag, self._format_version, self.display_id)
495 raise error.RevlogError(msg)
496
497 self._inline = False 503 self._inline = False
498 self._generaldelta = False 504 self._generaldelta = False
499
500 elif self._format_version == REVLOGV1: 505 elif self._format_version == REVLOGV1:
501 if self._format_flags & ~REVLOGV1_FLAGS:
502 msg = _(b'unknown flags (%#04x) in version %d revlog %s')
503 display_flag = self._format_flags >> 16
504 msg %= (display_flag, self._format_version, self.display_id)
505 raise error.RevlogError(msg)
506
507 self._inline = self._format_flags & FLAG_INLINE_DATA 506 self._inline = self._format_flags & FLAG_INLINE_DATA
508 self._generaldelta = self._format_flags & FLAG_GENERALDELTA 507 self._generaldelta = self._format_flags & FLAG_GENERALDELTA
509
510 elif self._format_version == REVLOGV2: 508 elif self._format_version == REVLOGV2:
511 if self._format_flags & ~REVLOGV2_FLAGS:
512 msg = _(b'unknown flags (%#04x) in version %d revlog %s')
513 display_flag = self._format_flags >> 16
514 msg %= (display_flag, self._format_version, self.display_id)
515 raise error.RevlogError(msg)
516
517 # There is a bug in the transaction handling when going from an 509 # There is a bug in the transaction handling when going from an
518 # inline revlog to a separate index and data file. Turn it off until 510 # inline revlog to a separate index and data file. Turn it off until
519 # it's fixed, since v2 revlogs sometimes get rewritten on exchange. 511 # it's fixed, since v2 revlogs sometimes get rewritten on exchange.
520 # See issue6485 512 # See issue6485
521 self._inline = False 513 self._inline = False
522 # generaldelta implied by version 2 revlogs. 514 # generaldelta implied by version 2 revlogs.
523 self._generaldelta = True 515 self._generaldelta = True
524 # revlog-v2 has built in sidedata support 516 # revlog-v2 has built in sidedata support
525 self.hassidedata = True 517 self.hassidedata = True
526
527 else: 518 else:
528 msg = _(b'unknown version (%d) in revlog %s') 519 assert False, 'unreachable'
529 msg %= (self._format_version, self.display_id)
530 raise error.RevlogError(msg)
531 520
532 index_data = entry_data 521 index_data = entry_data
533 self._indexfile = entry_point 522 self._indexfile = entry_point
534 523
535 if self.postfix is None or self.postfix == b'a': 524 if self.postfix is None or self.postfix == b'a':