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.
--- 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)