Skip to content
Permalink
Browse files

Allow the python side to use newer helper features when supported

  • Loading branch information...
glandium committed Mar 6, 2019
1 parent 7c5a49b commit 918274ec74a3217aef7ea7301fbaf2186c27b128
Showing with 21 additions and 9 deletions.
  1. +1 −1 cinnabar/cmd/util.py
  2. +20 −8 cinnabar/helper.py
@@ -136,7 +136,7 @@ def module_version():
def helper_version():
from cinnabar.helper import GitHgHelper
try:
with GitHgHelper.query('version') as out:
with GitHgHelper.query('revision') as out:
version = out.read(40)
except Exception:
version = 'unknown'
@@ -49,8 +49,7 @@ def close(self):
self._helper = self

@classmethod
@contextmanager
def query(self, name, *args):
def _ensure_helper(self):
if self._helper is False:
helper_path = Git.config('cinnabar.helper')
env = {
@@ -72,7 +71,6 @@ def query(self, name, *args):
response = None

if not response:
logger = logging.getLogger('helper')
if self._helper and self._helper.wait() == 128:
message = ('Cinnabar helper executable is outdated. '
'Please try `git cinnabar download` or '
@@ -84,14 +82,23 @@ def query(self, name, *args):

raise NoHelperAbort(message)
else:
self._version = response.lstrip('ok\n') or 'unknown'
version = response.lstrip('ok\n') or 'unknown'
self._revision, _, version = version.partition(' ')
if version:
self._version = int(version)
else:
self._version = self.VERSION
atexit.register(self.close)

if self._helper is self:
raise HelperClosedError

if name == 'version':
yield StringIO(self._version)
@classmethod
@contextmanager
def query(self, name, *args):
self._ensure_helper()
if name == 'revision':
yield StringIO(self._revision)
return

helper = self._helper
@@ -140,9 +147,14 @@ def _read_data(self, stdout):
assert lf == '\n'
return ret

@classmethod
def supports(self, version):
self._ensure_helper()
return version <= self._version


class GitHgHelper(BaseHelper):
VERSION = 30
VERSION = 3000
_helper = False

@classmethod
@@ -443,7 +455,7 @@ def filemodify(self, path, sha1=None, typ='regular', content=None):


class HgRepoHelper(BaseHelper):
VERSION = 30
VERSION = 3000
_helper = False

@classmethod

0 comments on commit 918274e

Please sign in to comment.
You can’t perform that action at this time.