changeset 5954:fb90474ec53f

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.
author Anton Shestakov <av6@dwimlabs.net>
date Sat, 05 Jun 2021 00:34:53 +0800
parents daca8f4f7014
children 9b507e5e6744
files hgext3rd/evolve/obsdiscovery.py hgext3rd/evolve/obsexchange.py
diffstat 2 files changed, 3 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- 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 ###
--- 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"