# HG changeset patch # User Matt Harbison # Date 1546224746 18000 # Node ID 13f50ea8ac3b5e9028b5733e7b746b9036341e6a # Parent 9d35ae3d9999a915f701386e9e2ac7976abf5000 registrar: add a method to merge registrar instances This provides sanity checking beyond simply merging the underlying dictionaries. diff -r 9d35ae3d9999 -r 13f50ea8ac3b 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 """