changeset 6644:23cad1a872b6 stable

topic: add tns_heads method to wirepeer directly instead of using a subclass Otherwise other classes (e.g. sshpeer) that inherit from the old class will diverge from the new implementation if their modules were loaded before topic extension was initialized, which might happen for multi-repo servers.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 09 Jan 2024 17:01:13 +0100
parents c8779efa4fb4
children 4443117fdf94
files hgext3rd/topic/server.py
diffstat 1 files changed, 16 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/topic/server.py	Sun Dec 31 16:22:15 2023 -0300
+++ b/hgext3rd/topic/server.py	Tue Jan 09 17:01:13 2024 +0100
@@ -108,31 +108,27 @@
 
     if util.safehasattr(wireprotov1peer, 'future'):
         # hg <= 5.9 (c424ff4807e6)
-        class tnspeer(wireprotov1peer.wirepeer):
-            """ wirepeer that uses `future` class from before c424ff4807e6 """
-            @wireprotov1peer.batchable
-            def tns_heads(self, namespaces):
-                f = wireprotov1peer.future()
-                yield {b'namespaces': wireprototypes.encodelist(namespaces)}, f
-                d = f.value
+        @wireprotov1peer.batchable
+        def wp_tns_heads(self, namespaces):
+            f = wireprotov1peer.future()
+            yield {b'namespaces': wireprototypes.encodelist(namespaces)}, f
+            d = f.value
+            try:
+                yield wireprototypes.decodelist(d[:-1])
+            except ValueError:
+                self._abort(error.ResponseError(_(b"unexpected response:"), d))
+    else:
+        @wireprotov1peer.batchable
+        def wp_tns_heads(self, namespaces):
+            def decode(d):
                 try:
-                    yield wireprototypes.decodelist(d[:-1])
+                    return wireprototypes.decodelist(d[:-1])
                 except ValueError:
                     self._abort(error.ResponseError(_(b"unexpected response:"), d))
-    else:
-        class tnspeer(wireprotov1peer.wirepeer):
-            """ wirepeer that uses newer batchable scheme from c424ff4807e6 """
-            @wireprotov1peer.batchable
-            def tns_heads(self, namespaces):
-                def decode(d):
-                    try:
-                        return wireprototypes.decodelist(d[:-1])
-                    except ValueError:
-                        self._abort(error.ResponseError(_(b"unexpected response:"), d))
 
-                return {b'namespaces': wireprototypes.encodelist(namespaces)}, decode
+            return {b'namespaces': wireprototypes.encodelist(namespaces)}, decode
 
-    wireprotov1peer.wirepeer = tnspeer
+    wireprotov1peer.wirepeer.tns_heads = wp_tns_heads
 
     class topicpeerexecutor(wireprotov1peer.peerexecutor):