Patchwork [3,of,4] transaction: remove the redundant 'onclose' mechanism

login
register
mail settings
Submitter Pierre-Yves David
Date Dec. 9, 2014, 1:26 a.m.
Message ID <6187b0dbeaf5ce313b6d.1418088374@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/7025/
State Accepted
Commit 0ff6b65afeb05900065ecf4e8f75712d3e513be8
Headers show

Comments

Pierre-Yves David - Dec. 9, 2014, 1:26 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1417729901 28800
#      Thu Dec 04 13:51:41 2014 -0800
# Node ID 6187b0dbeaf5ce313b6dae85f1f01c3ec67e866f
# Parent  4e336e79c48b48dda748198dde5a66ecc56edd2a
transaction: remove the redundant 'onclose' mechanism

It is superseded by the 'addfinalize' function and all its user have been
migrated.

Patch

diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -82,20 +82,18 @@  def _playback(journal, report, opener, v
         # only pure backup file remains, it is sage to ignore any error
         pass
 
 class transaction(object):
     def __init__(self, report, opener, vfsmap, journal, after=None,
-                 createmode=None, onclose=None, onabort=None):
+                 createmode=None, onabort=None):
         """Begin a new transaction
 
         Begins a new transaction that allows rolling back writes in the event of
         an exception.
 
         * `after`: called after the transaction has been committed
         * `createmode`: the mode of the journal file that will be created
-        * `onclose`: called as the transaction is closing, but before it is
-        closed
         * `onabort`: called as the transaction is aborting, but before any files
         have been truncated
         """
         self.count = 1
         self.usages = 1
@@ -105,11 +103,10 @@  class transaction(object):
         # a map to access file in various {location -> vfs}
         vfsmap = vfsmap.copy()
         vfsmap[''] = opener  # set default value
         self._vfsmap = vfsmap
         self.after = after
-        self.onclose = onclose
         self.onabort = onabort
         self.entries = []
         self.map = {}
         self.journal = journal
         self._queue = []
@@ -373,12 +370,10 @@  class transaction(object):
         if self.count == 1:
             self._generatefiles()
             categories = sorted(self._finalizecallback)
             for cat in categories:
                 self._finalizecallback[cat](self)
-            if self.onclose is not None:
-                self.onclose()
 
         self.count -= 1
         if self.count != 0:
             return
         self.file.close()
diff --git a/tests/test-fncache.t b/tests/test-fncache.t
--- a/tests/test-fncache.t
+++ b/tests/test-fncache.t
@@ -239,26 +239,26 @@  Aborting transaction prevents fncache ch
 
 Aborted transactions can be recovered later
 
   $ cat > ../exceptionext.py <<EOF
   > import os
-  > from mercurial import commands, util, transaction
+  > from mercurial import commands, util, transaction, localrepo
   > from mercurial.extensions import wrapfunction
   > 
-  > def closewrapper(orig, self, *args, **kwargs):
-  >     origonclose = self.onclose
-  >     def onclose():
-  >         origonclose()
+  > def trwrapper(orig, self, *args, **kwargs):
+  >     tr = orig(self, *args, **kwargs)
+  >     def fail(tr):
   >         raise util.Abort("forced transaction failure")
-  >     self.onclose = onclose
-  >     return orig(self, *args, **kwargs)
+  >     # zzz prefix to ensure it sorted after store.write
+  >     tr.addfinalize('zzz-forcefails', fail)
+  >     return tr
   > 
   > def abortwrapper(orig, self, *args, **kwargs):
   >     raise util.Abort("forced transaction failure")
   > 
   > def uisetup(ui):
-  >     wrapfunction(transaction.transaction, 'close', closewrapper)
+  >     wrapfunction(localrepo.localrepository, 'transaction', trwrapper)
   >     wrapfunction(transaction.transaction, '_abort', abortwrapper)
   > 
   > cmdtable = {}
   > 
   > EOF