Patchwork lock: show more detail for new-style locks in lock waiting message (issue4752)

login
register
mail settings
Submitter Mark Ignacio
Date Aug. 30, 2016, 4:35 p.m.
Message ID <2a7ad7d5c01d222d9057.1472574958@dev11494.prn1.facebook.com>
Download mbox | patch
Permalink /patch/16484/
State Accepted
Headers show

Comments

Mark Ignacio - Aug. 30, 2016, 4:35 p.m.
# HG changeset patch
# User Mark Ignacio <mignacio@fb.com>
# Date 1472574300 25200
#      Tue Aug 30 09:25:00 2016 -0700
# Node ID 2a7ad7d5c01d222d9057cba6b8d5b751cd200dc8
# Parent  f148bfa40489269be2e48046734f81065129847a
lock: show more detail for new-style locks in lock waiting message (issue4752)

Improve the lock waiting warning message by explicitly saying that a host and
process are holding the lock. This nudges confused new users in the direction
of investigating the other process instead of removing the lock.
Augie Fackler - Aug. 30, 2016, 9:29 p.m.
On Tue, Aug 30, 2016 at 09:35:58AM -0700, Mark Ignacio wrote:
> # HG changeset patch
> # User Mark Ignacio <mignacio@fb.com>
> # Date 1472574300 25200
> #      Tue Aug 30 09:25:00 2016 -0700
> # Node ID 2a7ad7d5c01d222d9057cba6b8d5b751cd200dc8
> # Parent  f148bfa40489269be2e48046734f81065129847a
> lock: show more detail for new-style locks in lock waiting message (issue4752)

Seems fine to me, queued. Thanks.

>
> Improve the lock waiting warning message by explicitly saying that a host and
> process are holding the lock. This nudges confused new users in the direction
> of investigating the other process instead of removing the lock.
>
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -1290,8 +1290,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))
> +            # show more details for new-style locks
> +            if ':' in inst.locker:
> +                host, pid = inst.locker.split(":", 1)
> +                self.ui.warn(
> +                    _("waiting for lock on %s held by process %r "
> +                      "on host %r\n") % (desc, pid, host))
> +            else:
> +                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", "600")),
> diff --git a/tests/test-lock-badness.t b/tests/test-lock-badness.t
> --- a/tests/test-lock-badness.t
> +++ b/tests/test-lock-badness.t
> @@ -60,7 +60,7 @@
>    > > preup 2>&1
>    $ wait
>    $ cat preup
> -  waiting for lock on working directory of b held by '*:*' (glob)
> +  waiting for lock on working directory of b held by process '*' on host '*' (glob)
>    got lock after * seconds (glob)
>    $ cat stdout
>    adding b
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1290,8 +1290,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))
+            # show more details for new-style locks
+            if ':' in inst.locker:
+                host, pid = inst.locker.split(":", 1)
+                self.ui.warn(
+                    _("waiting for lock on %s held by process %r "
+                      "on host %r\n") % (desc, pid, host))
+            else:
+                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", "600")),
diff --git a/tests/test-lock-badness.t b/tests/test-lock-badness.t
--- a/tests/test-lock-badness.t
+++ b/tests/test-lock-badness.t
@@ -60,7 +60,7 @@ 
   > > preup 2>&1
   $ wait
   $ cat preup
-  waiting for lock on working directory of b held by '*:*' (glob)
+  waiting for lock on working directory of b held by process '*' on host '*' (glob)
   got lock after * seconds (glob)
   $ cat stdout
   adding b