Commit 06d777a8 authored by Anton Shestakov's avatar Anton Shestakov
Browse files

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.
parent daca8f4f7014
Pipeline #23345 passed with stage
in 5 minutes and 21 seconds
......@@ -47,7 +47,7 @@ from . import (
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 @@ def _obshashrange_capabilities(orig, repo, proto):
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 ###
......
......@@ -117,15 +117,11 @@ def _getbundleobsmarkerpart(orig, bundler, repo, source, **kwargs):
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 @@ def extsetup_obscommon(ui):
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"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment