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

login
register
mail settings
Submitter Pierre-Yves David
Date March 28, 2014, 10:40 p.m.
Message ID <b543d97beb42db45c295.1396046431@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4125/
State Accepted
Commit 7a634b34fc9114e8e1de7d726d32379f7262ef5b
Headers show

Comments

Pierre-Yves David - March 28, 2014, 10:40 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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)

Patch

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'),
-}
+})