Patchwork [1,of,4,marmoute-reviewed] localrepo: add a way to get the current lock if it's held

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

Comments

Siddharth Agarwal - Oct. 5, 2015, 9:48 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1444080413 25200
#      Mon Oct 05 14:26:53 2015 -0700
# Node ID c408266451c7b989b05f089cfa3c7b103b1c8b06
# Parent  efd57cd6fd1d5eb76102fabfc45676873bbba29d
localrepo: add a way to get the current lock if it's held

We'll use this in upcoming patches to return a reference to the wlock if it's
held.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1300,6 +1300,15 @@  class localrepository(object):
         self._wlockref = weakref.ref(l)
         return l
 
+    def _currentlock(self, lockref):
+        """Returns the lock if it's held, or None if it's not."""
+        if lockref is None:
+            return None
+        l = lockref()
+        if l is None or not l.held:
+            return None
+        return l
+
     def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist):
         """
         commit an individual file as part of a larger transaction