Patchwork [1,of,3] cmdserver: use given streams as pipe channels like other commands

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 15, 2014, 10:34 a.m.
Message ID <546edd445faa8da409bc.1416047665@mimosa>
Download mbox | patch
Permalink /patch/6742/
State Accepted
Commit 000cfc8b3913b8eac263a9ff1aa6e4b7b5238d11
Headers show

Comments

Yuya Nishihara - Nov. 15, 2014, 10:34 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1416023015 -32400
#      Sat Nov 15 12:43:35 2014 +0900
# Node ID 546edd445faa8da409bc5df17629705de0d8d774
# Parent  991098579940552536d0a99fa3602dd1661aa388
cmdserver: use given streams as pipe channels like other commands

Because commandserver itself is an hg subcommand, it shouldn't use stdio
directly in principle.

Patch

diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -7,7 +7,7 @@ 
 
 from i18n import _
 import struct
-import sys, os, errno, traceback, SocketServer
+import os, errno, traceback, SocketServer
 import dispatch, encoding, util
 
 logfile = None
@@ -250,7 +250,7 @@  class server(object):
 
 class pipeservice(object):
     def __init__(self, ui, repo, opts):
-        self.server = server(ui, repo, sys.stdin, sys.stdout)
+        self.server = server(ui, repo, ui.fin, ui.fout)
 
     def init(self):
         pass
diff --git a/tests/test-commandserver.t b/tests/test-commandserver.t
--- a/tests/test-commandserver.t
+++ b/tests/test-commandserver.t
@@ -524,6 +524,27 @@  check that local configs for the cached 
   prompt: 5678
 
 
+run commandserver in commandserver, which is silly but should work:
+
+  >>> import cStringIO
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def nested(server):
+  ...     print '%c, %r' % readchannel(server)
+  ...     class nestedserver(object):
+  ...         stdin = cStringIO.StringIO('getencoding\n')
+  ...         stdout = cStringIO.StringIO()
+  ...     runcommand(server, ['serve', '--cmdserver', 'pipe'],
+  ...                output=nestedserver.stdout, input=nestedserver.stdin)
+  ...     nestedserver.stdout.seek(0)
+  ...     print '%c, %r' % readchannel(nestedserver)  # hello
+  ...     print '%c, %r' % readchannel(nestedserver)  # getencoding
+  o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
+  *** runcommand serve --cmdserver pipe
+  o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
+  r, '*' (glob)
+
+
 start without repository:
 
   $ cd ..