D3399: wireproto: move version 2 commands dict to wireprotov2server

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Wed Apr 18 14:41:29 EDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHGee0d5e9d77b2: wireproto: move version 2 commands dict to wireprotov2server (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3399?vs=8370&id=8388

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

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

CHANGE DETAILS

diff --git a/mercurial/wireprotov2server.py b/mercurial/wireprotov2server.py
--- a/mercurial/wireprotov2server.py
+++ b/mercurial/wireprotov2server.py
@@ -21,15 +21,16 @@
     pycompat,
     streamclone,
     util,
-    wireproto,
     wireprotoframing,
     wireprototypes,
 )
 
 FRAMINGTYPE = b'application/mercurial-exp-framing-0005'
 
 HTTP_WIREPROTO_V2 = wireprototypes.HTTP_WIREPROTO_V2
 
+COMMANDS = wireprototypes.commanddict()
+
 def handlehttpv2request(rctx, req, res, checkperm, urlparts):
     from .hgweb import common as hgwebcommon
 
@@ -87,7 +88,7 @@
     # extension.
     extracommands = {'multirequest'}
 
-    if command not in wireproto.commandsv2 and command not in extracommands:
+    if command not in COMMANDS and command not in extracommands:
         res.status = b'404 Not Found'
         res.headers[b'Content-Type'] = b'text/plain'
         res.setbodybytes(_('unknown wire protocol command: %s\n') % command)
@@ -98,7 +99,7 @@
 
     proto = httpv2protocolhandler(req, ui)
 
-    if (not wireproto.commandsv2.commandavailable(command, proto)
+    if (not COMMANDS.commandavailable(command, proto)
         and command not in extracommands):
         res.status = b'404 Not Found'
         res.headers[b'Content-Type'] = b'text/plain'
@@ -254,7 +255,7 @@
     proto = httpv2protocolhandler(req, ui, args=command['args'])
 
     if reqcommand == b'multirequest':
-        if not wireproto.commandsv2.commandavailable(command['command'], proto):
+        if not COMMANDS.commandavailable(command['command'], proto):
             # TODO proper error mechanism
             res.status = b'200 OK'
             res.headers[b'Content-Type'] = b'text/plain'
@@ -264,7 +265,7 @@
 
         # TODO don't use assert here, since it may be elided by -O.
         assert authedperm in (b'ro', b'rw')
-        wirecommand = wireproto.commandsv2[command['command']]
+        wirecommand = COMMANDS[command['command']]
         assert wirecommand.permission in ('push', 'pull')
 
         if authedperm == b'ro' and wirecommand.permission != 'pull':
@@ -334,7 +335,7 @@
 def dispatch(repo, proto, command):
     repo = getdispatchrepo(repo, proto, command)
 
-    func, spec = wireproto.commandsv2[command]
+    func, spec = COMMANDS[command]
     args = proto.getargs(spec)
 
     return func(repo, proto, **args)
@@ -404,7 +405,7 @@
         'framingmediatypes': [FRAMINGTYPE],
     }
 
-    for command, entry in wireproto.commandsv2.items():
+    for command, entry in COMMANDS.items():
         caps['commands'][command] = {
             'args': entry.args,
             'permissions': [entry.permission],
@@ -445,11 +446,11 @@
                                      'must be declared as dicts')
 
     def register(func):
-        if name in wireproto.commandsv2:
+        if name in COMMANDS:
             raise error.ProgrammingError('%s command already registered '
                                          'for version 2' % name)
 
-        wireproto.commandsv2[name] = wireprototypes.commandentry(
+        COMMANDS[name] = wireprototypes.commandentry(
             func, args=args, transports=transports, permission=permission)
 
         return func
diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -114,12 +114,8 @@
 
     return ui.configbool('server', 'bundle1')
 
-# For version 1 transports.
 commands = wireprototypes.commanddict()
 
-# For version 2 transports.
-commandsv2 = wireprototypes.commanddict()
-
 def wireprotocommand(name, args=None, permission='push'):
     """Decorator to declare a wire protocol command.
 



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


More information about the Mercurial-devel mailing list