Mercurial > hg
changeset 26490:f0d730efb02f
scmutil: add a way for a subprocess to be run with an inheritable lock
This is part of a series that will allow locks to be inherited by subprocesses
in limited circumstances.
In an upcoming patch, we'll add an API for the wlock to be inherited.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Mon, 05 Oct 2015 14:34:52 -0700 |
parents | 2a3fc0272e3f |
children | 366d489295ca |
files | mercurial/scmutil.py |
diffstat | 1 files changed, 10 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/scmutil.py Mon Oct 05 14:27:37 2015 -0700 +++ b/mercurial/scmutil.py Mon Oct 05 14:34:52 2015 -0700 @@ -1148,3 +1148,13 @@ del obj.__dict__[self.name] except KeyError: raise AttributeError(self.name) + +def _locksub(repo, lock, envvar, cmd, environ=None, *args, **kwargs): + if lock is None: + raise error.LockInheritanceContractViolation( + 'lock can only be inherited while held') + if environ is None: + environ = {} + with lock.inherit() as locker: + environ[envvar] = locker + return repo.ui.system(cmd, environ=environ, *args, **kwargs)