Patchwork D3397: wireproto: reimplement dispatch() for version 2 server

login
register
mail settings
Submitter phabricator
Date April 18, 2018, 6:41 p.m.
Message ID <8193ee91b7b8e6b94391f14fe9410084@localhost.localdomain>
Download mbox | patch
Permalink /patch/31184/
State Not Applicable
Headers show

Comments

phabricator - April 18, 2018, 6:41 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG99accae4cc59: wireproto: reimplement dispatch() for version 2 server (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3397?vs=8368&id=8386

REVISION DETAIL
  https://phab.mercurial-scm.org/D3397

AFFECTED FILES
  mercurial/wireproto.py
  mercurial/wireprotov2server.py

CHANGE DETAILS




To: indygreg, #hg-reviewers, durin42
Cc: mercurial-devel

Patch

diff --git a/mercurial/wireprotov2server.py b/mercurial/wireprotov2server.py
--- a/mercurial/wireprotov2server.py
+++ b/mercurial/wireprotov2server.py
@@ -296,7 +296,7 @@ 
             res.setbodybytes(_('command in frame must match command in URL'))
             return True
 
-    rsp = wireproto.dispatch(repo, proto, command['command'])
+    rsp = dispatch(repo, proto, command['command'])
 
     res.status = b'200 OK'
     res.headers[b'Content-Type'] = FRAMINGTYPE
@@ -328,6 +328,17 @@ 
         raise error.ProgrammingError('unhandled event from reactor: %s' %
                                      action)
 
+def getdispatchrepo(repo, proto, command):
+    return repo.filtered('served')
+
+def dispatch(repo, proto, command):
+    repo = getdispatchrepo(repo, proto, command)
+
+    func, spec = wireproto.commandsv2[command]
+    args = proto.getargs(spec)
+
+    return func(repo, proto, **args)
+
 @zi.implementer(wireprototypes.baseprotocolhandler)
 class httpv2protocolhandler(object):
     def __init__(self, req, ui, args=None):
diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -69,20 +69,10 @@ 
 def dispatch(repo, proto, command):
     repo = getdispatchrepo(repo, proto, command)
 
-    transportversion = wireprototypes.TRANSPORTS[proto.name]['version']
-    commandtable = commandsv2 if transportversion == 2 else commands
-    func, spec = commandtable[command]
-
+    func, spec = commands[command]
     args = proto.getargs(spec)
 
-    # Version 1 protocols define arguments as a list. Version 2 uses a dict.
-    if isinstance(args, list):
-        return func(repo, proto, *args)
-    elif isinstance(args, dict):
-        return func(repo, proto, **args)
-    else:
-        raise error.ProgrammingError('unexpected type returned from '
-                                     'proto.getargs(): %s' % type(args))
+    return func(repo, proto, *args)
 
 def options(cmd, keys, others):
     opts = {}