# HG changeset patch # User Yuya Nishihara # Date 2016-05-21 06:12:19 # Node ID 540c01a18bb733d0dd84661244b4113c7499ac1c # Parent 19205a0e2bf17d6d05e0897e77825e0305bae99a commandserver: extract method to create commandserver instance per request This is a step toward merging chgserver._requesthandler with commandserver's. diff --git a/hgext/chgserver.py b/hgext/chgserver.py --- a/hgext/chgserver.py +++ b/hgext/chgserver.py @@ -545,11 +545,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 @@ -576,6 +574,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