[PATCH 3 of 7] cmdserver: make server streams switchable

Yuya Nishihara yuya at tcha.org
Sat Oct 4 05:52:26 CDT 2014


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1411798214 -32400
#      Sat Sep 27 15:10:14 2014 +0900
# Node ID 01ae3e539d1f1f9221a0e04a6833a2b50a410bb3
# Parent  4545d11a3950be83e452bafda4ba22ce847efecf
cmdserver: make server streams switchable

In 'unix' mode, server instance will be created per connection, and fin/fout
are set to socket files.

diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -126,10 +126,10 @@ class channeledinput(object):
 
 class server(object):
     """
-    Listens for commands on stdin, runs them and writes the output on a channel
-    based stream to stdout.
+    Listens for commands on fin, runs them and writes the output on a channel
+    based stream to fout.
     """
-    def __init__(self, ui, repo):
+    def __init__(self, ui, repo, fin, fout):
         self.cwd = os.getcwd()
 
         logpath = ui.config("cmdserver", "log", None)
@@ -137,7 +137,7 @@ class server(object):
             global logfile
             if logpath == '-':
                 # write log on a special 'd' (debug) channel
-                logfile = channeledoutput(sys.stdout, 'd')
+                logfile = channeledoutput(fout, 'd')
             else:
                 logfile = open(logpath, 'a')
 
@@ -151,12 +151,12 @@ class server(object):
             self.ui = ui
             self.repo = self.repoui = None
 
-        self.cerr = channeledoutput(sys.stdout, 'e')
-        self.cout = channeledoutput(sys.stdout, 'o')
-        self.cin = channeledinput(sys.stdin, sys.stdout, 'I')
-        self.cresult = channeledoutput(sys.stdout, 'r')
+        self.cerr = channeledoutput(fout, 'e')
+        self.cout = channeledoutput(fout, 'o')
+        self.cin = channeledinput(fin, fout, 'I')
+        self.cresult = channeledoutput(fout, 'r')
 
-        self.client = sys.stdin
+        self.client = fin
 
     def _read(self, size):
         if not size:
@@ -248,7 +248,7 @@ class server(object):
 
 class pipeservice(object):
     def __init__(self, ui, repo, opts):
-        self.server = server(ui, repo)
+        self.server = server(ui, repo, sys.stdin, sys.stdout)
 
     def init(self):
         pass


More information about the Mercurial-devel mailing list