Mercurial > public > mercurial-scm > hg-stable
diff contrib/hgclient.py @ 40636:054d0fcba2c4
commandserver: add experimental option to use separate message channel
This is loosely based on the idea of the TortoiseHg's pipeui extension,
which attaches ui.label to message text so the command-server client can
capture prompt text, for example.
https://bitbucket.org/tortoisehg/thg/src/4.7.2/tortoisehg/util/pipeui.py
I was thinking that this functionality could be generalized to templating,
but changed mind as doing template stuff would be unnecessarily complex.
It's merely a status message, a simple serialization option should suffice.
Since this slightly changes the command-server protocol, it's gated by a
config knob. If the config is enabled, and if it's supported by the server,
"message-encoding: <name>" is advertised so the client can stop parsing
'o'/'e' channel data and read encoded messages from the 'm' channel. As we
might add new message encodings in future releases, client can specify a list
of encoding names in preferred order.
This patch includes 'cbor' encoding as example. Perhaps, 'json' should be
supported as well.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 18 Jan 2015 18:49:59 +0900 |
parents | 6958eb9bdcd6 |
children | 6a372f943e49 |
line wrap: on
line diff
--- a/contrib/hgclient.py Wed Nov 07 22:37:51 2018 +0900 +++ b/contrib/hgclient.py Sun Jan 18 18:49:59 2015 +0900 @@ -27,10 +27,11 @@ stringio = cStringIO.StringIO bprint = print -def connectpipe(path=None): +def connectpipe(path=None, extraargs=()): cmdline = [b'hg', b'serve', b'--cmdserver', b'pipe'] if path: cmdline += [b'-R', path] + cmdline.extend(extraargs) server = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE) @@ -114,6 +115,8 @@ writeblock(server, input.read(data)) elif ch == b'L': writeblock(server, input.readline(data)) + elif ch == b'm': + bprint(b"message: %r" % data) elif ch == b'r': ret, = struct.unpack('>i', data) if ret != 0: @@ -132,3 +135,8 @@ finally: server.stdin.close() server.wait() + +def checkwith(connect=connectpipe, **kwargs): + def wrap(func): + return check(func, lambda: connect(**kwargs)) + return wrap