[PATCH 05 of 22] wireproto: add decorator for wire protocol command

pierre-yves.david at ens-lyon.org pierre-yves.david at ens-lyon.org
Fri Mar 28 17:40:31 CDT 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1396042211 25200
#      Fri Mar 28 14:30:11 2014 -0700
# Node ID b543d97beb42db45c2952031a87e6c4f75f2b820
# Parent  927f1610e6958d2b1e694e13365e7250eda2f791
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)

diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -469,10 +469,20 @@ def options(cmd, keys, others):
     if others:
         sys.stderr.write("abort: %s got unexpected arguments %s\n"
                          % (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 = []
     for pair in cmds.split(';'):
         op, args = pair.split(' ', 1)
@@ -768,11 +778,11 @@ def unbundle(repo, proto, heads):
 
     finally:
         fp.close()
         os.unlink(tempname)
 
-commands = {
+commands.update({
     'batch': (batch, 'cmds *'),
     'between': (between, 'pairs'),
     'branchmap': (branchmap, ''),
     'branches': (branches, 'nodes'),
     'capabilities': (capabilities, ''),
@@ -786,6 +796,6 @@ commands = {
     'listkeys': (listkeys, 'namespace'),
     'lookup': (lookup, 'key'),
     'pushkey': (pushkey, 'namespace key old new'),
     'stream_out': (stream, ''),
     'unbundle': (unbundle, 'heads'),
-}
+})


More information about the Mercurial-devel mailing list