changeset 20775:982f13bef503

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.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Wed, 12 Mar 2014 14:46:41 -0700
parents cdc3ac896997
children d00c731f4637
files mercurial/wireproto.py
diffstat 1 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/wireproto.py	Tue Mar 11 01:38:02 2014 -0700
+++ b/mercurial/wireproto.py	Wed Mar 12 14:46:41 2014 -0700
@@ -417,7 +417,17 @@
 
 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 @@
             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)