# HG changeset patch # User Idan Kamara # Date 1324573967 -7200 # Node ID 0383fc37102b54870aac5b6586dec2767986f0f6 # Parent b894c2222dff30183d26388812a257c93e8f8a5a 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). diff -r b894c2222dff -r 0383fc37102b hglib/client.py --- 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