changeset 41081:13f50ea8ac3b

registrar: add a method to merge registrar instances This provides sanity checking beyond simply merging the underlying dictionaries.
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 30 Dec 2018 21:52:26 -0500
parents 9d35ae3d9999
children 4d40f6bb4cef
files mercurial/registrar.py
diffstat 1 files changed, 19 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/registrar.py	Sat Dec 29 01:51:02 2018 -0500
+++ b/mercurial/registrar.py	Sun Dec 30 21:52:26 2018 -0500
@@ -73,6 +73,25 @@
 
         return func
 
+    def _merge(self, registrarbase):
+        """Merge the entries of the given registrar object into this one.
+
+        The other registrar object must not contain any entries already in the
+        current one, or a ProgrammmingError is raised.  Additionally, the types
+        of the two registrars must match.
+        """
+        if type(self) != type(registrarbase):
+            msg = "cannot merge different types of registrar"
+            raise error.ProgrammingError(msg)
+
+        dups = set(registrarbase._table.keys()).intersection(self._table.keys())
+
+        if dups:
+            msg = 'duplicate registration for names: "%s"' % '", "'.join(dups)
+            raise error.ProgrammingError(msg)
+
+        self._table.update(registrarbase._table)
+
     def _parsefuncdecl(self, decl):
         """Parse function declaration and return the name of function in it
         """