Mercurial > public > mercurial-scm > hg
comparison mercurial/revlogutils/nodemap.py @ 44497: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 | 283fd803afa5 |
children | 6c906eaedd0d |
comparison
equal
deleted
inserted
replaced
44496:897f0ce4b484 | 44497:3265c92f7d13 |
---|---|
71 if revlog.nodemap_file is None: | 71 if revlog.nodemap_file is None: |
72 return # we do not use persistent_nodemap on this revlog | 72 return # we do not use persistent_nodemap on this revlog |
73 callback_id = b"revlog-persistent-nodemap-%s" % revlog.nodemap_file | 73 callback_id = b"revlog-persistent-nodemap-%s" % revlog.nodemap_file |
74 if tr.hasfinalize(callback_id): | 74 if tr.hasfinalize(callback_id): |
75 return # no need to register again | 75 return # no need to register again |
76 tr.addfinalize( | 76 tr.addfinalize(callback_id, lambda tr: _persist_nodemap(tr, revlog)) |
77 callback_id, lambda tr: _persist_nodemap(tr.addpostclose, revlog) | 77 |
78 ) | 78 |
79 class _NoTransaction(object): | |
80 """transaction like object to update the nodemap outside a transaction | |
81 """ | |
82 | |
83 def __init__(self): | |
84 self._postclose = {} | |
85 | |
86 def addpostclose(self, callback_id, callback_func): | |
87 self._postclose[callback_id] = callback_func | |
79 | 88 |
80 | 89 |
81 def update_persistent_nodemap(revlog): | 90 def update_persistent_nodemap(revlog): |
82 """update the persistent nodemap right now | 91 """update the persistent nodemap right now |
83 | 92 |
84 To be used for updating the nodemap on disk outside of a normal transaction | 93 To be used for updating the nodemap on disk outside of a normal transaction |
85 setup (eg, `debugupdatecache`). | 94 setup (eg, `debugupdatecache`). |
86 """ | 95 """ |
87 cleanups = [] | 96 notr = _NoTransaction() |
88 _persist_nodemap((lambda x, y: cleanups.append(y)), revlog) | 97 _persist_nodemap(notr, revlog) |
89 for c in cleanups: | 98 for k in sorted(notr._postclose): |
90 c(None) | 99 notr._postclose[k](None) |
91 | 100 |
92 | 101 |
93 def _persist_nodemap(cleaner, revlog): | 102 def _persist_nodemap(tr, revlog): |
94 """Write nodemap data on disk for a given revlog | 103 """Write nodemap data on disk for a given revlog |
95 """ | 104 """ |
96 if getattr(revlog, 'filteredrevs', ()): | 105 if getattr(revlog, 'filteredrevs', ()): |
97 raise error.ProgrammingError( | 106 raise error.ProgrammingError( |
98 "cannot persist nodemap of a filtered changelog" | 107 "cannot persist nodemap of a filtered changelog" |
175 def cleanup(tr): | 184 def cleanup(tr): |
176 for oldfile in olds: | 185 for oldfile in olds: |
177 realvfs.tryunlink(oldfile) | 186 realvfs.tryunlink(oldfile) |
178 | 187 |
179 callback_id = b"revlog-cleanup-nodemap-%s" % revlog.nodemap_file | 188 callback_id = b"revlog-cleanup-nodemap-%s" % revlog.nodemap_file |
180 cleaner(callback_id, cleanup) | 189 tr.addpostclose(callback_id, cleanup) |
181 | 190 |
182 | 191 |
183 ### Nodemap docket file | 192 ### Nodemap docket file |
184 # | 193 # |
185 # The nodemap data are stored on disk using 2 files: | 194 # The nodemap data are stored on disk using 2 files: |