Patchwork [1,of,3] commandserver: extract method to create commandserver instance per request

login
register
mail settings
Submitter Yuya Nishihara
Date June 30, 2016, 2:26 p.m.
Message ID <ced2dca6ea44867d8b02.1467296813@mimosa>
Download mbox | patch
Permalink /patch/15693/
State Accepted
Headers show

Comments

Yuya Nishihara - June 30, 2016, 2:26 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1463811139 -32400
#      Sat May 21 15:12:19 2016 +0900
# Node ID ced2dca6ea44867d8b02d6026d38fa099c30c6c1
# Parent  5b71a8d7f7ffc2662ceb58ad8eec806e147ae13d
commandserver: extract method to create commandserver instance per request

This is a step toward merging chgserver._requesthandler with commandserver's.

Patch

diff --git a/hgext/chgserver.py b/hgext/chgserver.py
--- a/hgext/chgserver.py
+++ b/hgext/chgserver.py
@@ -541,11 +541,9 @@  class _requesthandler(socketserver.Strea
         # same state inherited from parent.
         random.seed()
         ui = self.server.ui
-        repo = self.server.repo
         sv = None
         try:
-            sv = chgcmdserver(ui, repo, self.rfile, self.wfile, self.connection,
-                              self.server.hashstate, self.server.baseaddress)
+            sv = self._createcmdserver()
             try:
                 sv.serve()
             # handle exceptions that may be raised by command server. most of
@@ -572,6 +570,12 @@  class _requesthandler(socketserver.Strea
             # trigger __del__ since ForkingMixIn uses os._exit
             gc.collect()
 
+    def _createcmdserver(self):
+        ui = self.server.ui
+        repo = self.server.repo
+        return chgcmdserver(ui, repo, self.rfile, self.wfile, self.connection,
+                            self.server.hashstate, self.server.baseaddress)
+
 def _tempaddress(address):
     return '%s.%d.tmp' % (address, os.getpid())
 
diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -334,10 +334,9 @@  class pipeservice(object):
 class _requesthandler(socketserver.StreamRequestHandler):
     def handle(self):
         ui = self.server.ui
-        repo = self.server.repo
         sv = None
         try:
-            sv = server(ui, repo, self.rfile, self.wfile)
+            sv = self._createcmdserver()
             try:
                 sv.serve()
             # handle exceptions that may be raised by command server. most of
@@ -359,6 +358,11 @@  class _requesthandler(socketserver.Strea
             traceback.print_exc(file=cerr)
             raise
 
+    def _createcmdserver(self):
+        ui = self.server.ui
+        repo = self.server.repo
+        return server(ui, repo, self.rfile, self.wfile)
+
 class unixservice(object):
     """
     Listens on unix domain socket and forks server per connection