Patchwork [1,of,4] fncache: drop dedicated 'onclose' function in favor of 'tr.addfinalize'

login
register
mail settings
Submitter Pierre-Yves David
Date Dec. 9, 2014, 1:26 a.m.
Message ID <46c541236d6aa784fe3d.1418088372@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/7022/
State Superseded
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 1417729785 28800
#      Thu Dec 04 13:49:45 2014 -0800
# Node ID 46c541236d6aa784fe3d863589b9eec1ff9c644b
# Parent  c237499a7fba65c88a2da721a22b66df4f39cf4e
fncache: drop dedicated 'onclose' function in favor of  'tr.addfinalize'

Now that we have a shiny generic mechanism, we can use it.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -881,22 +881,19 @@  class localrepository(object):
         if self.svfs.exists("journal"):
             raise error.RepoError(
                 _("abandoned transaction found"),
                 hint=_("run 'hg recover' to clean up transaction"))
 
-        def onclose():
-            self.store.write(self._transref())
-
         self._writejournal(desc)
         renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()]
         rp = report and report or self.ui.warn
         vfsmap = {'plain': self.opener} # root of .hg/
         tr = transaction.transaction(rp, self.sopener, vfsmap,
                                      "journal",
                                      aftertrans(renames),
-                                     self.store.createmode,
-                                     onclose)
+                                     self.store.createmode)
+        tr.addfinalize('repo.store.write', self.store.write)
         self._transref = weakref.ref(tr)
         return tr
 
     def _journalfiles(self):
         return ((self.svfs, 'journal'),
diff --git a/tests/test-fncache.t b/tests/test-fncache.t
--- a/tests/test-fncache.t
+++ b/tests/test-fncache.t
@@ -208,23 +208,23 @@  Aborting lock does not prevent fncache w
 
 Aborting transaction prevents fncache change
 
   $ cat > ../exceptionext.py <<EOF
   > import os
-  > from mercurial import commands, util, transaction
+  > from mercurial import commands, util, localrepo
   > from mercurial.extensions import wrapfunction
   > 
   > def wrapper(orig, self, *args, **kwargs):
-  >     origonclose = self.onclose
-  >     def onclose():
-  >         origonclose()
+  >     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 uisetup(ui):
-  >     wrapfunction(transaction.transaction, 'close', wrapper)
+  >     wrapfunction(localrepo.localrepository, 'transaction', wrapper)
   > 
   > cmdtable = {}
   > 
   > EOF
   $ rm -f "${extpath}c"