diff mercurial/localrepo.py @ 26251:5c0f5db65c6b

localrepo: refresh filecache stats only if transaction finished successfully If commit is aborted by pretxncommit hook, in-memory changelog and manifest have entries that would be added. So they must be discarded on invalidate(). But the mechanism introduced by a710936c3037 doesn't handle this case well. It tries to mitigate the penalty of invalidate() by marking in-memory cache as "clean" on unlock assuming that they are identical to the stored data. But this assumption is wrong if stored data are rolled back by tr.abort(). This patch moves the hook to post-close action so that it will never be triggered on abort. This bug was originally reported to thg, which is only reproducible in command-server process on unix, evolve disabled. https://bitbucket.org/tortoisehg/thg/issues/4285/
author Yuya Nishihara <yuya@tcha.org>
date Tue, 15 Sep 2015 00:32:39 +0900
parents bc1f8a79b4e4
children 3ac7acb99b04
line wrap: on
line diff
--- a/mercurial/localrepo.py	Tue Sep 15 21:00:28 2015 +0900
+++ b/mercurial/localrepo.py	Tue Sep 15 00:32:39 2015 +0900
@@ -1021,6 +1021,9 @@
             reporef().hook('txnabort', throw=False, txnname=desc,
                            **tr2.hookargs)
         tr.addabort('txnabort-hook', txnaborthook)
+        # avoid eager cache invalidation. in-memory data should be identical
+        # to stored data if transaction has no error.
+        tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats)
         self._transref = weakref.ref(tr)
         return tr
 
@@ -1198,7 +1201,7 @@
         self.invalidate()
         self.invalidatedirstate()
 
-    def _refreshfilecachestats(self):
+    def _refreshfilecachestats(self, tr):
         """Reload stats of cached files so that they are flagged as valid"""
         for k, ce in self._filecache.items():
             if k == 'dirstate' or k not in self.__dict__:
@@ -1247,7 +1250,7 @@
             l.lock()
             return l
 
-        l = self._lock(self.svfs, "lock", wait, self._refreshfilecachestats,
+        l = self._lock(self.svfs, "lock", wait, None,
                        self.invalidate, _('repository %s') % self.origroot)
         self._lockref = weakref.ref(l)
         return l