diff -r 2a3fc0272e3f -r f0d730efb02f 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)