Patchwork [4,of,8] chgserver: make S channel support pager request

login
register
mail settings
Submitter Jun Wu
Date Jan. 9, 2017, 11:12 p.m.
Message ID <483eabc8ccbbdfabed7f.1484003544@x1c>
Download mbox | patch
Permalink /patch/18156/
State Accepted
Headers show

Comments

Jun Wu - Jan. 9, 2017, 11:12 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1484002761 -28800
#      Tue Jan 10 06:59:21 2017 +0800
# Node ID 483eabc8ccbbdfabed7f0f0abd74fb131adcd3c3
# Parent  97e3f81b69bc7bc670459c62056f706c2b6ff941
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 483eabc8ccbb
chgserver: make S channel support pager request

This patch adds the "pager" support for the S channel. The pager API allows
running some subcommands, namely attachio, and waiting for the client to be
properly synchronized.

Patch

diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
--- a/mercurial/chgserver.py
+++ b/mercurial/chgserver.py
@@ -288,4 +288,8 @@  class channeledsystem(object):
     exitcode length (unsigned int),
     exitcode (int)
+
+    if type == 'pager', repetitively waits for a command name ending with '\n'
+    and executes it defined by cmdtable, or exits the loop if the command name
+    is empty.
     """
     def __init__(self, in_, out, channel):
@@ -294,5 +298,5 @@  class channeledsystem(object):
         self.channel = channel
 
-    def __call__(self, cmd, environ, cwd, type='system'):
+    def __call__(self, cmd, environ, cwd=None, type='system', cmdtable=None):
         args = [type, util.quotecommand(cmd), os.path.abspath(cwd or '.')]
         args.extend('%s=%s' % (k, v) for k, v in environ.iteritems())
@@ -309,4 +313,14 @@  class channeledsystem(object):
             rc, = struct.unpack('>i', self.in_.read(4))
             return rc
+        elif type == 'pager':
+            while True:
+                cmd = self.in_.readline()[:-1]
+                if not cmd:
+                    break
+                if cmdtable and cmd in cmdtable:
+                    _log('pager subcommand: %s' % cmd)
+                    cmdtable[cmd]()
+                else:
+                    raise error.Abort(_('unexpected command: %s') % cmd)
         else:
             raise error.ProgrammingError('invalid S channel type: %s' % type)