diff --git a/mercurial/configitems.py b/mercurial/configitems.py --- a/mercurial/configitems.py +++ b/mercurial/configitems.py @@ -1127,6 +1127,9 @@ coreconfigitem('ui', 'report_untrusted', coreconfigitem('ui', 'rollback', default=True, ) +coreconfigitem('ui', 'signal-safe-lock', + default=True, +) coreconfigitem('ui', 'slash', default=False, ) diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1693,12 +1693,15 @@ class localrepository(object): if wait: timeout = self.ui.configint("ui", "timeout") warntimeout = self.ui.configint("ui", "timeout.warn") + # internal config: ui.signal-safe-lock + signalsafe = self.ui.configbool('ui', 'signal-safe-lock') l = lockmod.trylock(self.ui, vfs, lockname, timeout, warntimeout, releasefn=releasefn, acquirefn=acquirefn, desc=desc, inheritchecker=inheritchecker, - parentlock=parentlock) + parentlock=parentlock, + signalsafe=signalsafe) return l def _afterlock(self, callback): diff --git a/mercurial/lock.py b/mercurial/lock.py --- a/mercurial/lock.py +++ b/mercurial/lock.py @@ -21,6 +21,7 @@ from . import ( encoding, error, pycompat, + util, ) from .utils import ( @@ -177,7 +178,7 @@ class lock(object): def __init__(self, vfs, fname, timeout=-1, releasefn=None, acquirefn=None, desc=None, inheritchecker=None, parentlock=None, - dolock=True): + signalsafe=True, dolock=True): self.vfs = vfs self.f = fname self.held = 0 @@ -189,6 +190,10 @@ class lock(object): self.parentlock = parentlock self._parentheld = False self._inherited = False + if signalsafe: + self._maybedelayedinterrupt = _delayedinterrupt + else: + self._maybedelayedinterrupt = util.nullcontextmanager self.postrelease = [] self.pid = self._getpid() if dolock: @@ -244,7 +249,7 @@ class lock(object): while not self.held and retry: retry -= 1 try: - with _delayedinterrupt(): + with self._maybedelayedinterrupt(): self.vfs.makelock(lockname, self.f) self.held = 1 except (OSError, IOError) as why: