D2391: sshpeer: factor out code for creating peers from pipes

2018-03-01 Thread indygreg (Gregory Szorc)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGcaf423782b3a: sshpeer: factor out code for creating peers 
from pipes (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2391?vs=6133=6243

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

AFFECTED FILES
  mercurial/sshpeer.py

CHANGE DETAILS

diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py
--- a/mercurial/sshpeer.py
+++ b/mercurial/sshpeer.py
@@ -531,6 +531,35 @@
 # And handshake is performed before the peer is instantiated. So
 # we need no custom code.
 
+def makepeer(ui, path, proc, stdin, stdout, stderr):
+"""Make a peer instance from existing pipes.
+
+``path`` and ``proc`` are stored on the eventual peer instance and may
+not be used for anything meaningful.
+
+``stdin``, ``stdout``, and ``stderr`` are the pipes connected to the
+SSH server's stdio handles.
+
+This function is factored out to allow creating peers that don't
+actually spawn a new process. It is useful for starting SSH protocol
+servers and clients via non-standard means, which can be useful for
+testing.
+"""
+try:
+protoname, caps = _performhandshake(ui, stdin, stdout, stderr)
+except Exception:
+_cleanuppipes(ui, stdout, stdin, stderr)
+raise
+
+if protoname == wireprotoserver.SSHV1:
+return sshv1peer(ui, path, proc, stdin, stdout, stderr, caps)
+elif protoname == wireprotoserver.SSHV2:
+return sshv2peer(ui, path, proc, stdin, stdout, stderr, caps)
+else:
+_cleanuppipes(ui, stdout, stdin, stderr)
+raise error.RepoError(_('unknown version of SSH protocol: %s') %
+  protoname)
+
 def instance(ui, path, create):
 """Create an SSH peer.
 
@@ -565,17 +594,4 @@
 proc, stdin, stdout, stderr = _makeconnection(ui, sshcmd, args, remotecmd,
   remotepath, sshenv)
 
-try:
-protoname, caps = _performhandshake(ui, stdin, stdout, stderr)
-except Exception:
-_cleanuppipes(ui, stdout, stdin, stderr)
-raise
-
-if protoname == wireprotoserver.SSHV1:
-return sshv1peer(ui, path, proc, stdin, stdout, stderr, caps)
-elif protoname == wireprotoserver.SSHV2:
-return sshv2peer(ui, path, proc, stdin, stdout, stderr, caps)
-else:
-_cleanuppipes(ui, stdout, stdin, stderr)
-raise error.RepoError(_('unknown version of SSH protocol: %s') %
-  protoname)
+return makepeer(ui, path, proc, stdin, stdout, stderr)



To: indygreg, #hg-reviewers, yuja
Cc: dhduvall, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2391: sshpeer: factor out code for creating peers from pipes

2018-02-26 Thread indygreg (Gregory Szorc)
indygreg updated this revision to Diff 6133.
indygreg edited the summary of this revision.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2391?vs=6018=6133

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

AFFECTED FILES
  mercurial/sshpeer.py

CHANGE DETAILS

diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py
--- a/mercurial/sshpeer.py
+++ b/mercurial/sshpeer.py
@@ -531,6 +531,35 @@
 # And handshake is performed before the peer is instantiated. So
 # we need no custom code.
 
+def makepeer(ui, path, proc, stdin, stdout, stderr):
+"""Make a peer instance from existing pipes.
+
+``path`` and ``proc`` are stored on the eventual peer instance and may
+not be used for anything meaningful.
+
+``stdin``, ``stdout``, and ``stderr`` are the pipes connected to the
+SSH server's stdio handles.
+
+This function is factored out to allow creating peers that don't
+actually spawn a new process. It is useful for starting SSH protocol
+servers and clients via non-standard means, which can be useful for
+testing.
+"""
+try:
+protoname, caps = _performhandshake(ui, stdin, stdout, stderr)
+except Exception:
+_cleanuppipes(ui, stdout, stdin, stderr)
+raise
+
+if protoname == wireprotoserver.SSHV1:
+return sshv1peer(ui, path, proc, stdin, stdout, stderr, caps)
+elif protoname == wireprotoserver.SSHV2:
+return sshv2peer(ui, path, proc, stdin, stdout, stderr, caps)
+else:
+_cleanuppipes(ui, stdout, stdin, stderr)
+raise error.RepoError(_('unknown version of SSH protocol: %s') %
+  protoname)
+
 def instance(ui, path, create):
 """Create an SSH peer.
 
@@ -565,17 +594,4 @@
 proc, stdin, stdout, stderr = _makeconnection(ui, sshcmd, args, remotecmd,
   remotepath, sshenv)
 
-try:
-protoname, caps = _performhandshake(ui, stdin, stdout, stderr)
-except Exception:
-_cleanuppipes(ui, stdout, stdin, stderr)
-raise
-
-if protoname == wireprotoserver.SSHV1:
-return sshv1peer(ui, path, proc, stdin, stdout, stderr, caps)
-elif protoname == wireprotoserver.SSHV2:
-return sshv2peer(ui, path, proc, stdin, stdout, stderr, caps)
-else:
-_cleanuppipes(ui, stdout, stdin, stderr)
-raise error.RepoError(_('unknown version of SSH protocol: %s') %
-  protoname)
+return makepeer(ui, path, proc, stdin, stdout, stderr)



To: indygreg, #hg-reviewers
Cc: dhduvall, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2391: sshpeer: factor out code for creating peers from pipes

2018-02-23 Thread indygreg (Gregory Szorc)
indygreg updated this revision to Diff 6018.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2391?vs=6004=6018

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

AFFECTED FILES
  mercurial/sshpeer.py

CHANGE DETAILS

diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py
--- a/mercurial/sshpeer.py
+++ b/mercurial/sshpeer.py
@@ -531,6 +531,35 @@
 # And handshake is performed before the peer is instantiated. So
 # we need no custom code.
 
+def makepeer(ui, path, proc, stdin, stdout, stderr):
+"""Make a peer instance from existing pipes.
+
+``path`` and ``proc`` are stored on the eventual peer instance and may
+not be used for anything meaningful.
+
+``stdin``, ``stdout``, and ``stderr`` are the pipes connected to the
+SSH server's stdio handles.
+
+This function is factored out to allow creating peers that don't
+actually spawn a new process. It is useful for starting SSH protocol
+servers and clients via non-standard means, which can be useful for
+testing.
+"""
+try:
+protoname, caps = _performhandshake(ui, stdin, stdout, stderr)
+except Exception:
+_cleanuppipes(ui, stdout, stdin, stderr)
+raise
+
+if protoname == wireprotoserver.SSHV1:
+return sshv1peer(ui, path, proc, stdin, stdout, stderr, caps)
+elif protoname == wireprotoserver.SSHV2:
+return sshv2peer(ui, path, proc, stdin, stdout, stderr, caps)
+else:
+_cleanuppipes(ui, stdout, stdin, stderr)
+raise error.RepoError(_('unknown version of SSH protocol: %s') %
+  protoname)
+
 def instance(ui, path, create):
 """Create an SSH peer.
 
@@ -565,17 +594,4 @@
 proc, stdin, stdout, stderr = _makeconnection(ui, sshcmd, args, remotecmd,
   remotepath, sshenv)
 
-try:
-protoname, caps = _performhandshake(ui, stdin, stdout, stderr)
-except Exception:
-_cleanuppipes(ui, stdout, stdin, stderr)
-raise
-
-if protoname == wireprotoserver.SSHV1:
-return sshv1peer(ui, path, proc, stdin, stdout, stderr, caps)
-elif protoname == wireprotoserver.SSHV2:
-return sshv2peer(ui, path, proc, stdin, stdout, stderr, caps)
-else:
-_cleanuppipes(ui, stdout, stdin, stderr)
-raise error.RepoError(_('unknown version of SSH protocol: %s') %
-  protoname)
+return makepeer(ui, path, proc, stdin, stdout, stderr)



To: indygreg, #hg-reviewers
Cc: dhduvall, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2391: sshpeer: factor out code for creating peers from pipes

2018-02-22 Thread dhduvall (Danek Duvall)
dhduvall added inline comments.

INLINE COMMENTS

> sshpeer.py:537
> +
> +``path`` and ``path`` are stored on the eventual peer instance and may
> +not be used for anything meaningful.

That second `path` should be `proc`?

REPOSITORY
  rHG Mercurial

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

To: indygreg, #hg-reviewers
Cc: dhduvall, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2391: sshpeer: factor out code for creating peers from pipes

2018-02-22 Thread indygreg (Gregory Szorc)
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  An upcoming commit will want to instantiate an SSH peer via
  an alternate mechanism that doesn't require running a new
  SSH command. To facilitate that, we extract the code for
  creating a peer from pipes to its own function.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/sshpeer.py

CHANGE DETAILS

diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py
--- a/mercurial/sshpeer.py
+++ b/mercurial/sshpeer.py
@@ -531,6 +531,35 @@
 # And handshake is performed before the peer is instantiated. So
 # we need no custom code.
 
+def makepeer(ui, path, proc, stdin, stdout, stderr):
+"""Make a peer instance from existing pipes.
+
+``path`` and ``path`` are stored on the eventual peer instance and may
+not be used for anything meaningful.
+
+``stdin``, ``stdout``, and ``stderr`` are the pipes connected to the
+SSH server's stdio handles.
+
+This function is factored out to allow creating peers that don't
+actually spawn a new process. It is useful for starting SSH protocol
+servers and clients via non-standard means, which can be useful for
+testing.
+"""
+try:
+protoname, caps = _performhandshake(ui, stdin, stdout, stderr)
+except Exception:
+_cleanuppipes(ui, stdout, stdin, stderr)
+raise
+
+if protoname == wireprotoserver.SSHV1:
+return sshv1peer(ui, path, proc, stdin, stdout, stderr, caps)
+elif protoname == wireprotoserver.SSHV2:
+return sshv2peer(ui, path, proc, stdin, stdout, stderr, caps)
+else:
+_cleanuppipes(ui, stdout, stdin, stderr)
+raise error.RepoError(_('unknown version of SSH protocol: %s') %
+  protoname)
+
 def instance(ui, path, create):
 """Create an SSH peer.
 
@@ -565,17 +594,4 @@
 proc, stdin, stdout, stderr = _makeconnection(ui, sshcmd, args, remotecmd,
   remotepath, sshenv)
 
-try:
-protoname, caps = _performhandshake(ui, stdin, stdout, stderr)
-except Exception:
-_cleanuppipes(ui, stdout, stdin, stderr)
-raise
-
-if protoname == wireprotoserver.SSHV1:
-return sshv1peer(ui, path, proc, stdin, stdout, stderr, caps)
-elif protoname == wireprotoserver.SSHV2:
-return sshv2peer(ui, path, proc, stdin, stdout, stderr, caps)
-else:
-_cleanuppipes(ui, stdout, stdin, stderr)
-raise error.RepoError(_('unknown version of SSH protocol: %s') %
-  protoname)
+return makepeer(ui, path, proc, stdin, stdout, stderr)



To: indygreg, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel