Patchwork [1,of,7] cmdserver: wrap 'pipe' mode server by service object

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 4, 2014, 10:52 a.m.
Message ID <ad2f42cf0437da2a20df.1412419944@mimosa>
Download mbox | patch
Permalink /patch/6108/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 4, 2014, 10:52 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1411797129 -32400
#      Sat Sep 27 14:52:09 2014 +0900
# Node ID ad2f42cf0437da2a20df23c200d6c1f05b69db8d
# Parent  2fd6a371c4af15b547e105fb79b633694edec8b7
cmdserver: wrap 'pipe' mode server by service object

This is the stub for new mode that will listen for connections on unix domain
socket.

Though --daemon option is not banned in 'pipe' mode, it is useless because
the detached 'pipe' mode server exits immediately due to null stdin. Should
it abort if --daemon is specified with --cmdserver pipe or --stdio?

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5544,8 +5544,8 @@  def serve(ui, repo, **opts):
         s.serve_forever()
 
     if opts["cmdserver"]:
-        s = commandserver.server(ui, repo, opts["cmdserver"])
-        return s.serve()
+        service = commandserver.pipeservice(ui, repo, opts)
+        return cmdutil.service(opts, initfn=service.init, runfn=service.run)
 
     # this way we can check if something was given in the command-line
     if opts.get('port'):
diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -248,3 +248,13 @@  class server(object):
             return 1
 
         return 0
+
+class pipeservice(object):
+    def __init__(self, ui, repo, opts):
+        self.server = server(ui, repo, opts['cmdserver'])
+
+    def init(self):
+        pass
+
+    def run(self):
+        return self.server.serve()