D2482: wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Tue Feb 27 18:50:00 EST 2018


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  To avoid a cycle between modules in an upcoming commit.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/sshpeer.py
  mercurial/wireprotoserver.py
  mercurial/wireprototypes.py

CHANGE DETAILS

diff --git a/mercurial/wireprototypes.py b/mercurial/wireprototypes.py
--- a/mercurial/wireprototypes.py
+++ b/mercurial/wireprototypes.py
@@ -7,6 +7,12 @@
 
 import abc
 
+# Names of the SSH protocol implementations.
+SSHV1 = 'ssh-v1'
+# This is advertised over the wire. Incremental the counter at the end
+# to reflect BC breakages.
+SSHV2 = 'exp-ssh-v2-0001'
+
 class bytesresponse(object):
     """A wire protocol response consisting of raw bytes."""
     def __init__(self, data):
diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py
--- a/mercurial/wireprotoserver.py
+++ b/mercurial/wireprotoserver.py
@@ -34,11 +34,8 @@
 HGTYPE2 = 'application/mercurial-0.2'
 HGERRTYPE = 'application/hg-error'
 
-# Names of the SSH protocol implementations.
-SSHV1 = 'ssh-v1'
-# This is advertised over the wire. Incremental the counter at the end
-# to reflect BC breakages.
-SSHV2 = 'exp-ssh-v2-0001'
+SSHV1 = wireprototypes.SSHV1
+SSHV2 = wireprototypes.SSHV2
 
 def decodevaluefromheaders(req, headerprefix):
     """Decode a long value from multiple HTTP request headers.
@@ -325,7 +322,7 @@
 
     @property
     def name(self):
-        return SSHV1
+        return wireprototypes.SSHV1
 
     def getargs(self, args):
         data = {}
@@ -493,7 +490,7 @@
             # We should never transition into this state if we've switched
             # protocols.
             assert not protoswitched
-            assert proto.name == SSHV1
+            assert proto.name == wireprototypes.SSHV1
 
             # Expected: upgrade <token> <capabilities>
             # If we get something else, the request is malformed. It could be
diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py
--- a/mercurial/sshpeer.py
+++ b/mercurial/sshpeer.py
@@ -17,6 +17,7 @@
     util,
     wireproto,
     wireprotoserver,
+    wireprototypes,
 )
 
 def _serverquote(s):
@@ -257,7 +258,7 @@
         badresponse()
 
     # Assume version 1 of wire protocol by default.
-    protoname = wireprotoserver.SSHV1
+    protoname = wireprototypes.SSHV1
     reupgraded = re.compile(b'^upgraded %s (.*)$' % re.escape(token))
 
     lines = ['', 'dummy']
@@ -296,7 +297,7 @@
 
     # For version 1, we should see a ``capabilities`` line in response to the
     # ``hello`` command.
-    if protoname == wireprotoserver.SSHV1:
+    if protoname == wireprototypes.SSHV1:
         for l in reversed(lines):
             # Look for response to ``hello`` command. Scan from the back so
             # we don't misinterpret banner output as the command reply.
@@ -555,10 +556,10 @@
         _cleanuppipes(ui, stdout, stdin, stderr)
         raise
 
-    if protoname == wireprotoserver.SSHV1:
+    if protoname == wireprototypes.SSHV1:
         return sshv1peer(ui, path, proc, stdin, stdout, stderr, caps,
                          autoreadstderr=autoreadstderr)
-    elif protoname == wireprotoserver.SSHV2:
+    elif protoname == wireprototypes.SSHV2:
         return sshv2peer(ui, path, proc, stdin, stdout, stderr, caps,
                          autoreadstderr=autoreadstderr)
     else:



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


More information about the Mercurial-devel mailing list