Patchwork [4,of,4,marmoute-reviewed] scmutil: add a way for a repo's wlock to be inherited by a subprocess

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

Comments

Siddharth Agarwal - Oct. 5, 2015, 9:48 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1444081079 25200
#      Mon Oct 05 14:37:59 2015 -0700
# Node ID ea8c9f448f2eb74f83adf979e06601ce41412e86
# Parent  1b89f2df6e255380272c8e350d7aa439de908c54
scmutil: add a way for a repo's wlock to be inherited by a subprocess

This is part of a series that will allow locks to be inherited by subprocesses
in limited circumstances.

In the future, we'll call this for custom merge drivers.
Pierre-Yves David - Oct. 6, 2015, 9:42 p.m.
On 10/05/2015 02:48 PM, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1444081079 25200
> #      Mon Oct 05 14:37:59 2015 -0700
> # Node ID ea8c9f448f2eb74f83adf979e06601ce41412e86
> # Parent  1b89f2df6e255380272c8e350d7aa439de908c54
> scmutil: add a way for a repo's wlock to be inherited by a subprocess

Pushed to the clowncopter, thanks

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -1158,3 +1158,12 @@  def _locksub(repo, lock, envvar, cmd, en
     with lock.inherit() as locker:
         environ[envvar] = locker
         return repo.ui.system(cmd, environ=environ, *args, **kwargs)
+
+def wlocksub(repo, cmd, *args, **kwargs):
+    """run cmd as a subprocess that allows inheriting repo's wlock
+
+    This can only be called while the wlock is held. This takes all the
+    arguments that ui.system does, and returns the exit code of the
+    subprocess."""
+    return _locksub(repo, repo.currentwlock(), 'HG_WLOCK_LOCKER', cmd, *args,
+                    **kwargs)