registrar: add a method to merge registrar instances
This provides sanity checking beyond simply merging the underlying dictionaries.
--- 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
"""