Patchwork D10622: revlog: unify flag processing when loading index

login
register
mail settings
Submitter phabricator
Date May 3, 2021, 12:08 p.m.
Message ID <differential-rev-PHID-DREV-cqcyby6jlzyklyvovcd4-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48939/
State New
Headers show

Comments

phabricator - May 3, 2021, 12:08 p.m.
marmoute created this revision.
Herald added a reviewer: indygreg.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10622

AFFECTED FILES
  mercurial/revlog.py
  mercurial/revlogutils/constants.py

CHANGE DETAILS




To: marmoute, indygreg, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/revlogutils/constants.py b/mercurial/revlogutils/constants.py
--- a/mercurial/revlogutils/constants.py
+++ b/mercurial/revlogutils/constants.py
@@ -120,4 +120,34 @@ 
     REVLOGV2: REVLOGV2_FLAGS,
 }
 
+_no = lambda flags: False
+_yes = lambda flags: True
+
+
+def _from_flag(flag):
+    return lambda flags: bool(flags & flag)
+
+
+FEATURES_BY_VERSION = {
+    REVLOGV0: {
+        b'inline': _no,
+        b'generaldelta': _no,
+        b'sidedata': False,
+    },
+    REVLOGV1: {
+        b'inline': _from_flag(FLAG_INLINE_DATA),
+        b'generaldelta': _from_flag(FLAG_GENERALDELTA),
+        b'sidedata': False,
+    },
+    REVLOGV2: {
+        # There is a bug in the transaction handling when going from an
+        # inline revlog to a separate index and data file. Turn it off until
+        # it's fixed, since v2 revlogs sometimes get rewritten on exchange.
+        # See issue6485
+        b'inline': _no,
+        b'generaldelta': _yes,
+        b'sidedata': True,
+    },
+}
+
 SPARSE_REVLOG_MAX_CHAIN_LENGTH = 1000
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -35,6 +35,7 @@ 
 from .pycompat import getattr
 from .revlogutils.constants import (
     ALL_KINDS,
+    FEATURES_BY_VERSION,
     FLAG_GENERALDELTA,
     FLAG_INLINE_DATA,
     INDEX_HEADER,
@@ -499,24 +500,10 @@ 
             msg %= (display_flag, self._format_version, self.display_id)
             raise error.RevlogError(msg)
 
-        if self._format_version == REVLOGV0:
-            self._inline = False
-            self._generaldelta = False
-        elif self._format_version == REVLOGV1:
-            self._inline = self._format_flags & FLAG_INLINE_DATA
-            self._generaldelta = self._format_flags & FLAG_GENERALDELTA
-        elif self._format_version == REVLOGV2:
-            # There is a bug in the transaction handling when going from an
-            # inline revlog to a separate index and data file. Turn it off until
-            # it's fixed, since v2 revlogs sometimes get rewritten on exchange.
-            # See issue6485
-            self._inline = False
-            # generaldelta implied by version 2 revlogs.
-            self._generaldelta = True
-            # revlog-v2 has built in sidedata support
-            self.hassidedata = True
-        else:
-            assert False, 'unreachable'
+        features = FEATURES_BY_VERSION[self._format_version]
+        self._inline = features[b'inline'](self._format_flags)
+        self._generaldelta = features[b'generaldelta'](self._format_flags)
+        self.hassidedata = features[b'sidedata']
 
         index_data = entry_data
         self._indexfile = entry_point