Patchwork D10358: sidedata: add a way of replacing an existing sidedata computer

login
register
mail settings
Submitter phabricator
Date April 10, 2021, 7:16 p.m.
Message ID <differential-rev-PHID-DREV-2xqx2nlfcck6jrfcmd7k-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48675/
State Superseded
Headers show

Comments

phabricator - April 10, 2021, 7:16 p.m.
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This will be useful in a future patch to replace a sequential computer with
  a parallel computer. We only allow for explicit replacement, to force the users
  to think about overriding computers.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/interfaces/repository.py
  mercurial/localrepo.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -3365,16 +3365,25 @@ 
             return
         self._wanted_sidedata.add(pycompat.bytestr(category))
 
-    def register_sidedata_computer(self, kind, category, keys, computer, flags):
+    def register_sidedata_computer(
+        self, kind, category, keys, computer, flags, replace=False
+    ):
         if kind not in (b"changelog", b"manifest", b"filelog"):
             msg = _(b"unexpected revlog kind '%s'.")
             raise error.ProgrammingError(msg % kind)
         category = pycompat.bytestr(category)
-        if category in self._sidedata_computers.get(kind, []):
+        already_registered = category in self._sidedata_computers.get(kind, [])
+        if already_registered and not replace:
             msg = _(
                 b"cannot register a sidedata computer twice for category '%s'."
             )
             raise error.ProgrammingError(msg % category)
+        if replace and not already_registered:
+            msg = _(
+                b"cannot replace a sidedata computer that isn't registered "
+                b"for category '%s'."
+            )
+            raise error.ProgrammingError(msg % category)
         self._sidedata_computers.setdefault(kind, {})
         self._sidedata_computers[kind][category] = (keys, computer, flags)
 
diff --git a/mercurial/interfaces/repository.py b/mercurial/interfaces/repository.py
--- a/mercurial/interfaces/repository.py
+++ b/mercurial/interfaces/repository.py
@@ -1856,7 +1856,9 @@ 
     def savecommitmessage(text):
         pass
 
-    def register_sidedata_computer(kind, category, keys, computer, flags):
+    def register_sidedata_computer(
+        kind, category, keys, computer, flags, replace=False
+    ):
         pass
 
     def register_wanted_sidedata(category):