hgext/chgserver.py
changeset 28350 8f9661d1637b
parent 28342 bd05d38a1002
child 28454 8062869860b8
--- a/hgext/chgserver.py	Sun Feb 14 13:58:46 2016 +0900
+++ b/hgext/chgserver.py	Sat Mar 05 13:56:59 2016 +0000
@@ -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
@@ -413,6 +419,31 @@
             setattr(ui, fn, fp)
         del self._oldios[:]
 
+    def validate(self):
+        """Reload the config and check if the server is up to date
+
+        Read a list of '\0' separated arguments.
+        Write a non-empty list of '\0' separated instruction strings or '\0'
+        if the list is empty.
+        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) or '\0')
+
     def chdir(self):
         """Change current directory