# HG changeset patch # User Pierre-Yves David # Date 1429177009 14400 # Node ID 7d0421de8de3188d85e58cf7fe10a5b90daad179 # Parent 89c5881d692caec161bd5f6d387d3a943d0eacbe hooks: add a 'txnabort' hook This hook will be called whenever a transaction is aborted. This will make it easy for people to clean up temporary content they may have created during a transaction. diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt --- a/mercurial/help/config.txt +++ b/mercurial/help/config.txt @@ -833,6 +833,10 @@ after the lock is released. see ``pretxnclose`` docs for details about available variables. +``txnabort`` + Run when a transaction is aborted. see ``pretxnclose`` docs for details about + available variables. + ``pretxnchangegroup`` Run after a changegroup has been added via push, pull or unbundle, but before the transaction has been committed. Changegroup is diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -975,6 +975,12 @@ **tr2.hookargs) reporef()._afterlock(hook) tr.addfinalize('txnclose-hook', txnclosehook) + def txnaborthook(tr2): + """To be run if transaction is aborted + """ + reporef().hook('txnabort', throw=False, txnname=desc, + **tr2.hookargs) + tr.addabort('txnabort-hook', txnaborthook) self._transref = weakref.ref(tr) return tr diff --git a/tests/test-hook.t b/tests/test-hook.t --- a/tests/test-hook.t +++ b/tests/test-hook.t @@ -15,6 +15,7 @@ > pretxnopen = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" pretxnopen" > pretxnclose = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" pretxnclose" > txnclose = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" txnclose" + > txnabort = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" txnabort" > EOF $ echo a > a $ hg add a @@ -161,6 +162,7 @@ 5:6f611f8018c1 pretxncommit.forbid hook: HG_NODE=6f611f8018c10e827fee6bd2bc807f937e761567 HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PENDING=$TESTTMP/a transaction abort! + txnabort hook: HG_TXNID=TXN:* HG_TXNNAME=commit (glob) rollback completed abort: pretxncommit.forbid1 hook exited with status 1 [255]