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

login
register
mail settings
Submitter Siddharth Agarwal
Date Oct. 5, 2015, 9:48 p.m.
Message ID <1b89f2df6e255380272c.1444081683@dev6666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/10816/
State Accepted
Headers show

Comments

Siddharth Agarwal - Oct. 5, 2015, 9:48 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@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.

Patch

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)