##// END OF EJS Templates
chgserver: reorder service classes to make future patches readable...
Yuya Nishihara -
r29545:28aca3fa default
parent child Browse files
Show More
@@ -532,18 +532,61 b' class chgcmdserver(commandserver.server)'
532 'setenv': setenv,
532 'setenv': setenv,
533 'setumask': setumask})
533 'setumask': setumask})
534
534
535 class _requesthandler(commandserver._requesthandler):
536 def _createcmdserver(self, repo, conn, fin, fout):
537 ui = self.server.ui
538 return chgcmdserver(ui, repo, fin, fout, conn,
539 self.server.hashstate, self.server.baseaddress)
540
541 def _tempaddress(address):
535 def _tempaddress(address):
542 return '%s.%d.tmp' % (address, os.getpid())
536 return '%s.%d.tmp' % (address, os.getpid())
543
537
544 def _hashaddress(address, hashstr):
538 def _hashaddress(address, hashstr):
545 return '%s-%s' % (address, hashstr)
539 return '%s-%s' % (address, hashstr)
546
540
541 class chgunixservice(commandserver.unixservice):
542 def __init__(self, ui, repo, opts):
543 super(chgunixservice, self).__init__(ui, repo=None, opts=opts)
544 if repo:
545 # one chgserver can serve multiple repos. drop repo infomation
546 self.ui.setconfig('bundle', 'mainreporoot', '', 'repo')
547
548 def init(self):
549 self._inithashstate()
550 self._checkextensions()
551 class cls(AutoExitMixIn, socketserver.ForkingMixIn,
552 socketserver.UnixStreamServer):
553 ui = self.ui
554 repo = self.repo
555 hashstate = self.hashstate
556 baseaddress = self.baseaddress
557 self.server = cls(self.address, _requesthandler)
558 self.server.idletimeout = self.ui.configint(
559 'chgserver', 'idletimeout', self.server.idletimeout)
560 self.server.startautoexitthread()
561 self._createsymlink()
562
563 def _inithashstate(self):
564 self.baseaddress = self.address
565 if self.ui.configbool('chgserver', 'skiphash', False):
566 self.hashstate = None
567 return
568 self.hashstate = hashstate.fromui(self.ui)
569 self.address = _hashaddress(self.address, self.hashstate.confighash)
570
571 def _checkextensions(self):
572 if not self.hashstate:
573 return
574 if extensions.notloaded():
575 # one or more extensions failed to load. mtimehash becomes
576 # meaningless because we do not know the paths of those extensions.
577 # set mtimehash to an illegal hash value to invalidate the server.
578 self.hashstate.mtimehash = ''
579
580 def _createsymlink(self):
581 if self.baseaddress == self.address:
582 return
583 tempaddress = _tempaddress(self.baseaddress)
584 os.symlink(os.path.basename(self.address), tempaddress)
585 util.rename(tempaddress, self.baseaddress)
586
587 def _cleanup(self):
588 self.server.unlinksocketfile()
589
547 class AutoExitMixIn: # use old-style to comply with SocketServer design
590 class AutoExitMixIn: # use old-style to comply with SocketServer design
548 lastactive = time.time()
591 lastactive = time.time()
549 idletimeout = 3600 # default 1 hour
592 idletimeout = 3600 # default 1 hour
@@ -604,54 +647,11 b' class AutoExitMixIn: # use old-style to'
604 if exc.errno != errno.ENOENT:
647 if exc.errno != errno.ENOENT:
605 raise
648 raise
606
649
607 class chgunixservice(commandserver.unixservice):
650 class _requesthandler(commandserver._requesthandler):
608 def __init__(self, ui, repo, opts):
651 def _createcmdserver(self, repo, conn, fin, fout):
609 super(chgunixservice, self).__init__(ui, repo=None, opts=opts)
652 ui = self.server.ui
610 if repo:
653 return chgcmdserver(ui, repo, fin, fout, conn,
611 # one chgserver can serve multiple repos. drop repo infomation
654 self.server.hashstate, self.server.baseaddress)
612 self.ui.setconfig('bundle', 'mainreporoot', '', 'repo')
613
614 def init(self):
615 self._inithashstate()
616 self._checkextensions()
617 class cls(AutoExitMixIn, socketserver.ForkingMixIn,
618 socketserver.UnixStreamServer):
619 ui = self.ui
620 repo = self.repo
621 hashstate = self.hashstate
622 baseaddress = self.baseaddress
623 self.server = cls(self.address, _requesthandler)
624 self.server.idletimeout = self.ui.configint(
625 'chgserver', 'idletimeout', self.server.idletimeout)
626 self.server.startautoexitthread()
627 self._createsymlink()
628
629 def _inithashstate(self):
630 self.baseaddress = self.address
631 if self.ui.configbool('chgserver', 'skiphash', False):
632 self.hashstate = None
633 return
634 self.hashstate = hashstate.fromui(self.ui)
635 self.address = _hashaddress(self.address, self.hashstate.confighash)
636
637 def _checkextensions(self):
638 if not self.hashstate:
639 return
640 if extensions.notloaded():
641 # one or more extensions failed to load. mtimehash becomes
642 # meaningless because we do not know the paths of those extensions.
643 # set mtimehash to an illegal hash value to invalidate the server.
644 self.hashstate.mtimehash = ''
645
646 def _createsymlink(self):
647 if self.baseaddress == self.address:
648 return
649 tempaddress = _tempaddress(self.baseaddress)
650 os.symlink(os.path.basename(self.address), tempaddress)
651 util.rename(tempaddress, self.baseaddress)
652
653 def _cleanup(self):
654 self.server.unlinksocketfile()
655
655
656 def uisetup(ui):
656 def uisetup(ui):
657 commandserver._servicemap['chgunix'] = chgunixservice
657 commandserver._servicemap['chgunix'] = chgunixservice
General Comments 0
You need to be logged in to leave comments. Login now