diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -912,6 +912,15 @@ class localrepository(repo.repository): acquirefn() return l + def _postrelease(self, callback): + """add a callback to the current repository lock. + + The callback will be executed on lock release.""" + l = self._lockref and self._lockref() + assert l is not None + assert l.held + l.postreleasehooks.append(callback) + def lock(self, wait=True): '''Lock the repository store (.hg/store) and return a weak reference to the lock. Use this before modifying the store (e.g. committing or diff --git a/mercurial/lock.py b/mercurial/lock.py --- a/mercurial/lock.py +++ b/mercurial/lock.py @@ -35,6 +35,7 @@ class lock(object): self.timeout = timeout self.releasefn = releasefn self.desc = desc + self.postreleasehooks = [] self.lock() def __del__(self): @@ -119,6 +120,10 @@ class lock(object): return locker def release(self): + """release the lock and execute callback function if any + + If the lock have been aquired multiple time, the actual release is + delayed to the last relase call.""" if self.held > 1: self.held -= 1 elif self.held == 1: @@ -129,6 +134,8 @@ class lock(object): util.unlink(self.f) except OSError: pass + for callback in self.postreleasehooks: + callback() def release(*locks): for lock in locks: