scmutil: add a way for a subprocess to be run with an inheritable lock
authorSiddharth Agarwal <sid0@fb.com>
Mon, 05 Oct 2015 14:34:52 -0700
changeset 26490 f0d730efb02f
parent 26489 2a3fc0272e3f
child 26491 366d489295ca
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.
mercurial/scmutil.py
--- 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)