# HG changeset patch # User Pierre-Yves David # Date 1704816073 -3600 # Node ID 23cad1a872b6fa8bfa33c58e42685a1caf906817 # Parent c8779efa4fb4beac703908976f6a7e0d2aced45f 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. diff -r c8779efa4fb4 -r 23cad1a872b6 hgext3rd/topic/server.py --- 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):