[PATCH 4 of 4] lock message: provide feedback how to handle "waiting for lock on repository" in error message

Tuli Uchitel tuli at fb.com
Tue Mar 8 15:50:17 EST 2016


# HG changeset patch
# User Tuli Uchitel <tuli at fb.com>
# Date 1457464102 0
#      Tue Mar 08 19:08:22 2016 +0000
# Branch stable
# Node ID 068e106bb16cfe91d510518aa86e05229fe6d2ed
# Parent  d3da9ce4c07018109275c91e41b2c33231449104
lock message: provide feedback how to handle "waiting for lock on repository" in error message

(issue4752) currently, whenever there is an attempt to acquire the lock to a repository, which is already occupied, we have a laconic message of the form 'waiting for lock on <description> held by <hostname:pid>'. This message doesn't provide the user any feedback that can help to resolve the issue. This series of commits, intends to provide a mechanism that provides the means, to record description of operations being carried out after a lock is acquired, that can later be retrieved in order to give information for the reason of the lock's acquisition. In particular we shall be using this mechanism, to record information about an editor being opened, as in the case of commiting a change. We also improve the formulation of the original message.
The new message will be of the form: 'waiting for lock on <description> help by process <pid> on host <hostname>(user <username> requested to open a <editor executable path> session on host <hostname>)'

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1244,6 +1244,18 @@
             lockdescriptionfilename = "%s.description" % lockfilename
         return lockdescriptionfilename
 
+    def _createwarningmessages(self, desc, inst):
+        try:
+            host, pid = inst.locker.split(":", 1)
+            basicwarningmessage = 'waiting for lock on %s held by process %s on host %s' % (desc, pid, host)
+        except ValueError:
+            basicwarningmessage = 'waiting for lock on %s held by %r\n' % (desc, inst.locker)
+        detailedwarningmessage = None
+        lockloggerfilename = self._getlockdescriptionfilename(inst.filename)
+        if lockloggerfilename is not None and self.vfs.exists(lockloggerfilename):
+            detailedwarningmessage = self.vfs.read(lockloggerfilename)
+        return basicwarningmessage, detailedwarningmessage
+
     def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc,
               inheritchecker=None, parentenvvar=None):
         parentlock = None
@@ -1259,8 +1271,15 @@
         except error.LockHeld as inst:
             if not wait:
                 raise
-            self.ui.warn(_("waiting for lock on %s held by %r\n") %
-                         (desc, inst.locker))
+
+            # Print warning messages for user about the lock
+            basicwarningmessage, detailedwarningmessage = self._createwarningmessages(desc, inst)
+            if detailedwarningmessage is not None:
+                warningmessage = _("{} ({})\n").format(basicwarningmessage, detailedwarningmessage)
+            else:
+                warningmessage = _("{}\n").format(basicwarningmessage)
+            self.ui.warn(warningmessage)
+
             # default to 600 seconds timeout
             l = lockmod.lock(vfs, lockname,
                              int(self.ui.config("ui", "timeout", "600")),


More information about the Mercurial-devel mailing list