Mercurial > python-hglib
changeset 91:0383fc37102b
client: refactor opening of the cmd server to an open method
so we can create instances of hgclient without automatically opening a command
server (needed for clone/init).
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Thu, 22 Dec 2011 19:12:47 +0200 |
parents | b894c2222dff |
children | 07efbd3bd09a |
files | hglib/client.py |
diffstat | 1 files changed, 18 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/hglib/client.py Thu Dec 22 19:12:39 2011 +0200 +++ b/hglib/client.py Thu Dec 22 19:12:47 2011 +0200 @@ -37,21 +37,23 @@ outputfmtsize = struct.calcsize(outputfmt) retfmt = '>i' - def __init__(self, path, encoding, configs): - args = [hglib.HGPATH, 'serve', '--cmdserver', 'pipe', + def __init__(self, path, encoding, configs, connect=True): + self._args = [hglib.HGPATH, 'serve', '--cmdserver', 'pipe', '--config', 'ui.interactive=True'] if path: - args += ['-R', path] + self._args += ['-R', path] if configs: - args += ['--config'] + configs - env = {} + self._args += ['--config'] + configs + self._env = {} if encoding: - env['HGENCODING'] = encoding + self._env['HGENCODING'] = encoding - self.server = util.popen(args, env) - self._readhello() + self.server = None self._version = None + if connect: + self.open() + def __enter__(self): return self @@ -164,6 +166,14 @@ return eh(ret, out, err) return out + def open(self): + if self.server is not None: + raise ValueError('server already open') + + self.server = util.popen(self._args, self._env) + self._readhello() + return self + def close(self): """ Closes the command server instance and waits for it to exit, returns the