changeset 20906:7a634b34fc91

wireproto: add decorator for wire protocol command Move move in the same direction we took for command line commands. each wire protocol function will be decorated with its name and arguments. Beside beside easier to read, this open the road to easily adding more metadata (like security level or return type)
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 28 Mar 2014 14:30:11 -0700
parents 167047ba3cfa
children aedec880e095
files mercurial/wireproto.py
diffstat 1 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/wireproto.py	Fri Mar 28 14:24:13 2014 -0700
+++ b/mercurial/wireproto.py	Fri Mar 28 14:30:11 2014 -0700
@@ -471,6 +471,16 @@
                          % (cmd, ",".join(others)))
     return opts
 
+# list of commands
+commands = {}
+
+def wireprotocommand(name, args=''):
+    """decorator for wireprotocol command"""
+    def register(func):
+        commands[name] = (func, args)
+        return func
+    return register
+
 def batch(repo, proto, cmds, others):
     repo = repo.filtered("served")
     res = []
@@ -770,7 +780,7 @@
         fp.close()
         os.unlink(tempname)
 
-commands = {
+commands.update({
     'batch': (batch, 'cmds *'),
     'between': (between, 'pairs'),
     'branchmap': (branchmap, ''),
@@ -788,4 +798,4 @@
     'pushkey': (pushkey, 'namespace key old new'),
     'stream_out': (stream, ''),
     'unbundle': (unbundle, 'heads'),
-}
+})