revlog: split the `version` attribute into its two components
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 03 May 2021 12:20:45 +0200
changeset 47139 f58a13c52726
parent 47138 bc138f2a2e47
child 47140 c55afa35a5c8
revlog: split the `version` attribute into its two components The `revlog.version` attribute contained an integer coding 2 different informations: * the revlog version number * a bit field defining some specific feature of the revlog We now explicitly store the two components independently. This avoid exposing the implementation details all around the code and prepare for future revlog version that would encode the information in a different way. In the process we drop the `version` attribute from the interface. It was flagged for removal when that interface was created. Differential Revision: https://phab.mercurial-scm.org/D10565
mercurial/changelog.py
mercurial/debugcommands.py
mercurial/interfaces/repository.py
mercurial/manifest.py
mercurial/revlog.py
mercurial/verify.py
--- a/mercurial/changelog.py	Mon May 03 12:20:35 2021 +0200
+++ b/mercurial/changelog.py	Mon May 03 12:20:45 2021 +0200
@@ -413,10 +413,10 @@
             concurrencychecker=concurrencychecker,
         )
 
-        if self._initempty and (self.version & 0xFFFF == revlog.REVLOGV1):
+        if self._initempty and (self._format_version == revlog.REVLOGV1):
             # changelogs don't benefit from generaldelta.
 
-            self.version &= ~revlog.FLAG_GENERALDELTA
+            self._format_flags &= ~revlog.FLAG_GENERALDELTA
             self._generaldelta = False
 
         # Delta chains for changelogs tend to be very small because entries
--- a/mercurial/debugcommands.py	Mon May 03 12:20:35 2021 +0200
+++ b/mercurial/debugcommands.py	Mon May 03 12:20:45 2021 +0200
@@ -2972,8 +2972,8 @@
             )
         return 0
 
-    v = r.version
-    format = v & 0xFFFF
+    format = r._format_version
+    v = r._format_flags
     flags = []
     gdelta = False
     if v & revlog.FLAG_INLINE_DATA:
--- a/mercurial/interfaces/repository.py	Mon May 03 12:20:35 2021 +0200
+++ b/mercurial/interfaces/repository.py	Mon May 03 12:20:45 2021 +0200
@@ -1181,13 +1181,6 @@
         """
     )
 
-    version = interfaceutil.Attribute(
-        """Revlog version number.
-
-        TODO this is revlog specific and should not be exposed.
-        """
-    )
-
     _generaldelta = interfaceutil.Attribute(
         """Whether generaldelta storage is being used.
 
--- a/mercurial/manifest.py	Mon May 03 12:20:35 2021 +0200
+++ b/mercurial/manifest.py	Mon May 03 12:20:45 2021 +0200
@@ -1623,7 +1623,6 @@
         )
 
         self.index = self._revlog.index
-        self.version = self._revlog.version
         self._generaldelta = self._revlog._generaldelta
 
     def _setupmanifestcachehooks(self, repo):
--- a/mercurial/revlog.py	Mon May 03 12:20:35 2021 +0200
+++ b/mercurial/revlog.py	Mon May 03 12:20:45 2021 +0200
@@ -451,10 +451,8 @@
 
             versionflags = newversionflags
 
-        self.version = versionflags
-
-        flags = versionflags & ~0xFFFF
-        fmt = versionflags & 0xFFFF
+        flags = self._format_flags = versionflags & ~0xFFFF
+        fmt = self._format_version = versionflags & 0xFFFF
 
         if fmt == REVLOGV0:
             if flags:
@@ -519,7 +517,7 @@
                 use_rust_index = self.opener.options.get(b'rust.index')
 
         self._parse_index = parse_index_v1
-        if self.version == REVLOGV0:
+        if self._format_version == REVLOGV0:
             self._parse_index = revlogv0.parse_index_v0
         elif fmt == REVLOGV2:
             self._parse_index = parse_index_v2
@@ -1945,12 +1943,13 @@
                     trindex = r
 
         with self._indexfp(b'w') as fp:
-            self.version &= ~FLAG_INLINE_DATA
+            self._format_flags &= ~FLAG_INLINE_DATA
             self._inline = False
             for i in self:
                 e = self.index.entry_binary(i)
                 if i == 0:
-                    header = self.index.pack_header(self.version)
+                    header = self._format_flags | self._format_version
+                    header = self.index.pack_header(header)
                     e = header + e
                 fp.write(e)
 
@@ -2269,13 +2268,14 @@
             len(serialized_sidedata),
         )
 
-        if self.version & 0xFFFF != REVLOGV2:
+        if self._format_version != REVLOGV2:
             e = e[:8]
 
         self.index.append(e)
         entry = self.index.entry_binary(curr)
         if curr == 0:
-            header = self.index.pack_header(self.version)
+            header = self._format_flags | self._format_version
+            header = self.index.pack_header(header)
             entry = header + entry
         self._writeentry(
             transaction,
@@ -2307,7 +2307,7 @@
         to `n - 1`'s sidedata being written after `n`'s data.
 
         TODO cache this in a docket file before getting out of experimental."""
-        if self.version & 0xFFFF != REVLOGV2:
+        if self._format_version != REVLOGV2:
             return self.end(prev)
 
         offset = 0
@@ -2847,9 +2847,10 @@
                 addrevisioncb(self, rev, node)
 
     def censorrevision(self, tr, censornode, tombstone=b''):
-        if (self.version & 0xFFFF) == REVLOGV0:
+        if self._format_version == REVLOGV0:
             raise error.RevlogError(
-                _(b'cannot censor with version %d revlogs') % self.version
+                _(b'cannot censor with version %d revlogs')
+                % self._format_version
             )
 
         censorrev = self.rev(censornode)
@@ -2875,7 +2876,8 @@
             datafile=newdatafile,
             censorable=True,
         )
-        newrl.version = self.version
+        newrl._format_version = self._format_version
+        newrl._format_flags = self._format_flags
         newrl._generaldelta = self._generaldelta
         newrl._parse_index = self._parse_index
 
@@ -2947,7 +2949,7 @@
         if di:
             yield revlogproblem(error=_(b'index contains %d extra bytes') % di)
 
-        version = self.version & 0xFFFF
+        version = self._format_version
 
         # The verifier tells us what version revlog we should be.
         if version != state[b'expectedversion']:
@@ -3137,6 +3139,7 @@
                 self.index.replace_sidedata_info(rev, e[8], e[9], e[0])
                 packed = self.index.entry_binary(rev)
                 if rev == 0:
-                    header = self.index.pack_header(self.version)
+                    header = self._format_flags | self._format_version
+                    header = self.index.pack_header(header)
                     packed = header + packed
                 fp.write(packed)
--- a/mercurial/verify.py	Mon May 03 12:20:35 2021 +0200
+++ b/mercurial/verify.py	Mon May 03 12:20:45 2021 +0200
@@ -51,7 +51,7 @@
         self.warnings = 0
         self.havecl = len(repo.changelog) > 0
         self.havemf = len(repo.manifestlog.getstorage(b'')) > 0
-        self.revlogv1 = repo.changelog.version != revlog.REVLOGV0
+        self.revlogv1 = repo.changelog._format_version != revlog.REVLOGV0
         self.lrugetctx = util.lrucachefunc(repo.unfiltered().__getitem__)
         self.refersmf = False
         self.fncachewarned = False
@@ -102,7 +102,7 @@
         if d[1]:
             self._err(None, _(b"index contains %d extra bytes") % d[1], name)
 
-        if obj.version != revlog.REVLOGV0:
+        if obj._format_version != revlog.REVLOGV0:
             if not self.revlogv1:
                 self._warn(_(b"warning: `%s' uses revlog format 1") % name)
         elif self.revlogv1:
@@ -483,7 +483,7 @@
 
         state = {
             # TODO this assumes revlog storage for changelog.
-            b'expectedversion': self.repo.changelog.version & 0xFFFF,
+            b'expectedversion': self.repo.changelog._format_version,
             b'skipflags': self.skipflags,
             # experimental config: censor.policy
             b'erroroncensored': ui.config(b'censor', b'policy') == b'abort',