[PATCH 2 of 5 V2] chgserver: implement validate command

Jun Wu quark at fb.com
Fri Mar 4 08:28:55 EST 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1456914735 0
#      Wed Mar 02 10:32:15 2016 +0000
# Node ID 099b8303cd3dcfa7d4446bf31f07f4f0975bda08
# Parent  8868538a8a0d5ca8f36f0bdea8d11192ff4e8ca0
chgserver: implement validate command

validate will load the repo config and check if the server has up-to-date
config to continue serve the client. In case it does not, the server will
send instructions to the client about what to do next, including to retry
with a different address or to unlink an outdated socket file to stop an
old server.

diff --git a/hgext/chgserver.py b/hgext/chgserver.py
--- a/hgext/chgserver.py
+++ b/hgext/chgserver.py
@@ -25,6 +25,9 @@
 'setumask' command
     set umask
 
+'validate' command
+    reload the config and check if the server is up to date
+
 'SIGHUP' signal
     reload configuration files
 
@@ -341,6 +344,9 @@
         self._oldios = []  # original (self.ch, ui.fp, fd) before "attachio"
         self.hashstate = hashstate
         self.baseaddress = baseaddress
+        if hashstate is not None:
+            self.capabilities = self.capabilities.copy()
+            self.capabilities['validate'] = chgcmdserver.validate
 
     def cleanup(self):
         # dispatch._runcatch() does not flush outputs if exception is not
@@ -387,6 +393,30 @@
 
         self.cresult.write(struct.pack('>i', len(clientfds)))
 
+    def validate(self):
+        """reload the config and check if the server is up to date
+
+        read a list of NULL terminated arguments.
+        write a list of NULL terminated instruction strings.
+        an instruction string could be either:
+            - "unlink $path", the client should unlink the path to stop the
+              outdated server.
+            - "redirect $path", the client should try to connect to another
+              server instead.
+        """
+        args = self._readlist()
+        self.ui = _renewui(self.ui, args)
+        newhash = hashstate.fromui(self.ui, self.hashstate.mtimepaths)
+        insts = []
+        if newhash.mtimehash != self.hashstate.mtimehash:
+            addr = _hashaddress(self.baseaddress, self.hashstate.confighash)
+            insts.append('unlink %s' % addr)
+        if newhash.confighash != self.hashstate.confighash:
+            addr = _hashaddress(self.baseaddress, newhash.confighash)
+            insts.append('redirect %s' % addr)
+        _log('validate: %s\n' % insts)
+        self.cresult.write('\0'.join(insts) + '\0')
+
     def _saveio(self):
         if self._oldios:
             return False


More information about the Mercurial-devel mailing list