diff hgext3rd/topic/server.py @ 6651:e9650b5616ac

branching: merge with stable
author Anton Shestakov <av6@dwimlabs.net>
date Wed, 17 Jan 2024 14:27:57 -0300
parents b162b76a1ee9 23cad1a872b6
children 92fd4581f569
line wrap: on
line diff
--- a/hgext3rd/topic/server.py	Sat Jan 06 13:26:13 2024 -0300
+++ b/hgext3rd/topic/server.py	Wed Jan 17 14:27:57 2024 -0300
@@ -109,31 +109,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()  # pytype: disable=module-attr
-                yield {b'namespaces': wireprototypes.encodelist(namespaces)}, f
-                d = f.value
+        @wireprotov1peer.batchable
+        def wp_tns_heads(self, namespaces):
+            f = wireprotov1peer.future()  # pytype: disable=module-attr
+            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):