Patchwork D8186: nodemap: deal with the "debugupdatecache" case using a "fake" transaction

login
register
mail settings
Submitter phabricator
Date Feb. 28, 2020, 6:54 p.m.
Message ID <differential-rev-PHID-DREV-qk2iafidictbknzoz23w-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/45394/
State Superseded
Headers show

Comments

phabricator - Feb. 28, 2020, 6:54 p.m.
marmoute created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8186

AFFECTED FILES
  mercurial/revlogutils/nodemap.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/revlogutils/nodemap.py b/mercurial/revlogutils/nodemap.py
--- a/mercurial/revlogutils/nodemap.py
+++ b/mercurial/revlogutils/nodemap.py
@@ -75,9 +75,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):
@@ -86,13 +95,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', ()):
@@ -180,7 +189,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