[PATCH 2 of 3] registrar: add a method to merge registrar instances

Matt Harbison mharbison72 at gmail.com
Sun Dec 30 22:55:08 EST 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1546224746 18000
#      Sun Dec 30 21:52:26 2018 -0500
# Node ID 94d4ffb62049c77f4631ae76732765b17033d2dd
# Parent  a567c612e90996a1a6410c0400634447405df996
registrar: add a method to merge registrar instances

This provides sanity checking beyond simply merging the underlying dictionaries.

diff --git a/mercurial/registrar.py b/mercurial/registrar.py
--- a/mercurial/registrar.py
+++ b/mercurial/registrar.py
@@ -73,6 +73,25 @@ class _funcregistrarbase(object):
 
         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
         """


More information about the Mercurial-devel mailing list