Mercurial > hg-stable
changeset 28156:75f586a1bf55
commandserver: add _readstr and _readlist
Reading a string or a list are common operations for commandserver and
chgserver. This patch adds _readstr and _readlist to avoid duplication.
author | Jun Wu <quark@fb.com> |
---|---|
date | Tue, 16 Feb 2016 19:11:45 +0000 |
parents | 7f430b2ac7fd |
children | e7c9b59dbbcf |
files | mercurial/commandserver.py |
diffstat | 1 files changed, 19 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commandserver.py Wed Feb 10 16:59:34 2016 +0000 +++ b/mercurial/commandserver.py Tue Feb 16 19:11:45 2016 +0000 @@ -190,6 +190,25 @@ return data + def _readstr(self): + """read a string from the channel + + format: + data length (uint32), data + """ + length = struct.unpack('>I', self._read(4))[0] + if not length: + return '' + return self._read(length) + + def _readlist(self): + """read a list of NULL separated strings from the channel""" + s = self._readstr() + if s: + return s.split('\0') + else: + return [] + def runcommand(self): """ reads a list of \0 terminated arguments, executes and writes the return code to the result channel """