Mercurial > hg
changeset 30739:815e1cefd082
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.
author | Jun Wu <quark@fb.com> |
---|---|
date | Tue, 10 Jan 2017 06:59:21 +0800 |
parents | a45c0f42271f |
children | 493935e0327a |
files | mercurial/chgserver.py |
diffstat | 1 files changed, 15 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/chgserver.py Tue Jan 10 06:59:03 2017 +0800 +++ b/mercurial/chgserver.py Tue Jan 10 06:59:21 2017 +0800 @@ -287,13 +287,17 @@ 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): self.in_ = in_ self.out = out 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()) data = '\0'.join(args) @@ -308,6 +312,16 @@ raise error.Abort(_('invalid response')) 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)