Patchwork [2,of,7] commandserver: extract function that serves for the current connection

login
register
mail settings
Submitter Yuya Nishihara
Date July 14, 2016, 3:20 p.m.
Message ID <e374627f118e8aca6243.1468509640@mimosa>
Download mbox | patch
Permalink /patch/15855/
State Accepted
Headers show

Comments

Yuya Nishihara - July 14, 2016, 3:20 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1463888962 -32400
#      Sun May 22 12:49:22 2016 +0900
# Node ID e374627f118e8aca6243d263154aab9309abf1fc
# Parent  5944579fa6f60b65150bf9081264c199f4c86e65
commandserver: extract function that serves for the current connection

This will be used by new server implementation.

Patch

diff --git a/hgext/chgserver.py b/hgext/chgserver.py
--- a/hgext/chgserver.py
+++ b/hgext/chgserver.py
@@ -533,9 +533,8 @@  class chgcmdserver(commandserver.server)
                          'setumask': setumask})
 
 class _requesthandler(commandserver._requesthandler):
-    def _createcmdserver(self, conn, fin, fout):
+    def _createcmdserver(self, repo, conn, fin, fout):
         ui = self.server.ui
-        repo = self.server.repo
         return chgcmdserver(ui, repo, fin, fout, conn,
                             self.server.hashstate, self.server.baseaddress)
 
diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -338,8 +338,8 @@  class pipeservice(object):
             sv.cleanup()
             _restoreio(ui, fin, fout)
 
-class _requesthandler(socketserver.BaseRequestHandler):
-    def handle(self):
+def _serverequest(ui, repo, conn, createcmdserver):
+    if True:  # TODO: unindent
         # use a different process group from the master process, making this
         # process pass kernel "is_current_pgrp_orphaned" check so signals like
         # SIGTSTP, SIGTTIN, SIGTTOU are not ignored.
@@ -347,14 +347,12 @@  class _requesthandler(socketserver.BaseR
         # change random state otherwise forked request handlers would have a
         # same state inherited from parent.
         random.seed()
-        ui = self.server.ui
 
-        conn = self.request
         fin = conn.makefile('rb')
         fout = conn.makefile('wb')
         sv = None
         try:
-            sv = self._createcmdserver(conn, fin, fout)
+            sv = createcmdserver(repo, conn, fin, fout)
             try:
                 sv.serve()
             # handle exceptions that may be raised by command server. most of
@@ -387,9 +385,13 @@  class _requesthandler(socketserver.BaseR
             # trigger __del__ since ForkingMixIn uses os._exit
             gc.collect()
 
-    def _createcmdserver(self, conn, fin, fout):
+class _requesthandler(socketserver.BaseRequestHandler):
+    def handle(self):
+        _serverequest(self.server.ui, self.server.repo, self.request,
+                      self._createcmdserver)
+
+    def _createcmdserver(self, repo, conn, fin, fout):
         ui = self.server.ui
-        repo = self.server.repo
         return server(ui, repo, fin, fout)
 
 class unixservice(object):