# HG changeset patch # User Anton Shestakov # Date 1697220978 10800 # Node ID ef04d887c9a0593e839ed1ab308b46682639c24b # Parent 40875ca5e7245ad5a715ad097fde77cade51d493 topic: compatibility for tns_heads peer command with Mercurial 5.9 and older diff -r 40875ca5e724 -r ef04d887c9a0 hgext3rd/topic/server.py --- a/hgext3rd/topic/server.py Thu Oct 12 14:37:31 2023 -0300 +++ b/hgext3rd/topic/server.py Fri Oct 13 15:16:18 2023 -0300 @@ -10,6 +10,7 @@ extensions, localrepo, repoview, + util, wireprototypes, wireprotov1peer, wireprotov1server, @@ -103,16 +104,31 @@ wireprotov1server.wireprotocommand(b'tns_heads', b'namespaces', permission=b'pull')(tns_heads) extensions.wrapfunction(wireprotov1server, '_capabilities', wireprotocaps) - class tnspeer(wireprotov1peer.wirepeer): - @wireprotov1peer.batchable - def tns_heads(self, namespaces): - def decode(d): + 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 try: - return wireprototypes.decodelist(d[:-1]) + yield 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