changeset 44509:3265c92f7d13

nodemap: deal with the "debugupdatecache" case using a "fake" transaction We are going to need more and more methods of the transaction. So lets change approach. The `hg debugupdatecache` case do not need a transaction, because has the repositories locked, but is not adding any "store" data to it. Differential Revision: https://phab.mercurial-scm.org/D8186
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 27 Feb 2020 22:34:45 +0100
parents 897f0ce4b484
children aa0e1341457b
files mercurial/revlogutils/nodemap.py
diffstat 1 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlogutils/nodemap.py	Fri Feb 28 01:45:03 2020 +0100
+++ b/mercurial/revlogutils/nodemap.py	Thu Feb 27 22:34:45 2020 +0100
@@ -73,9 +73,18 @@
     callback_id = b"revlog-persistent-nodemap-%s" % revlog.nodemap_file
     if tr.hasfinalize(callback_id):
         return  # no need to register again
-    tr.addfinalize(
-        callback_id, lambda tr: _persist_nodemap(tr.addpostclose, revlog)
-    )
+    tr.addfinalize(callback_id, lambda tr: _persist_nodemap(tr, revlog))
+
+
+class _NoTransaction(object):
+    """transaction like object to update the nodemap outside a transaction
+    """
+
+    def __init__(self):
+        self._postclose = {}
+
+    def addpostclose(self, callback_id, callback_func):
+        self._postclose[callback_id] = callback_func
 
 
 def update_persistent_nodemap(revlog):
@@ -84,13 +93,13 @@
     To be used for updating the nodemap on disk outside of a normal transaction
     setup (eg, `debugupdatecache`).
     """
-    cleanups = []
-    _persist_nodemap((lambda x, y: cleanups.append(y)), revlog)
-    for c in cleanups:
-        c(None)
+    notr = _NoTransaction()
+    _persist_nodemap(notr, revlog)
+    for k in sorted(notr._postclose):
+        notr._postclose[k](None)
 
 
-def _persist_nodemap(cleaner, revlog):
+def _persist_nodemap(tr, revlog):
     """Write nodemap data on disk for a given revlog
     """
     if getattr(revlog, 'filteredrevs', ()):
@@ -177,7 +186,7 @@
                 realvfs.tryunlink(oldfile)
 
         callback_id = b"revlog-cleanup-nodemap-%s" % revlog.nodemap_file
-        cleaner(callback_id, cleanup)
+        tr.addpostclose(callback_id, cleanup)
 
 
 ### Nodemap docket file