Mercurial > public > mercurial-scm > hg-stable
diff mercurial/localrepo.py @ 24282:db8679812f84
hook: add a generic hook after transaction has been closed
We are adding generic hooking for all transactions. We may have useful
information about what happened during the transaction, user of the transaction
should have filled the 'hookargs' dictionnary of the transaction. This hook is
simple because it has no power to rollback the transaction.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Mon, 09 Mar 2015 22:36:56 -0700 |
parents | e9ede9b4c2f8 |
children | ff14b26fe5f4 |
line wrap: on
line diff
--- a/mercurial/localrepo.py Wed Dec 10 18:19:49 2014 -0800 +++ b/mercurial/localrepo.py Mon Mar 09 22:36:56 2015 -0700 @@ -924,6 +924,16 @@ # outdated when running hooks. As fncache is used for streaming clone, # this is not expected to break anything that happen during the hooks. tr.addfinalize('flush-fncache', self.store.write) + # we must avoid cyclic reference between repo and transaction. + reporef = weakref.ref(self) + def txnclosehook(tr2): + """To be run if transaction is successful, will schedule a hook run + """ + def hook(): + reporef().hook('txnclose', throw=False, txnname=desc, + **tr2.hookargs) + reporef()._afterlock(hook) + tr.addfinalize('txnclose-hook', txnclosehook) self._transref = weakref.ref(tr) return tr