hooks: provide access to transaction changes for internal hooks
authorJoerg Sonnenberger <joerg@bec.de>
Fri, 01 May 2020 01:32:08 +0200
changeset 44835 09da5cf44772
parent 44834 be6401a25726
child 44836 63edfea7dfde
hooks: provide access to transaction changes for internal hooks External hooks are skipped here as the environment often has a size limit in the low MBs and that can easily be reached by larger transactions. Differential Revision: https://phab.mercurial-scm.org/D8490
mercurial/hook.py
mercurial/localrepo.py
tests/test-hook.t
--- a/mercurial/hook.py	Thu May 07 23:54:37 2020 +0200
+++ b/mercurial/hook.py	Fri May 01 01:32:08 2020 +0200
@@ -158,6 +158,10 @@
     env[b'HG_HOOKNAME'] = name
 
     for k, v in pycompat.iteritems(args):
+        # transaction changes can accumulate MBs of data, so skip it
+        # for external hooks
+        if k == b'changes':
+            continue
         if callable(v):
             v = v()
         if isinstance(v, (dict, list)):
--- a/mercurial/localrepo.py	Thu May 07 23:54:37 2020 +0200
+++ b/mercurial/localrepo.py	Fri May 01 01:32:08 2020 +0200
@@ -2243,6 +2243,7 @@
 
         tr.hookargs[b'txnid'] = txnid
         tr.hookargs[b'txnname'] = desc
+        tr.hookargs[b'changes'] = tr.changes
         # note: writing the fncache only during finalize mean that the file is
         # outdated when running hooks. As fncache is used for streaming clone,
         # this is not expected to break anything that happen during the hooks.
--- a/tests/test-hook.t	Thu May 07 23:54:37 2020 +0200
+++ b/tests/test-hook.t	Fri May 01 01:32:08 2020 +0200
@@ -443,7 +443,7 @@
   HG_PENDING=$TESTTMP/a
   
   transaction abort!
-  txnabort Python hook: txnid,txnname
+  txnabort Python hook: changes,txnid,txnname
   txnabort hook: HG_HOOKNAME=txnabort.1
   HG_HOOKTYPE=txnabort
   HG_TXNID=TXN:$ID$