Patchwork D10353: revlog: replace the old `revlog_kind` approach with the new `target` one

login
register
mail settings
Submitter phabricator
Date April 9, 2021, 12:32 p.m.
Message ID <differential-rev-PHID-DREV-pp7dp43wdbk3wepncrp5-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48669/
State Superseded
Headers show

Comments

phabricator - April 9, 2021, 12:32 p.m.
Alphare created this revision.
Herald added a reviewer: indygreg.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The new `target` attribute supersedes the previous one.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  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

CHANGE DETAILS




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

Patch

diff --git a/tests/testlib/ext-sidedata-5.py b/tests/testlib/ext-sidedata-5.py
--- a/tests/testlib/ext-sidedata-5.py
+++ b/tests/testlib/ext-sidedata-5.py
@@ -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,
diff --git a/tests/testlib/ext-sidedata-3.py b/tests/testlib/ext-sidedata-3.py
--- a/tests/testlib/ext-sidedata-3.py
+++ b/tests/testlib/ext-sidedata-3.py
@@ -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,
diff --git a/tests/testlib/ext-sidedata-2.py b/tests/testlib/ext-sidedata-2.py
--- a/tests/testlib/ext-sidedata-2.py
+++ b/tests/testlib/ext-sidedata-2.py
@@ -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,
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -698,6 +698,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)
diff --git a/mercurial/metadata.py b/mercurial/metadata.py
--- a/mercurial/metadata.py
+++ b/mercurial/metadata.py
@@ -23,6 +23,7 @@ 
 )
 
 from .revlogutils import (
+    constants as revlogconst,
     flagutil as sidedataflag,
     sidedata as sidedatamod,
 )
@@ -829,7 +830,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,
diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -1621,7 +1621,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"""
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -3363,8 +3363,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, []):
diff --git a/mercurial/filelog.py b/mercurial/filelog.py
--- a/mercurial/filelog.py
+++ b/mercurial/filelog.py
@@ -39,7 +39,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):
diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -432,7 +432,6 @@ 
         self._filteredrevs = frozenset()
         self._filteredrevs_hashcache = {}
         self._copiesstorage = opener.options.get(b'copies-storage')
-        self.revlog_kind = b'changelog'
 
     @property
     def filteredrevs(self):
diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -34,6 +34,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")
@@ -386,15 +387,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,
@@ -417,15 +419,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"))
@@ -440,7 +443,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)