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

login
register
mail settings
Submitter phabricator
Date March 10, 2020, 8:48 p.m.
Message ID <acd8ba1290fa54f176709ded831ab939@localhost.localdomain>
Download mbox | patch
Permalink /patch/45680/
State Not Applicable
Headers show

Comments

phabricator - March 10, 2020, 8:48 p.m.
Closed by commit rHG3265c92f7d13: nodemap: deal with the &quot;debugupdatecache&quot; case using a &quot;fake&quot; transaction (authored by marmoute).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8186?vs=20389&id=20676

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8186/new/

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
@@ -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