revlog: replace the old `revlog_kind` approach with the new `target` one
authorPierre-Yves David <pierre-yves.david@octobus.net>
Thu, 08 Apr 2021 19:00:21 +0200
changeset 47073 64cd1496bb70
parent 47072 4c041c71ec01
child 47074 b409cdc6a139
revlog: replace the old `revlog_kind` approach with the new `target` one The new `target` attribute supersedes the previous one. Differential Revision: https://phab.mercurial-scm.org/D10353
mercurial/changegroup.py
mercurial/changelog.py
mercurial/filelog.py
mercurial/localrepo.py
mercurial/manifest.py
mercurial/metadata.py
mercurial/revlog.py
tests/testlib/ext-sidedata-2.py
tests/testlib/ext-sidedata-3.py
tests/testlib/ext-sidedata-5.py
--- a/mercurial/changegroup.py	Tue Apr 06 05:20:24 2021 +0200
+++ b/mercurial/changegroup.py	Thu Apr 08 19:00:21 2021 +0200
@@ -33,6 +33,7 @@
 
 from .interfaces import repository
 from .revlogutils import sidedata as sidedatamod
+from .revlogutils import constants as revlog_constants
 
 _CHANGEGROUPV1_DELTA_HEADER = struct.Struct(b"20s20s20s20s")
 _CHANGEGROUPV2_DELTA_HEADER = struct.Struct(b"20s20s20s20s20s")
@@ -385,15 +386,16 @@
                 _(b'manifests'), unit=_(b'chunks'), total=changesets
             )
             on_manifest_rev = None
-            if sidedata_helpers and b'manifest' in sidedata_helpers[1]:
+            if sidedata_helpers:
+                if revlog_constants.KIND_MANIFESTLOG in sidedata_helpers[1]:
 
-                def on_manifest_rev(manifest, rev):
-                    range = touched_manifests.get(manifest)
-                    if not range:
-                        touched_manifests[manifest] = (rev, rev)
-                    else:
-                        assert rev == range[1] + 1
-                        touched_manifests[manifest] = (range[0], rev)
+                    def on_manifest_rev(manifest, rev):
+                        range = touched_manifests.get(manifest)
+                        if not range:
+                            touched_manifests[manifest] = (rev, rev)
+                        else:
+                            assert rev == range[1] + 1
+                            touched_manifests[manifest] = (range[0], rev)
 
             self._unpackmanifests(
                 repo,
@@ -416,15 +418,16 @@
                         needfiles.setdefault(f, set()).add(n)
 
             on_filelog_rev = None
-            if sidedata_helpers and b'filelog' in sidedata_helpers[1]:
+            if sidedata_helpers:
+                if revlog_constants.KIND_FILELOG in sidedata_helpers[1]:
 
-                def on_filelog_rev(filelog, rev):
-                    range = touched_filelogs.get(filelog)
-                    if not range:
-                        touched_filelogs[filelog] = (rev, rev)
-                    else:
-                        assert rev == range[1] + 1
-                        touched_filelogs[filelog] = (range[0], rev)
+                    def on_filelog_rev(filelog, rev):
+                        range = touched_filelogs.get(filelog)
+                        if not range:
+                            touched_filelogs[filelog] = (rev, rev)
+                        else:
+                            assert rev == range[1] + 1
+                            touched_filelogs[filelog] = (range[0], rev)
 
             # process the files
             repo.ui.status(_(b"adding file changes\n"))
@@ -439,7 +442,7 @@
             )
 
             if sidedata_helpers:
-                if b'changelog' in sidedata_helpers[1]:
+                if revlog_constants.KIND_CHANGELOG in sidedata_helpers[1]:
                     cl.rewrite_sidedata(sidedata_helpers, clstart, clend - 1)
                 for mf, (startrev, endrev) in touched_manifests.items():
                     mf.rewrite_sidedata(sidedata_helpers, startrev, endrev)
--- a/mercurial/changelog.py	Tue Apr 06 05:20:24 2021 +0200
+++ b/mercurial/changelog.py	Thu Apr 08 19:00:21 2021 +0200
@@ -431,7 +431,6 @@
         self._filteredrevs = frozenset()
         self._filteredrevs_hashcache = {}
         self._copiesstorage = opener.options.get(b'copies-storage')
-        self.revlog_kind = b'changelog'
 
     @property
     def filteredrevs(self):
--- a/mercurial/filelog.py	Tue Apr 06 05:20:24 2021 +0200
+++ b/mercurial/filelog.py	Thu Apr 08 19:00:21 2021 +0200
@@ -36,7 +36,6 @@
         # Full name of the user visible file, relative to the repository root.
         # Used by LFS.
         self._revlog.filename = path
-        self._revlog.revlog_kind = b'filelog'
         self.nullid = self._revlog.nullid
 
     def __len__(self):
--- a/mercurial/localrepo.py	Tue Apr 06 05:20:24 2021 +0200
+++ b/mercurial/localrepo.py	Thu Apr 08 19:00:21 2021 +0200
@@ -3368,8 +3368,8 @@
         self._wanted_sidedata.add(pycompat.bytestr(category))
 
     def register_sidedata_computer(self, kind, category, keys, computer):
-        if kind not in (b"changelog", b"manifest", b"filelog"):
-            msg = _(b"unexpected revlog kind '%s'.")
+        if kind not in revlogconst.ALL_KINDS:
+            msg = _(b"unexpected revlog kind %r.")
             raise error.ProgrammingError(msg % kind)
         category = pycompat.bytestr(category)
         if category in self._sidedata_computers.get(kind, []):
--- a/mercurial/manifest.py	Tue Apr 06 05:20:24 2021 +0200
+++ b/mercurial/manifest.py	Thu Apr 08 19:00:21 2021 +0200
@@ -1625,7 +1625,6 @@
         self.index = self._revlog.index
         self.version = self._revlog.version
         self._generaldelta = self._revlog._generaldelta
-        self._revlog.revlog_kind = b'manifest'
 
     def _setupmanifestcachehooks(self, repo):
         """Persist the manifestfulltextcache on lock release"""
--- a/mercurial/metadata.py	Tue Apr 06 05:20:24 2021 +0200
+++ b/mercurial/metadata.py	Thu Apr 08 19:00:21 2021 +0200
@@ -20,6 +20,7 @@
 )
 
 from .revlogutils import (
+    constants as revlogconst,
     flagutil as sidedataflag,
     sidedata as sidedatamod,
 )
@@ -826,7 +827,7 @@
     if requirementsmod.COPIESSDC_REQUIREMENT in repo.requirements:
         repo.register_wanted_sidedata(sidedatamod.SD_FILES)
         repo.register_sidedata_computer(
-            b"changelog",
+            revlogconst.KIND_CHANGELOG,
             sidedatamod.SD_FILES,
             (sidedatamod.SD_FILES,),
             copies_sidedata_computer,
--- a/mercurial/revlog.py	Tue Apr 06 05:20:24 2021 +0200
+++ b/mercurial/revlog.py	Thu Apr 08 19:00:21 2021 +0200
@@ -559,6 +559,10 @@
         self._decompressors = {}
 
     @util.propertycache
+    def revlog_kind(self):
+        return self.target[0]
+
+    @util.propertycache
     def _compressor(self):
         engine = util.compengines[self._compengine]
         return engine.revlogcompressor(self._compengineopts)
--- a/tests/testlib/ext-sidedata-2.py	Tue Apr 06 05:20:24 2021 +0200
+++ b/tests/testlib/ext-sidedata-2.py	Thu Apr 08 19:00:21 2021 +0200
@@ -14,6 +14,7 @@
 import struct
 
 from mercurial.revlogutils import sidedata as sidedatamod
+from mercurial.revlogutils import constants
 
 
 def compute_sidedata_1(repo, revlog, rev, sidedata, text=None):
@@ -35,7 +36,7 @@
 
 def reposetup(ui, repo):
     # Sidedata keys happen to be the same as the categories, easier for testing.
-    for kind in (b'changelog', b'manifest', b'filelog'):
+    for kind in constants.ALL_KINDS:
         repo.register_sidedata_computer(
             kind,
             sidedatamod.SD_TEST1,
--- a/tests/testlib/ext-sidedata-3.py	Tue Apr 06 05:20:24 2021 +0200
+++ b/tests/testlib/ext-sidedata-3.py	Thu Apr 08 19:00:21 2021 +0200
@@ -20,6 +20,7 @@
 )
 
 from mercurial.revlogutils import sidedata as sidedatamod
+from mercurial.revlogutils import constants
 
 
 def compute_sidedata_1(repo, revlog, rev, sidedata, text=None):
@@ -65,7 +66,7 @@
 
 def reposetup(ui, repo):
     # Sidedata keys happen to be the same as the categories, easier for testing.
-    for kind in (b'changelog', b'manifest', b'filelog'):
+    for kind in constants.ALL_KINDS:
         repo.register_sidedata_computer(
             kind,
             sidedatamod.SD_TEST1,
--- a/tests/testlib/ext-sidedata-5.py	Tue Apr 06 05:20:24 2021 +0200
+++ b/tests/testlib/ext-sidedata-5.py	Thu Apr 08 19:00:21 2021 +0200
@@ -21,6 +21,7 @@
 
 
 from mercurial.revlogutils import sidedata as sidedatamod
+from mercurial.revlogutils import constants
 
 
 def compute_sidedata_1(repo, revlog, rev, sidedata, text=None):
@@ -42,7 +43,7 @@
 
 def reposetup(ui, repo):
     # Sidedata keys happen to be the same as the categories, easier for testing.
-    for kind in (b'changelog', b'manifest', b'filelog'):
+    for kind in constants.ALL_KINDS:
         repo.register_sidedata_computer(
             kind,
             sidedatamod.SD_TEST1,