[Updated] D12125: transaction: do not rely on a global variable to post_finalize file
marmoute (Pierre-Yves David)
phabricator at mercurial-scm.org
Thu Feb 3 16:52:32 UTC 2022
Closed by commit rHG21ac6aedd5e5: transaction: do not rely on a global variable to post_finalize file (authored by marmoute).
This revision was automatically updated to reflect the committed changes.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D12125?vs=32021&id=32043
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D12125/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D12125
AFFECTED FILES
mercurial/bookmarks.py
mercurial/dirstate.py
mercurial/transaction.py
tests/testlib/crash_transaction_late.py
CHANGE DETAILS
diff --git a/tests/testlib/crash_transaction_late.py b/tests/testlib/crash_transaction_late.py
--- a/tests/testlib/crash_transaction_late.py
+++ b/tests/testlib/crash_transaction_late.py
@@ -9,7 +9,6 @@
from mercurial import (
error,
- transaction,
)
@@ -18,14 +17,15 @@
def reposetup(ui, repo):
-
- transaction.postfinalizegenerators.add(b'late-abort')
-
class LateAbortRepo(repo.__class__):
def transaction(self, *args, **kwargs):
tr = super(LateAbortRepo, self).transaction(*args, **kwargs)
tr.addfilegenerator(
- b'late-abort', [b'late-abort'], abort, order=9999999
+ b'late-abort',
+ [b'late-abort'],
+ abort,
+ order=9999999,
+ post_finalize=True,
)
return tr
diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -25,16 +25,6 @@
version = 2
-# These are the file generators that should only be executed after the
-# finalizers are done, since they rely on the output of the finalizers (like
-# the changelog having been written).
-postfinalizegenerators = {
- b'bookmarks',
- b'dirstate-0-key-pre',
- b'dirstate-1-main',
- b'dirstate-2-key-post',
-}
-
GEN_GROUP_ALL = b'all'
GEN_GROUP_PRE_FINALIZE = b'prefinalize'
GEN_GROUP_POST_FINALIZE = b'postfinalize'
@@ -339,7 +329,13 @@
@active
def addfilegenerator(
- self, genid, filenames, genfunc, order=0, location=b''
+ self,
+ genid,
+ filenames,
+ genfunc,
+ order=0,
+ location=b'',
+ post_finalize=False,
):
"""add a function to generates some files at transaction commit
@@ -362,10 +358,14 @@
The `location` arguments may be used to indicate the files are located
outside of the the standard directory for transaction. It should match
one of the key of the `transaction.vfsmap` dictionary.
+
+ The `post_finalize` argument can be set to `True` for file generation
+ that must be run after the transaction has been finalized.
"""
# For now, we are unable to do proper backup and restore of custom vfs
# but for bookmarks that are handled outside this mechanism.
- self._filegenerators[genid] = (order, filenames, genfunc, location)
+ entry = (order, filenames, genfunc, location, post_finalize)
+ self._filegenerators[genid] = entry
@active
def removefilegenerator(self, genid):
@@ -385,13 +385,12 @@
for id, entry in sorted(pycompat.iteritems(self._filegenerators)):
any = True
- order, filenames, genfunc, location = entry
+ order, filenames, genfunc, location, post_finalize = entry
# for generation at closing, check if it's before or after finalize
- is_post = id in postfinalizegenerators
- if skip_post and is_post:
+ if skip_post and post_finalize:
continue
- elif skip_pre and not is_post:
+ elif skip_pre and not post_finalize:
continue
vfs = self._vfsmap[location]
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -730,12 +730,14 @@
(self._filename_tk,),
lambda f: self._write_tracked_key(tr, f),
location=b'plain',
+ post_finalize=True,
)
tr.addfilegenerator(
b'dirstate-1-main',
(self._filename,),
lambda f: self._writedirstate(tr, f),
location=b'plain',
+ post_finalize=True,
)
if write_key:
tr.addfilegenerator(
@@ -743,6 +745,7 @@
(self._filename_tk,),
lambda f: self._write_tracked_key(tr, f),
location=b'plain',
+ post_finalize=True,
)
return
@@ -1425,6 +1428,7 @@
(self._filename,),
lambda f: self._writedirstate(tr, f),
location=b'plain',
+ post_finalize=True,
)
# ensure that pending file written above is unlinked at
diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -212,7 +212,11 @@
The transaction is then responsible for updating the file content."""
location = b'' if bookmarksinstore(self._repo) else b'plain'
tr.addfilegenerator(
- b'bookmarks', (b'bookmarks',), self._write, location=location
+ b'bookmarks',
+ (b'bookmarks',),
+ self._write,
+ location=location,
+ post_finalize=True,
)
tr.hookargs[b'bookmark_moved'] = b'1'
To: marmoute, #hg-reviewers, Alphare
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20220203/ff80b37c/attachment-0002.html>
More information about the Mercurial-patches
mailing list