diff -r 146cccdb282b -r e16f80f89a29 mercurial/lock.py --- a/mercurial/lock.py Thu Sep 24 22:00:51 2015 -0700 +++ b/mercurial/lock.py Thu Sep 24 22:07:55 2015 -0700 @@ -102,7 +102,16 @@ self.held = 1 except (OSError, IOError) as why: if why.errno == errno.EEXIST: - locker = self.testlock() + locker = self._readlock() + # special case where a parent process holds the lock -- this + # is different from the pid being different because we do + # want the unlock and postrelease functions to be called, + # but the lockfile to not be removed. + if locker == self.parentlock: + self._parentheld = True + self.held = 1 + return + locker = self._testlock(locker) if locker is not None: raise error.LockHeld(errno.EAGAIN, self.vfs.join(self.f), self.desc,