Patchwork [6,of,7,main-line-of-work] transaction: pass the transaction to 'postclose' callback

login
register
mail settings
Submitter Pierre-Yves David
Date Nov. 11, 2014, 5:35 p.m.
Message ID <106e3ceedd34762e8355.1415727313@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6681/
State Accepted
Commit 6c1351352b6c7d90dcb280f03ed73af7186f080f
Headers show

Comments

Pierre-Yves David - Nov. 11, 2014, 5:35 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1415464515 0
#      Sat Nov 08 16:35:15 2014 +0000
# Node ID 106e3ceedd34762e8355a8b85d250992e654bd55
# Parent  76544974a3959aeeff65b0c21888b75e7a1e2db0
transaction: pass the transaction to 'postclose' callback

This mirror the API for 'pending' and 'finalize' callback. I do not have
immediate usage planned for it, but I'm sure some callback will be happy to
access transaction related data.

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -814,11 +814,11 @@  def addchangegroup(repo, source, srctype
                             "%s incoming changes - new heads: %s\n",
                             len(added),
                             ', '.join([hex(c[:6]) for c in newheads]))
 
             tr.addpostclose('changegroup-runhooks-%020i' % clstart,
-                            lambda: repo._afterlock(runhooks))
+                            lambda tr: repo._afterlock(runhooks))
 
         tr.close()
 
     finally:
         tr.release()
diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -859,11 +859,11 @@  class pulloperation(object):
                       **self._tr.hookargs)
             hookargs = dict(self._tr.hookargs)
             def runhooks():
                 repo.hook('b2x-transactionclose', **hookargs)
             self._tr.addpostclose('b2x-hook-transactionclose',
-                                  lambda: repo._afterlock(runhooks))
+                                  lambda tr: repo._afterlock(runhooks))
             self._tr.close()
 
     def releasetransaction(self):
         """release transaction if created"""
         if self._tr is not None:
@@ -1284,11 +1284,11 @@  def unbundle(repo, cg, heads, source, ur
                           **tr.hookargs)
                 hookargs = dict(tr.hookargs)
                 def runhooks():
                     repo.hook('b2x-transactionclose', **hookargs)
                 tr.addpostclose('b2x-hook-transactionclose',
-                                lambda: repo._afterlock(runhooks))
+                                lambda tr: repo._afterlock(runhooks))
                 tr.close()
             except Exception, exc:
                 exc.duringunbundle2 = True
                 raise
         else:
diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -313,10 +313,12 @@  class transaction(object):
 
     @active
     def addpostclose(self, category, callback):
         """add a callback to be called after the transaction is closed
 
+        The transaction will be given as callback first argument.
+
         Category is a unique identifier to allow overwriting an old callback
         with a newer callback.
         """
         self._postclosecallback[category] = callback
 
@@ -348,11 +350,11 @@  class transaction(object):
         self._backupentries = []
         self.journal = None
         # run post close action
         categories = sorted(self._postclosecallback)
         for cat in categories:
-            self._postclosecallback[cat]()
+            self._postclosecallback[cat](self)
 
     @active
     def abort(self):
         '''abort the transaction (generally called on error, or when the
         transaction is not explicitly committed before going out of