Patchwork [2,of,7] develwarn: use the lock helper in local repo

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 5, 2016, 1:59 p.m.
Message ID <9677e36d339bc11d8223.1470405555@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/16113/
State Accepted
Headers show

Comments

Pierre-Yves David - Aug. 5, 2016, 1:59 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1470397457 -7200
#      Fri Aug 05 13:44:17 2016 +0200
# Node ID 9677e36d339bc11d8223aadd9473eb7218b8b6cb
# Parent  9b65c0820c940442454e5f92a9475c4ec97f705c
# EXP-Topic vfsward
develwarn: use the lock helper in local repo

We have a helper function to know if a lock is taken. When checking lock usage
we now use it instead of manually accessing the locks.
Augie Fackler - Aug. 5, 2016, 6:33 p.m.
On Fri, Aug 05, 2016 at 03:59:15PM +0200, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
> # Date 1470397457 -7200
> #      Fri Aug 05 13:44:17 2016 +0200
> # Node ID 9677e36d339bc11d8223aadd9473eb7218b8b6cb
> # Parent  9b65c0820c940442454e5f92a9475c4ec97f705c
> # EXP-Topic vfsward
> develwarn: use the lock helper in local repo

I've taken this patch as it was separable from the rest of the series. Thanks!

>
> We have a helper function to know if a lock is taken. When checking lock usage
> we now use it instead of manually accessing the locks.
>
> diff -r 9b65c0820c94 -r 9677e36d339b mercurial/localrepo.py
> --- a/mercurial/localrepo.py	Thu Aug 04 16:56:50 2016 +0200
> +++ b/mercurial/localrepo.py	Fri Aug 05 13:44:17 2016 +0200
> @@ -1007,8 +1007,7 @@ class localrepository(object):
>      def transaction(self, desc, report=None):
>          if (self.ui.configbool('devel', 'all-warnings')
>                  or self.ui.configbool('devel', 'check-locks')):
> -            l = self._lockref and self._lockref()
> -            if l is None or not l.held:
> +            if self._currentlock(self._lockref) is None:
>                  raise RuntimeError('programming error: transaction requires '
>                                     'locking')
>          tr = self.currenttransaction()
> @@ -1320,8 +1319,8 @@ class localrepository(object):
>
>          If both 'lock' and 'wlock' must be acquired, ensure you always acquires
>          'wlock' first to avoid a dead-lock hazard.'''
> -        l = self._lockref and self._lockref()
> -        if l is not None and l.held:
> +        l = self._currentlock(self._lockref)
> +        if l is not None:
>              l.lock()
>              return l
>
> @@ -1352,8 +1351,7 @@ class localrepository(object):
>          # acquisition would not cause dead-lock as they would just fail.
>          if wait and (self.ui.configbool('devel', 'all-warnings')
>                       or self.ui.configbool('devel', 'check-locks')):
> -            l = self._lockref and self._lockref()
> -            if l is not None and l.held:
> +            if self._currentlock(self._lockref) is not None:
>                  self.ui.develwarn('"wlock" acquired after "lock"')
>
>          def unlock():
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Pierre-Yves David - Aug. 5, 2016, 10:42 p.m.
On 08/05/2016 08:33 PM, Augie Fackler wrote:
> On Fri, Aug 05, 2016 at 03:59:15PM +0200, Pierre-Yves David wrote:
>> # HG changeset patch
>> # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
>> # Date 1470397457 -7200
>> #      Fri Aug 05 13:44:17 2016 +0200
>> # Node ID 9677e36d339bc11d8223aadd9473eb7218b8b6cb
>> # Parent  9b65c0820c940442454e5f92a9475c4ec97f705c
>> # EXP-Topic vfsward
>> develwarn: use the lock helper in local repo
>
> I've taken this patch as it was separable from the rest of the series. Thanks!

Any reason you left patch 1 out?

Patch

diff -r 9b65c0820c94 -r 9677e36d339b mercurial/localrepo.py
--- a/mercurial/localrepo.py	Thu Aug 04 16:56:50 2016 +0200
+++ b/mercurial/localrepo.py	Fri Aug 05 13:44:17 2016 +0200
@@ -1007,8 +1007,7 @@  class localrepository(object):
     def transaction(self, desc, report=None):
         if (self.ui.configbool('devel', 'all-warnings')
                 or self.ui.configbool('devel', 'check-locks')):
-            l = self._lockref and self._lockref()
-            if l is None or not l.held:
+            if self._currentlock(self._lockref) is None:
                 raise RuntimeError('programming error: transaction requires '
                                    'locking')
         tr = self.currenttransaction()
@@ -1320,8 +1319,8 @@  class localrepository(object):
 
         If both 'lock' and 'wlock' must be acquired, ensure you always acquires
         'wlock' first to avoid a dead-lock hazard.'''
-        l = self._lockref and self._lockref()
-        if l is not None and l.held:
+        l = self._currentlock(self._lockref)
+        if l is not None:
             l.lock()
             return l
 
@@ -1352,8 +1351,7 @@  class localrepository(object):
         # acquisition would not cause dead-lock as they would just fail.
         if wait and (self.ui.configbool('devel', 'all-warnings')
                      or self.ui.configbool('devel', 'check-locks')):
-            l = self._lockref and self._lockref()
-            if l is not None and l.held:
+            if self._currentlock(self._lockref) is not None:
                 self.ui.develwarn('"wlock" acquired after "lock"')
 
         def unlock():