registrar: add a method to merge registrar instances
authorMatt Harbison <matt_harbison@yahoo.com>
Sun, 30 Dec 2018 21:52:26 -0500
changeset 41084 13f50ea8ac3b
parent 41083 9d35ae3d9999
child 41085 4d40f6bb4cef
registrar: add a method to merge registrar instances This provides sanity checking beyond simply merging the underlying dictionaries.
mercurial/registrar.py
--- 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
         """