[PATCH 1 of 3] lock: factor the actual in a utility closure

Boris Feld boris.feld at octobus.net
Mon Nov 27 23:18:09 UTC 2017


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1511802168 18000
#      Mon Nov 27 12:02:48 2017 -0500
# Node ID c59808ca8622826083bc997a3181589f47659f93
# Parent  8287df8b7be545fdafa22b771012ac65f6264d12
# EXP-Topic lock-message
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r c59808ca8622
lock: factor the actual in a utility closure

The lock logic tries to grab the lock multiple time with different timeouts
and display messages about it. We are about to make the message logic more
flexible, so we factor out some common part first to help with the coming
changeset.

Using the exact same call means we are passing some lock inheritance logic to
the second call. This should be harmless.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1590,11 +1590,16 @@ class localrepository(object):
         # determine whether it can be inherited
         if parentenvvar is not None:
             parentlock = encoding.environ.get(parentenvvar)
+
+        def trylock(timeout):
+            """try to acquire the lock with the given time out"""
+            return lockmod.lock(vfs, lockname, timeout, releasefn=releasefn,
+                                acquirefn=acquirefn, desc=desc,
+                                inheritchecker=inheritchecker,
+                                parentlock=parentlock)
+
         try:
-            l = lockmod.lock(vfs, lockname, 0, releasefn=releasefn,
-                             acquirefn=acquirefn, desc=desc,
-                             inheritchecker=inheritchecker,
-                             parentlock=parentlock)
+            l = trylock(0)
         except error.LockHeld as inst:
             if not wait:
                 raise
@@ -1608,10 +1613,7 @@ class localrepository(object):
                 self.ui.warn(_("waiting for lock on %s held by %r\n") %
                              (desc, inst.locker))
             # default to 600 seconds timeout
-            l = lockmod.lock(vfs, lockname,
-                             int(self.ui.config("ui", "timeout")),
-                             releasefn=releasefn, acquirefn=acquirefn,
-                             desc=desc)
+            l = trylock(int(self.ui.config("ui", "timeout")))
             self.ui.warn(_("got lock after %s seconds\n") % l.delay)
         return l
 


More information about the Mercurial-devel mailing list