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

login
register
mail settings
Submitter phabricator
Date March 11, 2020, 1:35 a.m.
Message ID <7a95fe0bfcde54ba7b2c22a7529c7c1f@localhost.localdomain>
Download mbox | patch
Permalink /patch/45685/
State Not Applicable
Headers show

Comments

phabricator - March 11, 2020, 1:35 a.m.
marmoute added a comment.
marmoute updated this revision to Diff 20683.


  rebase above latest default up to landed-D8182

REPOSITORY
  rHG Mercurial

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

BRANCH
  default

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