# HG changeset patch # User Idan Kamara # Date 1313437605 -10800 # Node ID e185c3922c68c1b6138e834da3e7941205c1ed76 # Parent 238efe4fd7dbcd9afc3d6ac63a18ab8d0946bd4d client: add version command diff -r 238efe4fd7db -r e185c3922c68 hglib/client.py --- a/hglib/client.py Mon Aug 15 22:46:45 2011 +0300 +++ b/hglib/client.py Mon Aug 15 22:46:45 2011 +0300 @@ -26,6 +26,7 @@ stdout=subprocess.PIPE, env=env) self._readhello() + self._version = None def _readhello(self): """ read the hello message the server sends when started """ @@ -645,3 +646,20 @@ counters = out.rstrip().split(', ') return tuple(int(s.split(' ', 1)[0]) for s in counters) + + @property + def version(self): + if self._version is None: + v = self.rawcommand(cmdbuilder('version', q=True)) + v = list(re.match(r'.*?(\d+)\.(\d+)\.?(\d+)?(\+[0-9a-f-]+)?', + v).groups()) + + for i in range(3): + try: + v[i] = int(v[i]) + except TypeError: + v[i] = 0 + + self._version = tuple(v) + + return self._version