mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 23:38:50 +03:00
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.
This commit is contained in:
parent
5ae59a4110
commit
ed9bebc440
@ -287,13 +287,17 @@ class channeledsystem(object):
|
|||||||
|
|
||||||
exitcode length (unsigned int),
|
exitcode length (unsigned int),
|
||||||
exitcode (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):
|
def __init__(self, in_, out, channel):
|
||||||
self.in_ = in_
|
self.in_ = in_
|
||||||
self.out = out
|
self.out = out
|
||||||
self.channel = channel
|
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 = [type, util.quotecommand(cmd), os.path.abspath(cwd or '.')]
|
||||||
args.extend('%s=%s' % (k, v) for k, v in environ.iteritems())
|
args.extend('%s=%s' % (k, v) for k, v in environ.iteritems())
|
||||||
data = '\0'.join(args)
|
data = '\0'.join(args)
|
||||||
@ -308,6 +312,16 @@ class channeledsystem(object):
|
|||||||
raise error.Abort(_('invalid response'))
|
raise error.Abort(_('invalid response'))
|
||||||
rc, = struct.unpack('>i', self.in_.read(4))
|
rc, = struct.unpack('>i', self.in_.read(4))
|
||||||
return rc
|
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:
|
else:
|
||||||
raise error.ProgrammingError('invalid S channel type: %s' % type)
|
raise error.ProgrammingError('invalid S channel type: %s' % type)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user