Mercurial > public > mercurial-scm > hg
diff mercurial/localrepo.py @ 35208:1b758105b5c7
lock: add a trylock method handling the timeout and messaging logic
We are about to make the messages around lock more flexible. We move all the
currently logic into a function in the lock module. We'll update the message
scheme in the next changeset.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Wed, 29 Nov 2017 20:36:29 -0500 |
parents | d210723b73e5 |
children | 9153871d50e0 |
line wrap: on
line diff
--- a/mercurial/localrepo.py Wed Nov 29 21:00:02 2017 -0500 +++ b/mercurial/localrepo.py Wed Nov 29 20:36:29 2017 -0500 @@ -1592,29 +1592,16 @@ # determine whether it can be inherited if parentenvvar is not None: parentlock = encoding.environ.get(parentenvvar) - try: - l = lockmod.lock(vfs, lockname, 0, releasefn=releasefn, - acquirefn=acquirefn, desc=desc, - inheritchecker=inheritchecker, - parentlock=parentlock) - except error.LockHeld as inst: - if not wait: - raise - # 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, - self.ui.configint("ui", "timeout"), - releasefn=releasefn, acquirefn=acquirefn, - desc=desc) - self.ui.warn(_("got lock after %s seconds\n") % l.delay) + + timeout = 0 + if wait: + timeout = self.ui.configint("ui", "timeout") + + l = lockmod.trylock(self.ui, vfs, lockname, timeout, + releasefn=releasefn, + acquirefn=acquirefn, desc=desc, + inheritchecker=inheritchecker, + parentlock=parentlock) return l def _afterlock(self, callback):