[PATCH 3 of 3] lock: allow to configure when the lock messages are displayed

Boris Feld boris.feld at octobus.net
Wed Nov 29 11:21:14 EST 2017


On Wed, 2017-11-29 at 22:57 +0900, Yuya Nishihara wrote:
> On Mon, 27 Nov 2017 18:18:11 -0500, Boris Feld wrote:
> > # HG changeset patch
> > # User Boris Feld <boris.feld at octobus.net>
> > # Date 1511801811 18000
> > #      Mon Nov 27 11:56:51 2017 -0500
> > # Node ID 15b8fcffac40607710816a75217219b5668baba5
> > # Parent  f40e9671a53992359c622dd9c46050b4ff09c374
> > # EXP-Topic lock-message
> > # Available At https://bitbucket.org/octobus/mercurial-devel/
> > #              hg pull https://bitbucket.org/octobus/mercurial-deve
> > l/ -r 15b8fcffac40
> > lock: allow to configure when the lock messages are displayed
> > diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> > --- a/mercurial/localrepo.py
> > +++ b/mercurial/localrepo.py
> > @@ -1609,16 +1609,38 @@ class localrepository(object):
> >                  msg = _("waiting for lock on %s held by %r\n") %
> > (desc, locker)
> >              printer(msg)
> >  
> > +        delaywarning = self.ui.configint("ui", "timeout.warn")
> > +        dowarn = True
> > +        if delaywarning < 0:
> > +            dowarn = False
> > +            delaywarning = 0
> > +        else:
> > +            delaywarning = delaywarning if wait else 0
> >          try:
> > -            l = trylock(0)
> > +            try:
> > +                l = trylock(0)
> > +            except error.LockHeld as inst:
> > +                if not wait:
> > +                    raise
> > +                printwarning(self.ui.debug, inst.locker)
> > +                if not delaywarning:
> > +                    raise
> > +                l = trylock(delaywarning)
> > +                # We got the lock while warning were silent,
> > inform debug output
> > +                msg = _("got lock after %s seconds\n") % (l.delay)
> > +                self.ui.debug(msg)
> >          except error.LockHeld as inst:
> >              if not wait:
> >                  raise
> > -            printwarning(self.ui.warn, inst.locker)
> > +            if dowarn:
> > +                printwarning(self.ui.warn, inst.locker)
> >              # default to 600 seconds timeout
> >              l = trylock(int(self.ui.config("ui", "timeout")))
> > -            msg = _("got lock after %s seconds\n") % l.delay
> > -            self.ui.warn(msg)
> > +            msg = _("got lock after %s seconds\n") % (l.delay +
> > delaywarning)
> > +            if dowarn:
> > +                self.ui.warn(msg)
> > +            else:
> > +                self.ui.debug(msg)
> 
> Looks okay, but seems unnecessarily complicated. I think it's better
> to factor
> out the lock.lock() loop to a utility function which takes ui and
> timeouts.
> 
>   def lock(ui, ...):
>       l = lockmod.lock(..., dolock=False)
>       while True:
>           try:
>               l._trylock()
>           except LockHeld:
>               if delay >= timeout.warn:
>                   ui.warn(...)
>               sleep(1)
>           ...
> 
> Thoughts?

Looks like a good idea, we will give it a shot.


More information about the Mercurial-devel mailing list