diff mercurial/revlog.py @ 47072:4c041c71ec01

revlog: introduce an explicit tracking of what the revlog is about Since the dawn of time, people have been forced to rely to lossy introspection of the index filename to determine what the purpose and role of the revlog they encounter is. This is hacky, error prone, inflexible, abstraction-leaky, <insert-your-own-complaints-here>. In f63299ee7e4d Raphaël introduced a new attribute to track this information: `revlog_kind`. However it is initialized in an odd place and various instances end up not having it set. In addition is only tracking some of the information we end up having to introspect in various pieces of code. So we add a new attribute that holds more data and is more strictly enforced. This work is done in collaboration with Raphaël. The `revlog_kind` one will be removed/adapted in the next changeset. We expect to be able to clean up various existing piece of code and to simplify coming work around the newer revlog format. Differential Revision: https://phab.mercurial-scm.org/D10352
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 06 Apr 2021 05:20:24 +0200
parents c5e1cc0b4c77
children 64cd1496bb70
line wrap: on
line diff
--- a/mercurial/revlog.py	Tue May 04 08:54:28 2021 -0700
+++ b/mercurial/revlog.py	Tue Apr 06 05:20:24 2021 +0200
@@ -34,6 +34,7 @@
 from .i18n import _
 from .pycompat import getattr
 from .revlogutils.constants import (
+    ALL_KINDS,
     FLAG_GENERALDELTA,
     FLAG_INLINE_DATA,
     INDEX_HEADER,
@@ -287,7 +288,8 @@
     def __init__(
         self,
         opener,
-        indexfile,
+        target,
+        indexfile=None,
         datafile=None,
         checkambig=False,
         mmaplargeindex=False,
@@ -302,6 +304,12 @@
         opener is a function that abstracts the file opening operation
         and can be used to implement COW semantics or the like.
 
+        `target`: a (KIND, ID) tuple that identify the content stored in
+        this revlog. It help the rest of the code to understand what the revlog
+        is about without having to resort to heuristic and index filename
+        analysis. Note: that this must be reliably be set by normal code, but
+        that test, debug, or performance measurement code might not set this to
+        accurate value.
         """
         self.upperboundcomp = upperboundcomp
         self.indexfile = indexfile
@@ -313,6 +321,9 @@
             )
 
         self.opener = opener
+        assert target[0] in ALL_KINDS
+        assert len(target) == 2
+        self.target = target
         #  When True, indexfile is opened with checkambig=True at writing, to
         #  avoid file stat ambiguity.
         self._checkambig = checkambig
@@ -2869,7 +2880,13 @@
         newdatafile = self.datafile + b'.tmpcensored'
 
         # This is a bit dangerous. We could easily have a mismatch of state.
-        newrl = revlog(self.opener, newindexfile, newdatafile, censorable=True)
+        newrl = revlog(
+            self.opener,
+            target=self.target,
+            indexfile=newindexfile,
+            datafile=newdatafile,
+            censorable=True,
+        )
         newrl.version = self.version
         newrl._generaldelta = self._generaldelta
         newrl._parse_index = self._parse_index