# HG changeset patch # User Anton Shestakov # Date 1622824493 -28800 # Node ID fb90474ec53f2951585ebc8e264eb2d6455e8bcd # Parent daca8f4f7014d8d7efcd77444c267a298ddc2a66 evolve: wrap the more modern wireprotov1server._capabilities() This function is recommended for wrapping instead of capabilities(). It also needs less code from extensions, as this patch demonstrates. The function exists since 982f13bef503, which is 2014, so we can rely on this function to be present in any modern Mercurial. diff -r daca8f4f7014 -r fb90474ec53f hgext3rd/evolve/obsdiscovery.py --- a/hgext3rd/evolve/obsdiscovery.py Sat May 29 14:32:05 2021 +0800 +++ b/hgext3rd/evolve/obsdiscovery.py Sat Jun 05 00:34:53 2021 +0800 @@ -47,7 +47,7 @@ stablerangecache, ) -from mercurial import wireprototypes, wireprotov1server +from mercurial import wireprotov1server from mercurial.wireprotov1peer import wirepeer from mercurial.wireprototypes import encodelist, decodelist @@ -729,23 +729,13 @@ caps = orig(repo, proto) enabled = _useobshashrange(repo) if obsolete.isenabled(repo, obsolete.exchangeopt) and enabled: - caps = caps.data.split() caps.append(b'_evoext_obshashrange_v1') - caps.sort() - caps = wireprototypes.bytesresponse(b' '.join(caps)) return caps @eh.extsetup def obshashrange_extsetup(ui): - ### - extensions.wrapfunction(wireprotov1server, 'capabilities', + extensions.wrapfunction(wireprotov1server, '_capabilities', _obshashrange_capabilities) - # wrap command content - oldcap, args = wireprotov1server.commands[b'capabilities'] - - def newcap(repo, proto): - return _obshashrange_capabilities(oldcap, repo, proto) - wireprotov1server.commands[b'capabilities'] = (newcap, args) ########################################## ### trigger discovery during exchange ### diff -r daca8f4f7014 -r fb90474ec53f hgext3rd/evolve/obsexchange.py --- a/hgext3rd/evolve/obsexchange.py Sat May 29 14:32:05 2021 +0800 +++ b/hgext3rd/evolve/obsexchange.py Sat Jun 05 00:34:53 2021 +0800 @@ -117,15 +117,11 @@ else: exchange.buildobsmarkerspart(bundler, markers) -# manual wrap up in extsetup because of the wireproto.commands mapping def _obscommon_capabilities(orig, repo, proto): """wrapper to advertise new capability""" caps = orig(repo, proto) if obsolete.isenabled(repo, obsolete.exchangeopt): - caps = caps.data.split() caps.append(b'_evoext_getbundle_obscommon') - caps.sort() - caps = wireprototypes.bytesresponse(b' '.join(caps)) return caps @eh.extsetup @@ -140,14 +136,8 @@ return _getbundleobsmarkerpart(origfunc, *args, **kwargs) exchange.getbundle2partsmapping[b'obsmarkers'] = newfunc - extensions.wrapfunction(wireprotov1server, 'capabilities', + extensions.wrapfunction(wireprotov1server, '_capabilities', _obscommon_capabilities) - # wrap command content - oldcap, args = wireprotov1server.commands[b'capabilities'] - - def newcap(repo, proto): - return _obscommon_capabilities(oldcap, repo, proto) - wireprotov1server.commands[b'capabilities'] = (newcap, args) abortmsg = b"won't exchange obsmarkers through pushkey" hint = b"upgrade your client or server to use the bundle2 protocol"