wireproto: move wireproto capabilities computation in a subfunction

It will help people that need to add capabilities (in a more subtle was that
just adding some to the list) in multiple way:

1. This function returns a list, not a string. Making it easier to look at,
   extend or alter the content.

2. The original capabilities function will be store in the dictionary of wire
   protocol command. So extension that wrap this function also need to update
   the dictionary entry.

   Both wrapping and update of the dictionary entry are needed because the
   `hello` wire protocol use the function itself. This is specifically sneaky for
   extension writer as ssh use the `hello` command while http use the
   `capabilities` command.

   With this new `_capabilities` function there is one and only one obvious
   place to wrap when needed.
This commit is contained in:
Pierre-Yves David 2014-03-12 14:46:41 -07:00
parent 342e942953
commit cae4a1d18a

View File

@ -417,7 +417,17 @@ def branches(repo, proto, nodes):
wireprotocaps = ['lookup', 'changegroupsubset', 'branchmap', 'pushkey',
'known', 'getbundle', 'unbundlehash', 'batch']
def capabilities(repo, proto):
def _capabilities(repo, proto):
"""return a list of capabilities for a repo
This function exists to allow extensions to easily wrap capabilities
computation
- returns a lists: easy to alter
- change done here will be propagated to both `capabilities` and `hello`
command without any other effort. without any other action needed.
"""
# copy to prevent modification of the global list
caps = list(wireprotocaps)
if _allowstream(repo.ui):
@ -432,7 +442,12 @@ def capabilities(repo, proto):
caps.append('streamreqs=%s' % ','.join(requiredformats))
caps.append('unbundle=%s' % ','.join(changegroupmod.bundlepriority))
caps.append('httpheader=1024')
return ' '.join(caps)
return caps
# If you are writting and extension and consider wrapping this function. Wrap
# `_capabilities` instead.
def capabilities(repo, proto):
return ' '.join(_capabilities(repo, proto))
def changegroup(repo, proto, roots):
nodes = decodelist(roots)