[PATCH 3 of 4 marmoute-reviewed] scmutil: add a way for a subprocess to be run with an inheritable lock

Siddharth Agarwal sid0 at fb.com
Mon Oct 5 16:48:03 CDT 2015


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1444080892 25200
#      Mon Oct 05 14:34:52 2015 -0700
# Node ID 1b89f2df6e255380272c8e350d7aa439de908c54
# Parent  6ed71ec8f372f273089dcddad5984d368c794f26
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.

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -1148,3 +1148,13 @@ class filecache(object):
             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)


More information about the Mercurial-devel mailing list